Stream: cql
Topic: Evaluating multiple patients at once
Richard Stanley (Jul 30 2021 at 19:54):
I have a use case where there's a main Patient resource, and links in it (link.other.reference) pointing to other Patient resources that are all the same person but come from different EHRs. To properly evaluate with CQL, I need to traverse multiple Patient resources. Can CQL evaluate more than one Patient in a run, or is this a job for unfiltered context, or some other approach or simple not possible?
JP (Jul 30 2021 at 20:06):
The context
value defines the Patient, Encounter, etc. that the CQL is written with respect to. For example:
context Patient
define "Encounters":
[Encounter]
returns the Encounters for a single patient. If you run Patient
context CQL for a single patient, you get one result with values for one Patient.
On the other hand,
context Unfiltered
define "Encounters":
[Encounter]
returns all the Encounters that are available. If you run Unfiltered
for multiple patients you get one result with values for multiple Patients.
You can both run Patient
context CQL for multiple patients (in which case you get multiple per-patient results) and run Unfiltered
context CQL for a single patient (in which case you get one result with values for one patient)
JP (Jul 30 2021 at 20:07):
Whoops. Posted before I was ready. Editing...
JP (Jul 30 2021 at 20:11):
To run Patient
context CQL in a Measure against multiple patients with the cqf-ruler, for example, you do this:
{server base}/Measure/{Id}/$evaluate-measure?periodStart=2019-01&periodEnd=2019-12
Note the lack of subject
parameter. That basically means run the Measure against all the Patients on this server.
JP (Jul 30 2021 at 20:15):
All of that said, neither of those handles the case where a logically identical Patient from a separate EHR should be considered as the same Patient. I think there would typically be some record-linking process prior to CQL evaluation that would consolidate those resources.
You could, in principle, write some CQL that would look up the related Patient from the EHR. I think that'd be something like:
include FHIRHelpers version '4.0.1'
using FHIR version '4.0.1'
context Patient
define "Related Patients":
"Get Related Patients"(Patient.id)
context Unfiltered
define function "Get Related Patients"(id String):
[Patient] P where P.whatever = id
JP (Jul 30 2021 at 20:19):
Obviously you'd have to substitute the logic appropriate for your specific use case to do the look-up of additional patients.
Richard Stanley (Jul 30 2021 at 22:38):
Ok, great thanks. The main Patient resource is actually from a service that already did record linkage. That 'golden record' has the links to the Patients from the EHRs in the same datastore. I'll try the last bit to see how far I get.
Last updated: Apr 12 2022 at 19:14 UTC