cql-engine
cql-engine copied to clipboard
Quantities don't normalize units, giving wrong answers
The CQL Engine does not handle unit normalization properly and so comparisons of Quantity of meters and centimeters don't give the right answers. The problem is characterized by that the unit of the left operand is treated as being the unit of both operands.
Run the following CQL:
define QuantityEqCM1M01 : 1'cm' = 0.01'm'
define GreaterM1CM1 : 1'm' > 1'cm'
define GreaterM1CM10 : 1'm' > 10'cm'
define GreaterOrEqualM1CM1 : 1'm' >= 1'cm'
define GreaterOrEqualM1CM10: 1'm' >= 10'cm'
define LessM1CM1 : 1'm' < 1'cm'
define LessM1CM10 : 1'm' < 10'cm'
define LessOrEqualM1CM1 : 1'm' <= 1'cm'
define LessOrEqualM1CM10 : 1'm' <= 10'cm'
define EquivEqCM1M01 : 1'cm' ~ 0.01'm'
define QuantityNotEqCM1M01 : 1'cm' != 0.01'm'
Expected result:
QuantityEqCM1M01 : true
GreaterM1CM1 : true
GreaterM1CM10 : true
GreaterOrEqualM1CM1 : true
GreaterOrEqualM1CM10: true
LessM1CM1 : false
LessM1CM10 : false
LessOrEqualM1CM1 : false
LessOrEqualM1CM10 : false
EquivEqCM1M01 : true
QuantityNotEqCM1M01 : false
Actual result (only 2 match):
>> QuantityEqCM1M01 [1:1] false
>> GreaterM1CM1 [2:1] false
>> GreaterM1CM10 [3:1] false
>> GreaterOrEqualM1CM1 [4:1] true
>> GreaterOrEqualM1CM10 [5:1] false
>> LessM1CM1 [6:1] false
>> LessM1CM10 [7:1] true
>> LessOrEqualM1CM1 [8:1] true
>> LessOrEqualM1CM10 [9:1] true
>> EquivEqCM1M01 [10:1] false
>> QuantityNotEqCM1M01 [11:1] true
These failing CQL Engine tests reflect this bug:
- CqlComparisonOperatorsTest.xml -> 9 of the 11 tests listed above
According to the CQL spec the engine should be returning null if it's unable to normalize:
https://cql.hl7.org/02-authorsguide.html#quantity-operators
Most likely this will be superseded by cqframework/clinical_quality_language#1071