GraphQL retrieve latest ServiceRequests
# support
j
I want to take the most recent 20 service requests by occurrence time. Currently we're using either
occurrenceDateTime
or
occurrencePeriod
. Is there any way to do this via a GraphQL list, when there are two fields?
r
Hi Jason, when searching in graphQL, you can use the same saerch parameters as with the REST Search API. See our docs here https://www.medplum.com/docs/graphql/basic-queries#how-to-fhir-perform-searches-with-graphql
Looking at ServiceRequest (https://www.medplum.com/docs/api/fhir/resources/servicerequest#search-parameters), I see that
occurence
is a search parameter
For sorting, you can use a special search parameter called
_sort
. So sorting (descending) by the
occurence
parameter would look something like:
Copy code
{
  ServiceRequestList(_sort:"-occurence") {
    id
    occurrenceDateTime
  }
}
Hi @jasonwa.ng - I just wanted to check in to see if this solution worked for you. We also have a new guide out about sort (https://www.medplum.com/docs/search/basic-search#sorting-the-results)
bumping this @jasonwa.ng
j
this is great, thank you!
we used
occurrence
(I was not aware you could just specify
occurrence
rather than
occurrenceDateTime
and
occurrencePeriod
how does
occurrence
sort? is it by period start / end vs. date time?
there's a few more subtle questions like that that I think are interesting, but I believe that the problem is resolved on our side
r
Good question. So as a reminder, searches use search parameters (https://www.medplum.com/docs/search/basic-search#search-parameters), technically not field names. It an be confusing, because often times search parameters match field names. Looking at ServiceRequest, the searchParamter
occurence
maps to either type of
occurence[x]
https://www.medplum.com/docs/api/fhir/resources/servicerequest#search-parameters
With regards to sort, i believe it sorts on period.start, then period.end
169 Views