Stream: implementers
Topic: Query a FHIR Server for multiple resources at once
Håkan MacLean (Nov 15 2021 at 14:36):
Let's say you have a FHIR Server with lots of data about a patient (i.e. different types of FHIR Resources) and then you want to create a UI that shows a "patient timeline".
What would be the preferred way for the UI to interact with the FHIR Server? Should one do one query per resource type? Or is there some other mechanism whereby someone can do one single but more complex query (FHIR Path?) and get a FHIR Bundle back with all the data needed for the timeline?
David Pyke (Nov 15 2021 at 14:39):
It depends on what you want to show in your timeline. the $everything operation will fetch every resource about that subject but that may not be what you want. It may be better to fetch all Encounters or all Conditions or another individual Resource and build it from there. It all depends on how you want to orient the timeline.
Håkan MacLean (Nov 15 2021 at 14:42):
Yeah I would assume the caller has some preferences on what data it wants to fetch, like only certain types of Resources or only Observations where code
comes from a pre-defined set of values.
David Pyke (Nov 15 2021 at 14:47):
The you do a fetch for Condition or Encounter where patient/subject is X or all Observations where code is X and patient is Y and then do _includes as necessary
Gino Canessa (Nov 15 2021 at 15:50):
If the data is consistent, I would suggest a batch query to get all the results together. You can also use chaining / including to do more complex queries, but it may be faster to do multiple 'simple' requests instead of trying to do a single 'complex' one.
I'm working on an updated pass of the search page now, but it's a ways off yet. The areas you'll want to look at are:
- reference and Chained Parameters have info about chaining (search criteria crossing resource boundaries, in the 'forward' direction - e.g., Encounter has a link to Patient, so search Encounter with properties from a Patient).
- Reverse Chaining is the same, but 'backwards' across links (e.g., Encounter has a link to Patient, so search Patient with properties from an Encounter)
- Including other resources in result has information on returning additional resources via
_include
(forward links) and_revinvlude
(backwards links). Same concept as chaining, but instead of search criteria it adds the resources to the returned bundle.
For information about batching queries, the best place to start is the batch/transaction section of the http page. Essentially, it's a bundle that has several requests 'batched' together in a single request.
Normal disclaimer, the more 'advanced' you get in your requests, the less likely they will be implemented on a server (on average). You'll want to be able to fall back from complex requests (e.g., complicated reverse include / chaining) into something simpler if you go that route.
Shameless plug - I try to cover this in my FHIR Search series of videos.
Hope this helps!
Yunwei Wang (Nov 15 2021 at 15:56):
It is possible to use $everything operation Patient/123/$everything?_type=Condition,Observation
Håkan MacLean (Nov 16 2021 at 13:24):
Thank you @Gino Canessa , the info about batch queries was exactly the info I was looking for!
Last updated: Apr 12 2022 at 19:14 UTC