Clinical Query Language (CQL) is a high-level query language to represent and generate unambiguous quality measures or clinical decision rules. I am not a CQL expert. These are my notes from a system development perspective. I am trying to make sense of this emerging concept and add my notes here in the hope that others may find this useful.
Clinical Query Language is designed to be intuitive for clinicians authoring the queries for quality measures and clinical decision support. The decision support rules are mostly alert type rules at the individual and population level that is calculated from a database (not usually diagnostic decision support). You can use any data model with CQL.
Here is an example segment of CQL:
define “InDemographic”:
AgeInYearsAt(start of MeasurementPeriod) >= 16 and AgeInYearsAt(start of MeasurementPeriod) < 24
and “Patient”.”gender” in “Female Administrative Sex”
As Clinical Query Language follows strict semantics, you can autogenerate lexers, parsers and visitors using ANTLR. In simple terms, CQL’s semantics can be represented as a ‘grammar’ that ANTLR can read and generate code to process any CQL in a variety of programming languages, including Java, Javascript, Python, C# and Go. The CQL grammar files are here: https://cql.hl7.org/08-a-cqlsyntax.html. Incidentally, CQL grammar inherits from fhirpath.
If you wish to generate code from these files, there are two things to note:
- You need to rename CQL.g4 to cql.g4 as the library names are case-sensitive and should correspond to the filename.
- Put fhirpath.g4 in the same folder as cql.g4, and cql refers to fhirpath grammar.
Clinical Query Language aims to provide a high-level domain-independent language for clinicians that can be translated into low-level database logic. As CQL does not prescribe a data model, an intermediary format linking CQL to the data management logic is required. That is called the Expression Logical Model (ELM) which we will discuss in part 2.
Update: cql-exec-vsac is a VSAC-enabled code service for the JavaScript CQL Execution project. This allows the CQL Execution Engine to execute CQL containing references to Value Sets that are published in the National Library of Medicine’s (NLM) Value Set Authority Center (VSAC). I have added a feature that adds support for any FHIR server other than VSAC to support private terminology servers. Check it out!
- Loading MIMIC dataset onto a FHIR server in two easy steps - November 20, 2024
- R&D and Innovation in IT; to or not to combine both - November 15, 2024
- Locally hosted LLMs - July 14, 2024
I have added support for FHIR terminology servers to CQL Execution VSAC Code Service: https://github.com/dermatologist/cql-exec-vsac
This fork adds support for FHIR Endpoints:
Open FHIR Endpoints can be specified by passing in the fhirBaseUrl parameter to the ensureValueSetsWithAPIKey or via the FHIR_BASE_URL environment variable. (Note that the fhirBaseUrl parameter is optional and if used the UMLS key is ignored.)
Pingback: LLM-in-the Loop CQL execution - Bell Eapen MD, PhD.