firely-cql-sdk icon indicating copy to clipboard operation
firely-cql-sdk copied to clipboard

How to handle type matching cases

Open ewoutkramer opened this issue 1 year ago • 3 comments

When we encounter case statements like this:

 when Event is AllergyIntolerance then
                  Interval[start of Event.onset.toInterval(), Event.lastOccurrence] overlaps after day of 
                                        ModerateOrSevereLVSDHFOutpatientEncounter.period
                    and Event.clinicalStatus ~ QICoreCommon."allergy-active"
                    and not (Event.verificationStatus ~ QICoreCommon."allergy-unconfirmed"
                        or Event.verificationStatus ~ QICoreCommon."allergy-refuted"
                        or Event.verificationStatus ~ "allergy-entered-in-error")
  when Event is MedicationRequest then
                  First( ( collapse (Event.dosageInstruction.timing.repeat.bounds DoseTime
                                        return DoseTime.toInterval()) ) DrugPeriods
                           sort by start of $this ) overlaps after day of ModerateOrSevereLVSDHFOutpatientEncounter.period
                    and Event.status in { 'active', 'completed' }
                    and Event.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
                    and Event.doNotPerform is not true

Here, it looks like the ExpressionBuilder is supposed to know that inside a when Event is TYPE, the type of Event is actually TYPE. I haven't checked deeply, but I would think this is the task of the CQL->ELM compiler to determine if this is the case, and this should somehow be present in the ELM. At the moment however, the type of Event is unknown, so things like Event.status are determined to be "late bound properties", for which the statically determined type is "Object". This means that when these properties are then used, e.g. in Event.status in { 'active', .... }, the ExpressionBuilder returns a null, instead of a boolean - causing further harm.

I have for now provided a dummy body for this function in CMS AHAOverall.cql, so we can at least continue our work.

ewoutkramer avatar Feb 23 '24 14:02 ewoutkramer