A clinic wants to pull up a list of patients who had the flu vaccine last week

How do we do that in FHIR?

The FHIR query we need to build uses what’s called ‘reverse chaining’. This is where you search for a target resource (Patient) referenced from another resource (Immunization).

We also add some search parameters to run against Immunization.

Reverse chaining is the area of FHIR search that causes the most problems for new developers. It looks unintuitive — almost backwards.

But once you get the hang of the syntax, it’s easy enough to use.

The CVX code for the flu vaccine is 140.

The query has three parts:

  1. /Patient/?
  2. _has:Immunization:patient:vaccine-code=http://hl7.org/fhir/sid/cvx|140&
  3. _has:Immunization:patient:date=gt2023-06-08

First, give me Patients.

Second, give me only Patients referenced from the ‘patient’ element of the Immunization resource, where the vaccine-code is the flu vaccine.

Finally, of those patients, only give me ones where the flu vaccine was administered after June 8th, 2023.

Here’s a working query using some data I added yesterday to the HAPI server:


It should return a single patient, Becky Sharp.

Again, the syntax surrounding the _has search modifier above looks wrong and causes a lot of scratched heads amongst new developers. But it’s here to stay.

More about reverse chaining: https://build.fhir.org/search.html#has



Sign up to “The Tuesday FHIR Sessions” and receive an email every Tuesday where I go deep on a single FHIR topic.