cqframework / vscode-cql

VS Code Clinical Quality Language Extension
Apache License 2.0
8 stars 5 forks source link

MedicationNotRequested Throwing Error When Evaluated #14

Closed JSRankins closed 1 year ago

JSRankins commented 2 years ago

The following CQL throws an error when executed...

`library HFBetaBlockerTherapyforLVSDQICore4 version '1.0.000'

using QICore version '4.1.1'

//refer to FHIRHelpers at https://github.com/cqframework/ecqm-content-qicore-2022/tree/master/input/cql include FHIRHelpers version '4.0.012' called FHIRHelpers

valueset "Beta Blocker Therapy for LVSD": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1184' valueset "Medical Reason": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1007' valueset "Patient Reason": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1008'

parameter "Measurement Period" default Interval[@2022-01-01, @2022-12-31]

exists ( ["MedicationNotRequested": "Beta Blocker Therapy for LVSD"] NoBetaBlockerOrdered //for AHA."Heart Failure Outpatient Encounter with History of Moderate or Severe LVSD" refer to https://github.com/JSRankins/ecqm-content-qicore-2022/blob/master/input/cql/AHAOverallQICore4.cql with AHA."Heart Failure Outpatient Encounter with History of Moderate or Severe LVSD" ModerateOrSevereLVSDHFOutpatientEncounter such that NoBetaBlockerOrdered.authoredOn during ModerateOrSevereLVSDHFOutpatientEncounter.period where ( NoBetaBlockerOrdered.reasonCode in "Medical Reason" or NoBetaBlockerOrdered.reasonCode in "Patient Reason") )`

This is the error stack: The following errors were encountered during evaluation: org.opencds.cqf.cql.engine.exception.CqlException: Could not resolve call to operator 'ToConcept(java.util.List)' in library 'FHIRHelpers'. at org.opencds.cqf.cql.engine.execution.Context.resolveFunctionRef(Context.java:606) at org.opencds.cqf.cql.engine.elm.execution.FunctionRefEvaluator.internalEvaluate(FunctionRefEvaluator.java:23) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.elm.execution.InValueSetEvaluator.internalEvaluate(InValueSetEvaluator.java:65) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.elm.execution.OrEvaluator.internalEvaluate(OrEvaluator.java:43) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.elm.execution.QueryEvaluator.evaluateWhere(QueryEvaluator.java:75) at org.opencds.cqf.cql.engine.elm.execution.QueryEvaluator.internalEvaluate(QueryEvaluator.java:198) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.elm.execution.ExistsEvaluator.internalEvaluate(ExistsEvaluator.java:28) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.elm.execution.ExpressionDefEvaluator.internalEvaluate(ExpressionDefEvaluator.java:19) at org.opencds.cqf.cql.engine.elm.execution.Executable.evaluate(Executable.java:18) at org.opencds.cqf.cql.engine.execution.CqlEngine.evaluateExpressions(CqlEngine.java:186) at org.opencds.cqf.cql.engine.execution.CqlEngine.evaluate(CqlEngine.java:164) at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:89) at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:76) at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:163) at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:34) at picocli.CommandLine.executeUserObject(CommandLine.java:1953) at picocli.CommandLine.access$1300(CommandLine.java:145) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352) at picocli.CommandLine$RunLast.handle(CommandLine.java:2346) at picocli.CommandLine$RunLast.handle(CommandLine.java:2311) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179) at picocli.CommandLine.execute(CommandLine.java:2078) at org.opencds.cqf.cql.evaluator.cli.Main.run(Main.java:19) at org.opencds.cqf.cql.ls.DebugCqlCommandContribution.executeCql(DebugCqlCommandContribution.java:37) at org.opencds.cqf.cql.ls.DebugCqlCommandContribution.executeCommand(DebugCqlCommandContribution.java:65) at org.opencds.cqf.cql.ls.service.CqlWorkspaceService.executeCommandFromContributions(CqlWorkspaceService.java:173) at org.opencds.cqf.cql.ls.service.CqlWorkspaceService.executeCommand(CqlWorkspaceService.java:121) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65) at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120) at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261) at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190) at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194) at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94) at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)

This is the test case bundle: { "resourceType": "Bundle", "id": "tests-denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-bundle", "type": "transaction", "entry": [ { "resource": { "resourceType": "Encounter", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-6", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter" ] }, "status": "finished", "class": { "code": "AMB", "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode", "display": "ambulatory" }, "type": [ { "coding": [ { "code": "99201", "system": "http://www.ama-assn.org/go/cpt", "display": "Office or other outpatient visit for the evaluation and management of a new patient, which requires these 3 key components: A problem focused history; A problem focused examination; Straightforward medical decision making. Counseling and/or coordination of care with other physicians, other qualified health care professionals, or agencies are provided consistent with the nature of the problem(s) and the patient's and/or family's needs. Usually, the presenting problem(s) are self limited or minor. Typically, 10 minutes are spent face-to-face with the patient and/or family." } ] } ], "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" }, "period": { "start": "2021-03-02T10:00:00.000Z", "end": "2021-03-02T10:30:00.000Z" } }, "request": { "method": "PUT", "url": "Encounter/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-6" } }, { "resource": { "resourceType": "Encounter", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-1", "status": "finished", "class": { "code": "AMB", "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode", "display": "ambulatory" }, "type": [ { "coding": [ { "code": "99201", "system": "http://www.ama-assn.org/go/cpt", "display": "Office or other outpatient visit for the evaluation and management of a new patient, which requires these 3 key components: A problem focused history; A problem focused examination; Straightforward medical decision making. Counseling and/or coordination of care with other physicians, other qualified health care professionals, or agencies are provided consistent with the nature of the problem(s) and the patient's and/or family's needs. Usually, the presenting problem(s) are self limited or minor. Typically, 10 minutes are spent face-to-face with the patient and/or family." } ] } ], "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" }, "period": { "start": "2022-01-02T10:00:00.000Z", "end": "2022-01-02T10:30:00.000Z" } }, "request": { "method": "PUT", "url": "Encounter/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-1" } }, { "resource": { "resourceType": "Encounter", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-2", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter" ] }, "status": "finished", "class": { "code": "AMB", "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode", "display": "ambulatory" }, "type": [ { "coding": [ { "code": "99201", "system": "http://www.ama-assn.org/go/cpt", "display": "Office or other outpatient visit for the evaluation and management of a new patient, which requires these 3 key components: A problem focused history; A problem focused examination; Straightforward medical decision making. Counseling and/or coordination of care with other physicians, other qualified health care professionals, or agencies are provided consistent with the nature of the problem(s) and the patient's and/or family's needs. Usually, the presenting problem(s) are self limited or minor. Typically, 10 minutes are spent face-to-face with the patient and/or family." } ] } ], "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" }, "period": { "start": "2022-03-02T10:00:00.000Z", "end": "2022-03-02T10:30:00.000Z" } }, "request": { "method": "PUT", "url": "Encounter/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-2" } }, { "resource": { "resourceType": "Condition", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-3", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition" ] }, "clinicalStatus" : { "coding" : [ { "system" : "http://terminology.hl7.org/CodeSystem/condition-clinical", "code" : "active" } ] }, "verificationStatus" : { "coding" : [ { "system" : "http://terminology.hl7.org/CodeSystem/condition-ver-status", "code" : "confirmed" } ] }, "category" : [ { "coding" : [ { "system" : "http://terminology.hl7.org/CodeSystem/condition-category", "code" : "encounter-diagnosis", "display" : "Encounter Diagnosis" } ] } ], "severity" : { "coding" : [ { "system" : "http://snomed.info/sct", "code" : "24484000", "display" : "Severe (severity modifier)" } ] }, "code": { "coding": [ { "code": "I11.0", "system": "http://hl7.org/fhir/sid/icd-10-cm", "display": "Hypertensive heart disease with heart failure" } ] }, "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" }, "onsetDateTime": "2020-11-01" }, "request": { "method": "PUT", "url": "Condition/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-3" } }, { "resource": { "resourceType": "Observation", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-4", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-observation" ] }, "status": "final", "category": [ { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "imaging", "display": "Imaging" } ] } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "10230-1", "display": "Left ventricular Ejection fraction" } ] }, "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" }, "effectiveDateTime": "2020-11-01T10:30:00.000Z", "issued": "2020-11-01T10:30:00.000Z", "valueQuantity": { "value": 55.0, "unit": "%", "system": "http://unitsofmeasure.org", "code": "%" }, "interpretation": [ { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation", "code": "N", "display": "Normal" } ], "text": "Normal" } ] }, "request": { "method": "PUT", "url": "Observation/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-4" } }, { "resource": { "resourceType": "MedicationRequest", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-5", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest" ] }, "status": "active", "intent": "order", "medicationCodeableConcept": { "coding": [ { "system": "http://www.nlm.nih.gov/research/umls/rxnorm", "code": "860516", "display": "24 HR carvedilol phosphate 20 MG Extended Release Oral Capsule" } ] }, "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4", "display": "Betty Dunn" }, "encounter": { "reference": "Encounter/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-6", "display": "encounter who leads to this prescription" }, "authoredOn": "2021-03-02T10:15:00.000Z", "note": [ { "text": "Patient told to take with food" } ], "dosageInstruction": [ { "sequence": 1, "text": "One tablet daily for 10 days starting on March 3, 2022", "additionalInstruction": [ { "coding": [ { "system": "http://snomed.info/sct", "code": "769557005", "display": "With meals" } ] } ], "timing": { "repeat": { "boundsPeriod": { "start": "2021-03-03", "end": "2021-03-12" }, "frequency": 1, "period": 1, "periodUnit": "d" } }, "route": { "coding": [ { "system": "http://snomed.info/sct", "code": "26643006", "display": "Oral Route" } ] }, "method": { "coding": [ { "system": "http://snomed.info/sct", "code": "421521009", "display": "Swallow - dosing instruction imperative (qualifier value)" } ] }, "doseAndRate": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/dose-rate-type", "code": "ordered", "display": "Ordered" } ] }, "doseQuantity": { "value": 1, "unit": "TAB", "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" } } ] }, { "sequence": 2, "text": "If tolerated, take 2 pills once a day starting March 13, 2022 for 10 days", "additionalInstruction": [ { "coding": [ { "system": "http://snomed.info/sct", "code": "769557005", "display": "With meals" } ] } ], "timing": { "repeat": { "boundsPeriod": { "start": "2021-03-13", "end": "2021-03-22" }, "frequency": 1, "period": 1, "periodUnit": "d" } }, "route": { "coding": [ { "system": "http://snomed.info/sct", "code": "26643006", "display": "Oral Route" } ] }, "doseAndRate": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/dose-rate-type", "code": "ordered", "display": "Ordered" } ] }, "doseQuantity": { "value": 2, "unit": "TAB", "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" } } ] }, { "sequence": 3, "text": "If tolerated, take 4 pills once a day from thereon starting March 23, 2022. At end, re-evaluate.", "additionalInstruction": [ { "coding": [ { "system": "http://snomed.info/sct", "code": "769557005", "display": "With meals" } ] } ], "timing": { "repeat": { "boundsPeriod": { "start": "2021-03-23", "end": "2021-04-02" }, "frequency": 1, "period": 1, "periodUnit": "d" } }, "route": { "coding": [ { "system": "http://snomed.info/sct", "code": "26643006", "display": "Oral Route" } ] }, "doseAndRate": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/dose-rate-type", "code": "ordered", "display": "Ordered" } ] }, "doseQuantity": { "value": 4, "unit": "TAB", "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" } } ] } ], "dispenseRequest": { "validityPeriod": { "start": "2021-03-02", "end": "2022-03-02" }, "numberOfRepeatsAllowed": 0, "quantity": { "value": 70, "unit": "TAB", "system": "http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm", "code": "TAB" }, "expectedSupplyDuration": { "value": 30, "unit": "days", "system": "http://unitsofmeasure.org", "code": "d" } }, "substitution": { "allowedBoolean": true, "reason": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v3-ActReason", "code": "FP", "display": "formulary policy" } ] } } }, "request": { "method": "PUT", "url": "MedicationRequest/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-5" } }, { "resource": { "resourceType": "MedicationRequest", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-7", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest" ] }, "status": "completed", "intent": "order", "category" : [ { "coding" : [ { "system" : "http://terminology.hl7.org/CodeSystem/medicationrequest-category", "code" : "community" } ] } ], "doNotPerform" : true, "medicationCodeableConcept": { "extension" : [ { "url" : "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-notDoneValueSet", "valueCanonical" : "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1184" } ], "text" : "Not Done Value Set: Beta Blocker Therapy for LVSD" }, "subject": { "reference": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4", "display": "Betty Dunn" }, "encounter": { "reference": "Encounter/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-2", "display": "encounter that leads to this medical reason documentation for not continuing beta blocker" }, "authoredOn": "2022-01-02T10:00:00.000Z", "note": [ { "text": "Patient has medical reason for not taking beta blocker - treatment not tolerated" } ], "reasonCode" : [ { "coding" : [ { "system": "http://snomed.info/sct", "code": "407563006", "display": "Treatment not tolerated (situation)" } ] } ] }, "request": { "method": "PUT", "url": "MedicationRequest/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4-7" } }, { "resource": { "resourceType": "Patient", "id": "denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-patient" ] }, "extension": [ { "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race", "extension": [ { "url": "ombCategory", "valueCoding": { "code": "2028-9", "system": "urn:oid:2.16.840.1.113883.6.238", "display": "Asian" } }, { "url": "text", "valueString": "Asian" } ] }, { "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity", "extension": [ { "url": "ombCategory", "valueCoding": { "code": "2135-2", "system": "urn:oid:2.16.840.1.113883.6.238", "display": "Hispanic or Latino" } }, { "url": "text", "valueString": "Hispanic or Latino" } ] } ], "identifier": [ { "use": "usual", "type": { "coding": [ { "code": "MR", "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "display": "Medical Record Number" } ] }, "system": "http://hospital.smarthealthit.org", "value": "685945948" } ], "name": [ { "family": "Dunn", "given": [ "Betty" ] } ], "gender": "female", "birthDate": "1978-01-01" }, "request": { "method": "PUT", "url": "Patient/denexcep-pos-HFBetaBlockerTherapyforLVSDQICore4" } } ] }

JSRankins commented 2 years ago

If it helps, in looking at model info file for MedicationNotRequested, there appears to be no primary code path. Unfortunately, pulling out the value set in the retrieve statement and into part of the where clause, I get the same error. That is,

exists ( ["MedicationNotRequested"] NoBetaBlockerOrdered with AHA."Heart Failure Outpatient Encounter with History of Moderate or Severe LVSD" ModerateOrSevereLVSDHFOutpatientEncounter such that NoBetaBlockerOrdered.authoredOn during ModerateOrSevereLVSDHFOutpatientEncounter.period where NoBetaBlockerOrdered.medication in "Beta Blocker Therapy for LVSD" and ( NoBetaBlockerOrdered.reasonCode in "Medical Reason" or NoBetaBlockerOrdered.reasonCode in "Patient Reason") )

gets the same error. Thoughts?

brynrhodes commented 1 year ago

Fixed in 0.4.0

JSRankins commented 1 year ago

Hi @brynrhodes. I'll take a look tomorrow and get back to you.