Stream: cql
Topic: Dealing w/ matching medication[x] against value sets
Chris Moesel (Apr 30 2018 at 20:13):
I'm writing some CQL that needs to match MedicationOrder
against a value set of possible medications. The tricky bit is that the medication code might be buried in a reference to a Medication
resource (rather than inlined in the MedicationOrder
). Here's what I came up with for FHIR DSTU2-based CQL, but I'm curious if anyone has come up w/ anything better:
[MedicationOrder] O where O.medicationCodeableConcept in "My Med VS" or exists( [Medication: "My Med VS"] M where EndsWith(O.medicationReference.reference.value, 'Medication/' + M.id.value) )
(I do realize that I could also use Match
w/ a regex instead of EndsWith
, but I'm looking for other approaches that might be more performant or easy to read.) I don't love this solution because it would be inefficient without optimization (since it pulls all the patient's MedicationOrder
s and all the Medication
s represented by the value set -- which could be hundreds).
Christopher Schuler (Apr 30 2018 at 22:58):
@Chris Moesel I am shooting from the hip but would this work?
[MedicationOrder: code in "My Med VS] union [MedicationOrder: medication in "My Med VS"]
Chris Moesel (May 01 2018 at 00:00):
Thanks for the reply @Christopher Schuler. I don't think that would work, as neither code
nor medication
are valid properties for MedicationOrder
in the FHIR 1.0.2 data model. You're definitely right that it could be expressed as a union though:
[MedicationOrder: "My Med VS"] union [MedicationOrder] O where exists ( [Medication: "My Med VS"] M where EndsWith(O.medicationReference.reference.value, 'Medication/' + M.id.value) )
I'm not sure if that's better or not. It may be a matter of preference?
Christopher Schuler (May 01 2018 at 00:08):
@Chris Moesel "code" and "medication" are search parameters defined in the FHIR spec (http://hl7.org/fhir/DSTU2/medicationorder.html#search). They should resolve correctly when building a URL to fetch the resource (e.g. {base}/MedicationOrder?code:in="My Med VS"). I am not sure how you're fetching resources though...
Christopher Schuler (May 01 2018 at 00:30):
The following is an example url of fetching orders by code:
http://fhirtest.uhn.ca/baseDstu2/MedicationOrder?code=http://www.nlm.nih.gov/research/umls/rxnorm|313782
Chris Moesel (May 01 2018 at 01:10):
@Christopher Schuler - Thanks for the clarification. I understand that code
and medication
are search parameters in FHIR, but they're not defined properties in the FHIR 1.0.2 model-info file that CQL uses (see here). That being the case, I don't think I can use them in CQL retrieves or queries (unless I defined my own custom model-info, but I'd rather stick to the published one).
Christopher Schuler (May 01 2018 at 01:32):
Hmm. I guess I am not explaining this well. Perhaps an example would help illustrate what I am trying to say. I have an environment that executes STU3 code, but the following concept should work for the DSTU2 model as well. Navigate to http://cql-runner.dataphoria.org. Paste the following CQL:
library Example version '1.0' using FHIR version '3.0.0' valueset "Benzo": 'benzodiazepines' context Patient // note that code is not a valid STU3 MedicationRequest property define BenzoMedication: [MedicationRequest: code in "Benzo"]
Select the config button and input example-rec-11-benzo-trigger-with-opioid as the patientId and press OK.
Select the Run button.
You should see a MedicationRequest in the results for the BenzoMedication expression.
Hopefully that shows that what I am suggesting is valid CQL with the published data model.
Chris Moesel (May 01 2018 at 01:48):
Wow. That's really interesting. I understand what you're getting at now and why we have a disconnect.
Are you sure cql-runner is using the published (on GitHub) FHIR 3.0.0 model-info file? I can't get your CQL to compile using the cql-to-elm
on GitHub's clinical_quality_language
master branch:
clinical-quality-language (master) $ cd Src/java/cql-to-elm/ cql-to-elm (master) $ gradle installDist > Task :cql-to-elm:compileJava Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. BUILD SUCCESSFUL in 3s 23 actionable tasks: 5 executed, 18 up-to-date cql-to-elm (master) $ vi Example.cql cql-to-elm (master) $ build/install/cql-to-elm/bin/cql-to-elm --input ./Example.cql ================================================================================ TRANSLATE ./Example.cql Translation completed with messages: Warning:[11:3, 11:38] Could not resolve code path code for the type of the retrieve FHIR.MedicationRequest. Warning:[11:3, 11:38] Could not resolve membership operator for terminology target of the retrieve. ELM output written to: ./Example.xml cql-to-elm (master) $
Christopher Schuler (May 01 2018 at 02:21):
Huh. That's weird. That project uses the cql-to-elm translator (v1.2.18) and I am not using a custom FHIR model-info. I am getting the same errors using the translator from the command line. Maybe the different versions are causing an issue? Dang... I'll have to investigate that.
Christopher Schuler (May 01 2018 at 03:15):
But if I remove "code" so it is [MedicationRequest: "Benzo"]
, then I get the following error:
Warning:[10:3, 10:30] Could not resolve code path medicationCodeableConcept for the type of the retrieve FHIR.MedicationRequest.
Chris Moesel (May 01 2018 at 13:11):
Ah. I think there is a bug in the model-info. I see that the primaryCodePath
is set to medicationCodeableConcept
, but when Bryn introduced the ChoiceType support, he changed the medicationCodeableConcept
property to medication
(with a choice) -- but did not update the primaryCodePath
. I think that must be what's going on there.
Last updated: Apr 12 2022 at 19:14 UTC