Translating Clinical Quality Language to SQL: How CQL Compiles to Relational Queries
When clinical informaticists and healthcare data engineers talk about CQL to SQL, they are addressing an architectural divide in health IT: computable clinical knowledge—such as CMS electronic Clinical Quality Measures (eCQMs) and decision support guidelines—is authored in HL7 Clinical Quality Language (CQL), but population analytics, quality reporting, and observational research run on relational data warehouses and SQL query engines.
(Note: "CQL" is also the acronym for Cassandra Query Language in Apache Cassandra database migrations. This article is about the HL7 healthcare standard: compiling Clinical Quality Language into relational SQL queries).
Traditionally, executing CQL has required an imperative, row-by-row Java engine (cqframework and HAPI FHIR). While that architecture works for transactional decision support on an individual patient in an EHR, evaluating thousands or millions of patients for quality reporting in a JVM quickly runs into memory and throughput walls.
Here is how compiling CQL directly to relational SQL works in fhir4ds, how the translator handles complex clinical constructs (temporal intervals, polymorphic choice fields, and terminology resolution), and the performance characteristics of running CQL as set-based relational algebra.