Search code examples
hl7-fhir

How to collect all records of the resource encounter that patients have the resource CarePlan with the status of active?


How to collect all records of the resource encounter that patients have the resource CarePlan with the status of active?

In this scenario, we have 3 resources involved, Pacient, CarePlan and Encounter.

So, in the request to the server, the objective is to obtain only the encounter data and any other data from another resource is prohibited.


Solution

  • Short answer - you can't - at least not with the standard search parameters. However, if you can live with getting back the Patient resource along with their encounters, you could do this:

    [base]/Patient?_has:CarePlan:patient:status=active&_revinclude=CarePlan:patient

    That will page through Patient and for each patient who has at least one active CarePlan will return the Patient and all associated encounters.

    Note that "all encounters" is generally not going to be that desirable - some patients may have hundreds or thousands going back decades. So you might be best running it as a 2-step query - first find the patient ids, then find the encounters for those patients - filtering further to only include the encounters actually of interest.