cqframework / cqf-tooling

Tooling for CQL and IG Authors
Apache License 2.0
19 stars 23 forks source link

Additional implicit conversions in FHIRHelpers #370

Open brynrhodes opened 2 years ago

brynrhodes commented 2 years ago

Consider the following expression:

Patient.birthDate < Now()

There are two implicit conversions happening here, one from the birthDate to a System.Date and one from a System.Date to a System.DateTime. CQL intentionally does not support transitive implicit conversion, and so this expression fails. However, the FHIRPath engines already do this because they are handling the conversions at run-time.

Define additional implicit conversions in FHIR helpers to account for implicit conversions defined in CQL types as well:

define function ToDateTime(value date): ToDateTime(value.value)
define function ToDecimal(value integer): ToDecimal(value.value)

These need to be reflected in the ModelInfo as ConversionInfo as well:

   <conversionInfo functionName="FHIRHelpers.ToDateTime" fromType="FHIR.date" toType="System.DateTime"/>
   <conversionInfo functionName="FHIRHelpers.ToDecimal" fromType="FHIR.integer" toType="System.Decimal"/>
brynrhodes commented 2 years ago

Note that this issue arises in the context of addressing this issue: https://github.com/cqframework/clinical_quality_language/issues/761

The fix for the FHIRModelInfo and FHIRHelpers.cql is already applied as part of the fix for that.

This issue is to track to make sure that these additional conversions get added to the FHIRModelInfo generation logic.

brynrhodes commented 2 years ago

On second thought, don't do this. It introduces ambiguities with other conversions, consider:

Patient.birthDate + 1 day

If the FHIR.date value can be converted to both a System.Date and a System.DateTime, the date arithmetic becomes ambiguous with Add(Date, Quantity) and Add(DateTime, Quantity.