This page is part of the Using CQL with FHIR Implementation Guide (v2.0.0: STU2) based on FHIR (HL7® FHIR® Standard) R4. This is the current published version in its permanent home (it will always be available at this URL). For a full list of available versions, see the Directory of published versions
Page standards status: Trial-use |
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 FHIR-ModelInfo) defines these implicit conversions.
To make use of these implicit conversions within a CQL library, include the FHIRHelpers library:
include hl7.fhir.uv.cql.FHIRHelpers version '4.0.1'
NOTE: Previous versions of the FHIRHelpers library were included A) as embedded resources in the CQL-to-ELM translator (referenced without a namespace and the version
4.0.1
), as well as B) in the CQFramework Common implementation guide (referenced with the namespacefhir.cqf.common
and the version4.0.1
). In both these cases, the content is the same as what is now published in this implementation guide, with the namespacehl7.fhir.uv.cql
and the version4.0.1
. Note that the version here is explicitly aligned with the FHIR specification version, because the FHIRHelpers library is generated as part of the process of constructing the model information and so is cohesively tied to the FHIR specification version.
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.
This implementation guide includes FHIR-ModelInfo, a ModelInfo for FHIR version 4.0.1.
NOTE: Previous versions of the FHIR-ModelInfo library were included A) as embedded resources in the CQL-to-ELM translator (referenced without a namespace and the semantic version of the FHIR specification being modeled), as well as B) in the CQFramework Common implementation guide (referenced with the canonical reference
http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
). The content of the 4.0.1 version of this ModelInfo is the same as what is now published in this implementation guide, with the canonical referencehttp://hl7.org/fhir/uv/cql/Library/FHIR-ModelInfo|4.0.1
. Note the model information version here is explicitly aligned with the FHIR specification version being modeled, not the version of this implementation guide. This is to avoid any confusion about what version of the FHIR model is being used in a given CQL library.
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.
There are multiple approaches to generating ModelInfo based on the profiles in an implementation guide. The first of these is Derived ModelInfo, which performs the following step for each profile:
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 StructureDefinition (without the prefix if the name is prefixed with the modelName)baseType
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 extenssionFor example, processing the US Core 7.0.0 implementation guide produces a ModelInfo with a ClassInfo for the EncounterProfile:
using USCore version '7.0.0'
...
define "Encounters":
["EncounterProfile"]
Conceptually, this expression results in any Encounter resource that conforms to the US Core Encounter Profile.
NOTE: How systems implement the requirement that retrieve expressions only result in resource instances that conform to the requested profile is not prescribed, because there are many different ways this requirement can be achieved. Because profile conformance testing can be expensive, there are performance tradeoffs associated with how this is done in any particular environment.
The second widely used approach to generating ModelInfo based on the profiles in an implementation guide is called Profile-informed Authoring, and takes greater advantage of the information defined in profiles, including slices and extensions. However, it also "flattens" the types produced in the ModelInfo, so that authors are presented with a complete picture of FHIR from the perspective of the particular implementation guide. This approach has some advantages, but it also has the primary disadvantage of preventing reuse of logic across implementation guides, because profiles in each implementation guide result in entirely separate classes in CQL.
This approach has been used for artifacts authored with USCore and QICore versions 6 and below, and is constructed by performing the following steps for each profile:
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 type
(as opposed to the baseDefinition
used for Derived ModelInfo)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
or codeOptions
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 or codeOptions 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:
NOTE: All the setting information provided by the StructureDefinition extensions (cqf-modelInfo-…) can be provided directly in the cqf-modelInfoSettings Parameters resource to support the case where the StructureDefinition resources being used for generation are already published or otherwise not under the authoring control of the model information author.