For AI agents: the documentation index is at /docs/aidbox/llms.txt. A Markdown version of this page is available at /docs/aidbox/modules/sql-on-fhir/operation-evaluate-measure.md or by requesting it with the Accept: text/markdown header.
Aidbox Docs

$evaluate-measure operation

Requires fhir-schema mode.

This functionality is available in Aidbox versions 2611 and later.

The $evaluate-measure operation computes a MeasureReport for a Measure over a period. Aidbox evaluates the Measure with SQL: each population points at a boolean column of a SQLQuery Library, and Aidbox counts the rows where the column is true. CQL expressions are not evaluated.

FHIR defines the operation in Measure/$evaluate-measure.

Endpoints

LevelEndpointMeasure source
InstanceGET or POST [base]/fhir/Measure/[id]/$evaluate-measureThe stored Measure with this id
TypeGET or POST [base]/fhir/Measure/$evaluate-measureThe Measure with the canonical in measure

At the type level, Aidbox looks for a stored Measure with the canonical first, then for a Measure from a FHIR package in the Artifact Registry. A canonical without |version resolves to the latest version.

POST takes a Parameters resource in the body. GET takes the same parameters in the query string.

Parameters

ParameterRequiredDescription
periodStartyesStart of the measurement period: YYYY, YYYY-MM, or YYYY-MM-DD. The period starts on the first day of it.
periodEndyesEnd of the measurement period, in the same formats. The period includes the whole last day, month, or year.
measureat the type levelCanonical of the Measure: url or url|version.
subjectnoPatient/<id>. Repeat it to count several patients. Aidbox keeps only the Library rows whose patient_id matches.
reportTypenosubject (or individual) returns an individual report for one subject. population (or summary) returns a summary report. Defaults to subject when the request has a subject and to population otherwise.
parametersnoA Parameters resource with values for the other parameters of the Library.

Aidbox answers 400 for reportType=subject-list and for the practitioner, provider, location, and lastReceivedOn parameters, which it doesn't support.

How Aidbox evaluates a Measure

The Library returns one row per patient: a patient_id column and a boolean column per population. Aidbox passes the period to the Library as two dateTime parameters, measurement_period_start and measurement_period_end, in UTC with the end excluded: periodStart=2026&periodEnd=2026 binds 2026-01-01T00:00:00Z and 2027-01-01T00:00:00Z. Declare them in Library.parameter to use the period in SQL.

Each population of the Measure names its column in an application/sql expression:

  • criteria.language is application/sql, or criteria carries a cqf-alternativeExpression extension with an application/sql expression;
  • expression is the column name;
  • reference is the canonical of the SQLQuery Library. All populations use one Library. Without reference, Aidbox uses the SQLQuery Library listed in Measure.library.

Aidbox reads the scoring from the cqfm-scoring extension of a group, then from group.scoring, then from Measure.scoring. It supports two scorings:

  • cohort: each population counts the rows where its column is true;
  • proportion: a population counts a row only if the row also belongs to the populations it depends on, as in CQF Measures. For example, numerator counts rows that are in initial-population and denominator, aren't in denominator-exclusion, and have numerator set to true. The report carries measureScore: (numerator - numerator-exclusion) / (denominator - denominator-exclusion - denominator-exception). Aidbox omits measureScore when the divisor is 0.

Example

The Library reads a ViewDefinition with the id, gender, and birth_date columns of Patient. A patient is in the initial population when born before the period ends, in the denominator when born before it starts, and in the numerator when also female:

SELECT id AS patient_id,
       birth_date::date < ((:measurement_period_end)::timestamptz AT TIME ZONE 'UTC')::date AS initial_population,
       birth_date::date < ((:measurement_period_start)::timestamptz AT TIME ZONE 'UTC')::date AS denominator,
       birth_date::date < ((:measurement_period_start)::timestamptz AT TIME ZONE 'UTC')::date
         AND gender = 'female' AS numerator
FROM patient
1

Create the SQLQuery Library with the SQL above in content.data:

POST /fhir/Library
Content-Type: application/json

{
  "resourceType": "Library",
  "id": "female-patients-lib",
  "url": "https://example.org/Library/female-patients-lib",
  "version": "1.0.0",
  "status": "active",
  "meta": {
    "profile": ["https://sql-on-fhir.org/ig/StructureDefinition/SQLQuery"]
  },
  "type": {
    "coding": [{
      "system": "https://sql-on-fhir.org/ig/CodeSystem/LibraryTypesCodes",
      "code": "sql-query"
    }]
  },
  "parameter": [
    {"name": "measurement_period_start", "use": "in", "type": "dateTime", "min": 1, "max": "1"},
    {"name": "measurement_period_end", "use": "in", "type": "dateTime", "min": 1, "max": "1"}
  ],
  "relatedArtifact": [{
    "type": "depends-on",
    "resource": "https://example.org/ViewDefinition/patient_view",
    "label": "patient"
  }],
  "content": [{
    "contentType": "application/sql",
    "data": "U0VMRUNUIGlkIEFTIHBhdGllbnRfaWQsCiAgICAgICBiaXJ0aF9kYXRlOjpkYXRlIDwgKCg6bWVhc3VyZW1lbnRfcGVyaW9kX2VuZCk6OnRpbWVzdGFtcHR6IEFUIFRJTUUgWk9ORSAnVVRDJyk6OmRhdGUgQVMgaW5pdGlhbF9wb3B1bGF0aW9uLAogICAgICAgYmlydGhfZGF0ZTo6ZGF0ZSA8ICgoOm1lYXN1cmVtZW50X3BlcmlvZF9zdGFydCk6OnRpbWVzdGFtcHR6IEFUIFRJTUUgWk9ORSAnVVRDJyk6OmRhdGUgQVMgZGVub21pbmF0b3IsCiAgICAgICBiaXJ0aF9kYXRlOjpkYXRlIDwgKCg6bWVhc3VyZW1lbnRfcGVyaW9kX3N0YXJ0KTo6dGltZXN0YW1wdHogQVQgVElNRSBaT05FICdVVEMnKTo6ZGF0ZQogICAgICAgICBBTkQgZ2VuZGVyID0gJ2ZlbWFsZScgQVMgbnVtZXJhdG9yCkZST00gcGF0aWVudA=="
  }]
}
2

Create a proportion Measure whose populations name the Library columns:

PUT /fhir/Measure/female-patients
Content-Type: application/json

{
  "resourceType": "Measure",
  "id": "female-patients",
  "url": "https://example.org/Measure/female-patients",
  "status": "active",
  "scoring": {
    "coding": [{
      "system": "http://terminology.hl7.org/CodeSystem/measure-scoring",
      "code": "proportion"
    }]
  },
  "group": [{
    "id": "g-1",
    "population": [
      {
        "code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "initial-population"}]},
        "criteria": {
          "language": "application/sql",
          "expression": "initial_population",
          "reference": "https://example.org/Library/female-patients-lib|1.0.0"
        }
      },
      {
        "code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "denominator"}]},
        "criteria": {"language": "application/sql", "expression": "denominator"}
      },
      {
        "code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "numerator"}]},
        "criteria": {"language": "application/sql", "expression": "numerator"}
      }
    ]
  }]
}

The denominator and numerator populations have no reference, so they use the Library of initial-population.

3

Evaluate the Measure for 2026:

GET /fhir/Measure/female-patients/$evaluate-measure?periodStart=2026&periodEnd=2026

With three patients born before 2027, two of them before 2026, and one of those two female, Aidbox returns:

{
  "resourceType": "MeasureReport",
  "status": "complete",
  "type": "summary",
  "measure": "https://example.org/Measure/female-patients",
  "date": "2026-12-03T10:00:00Z",
  "period": {"start": "2026", "end": "2026"},
  "group": [{
    "id": "g-1",
    "population": [
      {"code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "initial-population"}]}, "count": 3},
      {"code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "denominator"}]}, "count": 2},
      {"code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/measure-population", "code": "numerator"}]}, "count": 1}
    ],
    "measureScore": {"value": 0.5}
  }]
}

Add subject=Patient/<id> to get an individual report for one patient: each count is 1 or 0, and the report carries subject.

To run the evaluation on a read-only replica, send the request with the x-use-ro-replica header. In Aidbox UI notebooks, a measure cell runs this operation and renders the report.

Errors

StatusWhen
400periodStart or periodEnd is missing or has another format, periodEnd is before periodStart, a single-value parameter repeats, subject isn't Patient/<id>, reportType=subject comes with no subject or several subjects, parameters sets measurement_period_start or measurement_period_end, measure is missing at the type level, or a Library parameter is missing or has the wrong type.
404The Measure doesn't exist, or a Library dependency doesn't resolve.
422The Measure has no group, a group has no scoring or a scoring other than proportion and cohort, a population has no code or no single application/sql expression, the populations reference different Libraries, the Library is missing or isn't a SQLQuery Library, the Library result has no column for a population or the column isn't boolean, or the Library SQL fails.

The body of an error response is an OperationOutcome with the reason in diagnostics.

Last updated: