In FHIR we do this by building a query of chained search parameters from Encounter to Patient. What does this look like?
A patient, “Oliver James Smith,” calls up his clinic and asks about an appointment he had last week. The receptionist looks up his name in the system but nothing comes back.
She tries again, this time searching under recent appointments for the surname “Smith” and comes back with a single result for “Oliver J Smith”.
The appointment was for the correct day and the patient’s date of birth matches. She answers Oliver James’s questions.
If this were SQL, the query would look something like this:
select * from Patient, Encounter
where Patient.id = Encounter.subject.resource and Patient.name = 'smith'
order by Encounter.meta.lastUpdated desc
In FHIR we build a query that goes from Encounter to Patient via the Encounter’s subject resource reference. It looks like this:
/Encounter/
?subject.name=smith
&_include=Encounter:subject
&_sort=-_lastUpdated
In plain English this says: give me all the Encounters and associated Patients where the Encounter subject (the Patient) has the name “smith”, and sort the results in descending order by recently updated.
Here’s the query for real: https://hapi.fhir.org/baseR4/Encounter/?subject.name=smith&_include=Encounter:subject&_sort=-_lastUpdated
If you come from an SQL background, FHIR queries can appear verbose and difficult to understand. Break them down parameter by parameter, and the complexity disappears.
More about chained parameters: https://hl7.org/fhir/R4/search.html#chaining
---
Sign up to “The Tuesday FHIR Sessions” and receive an email every Tuesday where I go deep on a single FHIR topic.