23.1.1Table of Contents

 

23.1.2Introduction

 

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.

23.1.2.1CQL Implementation Guides

23.1.2.2Clinical Reasoning Operations

Smile CDR provides implementations of operations using CQL in DSTU3 and R4:

23.1.3CQL Module

 

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.

23.1.4CQL Evaluate Operation

 
  • This operation is defined to support evaluating CQL expressions directly via an operation
  • Start DQM Module in order to activate operation in CDR

23.1.4.1CQL Evaluate Operation Parameters

ParameterSupportedDescription
subjectSubject 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
expressionExpression to be evaluated. Note that this is an expression of CQL, not the text of a library with definition statements.
parametersAny 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.
libraryA 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).
dataData 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 EndpointAn 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.
contentEndpointAn 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.
terminologyEndpointAn 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.
contentnon-spec parameter using an inline CQL file

23.1.4.2CQL Operation Examples

Examples of using the $cql operation

23.1.4.2.1Loaded Library, expression

  • assumes Library is loaded in server

  • API Request

POST https://localhost/fhir_request/$cql?subject=Patient/numer-EXM130-Patient-1
  • Parameters in Body of Post
{
  "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"
                    }
                ]
        }
      }
  ]       
}
  • Response showing subject did not meet criteria of expression
{
    "resourceType": "Parameters",
    "parameter": [
        {
            "name": "return",
            "valueBoolean": false
        }
    ]
}

23.1.4.2.2Inline CQL expression

  • API Request
GET https://localhost/fhir_request/$cql?expression=Interval[Today() - 2 years, Today())
  • Response
{
    "resourceType": "Parameters",
    "parameter": [
        {
            "name": "return",
            "valuePeriod": {
                "start": "2022-03-05T00:00:00+00:00",
                "end": "2024-03-04T00:00:00+00:00"
            }
        }
    ]
}

23.1.5Library Evaluate Operation

 
  • This operation is defined to support evaluating the contents of a library directly via an operation
  • Start DQM Module in order to activate operation in CDR

23.1.5.1Library Evaluate Operation Parameters

ParameterSupportedDescription
subjectSubject 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
expressionExpression(s) to be evaluated. If no expression names are provided, the operation evaluates all public expression definitions in the library
parametersAny 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.
dataData 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.
dataEndpointAn 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.
contentEndpointAn 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.
terminologyEndpointAn 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.

23.1.5.2Evaluate Whole Library Resource with Subject

  • Request
GET https://localhost/fhir_request/Library/ColorectalCancerScreeningsFHIR/$evaluate?subject=Patient/numer-EXM130-Patient-1
  • Response
{
    "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"
            }
        }
    ]
}

23.1.5.3Evaluate Library Resource Expression with Subject

  • Request
GET https://localhost/fhir_request/Library/ColorectalCancerScreeningsFHIR/$evaluate?subject=Patient/numer-EXM130-Patient-1&expression=Numerator
  • Response
{
    "resourceType": "Parameters",
    "parameter": [
        {
            "name": "Numerator",
            "valueBoolean": false
        }
    ]
}

23.1.6Usage

 
  • CQL Module should be enabled on the admin page of SmileCDR. Once it is enabled after selecting the required values for the properties that needs to be applied to the other modules, the configurations are needed to be saved and the module need to be restarted.