Using CQL with FHIR, published by HL7 International / Clinical Decision Support. This guide is not an authorized publication; it is the continuous build for version 1.1.0-cibuild built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/cql-ig/ and changes regularly. See the Directory of published versions
This topic specifies conformance requirements for the use of Model Information as part of FHIR Knowledge Artifacts that make use of Clinical Quality Language (CQL).
To use CQL with FHIR, model information (ModelInfo) must be provided to the implementation environment. To create this ModelInfo FHIR StructureDefinition resources can be processed according to the following rules:
primitive-type
, complex-type
(except for types based on Extension), or resource
(with no derivation or a derivation of specialization
), a ClassInfo with the same name as the structure definition is created
If this process is run against the StructureDefinitions from the base FHIR specification, it produces a complete representation of all the FHIR Resources as classes in the ModelInfo. However, because FHIR primitive types actually have elements (e.g. value
, id
, and extension
), this process produces classes in the ModelInfo for each of the FHIR primitive types, and only the value
elements of these FHIR primitives are typed with the actual CQL primitive types. This means that to access the actual values of FHIR elements for comparison against CQL primitive values, the .value
path must be used:
Patient.gender.value = 'female'
To facilitate comparison by authors, these primitives can be implicitly converted to CQL primitive types, and the FHIRHelpers library (generated alongside the ModelInfo) defines these implicit conversions. See the CQF Common implementation guide for a complete FHIR ModelInfo as well as FHIRHelpers library representing the FHIR specification.
To make use of these implicit conversions within a CQL library, include the FHIRHelpers library:
include FHIRHelpers version '4.0.1'
Similar to CQL content, ModelInfo can be included in FHIR Library resources to facilitate distribution.
Conformance Requirement 6.1 (ModelInfo Libraries):
<CQL model namespace url>/Library/<CQL model name>-ModelInfo
<CQL model name>
<CQL model version>
The prohibition against underscores in CQL model names is required to ensure compliance with the canonical URL pattern (because URLs by convention should not use underscores). In addition, many publishing environments will use the canonical tail (i.e. the name of the library) as the logical id of the Library resource, which does not allow underscores per the FHIR specification.
CQL can be used with a FHIR ModelInfo directly, as described above. However, FHIR profiles include a wealth of computable information about the intended structure of the clinical data involved in an exchange, including terminology bindings, constraints, descriptive metadata, slices and extensions. To facilitate authoring that can easily reference this information, the tooling to construct ModelInfo from the base FHIR StructureDefinitions has been enhanced to support building ModelInfo that is specific to an implementation guide:
constraint
) results in a new ClassInfo in the ModelInfo, derived from the ClassInfo for the baseDefinition of the profile
namespace
is set to the modelName
name
is set to the name
element of the StructureDefinitionbaseType
is set to the qualified name of the class corresponding to the baseDefinition
identifier
is set to the canonical url
of the StructureDefinitionlabel
is set to the title
of the StructureDefinition (unless overridden by the cqf-modelInfo-label extension)retrievable
is set to true
(unless overridden by the cqf-modelInfo-isRetrievable extension)primaryCodePath
is set based on the cqf-modelInfo-primaryCodePath extenssionsliceName
element of the slice definition. An element of this type and named with the sliceName
is then added to the containing ClassInfo.Extension
ClassInfo and named based on the name
of the extension definition. An element of this type and named with the extension sliceName
is then added to the containing ClassInfo.cqf-notDoneValueSet
extension defined, the element is typed as a Choice of the terminology-value (CodeableConcept, Coding, or Code) and ValueSet, allowing retrieves to be performed against the ValueSet referenced by the cqf-notDoneValueSet extensionFor example, consider the US Core Blood Pressure Profile. This profile has two slices of the component
element, named systolic
and diastolic
. The resulting USCore ModelInfo has classes derived from the USCore.Observation.Component
class:
<typeInfo xsi:type="ClassInfo" namespace="USCore" name="Observation.Component.systolic" retrievable="false" baseType="USCore.Observation.Component"/>
<typeInfo xsi:type="ClassInfo" namespace="USCore" name="Observation.Component.diastolic" retrievable="false" baseType="USCore.Observation.Component"/>
and then elements in the USCore.BloodPressureProfile
class corresponding to these slices:
<element name="systolic" elementType="USCore.Observation.Component.systolic"/>
<element name="diastolic" elementType="USCore.Observation.Component.diastolic"/>
For extensions, consider the US Core Ethnicity Extension. This is a complex extension, and so the constructed ClassInfo has elements for each of the elements defined by the extension:
<typeInfo xsi:type="ClassInfo" namespace="USCore" name="EthnicityExtension" identifier="http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity" label="US Core Ethnicity Extension" retrievable="false" baseType="USCore.Extension">
<element name="ombCategory" elementType="System.Code"/>
<element name="detailed">
<elementTypeSpecifier xsi:type="ListTypeSpecifier" elementType="System.Code"/>
</element>
<element name="text" elementType="System.String"/>
<element name="url" elementType="System.String"/>
</typeInfo>
And the USCore.PatientProfile
class then has an element named ethnicity
of this type:
<element name="ethnicity" elementType="USCore.EthnicityExtension"/>
NOTE: Importantly, with profile-informed modelinfo, each element in the modelinfo includes a
target
mapping that specifies an expansion to be performed by the translator so that access in the ELM is performed directly against the base FHIR resources, rather than requiring engines (and by extension runtime environments) to deal with data in terms of the profile definitions. As a result, the ELM output of CQL libraries using profile-informed authoring is in terms of the base FHIR resources. Note that for implementations that support profile-informed CQL, this means that the result of retrieve expressions must respect the profile stated in thetemplateId
element of the retrieve. This is not to say that the FHIR resource must declare profiles to which they conform, only that with profile-informed authoring, there is an expectation that the ELM expects that FHIR resources returned through a retrieve will conform to the stated profiles. How that conformance is guaranteed is left up to implementations.
In addition, to support more fine-grained control over the process of producing ModelInfo from FHIR StructureDefinitions, this implementation guide defines several ModelInfo-related extensions: