[CQLIT-420] Unexpected error during execution Created: 11/09/23  Updated: 12/05/23  Resolved: 12/05/23

Status: Resolved
Project: CQL Issue Tracker
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question/Guidance Priority: Moderate
Reporter: Jasmin C Smith (Inactive) Assignee: Peter Muir
Resolution: Done Votes: 0
Labels: MD_impact_tracking
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File CMS125FHIR.txt     PNG File image-2023-11-09-14-52-39-257.png     PNG File image-2023-11-16-16-47-25-635.png     PNG File image-2023-11-20-10-37-28-939.png    
Submitter Resolution Confirmed: Yes
Measure Model: QI-Core/CQL
2024 Performance Period EC eCQMs:
CMS0125v12
Tool: MADiE

 Description   

I imported my test cases, and some of them are giving the following error, as well as the entire test case bundle not running with the same error.

"The following error occurred in the cql-execution engine: Encountered unexpected error during execution. Error Message: Cannot read properties of undefined (reading 'filter') CQL Library: BreastCancerScreeningFHIR|0.0.001 Expression: FunctionRef ELM Local ID: 126 CQL Locator: 91:25-91:67"

 



 Comments   
Comment by Peter Muir [ 12/05/23 ]

Thank you for notifying of your success. Yes, FHIRHelpers is needed to assist with FHIR to CQL processes. Will flag as resolved.

Comment by Jasmin C Smith (Inactive) [ 12/05/23 ]

I was able to solve this issue via a solution for fixing exports in ticket BONNIEMAT-1687.

By adding FHIRHelpers to the measure, I was not only able to export the measure, but the original logic worked without throwing the engine errors, and all of my test cases passed! 

Comment by Dorothy Lee [ 12/04/23 ]

Hi Kim/Peter/Bryn, we may have found the resolution to resolve the execution error upon further investigation. We will circle back with update/findings soon, so the group can probably hold off on adding this to meeting agendas.

Comment by Kimberly Smuk [ 12/04/23 ]

Hi Peter and NCQA - do you think it would be helpful to discuss this on tomorrow's FHIR Collab or Thursdays eCQM WG meeting?

Comment by Jasmin C Smith (Inactive) [ 11/28/23 ]

Hi Peter! 

I just wanted to update you with our findings so far. I have tried a couple of different functions based on your suggestions, and I will include the code snippets below. However, when I call in the  bodySite aspect, highlighted in red, it continuously causes the same engine execution error. 

define fluent function isRbodySiteQualifier(condition Condition):
    exists (condition.bodySite C
        where C ~ "Right (qualifier value)"
        )

define "Right Mastectomy Diagnosis":
             ( [Condition: "Status Post Right Mastectomy"] RightMastectomyProcedure
                  union ( [Condition: "Unilateral Mastectomy, Unspecified Laterality"] UnilateralMastectomyDiagnosis
                    where UnilateralMastectomyDiagnosis.isRbodySiteQualifier()
                  ) ) RightMastectomy
                  where RightMastectomy.prevalenceInterval() starts on or before 
                  end of "Measurement Period"

 

define "Right Mastectomy Diagnosis":
             ( [Condition: "Status Post Right Mastectomy"] RightMastectomyProcedure
                  union ( [Condition: "Unilateral Mastectomy, Unspecified Laterality"] UnilateralMastectomyDiagnosis

     where exists (UnilateralMastectomyDiagnosis.bodySite C
                        where C ~ "Right (qualifier value)"
                    )
                  ) ) RightMastectomy
                  where RightMastectomy.prevalenceInterval() starts on or before 
                  end of "Measurement Period"

 

Comment by Peter Muir [ 11/22/23 ]

Hi Dorothy. I have asked Bryn to respond.
In the interim, as suspected, bodySite is returned as a list, which would require a retrieve for the comparison similar to the following fluent function from QICoreCommon:
/*
@description: Returns true if the given observation is an exam observation
*/
define fluent function isExam(observation Observation):
exists (observation.category C
where C ~ "exam"
)

Note that "exam" is expressed as a code.
// Observation Category Codes
...
code "exam": 'exam' from "ObservationCategoryCodes" display 'Exam'
...

It might be beneficial for bodySite funluent function to be added to Authoring Patterns and QICoreCommon?
Hope this helps

Comment by Dorothy Lee [ 11/22/23 ]

Thank you for flagging and sharing your priorities. Sharing our additional findings in the meantime: MADiE currently doesn’t support display of CQL return type (that is a pending resolution for BONNIEMAT-1426), but we did try out a different CQL expression and based on the error can deduce that bodySite is recognized as list<System.Concept> and the direct reference code as System.Code. The original CQL expression (System.Code in List<System.Concept>) did saved successfully so we would be curious to know how else this can be expressed.

Comment by Peter Muir [ 11/20/23 ]

ADDENDUM:
I have flagged this for Bryn's attention. I think the issue is not the tooling but the measure CQL logic expressions to constrain Diagnosis bodysite data element which is a Codeable Concept to LOINC Direct Reference Code.

The rationale for previous suggestion to test of commenting out constraints was to identify that as the issue, not the timing.
Your testing confirms that the issue is related to laterality specified in bodysite which is a coding (Codeable Concept).
Your measure CQL logic expression ( "Left (qualifier value)" in UnilateralMastectomyDiagnosis.bodySite ) is testing for bodysite as code "Left (qualifier value)": '7771000' from "SNOMEDCT" display 'Left (qualifier value)' but QICOre profiles define it as:

. bodySite SΣ 0..* CodeableConcept Target body sites
Binding: SNOMEDCTBodyStructures (preferred): Codes describing anatomical locations. May include laterality

Laterality defined as a Direct Reference Code rather than as a member of a value set can have impact.
Since MADiE now provides a display of return content, you could create a DISPLAY ONLY definition that just returns the laterality from the test case to visualize how to best design the constraint logic. Currently, my priority is to AUr1 plus some pertinent CQLIT tickets related to AUr1.

Suggested next steps would be to leave Diagnosis which involve laterality with the laterality constraint commented out. Restore commented out expressions from in if no laterality is specified.
Subsequently, create a definition clone as "DISPLAY ONLY Diagnosis with laterality" to return
just the Diagnosis.bodysite This may require a trigger to display. I suspect that you will find the laterality displayed as a Codeable Concept with LOINC system and code as in your test case json.

Will get to myself when AUr1 tasks completed.

Comment by Dorothy Lee [ 11/20/23 ]

Hi Peter, based on these lines that needed to be comment out (in order to resolve the cql-execution error), it seems like the issue could be related to Condition.bodySite since the other lines are common authoring patterns which have not caused cql-execution errors in other measures. A reminder that these CQL lines were able to be saved successfully, and the cql-execution error only occurs when running the test case. The current test cases are all valid in MADiE, and the test cases inclusive of Condition.bodySite seem to be constructed correctly (see snippet below), so the issue seems to reside somewhere else beyond CQL and test case, perhaps in the tooling.

{
  "resourceType": "Bundle",
  "id": "DENEXPass-UniMastDxRQualOnJan1OfMP",
  "type": "collection",
  "entry": [
    {
      "fullUrl": "https://madie.cms.gov/Patient/7e5d94fa-3630-43b6-9b6e-b75c0fba7cd0",
      "resource": {
        "resourceType": "Patient",
        "id": "7e5d94fa-3630-43b6-9b6e-b75c0fba7cd0",
        "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": [
          {
            "system": "http://hospital.smarthealthit.org",
            "value": "999999995"
          }
        ],
        "name": [
          {
            "family": "Bertha",
            "given": [
              "Betty"
            ]
          }
        ],
        "birthDate": "1973-12-31",
        "gender": "female"
      }
    },
    {
      "fullUrl": "https://madie.cms.gov/Encounter/Encounter-10",
      "resource": {
        "resourceType": "Encounter",
        "id": "Encounter-10",
        "meta": {
          "profile": [
            "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter"
          ]
        },
        "subject": {
          "reference": "Patient/7e5d94fa-3630-43b6-9b6e-b75c0fba7cd0"
        },
        "status": "finished",
        "class": {
          "code": "AMB",
          "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
          "display": "ambulatory"
        },
        "type": [
          {
            "coding": [
              {
                "code": "185463005",
                "system": "http://snomed.info/sct",
                "display": "Visit out of hours (procedure)"
              }
            ]
          }
        ],
        "period": {
          "start": "2025-01-01T00:00:00.000Z",
          "end": "2025-01-01T00:00:00.000Z"
        }
      }
    },
    {
      "fullUrl": "https://madie.cms.gov/Condition/Condition-10",
      "resource": {
        "resourceType": "Condition",
        "id": "Condition-10",
        "meta": {
          "profile": [
            "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition"
          ]
        },
        "category": [
          {
            "coding": [
              {
                "code": "problem-list-item",
                "system": "http://terminology.hl7.org/CodeSystem/condition-category",
                "display": "Problem List Item"
              }
            ]
          }
        ],
        "subject": {
          "reference": "Patient/7e5d94fa-3630-43b6-9b6e-b75c0fba7cd0"
        },
        "code": {
          "coding": [
            {
              "code": "248802009",
              "system": "http://snomed.info/sct",
              "display": "Absence of breast (finding)"
            }
          ]
        },
        "onsetDateTime": "2025-01-01T00:00:00.000Z",
        "clinicalStatus": {
          "coding": [
            {
              "code": "active",
              "system": "http://terminology.hl7.org/CodeSystem/condition-clinical"
            }
          ]
        },
        "bodySite": [
          {
            "coding": [
              {
                "code": "24028007",
                "system": "http://snomed.info/sct",
                "display": "Right (qualifier value)"
              }
            ]
          }
        ]
      }
    }
  ]
}
Comment by Jasmin C Smith (Inactive) [ 11/20/23 ]

CMS125FHIR.txtHi Peter! 

After some more troubleshooting, I have narrowed down the issue to all of the following lines of code that are commented out. It seems to be something with the timing aspect of these functions, though I am following the same pattern used throughout our measures. 

When these lines of code are commented out, I am able to at least run the test cases. However, with even one of them commented back in, the test cases will not run at all either as a collective, or individually, with the same ELM errors indicating that particular line of code. 

Comment by Peter Muir [ 11/16/23 ]

Is there any further detail or localization to the error message?

The following is incompletely commented out which can cause issues:
define "Right Mastectomy Procedure":
(([Procedure: "Unilateral Mastectomy Right"]).isProcedurePerformed()) UnilateralMastectomyRightPerformed
// where UnilateralMastectomyRightPerformed.performed.toInterval() ends on or before
// end of "Measurement Period"

Also, you need to also comment out any definitions that used the procedure definition since calling an unknown function would throw an error.

Recommend commenting out all procedure definitions and from calling definitions.
If things work then add total mastectomy back in.
I am suspicious that bodysite, which is a codeable concept may be an issue.

Will flag for Bryn's attention - you missed your opportunity on the CQM WG call.
PMuir eCQM Standards Team

Comment by Jasmin C Smith (Inactive) [ 11/16/23 ]

I found that I was getting errors for both UnilateralMastectomyLeftPerformed.performed and UnilateralMastectomyRightPerformed.performed. I commented both definitions using these functions out, and then came across this error now. 

 

Comment by Peter Muir [ 11/16/23 ]

CQLIT-420 Unexpected error during execution CMS0125 v12
ADDENDUM:
Tip: When troubleshooting an issue, the best approach is to clone the offending definition, comment out /* the original definition */ and then simplify the working definition by removing all but the simplest constraints and then add them back in one by one until the offending constraint is determined. Adding returns as tuples with detailed data elements often identifies issues that are hidden when only an Encounter or Procedure is returned (i.e. DISPLAY ONLY definitions).

re:
The following error occurred in the cql-execution engine: Encountered unexpected error during execution. Error Message: functionDefs is undefined CQL Library: BreastCancerScreeningFHIR|0.0.001 Expression: FunctionRef ELM Local ID: 126 CQL Locator: 91:25-91:67

library BreastCancerScreeningFHIR version '0.0.001' contains:
```
define "Left Mastectomy Procedure":
(([Procedure: "Unilateral Mastectomy Left"]).isProcedurePerformed()) UnilateralMastectomyLeftPerformed
where UnilateralMastectomyLeftPerformed.performed.toInterval() ends on or before
end of "Measurement Period"
```
CQL line 91 char 25-57 points to immediately after the 'where' indicating an issue with UnilateralMastectomyLeftPerformed

ELM localID="126" points to:
```
<a:s r="127">
<a:s>where </a:s>
<a:s r="126">
<a:s r="123">
<a:s r="122">
<a:s r="121">
<a:s>UnilateralMastectomyLeftPerformed</a:s>
</a:s>
<a:s>.</a:s>
<a:s r="122">
<a:s>performed</a:s>
</a:s>
</a:s>
<a:s>.</a:s>
<a:s r="123">
<a:s>toInterval()</a:s>
</a:s>
</a:s>
<a:s r="126"> ends on or before
</a:s>
```

library Status version '1.6.000' contains:
```
define fluent function isProcedurePerformed(Proc List<Procedure>):
Proc P
where P.status ~ 'completed'
```

First, could you please try removing the .isProcedurePerformed() function from the initial retrieve to remove that as a potential factor.
If the issue is resolved then try adding the following to the where clause:
```
and UnilateralMastectomyLeftPerformed.status = 'completed'
```

Note that USCore and QICore for Procedure profile only specify performedDateTime as must support.
https://hl7.org/fhir/us/qicore/StructureDefinition-qicore-procedure.html

If the issue persists, could you please try removing the .toInterval() function from the initial retrieve to remove that as a potential factor. 'performed' for timing may be a <choice type> issue.
Please provide an update on your progress with the above.
PMuir eCQM Standards Team

Comment by Jasmin C Smith (Inactive) [ 11/16/23 ]

I have recreated the json bundle, confirmed the test case in question was no longer invalid, as well as deleted the entire test case, and am still having the issue. 

Comment by Peter Muir [ 11/16/23 ]

I have reopened since suggested course of action does not appear to have resolved your issue.
As per my response, there was an issue with UnilateralMastectomyLeftPerformed.performed which corresponded to an error in the test case json. Did you correct or remove that test case and the issue continue? I could not test earlier this week due to MADiE access issues. Cannot proceed without further details.
PMuir eCQM Standards Team

Comment by Lisa Anderson (Inactive) [ 11/16/23 ]

jasmincimone  can you provide additional context and information for what is not working?

Comment by Peter Muir [ 11/10/23 ]

CQLIT-420 CMS0125 BreastCancerScreeningFHIR Unexpected error during execution 20231110

Question:
I imported my test cases, and some of them are giving the following error, as well as the entire test case bundle not running with the same error.

"The following error occurred in the cql-execution engine: Encountered unexpected error during execution. Error Message: Cannot read properties of undefined (reading 'filter') CQL Library: BreastCancerScreeningFHIR|0.0.001 Expression: FunctionRef ELM Local ID: 126 CQL Locator: 91:25-91:67"

Response:
Thank you for your question. It would assist the evaluation of new issues if reporter indicated any version changes or test case additions. This response is based upon the CQl and brief review of measure and test cases in MADiE plus measure ELM in VScode.

CQL Locator: 91:25-91:67" indicates that the issue relates to line 91, characters 25-67 which is UnilateralMastectomyLeftPerformed.performed in the cql file.

Using VScode, one can open the CQL file then right click within and select view the ELM representation, and then search for localId="126".
```
<operand localId="126" locator="91:25-91:67" name="ToValue" libraryName="FHIRHelpers" xsi:type="FunctionRef">
<resultTypeSpecifier xsi:type="ChoiceTypeSpecifier">
<choice name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
<choice xsi:type="IntervalTypeSpecifier">
<pointType name="t:DateTime" xsi:type="NamedTypeSpecifier"/>
</choice>
</resultTypeSpecifier>
<operand path="performed" scope="UnilateralMastectomyLeftPerformed" xsi:type="Property"/>
```
This would indicate that there is an issue with capturing the timing of UnilateralMastectomyLeftPerformed.performed data element.

QICore and USCore specify that Procedure.performed[x] is MustSupport for performedDatetime but not for performedPeriod.
https://hl7.org/fhir/us/qicore/StructureDefinition-qicore-procedure.html
https://hl7.org/fhir/us/core/STU5.0.1/StructureDefinition-us-core-procedure.html

In MADiE, test case "DENEXFail-UniMastDxRQualOnJan1AfterMP" is invalid with the following Validation error message:
Error: HAPI-1861: Failed to parse JSON encoded FHIR content: Unexpected character ('[' (code 91)): was expecting double-quote to start field name at [Source: UNKNOWN; line: 149, column: 12 which points to the '[' indicated by the <<<<< in the following snippet from the test case json:
```
{
"fullUrl": "https://madie.cms.gov/Condition/Condition-27",
"resource": {
"resourceType": "Condition",
"id": "Condition-27",
"meta":

{ "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition" ] }

,
"category": [
{
"coding": [

{ "code": "problem-list-item", "system": "http://terminology.hl7.org/CodeSystem/condition-category", "display": "Problem List Item" }

]
}
],
"subject":

{ "reference": "Patient/d5eaf168-6467-48f6-af81-f8b878b433a5" }

,
"code": {
"coding": [

{ "code": "248802009", "system": "http://snomed.info/sct", "display": "Absence of breast (finding)" }

]
},
"onsetDateTime": "2026-01-01T00:00:00.000Z",
"clinicalStatus": {
"coding": [

{ "code": "active", "system": "http://terminology.hl7.org/CodeSystem/condition-clinical" }

]
},
"bodySite":

{ [ <<<<< Unexpected character ('[' (code 91)): was expecting double-quote to start field name at [Source: UNKNOWN; line: 149, column: 12 }

"coding": [

{ "code": "24028007", "system": "http://snomed.info/sct", "display": "Right (qualifier value)" }

]
}
]
}
```
The above looks like the indicated [ and the } on the following line are causing the issue in the test case. Recommend removing these (or the whole test case) to see if that resolves your issue. I attempted to create a test measure to confirm, but MADiE is not permitting me to create a new measure today.

If the above resolves your issue, please set the flag in the issue.
PMuir MD eCQM Standards Team

Comment by eCQM Standards Team [ 11/09/23 ]

Thank you for submitting a ticket to the CQL JIRA Issue Tracker. Our experts are reviewing your ticket and will provide feedback as soon as possible. Thank you for your patience.

Comment by Lisa Anderson (Inactive) [ 11/09/23 ]

jasmincimone did you update the test cases to align with the QI Core profile? If yes, can you update the Measure Model to QI Core? 

Generated at Sun Aug 31 08:12:19 UTC 2025 using Jira 10.3.8#10030008-sha1:cdaed80cecc964184c5b19b002388d56f96e274e.