Quality Measure Implementation Guide, published by HL7 International / Clinical Quality Information. This guide is not an authorized publication; it is the continuous build for version 2.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/fhir-cqm/ and changes regularly. See the Directory of published versions
This topic discusses the use of Clinical Quality Language (CQL) to provide computable and/or executable representation of the various criteria of a measure through the expression-valued elements of the Measure resource. The CQLMeasure and ELMMeasure profiles define the expectations for measures that make use of CQL and/or ELM. Support for the use of other expression languages is possible, but is out of scope for this implementation guide.
Measures that use CQL do so with libraries to contain the logic used to define the various criteria of the measure. CQL libraries are used in accordance with the Using CQL With FHIR (UCWF) implementation guide, as well as additional conformance requirements specific to the use of measures, as detailed in the following sections.
For the convenience of IG readers, the conformance requirements from the Using CQL with FHIR Implementation Guide are restated below; however, the Using CQL with FHIR IG remains the authoritative source.
The Conformance Summary Table lists the conformance sections in this implementation guide and indicates which of them further constrains the requirements defined by the UCWF IG. The table also provides direct links to the corresponding conformance statements.
Table 4-1: Conformance Summary Table
| Topic | Additional QM IG Constraints | Conformance Section |
|---|---|---|
| Library Usage | Yes | QM IG 4.1 (Library Usage) |
| Library Versioning | Yes | QM IG 4.2 (Library Versioning) |
| Nested Libraries | Yes | QM IG 4.3 (Nested Libraries) |
| Library Namespaces | No | UCWF:2.4 (Library Namespaces) |
| Data Model | Yes | UCWF:2.5 (Data Models) |
| Code Systems | No | UCWF:2.6 (Code System Specification) |
| Value Sets | No | UCWF:2.7 (Value Set Specification) |
| Value Set Version | No | UCWF:2.8 (Value Set Specification Including Version) |
| Value Set Expansion | No | UCWF:2.9 (Value Set Expansion) |
| String-based Membership Testing | No | UCWF:2.10 (String-based Membership Testing) |
| Codes | No | UCWF:2.11 (Direct-reference Codes) |
| Concepts | No | UCWF:2.12 (Concepts) |
| Library-level Identifiers | No | UCWF:2.13 (Library-level Identifiers) |
| Data Type Names | No | UCWF:2.14 (Data Type Names) |
| Element Names | No | UCWF:2.15 (Element Names) |
| Aliases and Argument Names | No | UCWF:2.16 (Aliases and Argument Names) |
Consistent with the UCWF IG, Measures that make use of CQL use Libraries.
Conformance Requirement 4.1 (Library Usage): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.1 (Library Declaration) 1. Any CQL library used by a FHIR artifact SHALL contain a library declaration. 2. The library identifier SHALL be a valid un-quoted identifier and SHALL NOT contain underscores. The library identifier SHALL only contain alphanumeric characters. |
1. CQL used by a Measure SHALL be contained in a CQL library. |
For example:
library EXM146 version '4.0.0'
Snippet 4-1: Library line from EXM146.cql
Consistent with the UCWF IG, this IG recommends an approach to Library Versioning used within Measures to help track and manage dependencies. The approach recommended here is based on the Semantic Versioning Scheme.
Conformance Requirement 4.2 (Library Versioning): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.2 (Library Versioning) 1. The library declaration in the CQL source NEED NOT specify a version, since version can be provided as part of the translation and publishing process. 2.The library version SHOULD follow the convention: < major >.< minor >.< patch > 3. For artifacts in draft status, a version is not required, the versioning scheme NEED NOT apply, and there is no expectation that artifact contents are stable. 4. When an artifact moves to active status, a version is required in either the CQL source, the translated ELM (if included), or the containing FHIR Library resources. |
1. CQL libraries used by Measures SHALL include a version as part of the library declaration. 2. In addition, CQL libraries used by Measures SHALL follow the convention : < major >.< minor >.< patch > 3. For measures in draft status, a version label MAY be included. 4. If a version label is included, it SHALL follow the convention: < major >.< minor >.< patch >-< label > |
For example:
library EXM146 version '3.0.0'
This would indicate the first major version of the EXM146 library. A minor change could be released by incrementing the minor version:
library EXM146 version '3.1.0'
And a major change could be released by incrementing the major version, and resetting the minor version: Minor changes are expected to retain backwards-compatibility, but may introduce new features and functionality, while patch changes are expected to retain forward and backwards-compatibility, and may only be used to fix issues.
library EXM146 version '4.0.0'
Snippet 4-2: Library line from EXM146.cql, the fourth major version.
Consistent with the UCWF IG, this IG allows measures to use Nested Libraries. However, this IG requires that all expressions referenced from a Measure be included in a single library to ensure that expression identifiers used in the Measure need not be qualified identifiers.
Conformance Requirement 4.3 (Nested Libraries): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.3 (Nested Libraries) 1. CQL libraries SHOULD be structured such that all CQL expressions referenced from a single FHIR resource are contained within a single library. - If an artifact makes use of multiple libraries, expression references in that artifact SHALL be qualified with the name of the library (i.e., library-name.expression-identifier), or with the alias of the library as specified using the cqf-libraryAlias extension. 2. CQL libraries SHALL use a called clause for all included libraries. 3. The called-alias for an included library SHOULD be consistent for usages across libraries. |
1. In addition, CQL libraries used by measures SHALL be structured such that all CQL expressions referenced by the Measure are contained within a single library. |
For example:
include Common version '2.0.0' called Common
Snippet 4-3: Nested library within EXM146.cql
Consistent with the UCWF IG, this IG recommends the use of Library Namespaces.
Conformance Requirement 4.4 (Library Namespaces): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.4 (Library Namespaces) 1.CQL libraries SHOULD use namespaces. 2. When a namespace is not used, the library SHALL be considered part of a "public" global namespace for the purposes of resolution within a given environment. 3. The root of the CQL namespace SHALL match the root of the url of the Library resource housing the CQL library. |
No additional conformances. |
For example, the following library declaration illustrates the use of a namespace:
library CMS.Common version '2.0.0'
Snippet 4-4: Library namespace
CQL can be used with any Data Model.
Conformance Requirement 4.5 (CQL Data Model): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.5 (Data Models) 1. All libraries and CQL expressions used directly or indirectly within a knowledge artifact SHOULD use FHIR-based data models. 2. Data Model declarations SHALL include a version declaration. |
1. All libraries and CQL expressions used directly or indirectly within a measure SHALL use FHIR based data models. For example, one could use QI Core and SDOH IGs. |
For example:
using FHIR version '4.0.1'
Snippet 4-5: Data Model line from EXM146.cql
For additional information on conformance requirements for the use of Model Information as part of FHIR Knowledge Artifacts that make use of CQL, reference the Using CQL with FHIR IG's section on Using ModelInfo
Consistent with the UCWF IG, Code Systems referenced within CQL expressions make use of the codesystem declaration in CQL.
Conformance Requirement 4.6 (Code System Specification): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.6 (Code System Specification) 1. Within CQL, the identifier of any code system reference SHALL be specified using a URI for the code system. 2. The URI SHALL be the canonical URL for the code system. 3. The Code System declaration MAY include a version, consistent with the URI specification for FHIR and the code system. |
No additional conformances. |
For example:
codesystem "SNOMED CT:20240901": 'http://snomed.info/sct'
version 'http://snomed.info/sct/731000124108/version/20240901'
Snippet 4-6: codesystem definition line from Terminology.cql.
The representation of codesystem declarations in a Library is discussed in the Terminology topic of this IG.
Consistent with the UCWF IG, Value Sets referenced within CQL expressions make use of the valueset declaration in CQL.
Conformance Requirement 4.7 (Value Set Specification): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.7 (Value Set Specification) 1. Within CQL, the identifier of any value set reference SHALL be specified using a URI for the value set. 2. The URI SHALL be the canonical URL for the value set. 3. The URI MAY include a version, consistent with versioned canonical URL references in FHIR |
No additional conformances. |
For example:
valueset "Acute Pharyngitis": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.102.12.1011'
Snippet 4-7: ValueSet reference from EXM146.cql
The canonical URL for a value set is typically defined by the value set author, though it may be provided by the
publisher as well. For example, value sets defined in the Value Set Authority Center and exposed via the VSAC FHIR
interface have a base URL of http://cts.nlm.nih.gov/fhir/. This base is then used to construct the canonical URL for
the value set (in the same way as any FHIR URL) using the resource type (ValueSet in this case) and the id (the value
set OID in this case). Note that the canonical URL is a globally unique, stable, version-independent identifier for the
value set. See Canonical URLs in the base FHIR specification for more information.
The local identifier for the value set within CQL should be the same as the name of the value set in the Value Set Authority Center (VSAC). However, because the name of the value set is not guaranteed to be unique, it is possible to reference multiple value sets with the same name, but different identifiers. When this happens in a CQL library, the local identifier should be the name of the value set with a qualifying suffix to preserve the value set name as a human-readable artifact, but still allow unique reference within the CQL library.
For example:
valueset "Acute Pharyngitis (1)": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.102.12.1011.1'
valueset "Acute Pharyngitis (2)": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.102.12.1011.2'
Snippet 4-8: ValueSet declarations for different value sets with the same name
Note carefully that although this URL may be resolvable for some terminology implementations, this is not necessarily the
case. This use of a canonical URL can be resolved as a search by the url element:
GET fhir/ValueSet?url=http%3A%2F%2Fcts.nlm.nih.gov%2Ffhir%2FValueSet%2F2.16.840.1.113883.3.464.1003.102.12.1011.1
Snippet 4-9: FHIR API query to retrieve a value set by its canonical identifier using the url search parameter
Consistent with the UCWF IG, Value Set Version information is not required to be included. As a best-practice, terminology versioning information is specified externally using a version manifest. However, if versioning information is included, it must be done in accordance with terminology usage specified by FHIR.
Conformance Requirement 4.8 (Value Set Specification By Version): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.8 (Value Set Specification Including Version) 1. When specifying the definition version of a value set to be used in a CQL library, use the version clause of the value set declaration. |
No additional conformances. |
For example:
valueset "Encounter Inpatient SNOMEDCT Value Set":
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307|20260210'
Snippet 4-10: ValueSet definition from Terminology.cql.
This is a version-specific value set reference, and can be resolved as a search by the url and version elements:
GET fhir/ValueSet?url=http%3A%2F%2Fcts.nlm.nih.gov%2Ffhir%2FValueSet%2F2.16.840.1.113883.3.666.7.307&version=20160929
Snippet 4-11: FHIR API query to retrieve a value set by its url and version
Measures that make use of CQL must do so in accordance with Value Set Expansion as described in the UCWF IG.
Conformance Requirement 4.9 (Value Set Expansion): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.9 (Value Set Expansion) 1. Value set membership testing SHOULD use the terminology membership operation in CQL (in(ValueSet)), as opposed to requiring computation on the lists of codes in a value set. See the Terminology Operators section of the CQL specification for more information. |
No additional conformances. |
The representation of valueset declarations in a Library is discussed in the Terminology topic of this IG, consistent with the Representation in Narrative topic in the UCWF IG.
Consistent with the UCWF IG, this implementation guide recommends against the use of string-based membership testing.
Conformance Requirement 4.10 (String-based Membership Testing): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.10 (String-based Membership Testing) 1. String-based membership testing SHOULD NOT be used in CQL libraries. |
No additional conformances. |
Consistent with the UCWF IG, CQL used with Measures can make use of direct-reference codes.
Conformance Requirement 4.11 (Direct-reference Codes): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.11 (Direct-reference Codes) When direct-reference codes are represented within CQL, the logical identifier: 1. SHALL NOT be a URI. 2. SHOULD be a code from the code system. |
No additional conformances. |
For example:
code "Venous foot pump, device (physical object)": '442023007' from "SNOMED CT"
Snippet 4-12: code definition from Terminology.cql.
The representation of code declarations in a Library is discussed in Terminology of this IG, consistent with the Representation in Narrative topic in the UCWF IG.
This implementation guide recommends the UCUM Best Practices found in the UCWF IG.
Consistent with the UCWF IG, CQL used with Measures may make use of the CQL concept declaration, but care must be taken to ensure that it is not used as a surrogate for proper value set definition.
Conformance Requirement 4.12 (Concepts): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.12 (Concepts) 1. The CQL concept construct MAY be used. 2. The CQL concept construct SHALL NOT be used as a surrogate for value set definition. |
No additional conformances. |
Consistent with the UCWF IG, CQL used by Measures should use descriptive and meaningful library-level identifiers, as discussed in the Library-level Identifiers topic
Conformance Requirement 4.13 (Library-level Identifiers): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.13 (Library-level Identifiers) Library-level identifiers in CQL: 1. SHOULD have descriptive, meaningful names. 2. SHOULD avoid abbreviations. 3. SHOULD use quoted identifiers if necessary. 4. SHOULD use initial case 5. MAY include spaces. |
No additional conformances. |
Consistent with the UCWF IG, CQL used by Measures must refer to Data Type Names as dictated by the CQL specification, as well as the Data Models in use. For FHIR-based quality measures using QI-Core profiles, these will be the author-friendly identifiers for the QI-Core profiles.
Conformance Requirement 4.14 (Data Type Names): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.14 (Data Type Names) Data type names referenced in CQL: 1. SHALL use PascalCase (unless dictated by the name of the type in the model). 2. SHALL NOT use quoted identifiers (unless required because the name of the type in the model contains spaces or is otherwise not a valid identifier without quoting). |
No additional conformances. |
For example:
define "Flexible Sigmoidoscopy Performed":
[Procedure: "Flexible Sigmoidoscopy"] FlexibleSigmoidoscopy
where FlexibleSigmoidoscopy.status = 'completed'
and FlexibleSigmoidoscopy.performed ends 5 years or less on or before end of "Measurement Period"
Snippet 4-13: Expression definition from EXM130.cql
Procedure is the name of the model data type (FHIR resource type) in this example.
Consistent with the UCWF IG, CQL used by Measures must refer to Element Names as dictated by the CQL specification, as well as the Data Models in use.
Note that when FHIR and FHIR IGs are used as the data model, the term "element" is synonymous with "attribute". Some data models, such as QDM, use the "attribute".
Conformance Requirement 4.15 (Element Names): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.15 (Element Names) Data model elements referenced in the CQL: 1. SHALL NOT use quoted identifiers (unless required due to the element name in the model not being a valid identifier in CQL). 2. SHOULD use camelCase (unless dictated by the element naming in the model being used). |
No additional conformances. |
Examples of elements (i.e. attributes) conforming to Conformance Requirement 4.15 are given below. For a full list of valid names of attributes for a data model, refer to an appropriate data model specification such as QI-Core.
period
authoredOn
result
Snippet 4-14: Example element names
Consistent with the UCWF IG, CQL used by Measures must follow conventions for naming of Aliases and Arguments. In addition, note that aliases should not be the same as any other identifiers in scope to avoid potential confusion.
Conformance Requirement 4.16 (Aliases and Argument Names): ![]()
| Conformance from UCWF | QM IG Differential |
|---|---|
| UCWF:2.16 (Aliases and Argument Names) Aliases and argument names referenced in the CQL: 1. SHALL NOT use quoted identifiers. 2. SHOULD use PascalCase for alias names. 3. SHOULD use camelCase for argument names. 4. SHOULD use descriptive names (rather than abbreviations). |
No additional conformances. |
For example:
define "Encounters During Measurement Period":
"Valid Encounters" QualifyingEncounter
where QualifyingEncounter.period during "Measurement Period"
define function "ED Stay Time"(Encounter "Encounter"):
duration in minutes of Encounter.period
Snippet 4-15: Example alias and argument names
QualifyingEncounter is the alias in this example, while Encounter is the argument name.
Inclusion of CQL content used within quality measures is accomplished through the use of Library Resources as described by the Using CQL With FHIR implementation guide. These libraries are then referenced from Measure resources using the library element. The content of the CQL library is included using the content element of the Library. Conformance requirements for Library resources included with Measure content are discussed in the Related Documents topic of this IG.
Additional guidance and best-practices for the use of CQL in measures can be found in the Patterns topic of the Using CQL With FHIR implementation guide, including guidance on:
The use of Expression Logical Model (ELM) as a basis for sharing logic is discussed in the Using ELM topic of the Using CQL With FHIR implementation guide, including guidance on: