FHIR query syntax: Note to self…

Just a short post to point out a ‘quirk’ in the FHIR syntax for querying so I can look it up again when I forget. (actually, it’s not really a quirk at all – it’s perfectly reasonable, though can be confusing).

It all came about when Josh pointed out an error in my post on retrieving documentReference resources from an server.

We were discussing how you could retrieve a filtered list of documentReference resources for a patient over a period of time, and used the example:

GET  http://registryserver/DocumentReference?subject=100&period >=2013-01-01

However, as Josh pointed out – and as the spec indicates, you need an ‘=’ symbol in there to bind the HTTP parameter ‘period‘ to the value ‘>= 2013-01-01‘ which is what the FHIR server is going to query on. Thus the correct syntax is:

GET  http://registryserver/DocumentReference?subject=100&period= >=2013-01-01

Now, if I had only tested the query out on one of the reference servers before I posted it, I would have avoided the error, but there you go…

About David Hay
I'm an independent contractor working with a number of Organizations in the health IT space. I'm an HL7 Fellow, Chair Emeritus of HL7 New Zealand and a co-chair of the FHIR Management Group. I have a keen interest in health IT, especially health interoperability with HL7 and the FHIR standard. I'm the author of a FHIR training and design tool - clinFHIR - which is sponsored by InterSystems Ltd.

8 Responses to FHIR query syntax: Note to self…

  1. Hi David.
    I have a number of Observation resources for a patient’s serial vital signs measurements (9 of them) each with pulse, bp, temperature data etc.
    What syntax can I use to query the repository to return me all diastolic blood pressure readings only, for example?

    The following query gives me a bundle of all Observation instances, including the vital signs:
    GET http://localhost:8080/baseDstu2/Observation?_format=xml

    The diastolic blood pressure concept is located at:
    Observation.component.code

    And the value is located at:
    Observation.component.value

    How do I query the repository to return me all the diastolic blood pressure readings only (across the 9 Observation resource instances) and their values?

    Thanks.

    • David Hay says:

      Hi Eneimi,

      If you have a look at the search parameters in the spec (http://hl7.org/fhir/observation.html#search ) you can see that there is a search parameter – component-code – that allows a search on Observation.component.code, so that should be what you need. cheers!

      • Thanks. I’m only just figuring out what those parameters do. Still have lots to learn!
        However this returns the entire resource instance that contains that component.code. Is there anyway to return results that ‘detach’ the component in question from the rest of the resource and only give me say ‘pulse rate’ values from a vital signs Observation instance? Sort of deconstructing a resource and giving me only a certain data element?

      • David Hay says:

        Hi Eneimi – no, the smallest ‘quantum’ you can retrieve (or update) currently is the resource. Note that there is a ‘summary’ option (check out the summary – http://hl7.org/fhir/search.html#summary) which can reduce the size a bit…

  2. Noted. Thanks for that.

  3. Lloyd McKenzie says:

    It is also possible to identify the specific elements you want returned, though not all servers will support that. See the _elements parameter.

    • Eneimi says:

      Many thanks. Yeah, I eventually stumbled on that option and realized it would only return ‘first order’ elements but not deeper. I realized to get the output I was looking for, I had to take apart the vital signs concept as an Observation resource and individually commit pulse, temperature, BP etc to separate Observation resources. Then the _elements parameter worked perfect for me.
      Thanks again.

      • David Hay says:

        yeah – separate observations is generally best as it’s easier to query them. Though some would argue that systolic and diastolic Blood Pressure are usually a pair so can be components in a single observation…

Leave a Reply

%d bloggers like this: