You can’t write complicated SQL queries in FHIR.
But search modifiers can extend the power of your queries. Here are four modifiers I use regularly.
1. :not
We’re used to searching for something that IS a specific value. But did you know that you could also search for something that is NOT a specific value?
Status is a good example. Let’s say we want to see all Procedures apart from those with a status of “entered-in-error.”
Here’s how that looks using the :not modifier:
http://hapi.fhir.org/baseR4/Procedure?status:not=entered-in-error
2. :missing
This allows us to filter results on whether or not a value exists. It’s one of the most useful search modifiers.
Example: Give me all Patients that have a family name but do not have a given name. Here, we get to use the :missing modifier twice:
http://hapi.fhir.org/baseR4/Patient?given:missing=true&family:missing=false
3. :exact
Human name searches are usually wildcard searches and case insensitive. The :exact modifier lets us force a precise match on a particular string, right down to the character case.
A good real world example is filtering names for middle initials, which often appear as given names.
http://hapi.fhir.org/baseR4/Patient?name:exact=Fred&given:exact=T
This returns a single result for Fred T Watts.
4. :contains
A sub-string search. Very useful when you know part of the string value but not the whole. An example might be a search for Devices with different model numbers, all of which begin with the same few characters.
First, using what we learned a minute ago, let’s find a Device resource where the Device.model is populated:
http://hapi.fhir.org/baseR4/Device?model:missing=false
A few pages into the results is a model of “SP-Model-001.”
Let’s assume that “SP-Model” is the prefix for a series of models we now want to find, but that the remainder of the string value might differ. The following query using the :contains modifier returns 5 matching resources.
http://hapi.fhir.org/baseR4/Device?model:contains=SP-Model
I can see a number of very specific use cases for :contains, particularly around less common and difficult to spell human names.
More about search modifiers: https://hl7.org/fhir/R4/search.html#modifiers
---