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

ELM parser for negation is implemented incorrectly

Open ewoutkramer opened this issue 1 year ago • 3 comments

When an expression contains the unary '-', our current parser only accepts literals and quantities and uses string concatenation and multiplication to execute the negation. However, negation is not limited to literals as the following is valid CQL:

library BareMinimum version '0.0.1'
    
using FHIR version '4.0.1'

include cq_core.FHIRHelpers version '4.0.1' called FHIRHelpers

context Patient

define x: 4

define y: -"x"

define z: -5

define q: 4 'kg'

define m: -"q"

The ELM tree should simply use the Negate ELM node instead, and accept any expression with the correct type. See https://cql.hl7.org/04-logicalspecification.html#negate

ewoutkramer avatar Oct 25 '23 14:10 ewoutkramer