cql-engine icon indicating copy to clipboard operation
cql-engine copied to clipboard

Primitive type profiles casting behavior

Open brynrhodes opened this issue 4 years ago • 0 comments

Primitive types that derive from other primitive types, rather than from element directly (such as SimpleQuantity) aren't strictly speaking subtypes, they are profiles, in that they are always serialize as the ancestor, and so can deserialize that way. This results in cases where casts that should be effective are failing (such as with the dose element of a doseAndRate, the type of the dose element is declared as a choice of Range and SimpleQuantity, but instances deserialize as Quantity, not SimpleQuantity). To reproduce the base behavior here:

library Scratchpad

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'

context Patient

define FHIRQuantity: FHIR.Quantity { value: FHIR.decimal { value: 1.0 }, code: FHIR.code { value: 'mg' } };
define CastFHIRQuantity: FHIRQuantity as FHIR.SimpleQuantity

The CastFHIRQuantity expression returns null, but this downcast is safe in theory, it's really more of a profile enforcement, and needs to be treated that way by the engine. In other words, the cast in the engine needs to be handled by the data model resolver, and cases like this need to be supported as validations, rather than actual casts.

brynrhodes avatar Jul 16 '20 02:07 brynrhodes