Stream: cql
Topic: Reducing results from 2 different FHIR resources
Michael Riley (Apr 08 2021 at 16:24):
I'm trying to build a cql definition in a patient context using the FHIR library that
- Retreives a set of immunization resources
- Retrieves a set of procedure resources
- Finds the most recent index from both sets
The problem is that since I'm comparing to , I need to either merge the lists together then find the most recent of the immunizations AND procedures, or I could instead find the most recent procedure and immunization, extract the datetime from each and then find the most recent from that list.
I'm trying to define my indexes as such:
context Patient
define "CovidImmunization": [Immunization: "Covid Vaccine Drug Exposure"]
define "CovidProcedure": [Procedure: "Covid Vaccine Drug Exposure"]
define "LastCovidInstanceDT":
Patient P
let IDT: MostRecentImmunizationDT("CovidImmunization"),
PDT: MostRecentProcedureDT("CovidProcedure")
if IDT after PDT
then
IDT
else
PDT
With the retrievals referencing appropriate concept sets or valuesets, ofc.
And my functions for retrieving the most recent occurrences are
define function MostRecentImmunizationDT(ImmunizationList List<FHIR.Immunization>):
from ImmunizationList I
let result: Last(ImmunizationList I sort by (occurrence as FHIR.dateTime).value)
return result.occurrence.value
define function MostRecentProcedureDT(ProcedureList List<FHIR.Procedure>):
from ProcedureList P
let result:Last(ProcedureList P sort by (performed as FHIR.dateTime).value)
return result.performed.value
I'm having 3 problems here.
1) As you can see, I'm trying to use the let statement for inscope definitions to prevent having to call the defined functions more than once, but I'm having a hard time getting the syntax of let to play nicely with the if conditional in the main definition should I forgo the let statement and make my main definition a top-level conditional?
2), In my return statements, I can't seem to reuse the cast as statement within my return clauses, so the return statement is confused on the typing of the function return. Should I define another variable that merely captures the datetime I need and return that variable?
3) This really only handles the case where the type is a FHIR.dateTime, sometimes they are also FHIR.Periods which we would transform into Intervals.
If there's anyway to reduce the query to a single list, that would be an interesting problem as well.
Last updated: Apr 12 2022 at 19:14 UTC