Executing Digital Quality Measures (dQMs) - $cql, $evaluate, $evaluate-measure, $data-requirementsο
Note
The features described on this page are available in the following Firely Server editions:
Firely dQM - π / πΊπΈ
Important
Please see Intro to Digital Quality Measures for an introduction to Digital Quality Reporting in FHIR.
FHIR provides several operations for executing Digital Quality Measures (dQMs), either partially (e.g. evaluating expressions) or fully (evaluating a complete measure). The appropriate operation depends on the specific use case and execution goal:
Library/$evaluateis most commonly used for debugging purposes. dQMs frequently reference multipleLibraryresources to encapsulate modular logic. When a measure produces unexpected resultsβsuch as an incorrect or zero scoreβit is often useful to investigate why a particular subject meets or fails to meet specific population criteria (e.g., initial population, denominator, numerator). In such cases, it can be helpful to execute a targeted set of CQL expressions or evaluate specific sub-libraries within the measure. This allows implementers to isolate and verify individual components of the logic without executing the entire measure.Measure/$measure-evaluateis the primary operation for executing a digital quality measure (dQM) as a whole. This operation evaluates aMeasureresource against a specified subject (such as a patient, group) using the measurement period and any associatedLibraryparameters.Measure/$evaluate-measureis typically used in production or formal testing scenarios to generate actual measure scores. It is also suitable for automated execution in quality reporting workflows. UnlikeLibrary/$evaluate, which targets specific expressions,Measure/$evaluate-measureexecutes the full population logic and scoring methodology defined in the measure, making it the most comprehensive method for end-to-end dQM evaluation.$cqlallows direct execution of CQL expressions, either inline or from referenced libraries. It is useful for rapid testing or prototyping when measure logic needs to be validated independently of aMeasureresource.
For the preperation of the execution data-requirements can be gathered using the following operations:
Library/$data-requirementsretrieves a structured representation of the data required to evaluate a measure, making it a supporting operation for bothLibrary/$evaluateandMeasure/$evaluate-measure. This operation identifies the necessary FHIR data types and elements, including value sets, code filters, and date constraints. It returns aLibraryresource containingDataRequirementelements, which describe the expected inputs for measure evaluation. This operation is particularly useful during implementation, data mapping, and integration planning, as it helps clarify what data must be available for successful execution of a digital quality measure.Measure/$data-requirementsfunctions identically, but aggregates the data requirements across all libraries referenced by the measure, providing a complete picture of the inputs needed for measure evaluation.
Library/$evaluateο
The Library/$evaluate operation executes one or more named CQL expressions within a FHIR Library resource in a given data context (e.g. a patient), and returns the evaluated results. It is primarily used to inspect and debug the logic underlying digital quality measures by allowing targeted execution of individual expressions without running the full measure.
Overviewο
- Operation name
Library/$evaluate- FHIR specification
- OperationDefinition
http://hl7.org/fhir/uv/cql/OperationDefinition/cql-library-evaluate- Scope
Invocation level:
type/instanceSupported resource type(s):
LibraryIdempotent:
yesAffects server state:
no
- HTTP methods
POST(type and instance level)GET(type and instance level, when all parameters can be provided as query parameters)
Configurationο
The Library/$evaluate operation is provided by the
Vonk.Plugin.Cql.Operations.Library.Evaluate namespace.
You can enable or disable this operation by including or excluding this namespace in the Firely Server pipeline options. See Available features and configuration for more information on configuring available plugins.
You can configure the behavior of this operation using the
LibraryEvaluateOperation section in the appsettings.
Database requirementsο
Execution of dQMs relies on retrieving clinical data from the Firely Server
data store. Internally, Firely Server uses the $everything operation to
collect all relevant data for a subject.
This functionality is only supported when the data store is backed by MongoDB or SQL Server. Therefore, to execute dQMs against data stored in Firely Server, the primary FHIR data database must use either MongoDB or SQL Server.
In addition, the Vonk.Plugin.PatientEverything plugin must be enabled
in the pipeline options, as it provides the $everything operation used
during data retrieval. See Available features and configuration for more information
on configuring available plugins.
The administration database (used for conformance resources such as
Library and Measure) can still be hosted on SQLite.
Alternatively, you can configure Firely Server to use only external data
sources by enabling the RemoteDataEndpointsOnly setting. In that case,
no local data retrieval (and thus no $everything support) is required.
External data endpointsο
Firely Server can retrieve clinical and claims data from external FHIR endpoints
during execution of Library/$evaluate.
This is used when the useServerData parameter is set to false in a request.
In that case, data is not retrieved from the local Firely Server database, but from
a configured external endpoint.
"LibraryEvaluateOperation": {
"RemoteDataEndpointsOnly": false,
"DataEndpoint": [
//{
// "Endpoint": "<base url>",
// "MediaType": "application/fhir+json",
// "RemoteDataEndpointAuthentication": "Jwt",
// "ClientId": "",
// "ClientSecret": "",
// "TokenEndpoint": "",
// "Audience": "",
// "Scopes": "system/*.rs"
//}
"ForwardedHeaders": [
"X-Custom-Auth-Header"
]
]
}
The DataEndpoint setting defines a list of pre-configured external FHIR endpoints.
Each endpoint can be referenced in a request using the dataEndpoint parameter.
Any dataEndpoint parameter provided in a request must match one of the
configured endpoints.
Each DataEndpoint entry supports the following fields:
Endpoint: Base URL of the external FHIR serverMediaType: The FHIR media type to use for requests to this endpoint (application/fhir+jsonandapplication/fhir+xmlare supported)ClientId/ClientSecret: Credentials for authentication (if required)TokenEndpoint: OAuth2 token endpoint (used for JWT authentication)Audience: Optional audience claim for the access tokenScopes: Space-separated list of SMART on FHIR scopes. Since Firely Server uses aclient_credentialsflow, only system-level scopes should be used (e.g.system/*.rs).RemoteDataEndpointAuthentication: Defines how Firely Server authenticates against the endpoint. Supported values includeJWTandNone
Important
Firely Server expects that the response of the remote $everything operation
is returned as a single Bundle page. Pagination is not supported in this context,
and Firely Server will not follow additional pages (e.g. via link[relation="next"])
returned by the remote endpoint.
The ForwardedHeaders setting can be used to forward custom HTTP headers
from the incoming request to external data endpoints.
Any headers listed in ForwardedHeaders are copied from the original request
to Firely Server and included in outgoing requests to configured
DataEndpoint entries. This can be used to propagate request-specific context, such as correlation IDs
or custom authorization headers, to external systems.
Supported parametersο
Firely Server supports the following parameters:
Parameter |
Supported |
Type |
Cardinality |
Additional Notes |
|---|---|---|---|---|
|
β |
|
0..1 |
Specifies the Since v2.0.0, Versioned canonical references
are allowed, e.g.,
|
|
β |
|
0..1 |
In-line logic library that contains executable CQL logic. This Library will not be stored in Firely Server. It MAY only contain CQL and will be compiled dynamically. If ELM content is provided, it will be re-used. |
|
β |
|
0..1 |
Only Patient references are supported, may be omitted if no βcontext Patientβ is included in the library. |
|
β |
|
0..* |
The name of the expression to evaluate. If omitted, all expressions in the library are evaluated. CQL Access Modifier extensions are not taken into account. |
|
β |
|
0..1 |
Input parameters passed into the evaluation context. These will be mapped from FHIR data types to CQL data types according to the FHIR Type Mapping. Most notably, this includes passing in the measurement period parameter as a FHIR Period. |
|
β |
|
0..1 |
Return the library results as a string without mapping the CQL result data types back to FHIR. This is a proprietary parameter of Firely Server. |
|
β |
|
0..1 |
When When In both cases, any data passed
via the |
|
β |
|
0..1 |
Inline FHIR data bundle to use as the data context during evaluation. The bundle type SHOULD be
either |
|
β |
|
0..1 |
Used only when
The endpoint must be
pre-registered in
|
|
β |
Complex |
0..* |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
External terminology services should be configured via the Terminology services options. |
Important
If the Library references any ValueSet resources, they must be preloaded into the Firely Serverβs administration endpoint before executing the Library.
Output parametersο
The Library/$evaluate operation returns a Parameters resource containing
the results of the evaluated CQL expressions.
Parameter |
Type |
Cardinality |
Description |
|---|---|---|---|
|
Parameters |
1..1 |
A Parameters resource in which
each output parameter
corresponds to a named CQL
expression. Each entry
includes the expression name,
its evaluated value, and
optional type information via
an extension (
|
When to use this operationο
Use Library/$evaluate when you want to:
evaluate specific expressions within a Library
debug measure logic
inspect intermediate results of CQL execution
Example: Type-Level Library/$evaluate Invocationο
This example evaluates the bp-check-logic library (version 1.0.0) against a specific patient
and a defined measurement period using a POST request to the type-level operation.
Request
POST [base]/Library/$evaluate
Request Body
{
"resourceType": "Parameters",
"parameter": [
{
"name": "url",
"valueCanonical": "http://example.org/fhir/Library/bp-check-logic|1.0.0"
},
{
"name": "subject",
"valueString": "Patient/cql-patient-test"
},
{
"name": "parameters",
"resource": {
"resourceType": "Parameters",
"parameter": [
{
"name": "Measurement Period",
"valuePeriod": {
"start": "2023-01-01",
"end": "2023-12-01"
}
}
]
}
}
]
}
Response Body
Given matching input data (see Example Library for context), specifically, a Patient resource and an Observation with a code of 8480-6 from the LOINC CodeSystem, and an effectiveDateTime that falls within the measurement period β the following output will be returned:
{
"resourceType": "Parameters",
"parameter": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-cqlType",
"valueString": "Fhir"
}
],
"name": "Patient",
"resource": {
"resourceType": "Patient",
"id": "cql-blood-pressure-check-test-match",
"meta": {
"versionId": "d36e61f8-300a-4c2f-8247-9fb4a6837236",
"lastUpdated": "2025-05-23T18:32:44.106+00:00"
},
"birthDate": "1990-06-15"
}
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-cqlType",
"valueString": "Boolean"
}
],
"name": "HasBPReading",
"valueBoolean": true
},
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-cqlType",
"valueString": "Boolean"
}
],
"name": "AdultPatients",
"valueBoolean": true
}
]
}
Measure/$evaluate-measureο
The Measure/$evaluate-measure operation executes a complete digital quality measure (dQM) and returns the calculated results for a given subject or population. It evaluates all referenced Library resources, applies the defined population criteria (e.g. initial population, denominator, numerator), and computes the final measure score.
This operation is the primary mechanism for end-to-end measure evaluation and is typically used in production or formal testing scenarios.
Overviewο
- Operation name
Measure/$evaluate-measure- FHIR specification
- OperationDefinition
http://hl7.org/fhir/OperationDefinition/Measure-evaluate-measure- Scope
Invocation level:
type/instanceSupported resource type(s):
MeasureIdempotent:
yesAffects server state: conditional
- HTTP methods
POST(type level)GET(type level, when all parameters can be provided as query parameters)
Important
Invocation at the instance level ([base]/Measure/[id]/$evaluate-measure)
is not currently supported. Use the type-level operation with the
measure parameter instead.
Note
The operation can optionally affect server state depending on the persist parameter.
When persist is set to true, the generated MeasureReport is stored
on the server. By default (persist = false), the report is returned in the
response only and is not persisted.
Configurationο
The Measure/$evaluate-measure operation is provided by the
Vonk.Plugin.Cql.Operations.Measure.EvaluateMeasure namespace.
You can enable or disable this operation by including or excluding this namespace in the Firely Server pipeline options. See Available features and configuration for more information.
Supported parametersο
Firely Server supports the following parameters:
Parameter |
Supported |
Type |
Cardinality |
Additional Notes |
|---|---|---|---|---|
|
β |
|
0..1 |
Canonical URL of the Measure to evaluate. Required for type-level invocation. Versioned canonical references are allowed,
e.g.,
|
|
β |
|
1..1 |
Reference to the subject for which the measure is evaluated. Supported resource types are When a When a |
|
β |
|
1..1 |
Start of the measurement period. |
|
β |
|
1..1 |
End of the measurement period. |
|
β |
|
0..1 |
The type of measure report:
The If not specified, the default is
|
|
β |
|
0..1 |
See |
|
β |
|
0..1 |
See |
|
β |
|
0..1 |
See |
|
β |
|
0..1 |
See |
|
β |
|
0..1 |
When When This is a proprietary parameter of Firely Server. |
|
β |
|
0..1 |
Return the results as a string without mapping the CQL result data types back to FHIR. This is a proprietary parameter of Firely Server. |
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
Output parametersο
The operation returns a MeasureReport resource containing the evaluation results.
The report includes:
population counts (e.g. initial population, denominator, numerator)
measure score (if applicable)
subject-level or population-level results depending on
reportType
When to use this operationο
Use Measure/$evaluate-measure when you want to:
execute a full digital quality measure
calculate population membership and scores
generate results for reporting or submission
validate measure behavior in end-to-end scenarios
Example: Type-Level Measure Evaluationο
Request
POST [base]/Measure/$evaluate-measure
Request Body
{
"resourceType": "Parameters",
"parameter": [
{
"name": "url",
"valueCanonical": "http://example.org/fhir/Measure/ExampleMeasure|1.0.0"
},
{
"name": "subject",
"valueString": "Patient/cql-patient-test"
},
{
"name": "periodStart",
"valueDate": "2023-01-01"
},
{
"name": "periodEnd",
"valueDate": "2023-12-31"
}
]
}
Response Body
{
"resourceType": "MeasureReport",
"status": "complete",
"type": "individual",
"measure": "http://example.org/fhir/Measure/ExampleMeasure|1.0.0",
"subject": {
"reference": "Patient/cql-patient-test"
},
"period": {
"start": "2023-01-01",
"end": "2023-12-31"
},
"group": [
{
"population": [
{
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "initial-population"
}
]
},
"count": 1
},
{
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "denominator"
}
]
},
"count": 1
},
{
"code": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/measure-population",
"code": "numerator"
}
]
},
"count": 1
}
],
"measureScore": {
"value": 1.0
}
}
]
}
$cqlο
The $cql operation executes a CQL expression directly and returns the
evaluated result. It is useful for rapid testing or prototyping when CQL logic
needs to be validated independently of a Library or Measure resource.
Overviewο
- Operation name
$cql- FHIR specification
- OperationDefinition
http://hl7.org/fhir/uv/cql/OperationDefinition/cql-cql- Scope
Invocation level:
systemIdempotent:
yesAffects server state:
no
- HTTP methods
POST
Supported parametersο
Firely Server supports the following parameters:
Parameter |
Supported |
Type |
Cardinality |
Additional Notes |
|---|---|---|---|---|
|
β |
|
1..1 |
Specifies an inline CQL expression to be executed. Only a single statement is supported per request. It cannot operate within a context (e.g. Patient) and will not execute correctly if input parameters are needed. |
|
β |
|
0..1 |
Only Patient references are supported. |
|
β |
|
0..1 |
Input parameters passed into
the evaluation context. See
|
|
β |
|
0..1 |
Return the execution results as a string without mapping the CQL result data types back to FHIR. This is a proprietary parameter of Firely Server. |
|
β |
Complex |
0..* |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
Complex |
0..* |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
|
|
β |
|
0..1 |
Output parametersο
The operation returns a Parameters resource containing the result of the
evaluated CQL expression.
The result is returned in a parameter named return. The value is mapped back
to a FHIR data type, unless the proprietary raw parameter is set to true.
When to use this operationο
Use $cql when you want to:
quickly test a simple CQL expression
validate basic CQL syntax or behavior
prototype logic before moving it into a
Libraryexecute logic that does not require a full
Measureevaluation
Example: System-Level $cql Invocationο
This examples demonstrates a simple calculation executed via the dQM engine.
Request
POST [base]/$cql
Request Body
{
"resourceType": "Parameters",
"parameter": [
{
"name": "expression",
"valueString": "'Hello'&' '&'World'"
}
]
}
Response Body
{
"resourceType": "Parameters",
"parameter": [
{
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/cqf-cqlType",
"valueString": "String"
}
],
"name": "return",
"valueString": "Hello World"
}
]
}
