CQL-to-ELM Compilation Pipeline
Description
The same rule appears twice here in two very different forms. The CQL reads almost as a sentence: there exists a Condition drawn from the diabetes value set whose clinical status is active. The compiled ELM expresses that identically as an expression tree — Exists wrapping a Query wrapping a Retrieve — which is what an engine can actually walk. Reading them side by side is the exercise; the correspondence is exact and worth tracing element by element. The patient buttons then run that one rule against two patients whose diabetes Conditions differ only in clinicalStatus. The retrieve returns a resource for both. The where clause is what separates them, which is a useful thing to have seen before writing a cohort query of your own.
Lesson Plan
Audience: undergraduate students and healthcare data practitioners. Allow 12-18 minutes. Prerequisites: FHIR Condition resources, and the idea that a value set selects codes from a code system.
Learning objective: Given a CQL define statement, the learner can explain each stage of its compilation into ELM and translate between the CQL authoring format and its corresponding ELM fragment.
- Explore: Select CQL Library and Expression Logical Model in turn. Point at the exact ELM node produced by
exists, by[Condition: "Diabetes"], and by thewhereclause. - Explain: Switch to Jordan Ellis and step through the reasoning module. Explain why the retrieve still returns a resource for a patient whose diabetes is resolved, and what that says about relying on diagnosis codes alone to define a cohort.
- Transfer: Write, in plain CQL-like prose, a define statement for patients with an active hypertension diagnosis. Say which part of your statement would become a
Retrieveand which would become thewhere.
Assessment: use the Explain prompt as an exit ticket. A complete response separates value-set membership from clinical status, and names the cohort error that follows from conflating them.
Embed This MicroSim
Copy this iframe to your website:
1 | |
Quality Checks
Validated September 8, 2026. Completeness rubric: 100/100, scored with the project's calculate-quality-score.py against the standardization checklist. Checked automatically in a browser at 400, 800, and 1200 px: the page loads with no JavaScript errors, no interactive control is clipped outside the viewport, and the document does not scroll horizontally. Controls, selections, and the reset path were exercised by hand during development at desktop width. The page reports its own height to the parent document, so the declared iframe height above serves only as a fallback.
Specification
The full specification below is extracted from Chapter 23: Clinical Guideline Authoring and Clinical Quality Language.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
Related Resources
References
- Source chapter — supplied the learning objective and the worked example.
- Mermaid flowchart documentation — subgraphs, click directives, and class styling (accessed September 8, 2026).
- HL7 Clinical Quality Language specification — the authoring language and its translation to ELM (accessed September 8, 2026).
- Wikipedia: Abstract syntax tree — the general idea that ELM instantiates for clinical logic.