Clinical Quality Language (CQL) is a high-level, domain-specific language focused on clinical quality and targeted at measure and decision support artifact authors. Smile CDR has an embedded CQL engine allowing the evaluation of clinical knowledge artifacts that use CQL to describe their logic.
A more detailed description of CQL is available at the CQL Specification Implementation Guide
The FHIR Clinical Reasoning module defines a set of resources, profiles, operations, etc. that can be used to work with clinical knowledge within FHIR. Smile CDR provides implementation for some of those operations, described in more detail below.
Smile CDR provides implementations of operations using CQL in DSTU3 and R4:
CQL module is used to configure CQL options that control how the CQL is executed and how the errors are reported during expression evaluation.
This module is to capture and set the CQL options to be used by other components or modules.
Following are the modules identified to be dependent on CQL properties module.
NOTE: The values set for the cql properties are applied for all the dependent modules. See Module for specific configuration options.
Parameter | Supported | Description |
---|---|---|
subject | ✓ | Subject for which the expression will be evaluated. This corresponds to the context in which the expression will be evaluated and is represented as a relative FHIR id (e.g. Patient/123), which establishes both the context and context value for the evaluation |
expression | ✓ | Expression to be evaluated. Note that this is an expression of CQL, not the text of a library with definition statements. |
parameters | ✓ | Any input parameters for the expression. Parameters defined in this input will be made available by name to the CQL expression. Parameter types are mapped to CQL as specified in the Using CQL section of this implementation guide. If a parameter appears more than once in the input Parameters resource, it is represented with a List in the input CQL. If a parameter has parts, it is represented as a Tuple in the input CQL. |
library | ✓ | A library to be included. The library is resolved by url and made available by name within the expression to be evaluated. |
useServerData | Whether to use data from the server performing the evaluation. If this parameter is true (the default), then the operation will use data first from any bundles provided as parameters (through the data and prefetch parameters), second data from the server performing the operation, and third, data from the dataEndpoint parameter (if provided). If this parameter is false, the operation will use data first from the bundles provided in the data or prefetch parameters, and second from the dataEndpoint parameter (if provided). | |
data | ✓ | Data to be made available to the library evaluation. This parameter is exclusive with the prefetchData parameter (i.e. either provide all data as a single bundle, or provide data using multiple bundles with prefetch descriptions). |
prefetchData | Data to be made available to the library evaluation, organized as prefetch response bundles. Each prefetchData parameter specifies either the name of the prefetchKey it is satisfying, a DataRequirement describing the prefetch, or both. | |
data Endpoint | ✓ | An endpoint to use to access data referenced by retrieve operations in the library. If provided, this endpoint is used after the data or prefetchData bundles, and the server, if the useServerData parameter is true. |
contentEndpoint | ✓ | An endpoint to use to access content (i.e. libraries) referenced by the library. If no content endpoint is supplied, the evaluation will attempt to retrieve content from the server on which the operation is being performed. |
terminologyEndpoint | ✓ | An endpoint to use to access terminology (i.e. valuesets, codesystems, and membership testing) referenced by the library. If no terminology endpoint is supplied, the evaluation will attempt to use the server on which the operation is being performed as the terminology server. |
content | ✓ | non-spec parameter using an inline CQL file |
Examples of using the $cql operation
assumes Library is loaded in server
API Request
POST https://localhost/fhir_request/$cql?subject=Patient/numer-EXM130-Patient-1
{
"resourceType": "Parameters",
"parameter":[
{
"name": "expression",
"valueString": "ColorectalCancerScreeningsFHIR.Numerator"
},
{
"name": "library",
"resource": {
"resourceType": "Parameters",
"parameter": [
{
"name": "name",
"valueString": "ColorectalCancerScreeningsFHIR"
},
{
"name": "url",
"valueCanonical": "https://localhost/fhir_request/Library/ColorectalCancerScreeningsFHIR|0.0.003"
}
]
}
}
]
}
{
"resourceType": "Parameters",
"parameter": [
{
"name": "return",
"valueBoolean": false
}
]
}
GET https://localhost/fhir_request/$cql?expression=Interval[Today() - 2 years, Today())
{
"resourceType": "Parameters",
"parameter": [
{
"name": "return",
"valuePeriod": {
"start": "2022-03-05T00:00:00+00:00",
"end": "2024-03-04T00:00:00+00:00"
}
}
]
}
Parameter | Supported | Description |
---|---|---|
subject | ✓ | Subject for which the expression will be evaluated. This corresponds to the context in which the expression will be evaluated and is represented as a relative FHIR id (e.g. Patient/123), which establishes both the context and context value for the evaluation |
expression | ✓ | Expression(s) to be evaluated. If no expression names are provided, the operation evaluates all public expression definitions in the library |
parameters | ✓ | Any input parameters for the expression. Parameters defined in this input will be made available by name to the CQL expression. Parameter types are mapped to CQL as specified in the Using CQL section of this implementation guide. If a parameter appears more than once in the input Parameters resource, it is represented with a List in the input CQL. If a parameter has parts, it is represented as a Tuple in the input CQL. |
data | ✓ | Data to be made available to the library evaluation. This parameter is exclusive with the prefetchData parameter (i.e. either provide all data as a single bundle, or provide data using multiple bundles with prefetch descriptions). |
prefetchData | Data to be made available to the library evaluation, organized as prefetch response bundles. Each prefetchData parameter specifies either the name of the prefetchKey it is satisfying, a DataRequirement describing the prefetch, or both. | |
dataEndpoint | ✓ | An endpoint to use to access data referenced by retrieve operations in the library. If provided, this endpoint is used after the data or prefetchData bundles, and the server, if the useServerData parameter is true. |
contentEndpoint | ✓ | An endpoint to use to access content (i.e. libraries) referenced by the library. If no content endpoint is supplied, the evaluation will attempt to retrieve content from the server on which the operation is being performed. |
terminologyEndpoint | ✓ | An endpoint to use to access terminology (i.e. valuesets, codesystems, and membership testing) referenced by the library. If no terminology endpoint is supplied, the evaluation will attempt to use the server on which the operation is being performed as the terminology server. |
GET https://localhost/fhir_request/Library/ColorectalCancerScreeningsFHIR/$evaluate?subject=Patient/numer-EXM130-Patient-1
{
"resourceType": "Parameters",
"parameter": [
{
"name": "Denominator",
"valueBoolean": false
},
{
"name": "Denominator Exclusions"
},
{
"name": "Initial Population",
"valueBoolean": false
},
{
"name": "Numerator",
"valueBoolean": false
},
{
"name": "Patient",
"resource": {
"resourceType": "Patient",
"id": "numer-EXM130-Patient-1",
"meta": {
"versionId": "1",
"lastUpdated": "2024-03-04T15:39:05.393+00:00",
"source": "#jHv5rnS3TIf8vzxr",
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
]
},
"extension": [
{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race",
"extension": [
{
"url": "ombCategory",
"valueCoding": {
"system": "urn:oid:2.16.840.1.113883.6.238",
"code": "2028-9",
"display": "Asian"
}
}
]
},
{
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
"extension": [
{
"url": "ombCategory",
"valueCoding": {
"system": "urn:oid:2.16.840.1.113883.6.238",
"code": "2135-2",
"display": "Hispanic or Latino"
}
}
]
}
],
"identifier": [
{
"use": "usual",
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "MR",
"display": "Medical Record Number"
}
]
},
"system": "http://hospital.smarthealthit.org",
"value": "999999992"
}
],
"name": [
{
"family": "Blitz",
"given": [
"Don"
]
}
],
"gender": "male",
"birthDate": "1965-01-01",
"generalPractitioner": [
{
"reference": "Practitioner/practitioner-group-org-1"
}
]
}
},
{
"name": "SDE Ethnicity",
"valueCoding": {
"system": "urn:oid:2.16.840.1.113883.6.238",
"code": "2135-2",
"display": "Hispanic or Latino"
}
},
{
"name": "SDE Race",
"valueCoding": {
"system": "urn:oid:2.16.840.1.113883.6.238",
"code": "2028-9",
"display": "Asian"
}
},
{
"name": "SDE Sex",
"valueCoding": {
"system": "http://hl7.org/fhir/v3/AdministrativeGender",
"code": "M",
"display": "Male"
}
}
]
}
GET https://localhost/fhir_request/Library/ColorectalCancerScreeningsFHIR/$evaluate?subject=Patient/numer-EXM130-Patient-1&expression=Numerator
{
"resourceType": "Parameters",
"parameter": [
{
"name": "Numerator",
"valueBoolean": false
}
]
}