cqframework/cql-execution

Cannot read properties of null (reading 'FHIRHelpers')

JSRankins opened this issue · 9 comments

@cmoesel and @brynrhodes Good morning gents. I've run into an error using FHIRHelpers and the QI-Core version of MATGlobalCommonFunctions library as it centers around the following function:

define fluent function hospitalArrivalTime(TheEncounter Encounter ): start of First( ( "Hospitalization Locations"(TheEncounter) ) HospitalLocation sort by start of period ).period

The issue arises when there is a missing location reference within an ED Encounter resource even though there is a location reference within the Inpatient Encounter resource.

I'm receiving the following message:

Cannot read properties of null (reading 'FHIRHelpers')

Problem with CQL logic or execution-engine? Thoughts?

The CQL referencing the hospitalArrivalTime function is here.

Patient-bundle:
{ "resourceType": "Bundle", "id": "denom-pass-EncounterLt2Days", "meta": { "versionId": "3", "lastUpdated": "2022-09-14T12:38:39.889+00:00" }, "type": "collection", "entry": [ { "fullUrl": "609bde3598086b0a16d79fc6", "resource": { "resourceType": "Patient", "id": "609bde3598086b0a16d79fc6", "meta": { "profile": [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-patient" ] }, "text": { "status": "generated", "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><div class=\"hapiHeaderText\">LocationPeriodStartTimeMissing <b>MSRPOPLEXSTRAT2PASS </b></div><table class=\"hapiPropertyTable\"><tbody><tr><td>Identifier</td><td>8065dc8d26797064d8766be71f2bf020</td></tr><tr><td>Date of birth</td><td><span>10 February 1954</span></td></tr></tbody></table></div>" }, "identifier": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "http://myGoodHealthcare.com/MRN", "value": "8065dc8d26797064d8766be71f2bf020" } ], "active": true, "name": [ { "use": "usual", "family": "IPPass", "given": [ "Encounter Less than 2 Days" ] } ], "gender": "male", "birthDate": "1954-02-10" } }, { "fullUrl": "5c6c61ceb84846536a9a98f9", "resource": { "resourceType": "Encounter", "id": "5c6c61ceb84846536a9a98f9", "status": "finished", "class" : { "system" : "http://terminology.hl7.org/CodeSystem/v3-ActCode", "code" : "IMP", "display" : "inpatient encounter" }, "type": [ { "coding": [ { "system": "http://snomed.info/sct", "code": "183452005", "display": "Emergency hospital admission (procedure)" } ] } ], "subject": { "reference": "Patient/609bde3598086b0a16d79fc6" }, "period": { "start": "2012-07-15T08:00:00+00:00", "end": "2012-07-16T09:00:00+00:00" }, "length": { "value": 1.0, "unit": "days" }, "location" : [ { "location" : { "reference" : "Location/4989ju789fn93bvy562loe87c", "display" : "Holy Family Hospital Inpatient" }, "period": { "start": "2012-07-15T08:00:00+00:00", "end": "2012-07-16T09:00:00+00:00" } } ] } }, { "fullUrl": "9dju7njdn764mdjy6dm92nje", "resource": { "resourceType": "Encounter", "id": "9dju7njdn764mdjy6dm92nje", "status": "finished", "class" : { "system" : "http://terminology.hl7.org/CodeSystem/v3-ActCode", "code" : "EMRGONLY", "display" : "Emergency only" }, "type": [ { "coding": [ { "system": "http://snomed.info/sct", "code": "4525004", "display": "Emergency department patient visit (procedure)" } ] } ], "subject": { "reference": "Patient/609bde3598086b0a16d79fc6" }, "period": { "start": "2012-07-14T23:00:00+00:00", "end": "2012-07-15T07:30:00+00:00" }, "length": { "value": 1.0, "unit": "days" } } }, { "fullUrl": "489juh6757h87j03jhy73mv7", "resource": { "resourceType" : "Location", "id" : "489juh6757h87j03jhy73mv7", "meta" : { "profile" : [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-location" ] }, "identifier" : [ { "use" : "official", "system" : "http://holycrosshospital.com/location", "value" : "489juh6757h87j03jhy73mv7" } ], "status" : "active", "name" : "South Wing, second floor" } }, { "fullUrl": "4989ju789fn93bvy562loe87c", "resource": { "resourceType" : "Location", "id" : "4989ju789fn93bvy562loe87c", "meta" : { "profile" : [ "http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-location" ] }, "identifier" : [ { "use" : "official", "system" : "http://holycrosshospital.com/location", "value" : "4989ju789fn93bvy562loe87c" } ], "status" : "active", "name" : "North Wing, second floor" } } ] }

Just checking status of this ticket...

Hi @JSRankins -- it seems that your link to the CQL in the post above is 404. Did that file move?

Hi @cmoesel. Yes. My apologies. Active in that repo right now, and I had a similarly named library. So I changed it just yesterday. It is here.

Thank you, @JSRankins. I don't know exactly how you're running this, but I was able to create a simple test project that reproduces the issue: ecqm-test.zip. The README contains instructions for running it.

I forgot to put this in the README, but note that I had to add the meta.profile to the Encounters in the Patient bundle since I'm running this in trusted environment mode.

I'll try to take a closer look at what's going on tomorrow.

Thanks @cmoesel. My apologies. I was in a hurry when I wrote this up. I was in a lower level MADiE environment when I ran into the issue. If you want version of Translator and fqm-execution that instance of tool was on when I encountered the issue, I'll need to do some digging, but I can let you know once I have those details. Next time (if there is one), I'll put those details in the ticket.

Don't worry about it, @JSRankins. Since I was able to reproduce this using the latest versions of our libraries, I'm at a good point to be able to investigate (and hopefully fix) it.

p9g commented

@JSRankins the Encounters in your test case do not have the meta.profile for QI-Core Encounter
Sorry I missed the @cmoesel comment above when I added this comment

@p9g, base FHIR doesn't require meta. In fact, it isn't even required in QI-Core. Understandably, it is needed when operating in trusted environment. If you see @cmoesel's comment above, he added meta to the Encounter resource instances, and the issue still occurs.

@JSRankins - I've found the problem and submitted a PR with the fix (#282). Thanks for reporting this!