Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ratio Literal Can't Reference Quantity Expression Values #455

Open
bdrillard opened this issue Sep 24, 2019 · 4 comments
Open

Ratio Literal Can't Reference Quantity Expression Values #455

bdrillard opened this issue Sep 24, 2019 · 4 comments

Comments

@bdrillard
Copy link

bdrillard commented Sep 24, 2019

It's possible to define a Ratio using the : literal and two Quantities:

define MyRatio: 0.1 'mg' : 0.5 'mg'

The definition of the ELM is such that Ratio accepts two Quantity types.

I would think the the following would produce a valid Ratio:

library Query
context Patient

define Numerator: 0.1 'mg'
define Denominator: 0.5 'mg'
define MyRatio: Numerator : Denominator

however, the ELM indicates only one of the element Quantities is returned instead:

<library xmlns="urn:hl7-org:elm:r1" xmlns:t="urn:hl7-org:elm-types:r1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fhir="http://hl7.org/fhir" xmlns:qdm43="urn:healthit-gov:qdm:v4_3" xmlns:qdm53="urn:healthit-gov:qdm:v5_3" xmlns:a="urn:hl7-org:cql-annotations:r1">
   <identifier id="Query"/>
   <schemaIdentifier id="urn:hl7-org:elm" version="r1"/>
   <usings>
      <def localIdentifier="System" uri="urn:hl7-org:elm-types:r1"/>
   </usings>
   <statements>
      <def name="Patient" context="Patient">
         <expression xsi:type="Null"/>
      </def>
      <def resultTypeName="t:Quantity" name="Numerator" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Quantity" value="0.1" unit="mg" xsi:type="Quantity"/>
      </def>
      <def resultTypeName="t:Quantity" name="Denominator" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Quantity" value="0.5" unit="mg" xsi:type="Quantity"/>
      </def>
      <def resultTypeName="t:Quantity" name="MyRatio" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Quantity" name="Numerator" xsi:type="ExpressionRef"/>
      </def>
   </statements>
</library>

Interestingly, the Denominator expression is completely ignored.

If we use the Instance constructor for Ratio directly, we get what we'd expect:

library Query
context Patient

define Numerator: 0.1 'mg'
define Denominator: 0.5 'mg'
define MyRatio: System.Ratio { numerator: Numerator, denominator: Denominator }
<library xmlns="urn:hl7-org:elm:r1" xmlns:t="urn:hl7-org:elm-types:r1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fhir="http://hl7.org/fhir" xmlns:qdm43="urn:healthit-gov:qdm:v4_3" xmlns:qdm53="urn:healthit-gov:qdm:v5_3" xmlns:a="urn:hl7-org:cql-annotations:r1">
   <identifier id="Query"/>
   <schemaIdentifier id="urn:hl7-org:elm" version="r1"/>
   <usings>
      <def localIdentifier="System" uri="urn:hl7-org:elm-types:r1"/>
   </usings>
   <statements>
      <def name="Patient" context="Patient">
         <expression xsi:type="Null"/>
      </def>
      <def resultTypeName="t:Quantity" name="Numerator" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Quantity" value="0.1" unit="mg" xsi:type="Quantity"/>
      </def>
      <def resultTypeName="t:Quantity" name="Denominator" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Quantity" value="0.5" unit="mg" xsi:type="Quantity"/>
      </def>
      <def resultTypeName="t:Ratio" name="MyRatio" context="Patient" accessLevel="Public">
         <expression resultTypeName="t:Ratio" classType="t:Ratio" xsi:type="Instance">
            <element name="numerator">
               <value resultTypeName="t:Quantity" name="Numerator" xsi:type="ExpressionRef"/>
            </element>
            <element name="denominator">
               <value resultTypeName="t:Quantity" name="Denominator" xsi:type="ExpressionRef"/>
            </element>
         </expression>
      </def>
   </statements>
</library>

Perhaps the : literal operator isn't correctly understanding Quantity-typed ExpressionRef instances?

@bdrillard bdrillard changed the title Ratios Can't Reference Quantity Values Ratio Literal Can't Reference Quantity Expression Values Sep 24, 2019
@brynrhodes
Copy link
Member

Hi @bdrillard , the ratio literal production rule only works with literals, it's not a ratio expression, so you can't say Numerator : Denominator, you have to use the Ratio instance constructor as you've discovered.

I am surprised you're not getting an error on that though, and I've verified that the latest versions of the CQL 1.3 and 1.4 translators correctly error on that. What version of the translator are you using?

@bdrillard
Copy link
Author

bdrillard commented Sep 25, 2019

We're consuming the info.cqframework.cql-to-elm dependency to handle our ELM generation, v1.3.15.

Your explanation this only applies to full Ratio & Quantity literals makes sense however. An error message would clear that up (and obviate any concerns that there's an open documentation issue), but our version of the ELM compiler didn't seem to surface ones, either during compilation or in the annotations of the produced AST.

@brynrhodes
Copy link
Member

Hmm.... that's definitely strange because I don't see it with the latest 1.3, but I don't see any fixes between 15 and 17 that would account for the difference. Are you getting any warnings or errors with the translation?

@brynrhodes
Copy link
Member

Is this still an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants