cqframework / clinical_quality_language

Clinical Quality Language (CQL) is an HL7 specification for the expression of clinical knowledge that can be used within both the Clinical Decision Support (CDS) and Clinical Quality Measurement (CQM) domains. This repository contains complementary tooling in support of that specification.
https://confluence.hl7.org/display/CDS/Clinical+Quality+Language
Apache License 2.0
258 stars 120 forks source link

Comments inside expression causing unexpected formatting #210

Closed jackcmeyer closed 7 years ago

jackcmeyer commented 7 years ago

When using the CQL Formatter on the following CQL Library:

library Test version '0.0.000'

using QDM version '5.3'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Test":
    // some coment here
     exists (
         ["Laboratory Test, Performed"]E
            where E.result > @2016-05-06
     )

results in:

library Test version '0.0.000'

using QDM version '5.3'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Test":

    // some coment here
      exists (["Laboratory Test, Performed"]E where E.result > @2016-05-06 )

Similarly, multi line comments have the same issue.

library Test version '0.0.000'

using QDM version '5.3'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Test":

        /* some coment here
            and another comment here
            and one more
         */
      exists (
            ["Laboratory Test, Performed"]E
                where E.result > @2016-05-06
        )

results in:

library Test version '0.0.000'

using QDM version '5.3'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Test":

        /* some coment here
            and another comment here
            and one more
         */
       exists (["Laboratory Test, Performed"]E where E.result > @2016-05-06 )
JSRankins commented 7 years ago

@brynrhodes and @c-schuler: Pull Request https://github.com/cqframework/clinical_quality_language/pull/211 was pushed to correct this issue. However, the comment in the pull request is not consistent with what is in CQL if we understand the comment correctly. The comment in the pull request is below.

Comment support is limited (comments within expressions will cause syntax issues - keep comments above or below expressions).

We do not understand what is intended by this comment, but it seems to imply that comments internal to a definition are not supported. If this is the case, then it is not consistent with the CQL standard.

In addition, we have found that the use of a comments provided internally in a definition will sometimes cause an error to return even when the CQL syntax is correct. For example, when the formatter operates on this code...

library Test version '0.0.000'

using QDM version '5.3'

valueset "Dapsone and pyrimethamine": 'urn:oid:2.16.840.1.113883.3.464.1003.196.12.1202' version 'urn:hl7:version:eCQM%20Update%202017-05-05'
valueset "Leucovorin": 'urn:oid:2.16.840.1.113883.3.464.1003.196.12.1205' version 'urn:hl7:version:eCQM%20Update%202017-05-05'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "CD4+ Count With Results and Medications 2":
                ["Medication, Order": "Leucovorin"] MOL
                                with ["Medication, Order": "Dapsone and pyrimethamine"] DapsoneOrder

                                // fdafds this statement
                                                such that DapsoneOrder.authorDatetime occurs 1 days or less after MOL.authorDatetime
                                with ["Medication, Order": "Dapsone and pyrimethamine"] MODP
                                                such that MODP.authorDatetime occurs 1 day or less after MOL.authorDatetime
                                where MOL.authorDatetime is not null

...the following output is received:

Encountered syntax errors:
[14:2]: mismatched input 'with' expecting {<EOF>, '<', '>', 'define', 'context', 'in', 'is', 'as', 'properly', 'between', 'and', '<=', '>=', '=', '!=', '~', '!~', 'contains', 'or', 'xor', 'implies', '|', 'union', 'intersect', 'except', 'less than', 'more than', 'on or', 'before', 'after', 'starts', 'ends', 'occurs', 'same', 'includes', 'during', 'included in', 'within', 'meets', 'overlaps', NUMBER}

Input CQL:
null

On the other hand, when the CQL expression is run through the CQL-to-ELM translator, it passes validation.

brynrhodes commented 7 years ago

Addressed in v1.2.12-SNAPSHOT.