clinical_quality_language icon indicating copy to clipboard operation
clinical_quality_language copied to clipboard

patientBirthDatePropertyName marked as deprecated but still required for SystemFunctionResolver

Open Zylox opened this issue 1 year ago • 1 comments

Some time ago, https://github.com/cqframework/clinical_quality_language/pull/439/commits/7b8f43536555e7b75dc40bfd8eb959617382a44f marked patientBirthDatePropertyName as deprecated within the modelinfo schema.

As such, i would expect to be able to omit it from the model info header if i define the patient context in my model info:

    <ns4:contextInfo name="Patient" keyElement="id" birthDateElement="birthDatetime">
        <ns4:contextType modelName="Example" name="Patient"/>
    </ns4:contextInfo>

Compiled against cql like this:

library example_1

using Example

context Patient

define "patients":
    AgeInYears() > 18

I would expect success.

However i get this instead

Error:[8:5, 8:16] Cannot invoke "String.indexOf(int)" because "birthDateProperty" is null

The problem seems to lie in this snippet here: https://github.com/cqframework/clinical_quality_language/blob/dfafdb933f23ab54ce750c4ed1d6d1bf910e9bed/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/SystemFunctionResolver.java#L414-L415

This code is still looking specifically at the information in the modelinfo header.

The "simple" fix seems like it would be to call getContextInfo() and retrieve the birthDateElement from one of the contexts returned. That would require it to be context aware to work properly, i think. Which is not information that i see readily available to the class right now.

Looking at the cql spec here: https://cql.hl7.org/07-physicalrepresentation.html i do see a clause that seems to describe an alternate behavior to what is happening here, under "Context Information":

For patient contexts, Patient Birth Date information must be supplied as well to allow the CQL-to-ELM translator to render references to patient-age-related functions (AgeInYears, AgeInYearsAt, etc.) into the non-patient-aware age-related functions in ELM (CalculateAgeInYears, CalculateAgeInYearsAt, etc.). This information is not required, but if it is not present, references to patient-age-related functions will be passed directly through to ELM as FunctionRefs.

I'm fairly green to the project, i fully admit i could be missing something, but i couldnt find any reference to this elsewhere so im logging this for at least a discussion/explanation of it.

Zylox avatar Aug 14 '24 02:08 Zylox

I think your assessment is correct. The FunctionRef would need to have context information attached to it. That information is available in the compiler at the point the FunctionRef is created, but it's not on that class. That said, I'm going to noodle on this a bit. In cases where the FunctionRef points to a function that's not system defined, the context is available on the corresponding FunctionDef. So this is something that impacts system-defined functions only. There also may be some implication here for cross-context function calls I need to think through.

JPercival avatar Dec 19 '24 16:12 JPercival