Clinical Quality Language STU3 Ballot (1.3)

This is the 2018 May Ballot Version of Clinical Quality Language STU 3
For a full list of available versions, see the Directory of published versions .

Clinical Decision Support Work GroupMaturity Level: 4Ballot Status: STU 3

Query Change Proposal

The current query syntax is defined as:

query
    : sourceClause letClause? queryInclusionClause* whereClause? returnClause? sortClause?
    ;

sourceClause
    : singleSourceClause
    | multipleSourceClause
    ;

singleSourceClause
    : aliasedQuerySource
    ;

multipleSourceClause
    : 'from' aliasedQuerySource (',' aliasedQuerySource)*
    ;

This syntax allows two flavors of query, single-source, and multi-source. Single-source queries are introduced with a trailing alias, which provides a concise syntax for expressing simple queries:

"Encounters" E where E.relevantPeriod during "Measurement Period"

To express queries involving more than one source, the from keyword is used:

  from
    "Encounters" E,
    "Warfarin Therapy" W,
    "Parenteral Therapy" P
  where W.effectiveTime starts during E.period
    and P.effectiveTime starts during E.period

However, the trailing alias syntax used in single-source queries complicates parsing of CQL because a single-source query cannot be detected until after the source has been parsed. This requires the parser to backtrack, and makes development of a CQL parser more difficult than it would otherwise be.

We therefore propose the following change to the grammar:

query
    : sourceClause letClause? queryInclusionClause* whereClause? returnClause? sortClause?
    ;

sourceClause
    : 'from' aliasedQuerySource (',' aliasedQuerySource)*
    ;

This would mean that all queries would have to start with the from keyword:

from "Encounters" E where E.relevantPeriod during "Measurement Period"

In support of keeping the current grammar: 1. Not having an initial keyword was an explicit design choice for single-source queries because it’s a simpler syntax from an authoring perspective. Because most queries can be expressed with single-source queries, many authors would never have to learn about or deal with multi-source queries and the from keyword. Note that the Author’s Guide never mentions multi-source queries, they are discussed as a more advanced topic in the Developer’s Guide. 2. Because the grammar is expressed using Antlr4, tooling to parse the grammar is automatically available in multiple platforms.

In support of changing the grammar as proposed: 1. Although tooling exists to facilitate parsing, many environments will want to integrate CQL support into their existing infrastructure. In these cases, Antlr4 tooling is not a good fit, and integrators will encounter difficulty in parsing CQL using their own frameworks. Making this change reduces that barrier to adoption. 2. Although requiring the from keyword on all queries is marginally less concise, it does mean that there is a consistent visual cue for the start of a query context. 3. The syntax change would also allow queries on arbitrary expressions without needing to use enclosing parentheses. (i.e. from A union B X instead of requiring from (A union B) X)

We are seeking additional input from all stakeholders on whether this change should be made.