cqframework / cqf-ruler

FHIR Clinical Reasoning Module Server
Apache License 2.0
63 stars 49 forks source link

CQFRuler exceptions testing MAT measure bundles for connectathon. #268

Open cday-semanticbits opened 3 years ago

cday-semanticbits commented 3 years ago

We are testing out running mat measure bundles in MAT to prepare for the connectathon. I am using CMS104 exported from MAT and running it with the valuesets/patients used for a previous connectathon: https://github.com/DBCG/connectathon/tree/master/fhir401/bundles/measure/EXM104-8.2.000/EXM104-8.2.000-files

CQL:

library CMS104 version '0.0.011'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.001' called FHIRHelpers
include SupplementalDataElementsFHIR4 version '2.0.000' called SDE
include MATGlobalCommonFunctionsFHIR4 version '5.0.000' called Global
include TJCOverallFHIR4 version '5.0.000' called TJC

codesystem "LOINC": 'http://loinc.org'
codesystem "RequestIntent": 'http://terminology.hl7.org/CodeSystem/request-intent'

valueset "Antithrombotic Therapy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.201'
valueset "Comfort Measures": 'http://cts.nlm.nih.gov/fhir/ValueSet/1.3.6.1.4.1.33895.1.3.0.45'
valueset "Discharge To Acute Care Facility": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.87'
valueset "Discharged to Health Care Facility for Hospice Care": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.207'
valueset "Discharged to Home for Hospice Care": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.209'
valueset "Emergency Department Visit": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292'
valueset "Ethnicity": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.837'
valueset "Hemorrhagic Stroke": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.212'
valueset "Ischemic Stroke": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.247'
valueset "Left Against Medical Advice": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.308'
valueset "Medical Reason": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.473'
valueset "Non-Elective Inpatient Encounter": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.424'
valueset "Observation Services": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.143'
valueset "ONC Administrative Sex": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1'
valueset "Patient Expired": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.309'
valueset "Patient Refusal": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.93'
valueset "Payer": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591'
valueset "Race": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.836'
valueset "Ticagrelor Therapy": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.39'

code "Birth date": '21112-8' from "LOINC" display 'Birth date'
code "Order": 'order' from "RequestIntent" display 'Order'

parameter "Measurement Period" Interval<DateTime>default Interval[@2019-01-01T00:00:00.0, @2020-01-01T00:00:00.0 )

context Patient

define "SDE Ethnicity":
  SDE."SDE Ethnicity"

define "SDE Payer":
  SDE."SDE Payer"

define "SDE Race":
  SDE."SDE Race"

define "SDE Sex":
  SDE."SDE Sex"

define "Initial Population":
  TJC."Encounter with Principal Diagnosis and Age"

define "Denominator":
  TJC."Ischemic Stroke Encounter"

define "Denominator Exclusion":
  TJC."Ischemic Stroke Encounters with Discharge Disposition"
      union TJC."Comfort Measures during Hospitalization"

define "Numerator":
  TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
      with "Antithrombotic Therapy at Discharge" DischargeAntithrombotic
        such that DischargeAntithrombotic.authoredOn during Global."Normalize Interval" ( IschemicStrokeEncounter.period )

define "Antithrombotic Therapy at Discharge":
  ["MedicationRequest": medication in "Antithrombotic Therapy"] Antithrombotic
        //Note: expressed as an or with equivalence semantics pending resolution of potential CQL issue.
      where exists ( Antithrombotic.category C
          where FHIRHelpers.ToConcept ( C ) ~ Global."Community"
            or FHIRHelpers.ToConcept ( C ) ~ Global."Discharge"
      )
        and Antithrombotic.status in { 'active', 'completed' }
        and Antithrombotic.intent.value = 'order'

define "Denominator Exception":
  "Encounter With No Antithrombotic At Discharge"
      union "Encounter With Ticagrelor at Discharge"

define "Encounter With No Antithrombotic At Discharge":
  TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
      with "Antithrombotic Not Given at Discharge" NoDischargeAntithrombotic
        such that NoDischargeAntithrombotic.authoredOn during IschemicStrokeEncounter.period

define "Antithrombotic Not Given at Discharge":
  ["MedicationRequest": medication in "Antithrombotic Therapy"] NoAntithromboticDischarge
      where NoAntithromboticDischarge.doNotPerform is true
        and ( NoAntithromboticDischarge.reasonCode in "Medical Reason"
            or NoAntithromboticDischarge.reasonCode in "Patient Refusal"
        )
            //Note: expressed as an or with equivalence semantics pending resolution of potential CQL issue.
        and exists ( NoAntithromboticDischarge.category C
            where FHIRHelpers.ToConcept ( C ) ~ Global."Community"
              or FHIRHelpers.ToConcept ( C ) ~ Global."Discharge"
        )
        and NoAntithromboticDischarge.status = 'completed'
        and NoAntithromboticDischarge.intent = 'order'

define "Encounter With Ticagrelor at Discharge":
  TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
      with "Ticagrelor Therapy at Discharge" DischargeTicagrelor
        such that DischargeTicagrelor.authoredOn during IschemicStrokeEncounter.period

define "Ticagrelor Therapy at Discharge":
  ["MedicationRequest": medication in TJC."Ticagrelor Therapy"] Ticagrelor
          //Note: expressed as an or with equivalence semantics pending resolution of potential CQL issue.
      where exists ( Ticagrelor.category C
          where FHIRHelpers.ToConcept ( C ) ~ Global."Community"
            or FHIRHelpers.ToConcept ( C ) ~ Global."Discharge"
      )
        and Ticagrelor.status in { 'active', 'completed' }
        and Ticagrelor.intent = 'order'

`

I am getting this exception:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.base/java.lang.String.substring(String.java:1837)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.lambda$processAccumulators$6(MeasureEvaluation.java:635)
    at java.base/java.util.HashMap.forEach(HashMap.java:1336)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.lambda$processAccumulators$7(MeasureEvaluation.java:627)
    at java.base/java.util.HashMap.forEach(HashMap.java:1336)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.processAccumulators(MeasureEvaluation.java:626)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.evaluate(MeasureEvaluation.java:568)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.evaluatePopulationMeasure(MeasureEvaluation.java:113)
    at org.opencds.cqf.r4.evaluation.MeasureEvaluation.evaluatePatientMeasure(MeasureEvaluation.java:65)
    at org.opencds.cqf.r4.providers.MeasureOperationsProvider.evaluateMeasure(MeasureOperationsProvider.java:175)
    ... 39 common frames omitted

Debug view of that line: image

It looks like it doesn't like our define named 'SDE Sex' it wants 'sde-sex' for some reason. This is something we add to all measure cql in MAT.

We are also trying to get this working before Connectathon on Jan 13th.

UPDATE: When we changed to supplementals to sde-sex,sde-ethnicity, etc it works. I really think it should use these mappings in the bundle:

{
            "id": "69f2b4a3-6411-4aa5-82bb-1587a43e8366",
            "usage": [
              {
                "coding": [
                  {
                    "system": "http://terminology.hl7.org/CodeSystem/measure-data-usage",
                    "code": "supplemental-data"
                  }
                ]
              }
            ],
            "criteria": {
              "language": "text/cql.identifier",
              "expression": "SDE Payer"
            }
          },
          {
            "id": "48b08970-2523-457b-ae0d-3b7c5aabe166",
            "usage": [
              {
                "coding": [
                  {
                    "system": "http://terminology.hl7.org/CodeSystem/measure-data-usage",
                    "code": "supplemental-data"
                  }
                ]
              }
            ],
            "criteria": {
              "language": "text/cql.identifier",
              "expression": "SDE Race"
            }
          },
          {
            "id": "2a89f7fd-caa5-413e-959a-fc5497d1bc9c",
            "usage": [
              {
                "coding": [
                  {
                    "system": "http://terminology.hl7.org/CodeSystem/measure-data-usage",
                    "code": "supplemental-data"
                  }
                ]
              }
            ],
            "criteria": {
              "language": "text/cql.identifier",
              "expression": "SDE Sex"
            }
          }

Also here is a copy of the bundle we are using: measure-json-bundle.txt

brynrhodes commented 3 years ago

It should definitely work with the expressions as specified there, so I'm marking this as a bug and we'll take a look.