Purpose
Measure Builder defines which aggregate clinical and operational values AMCDR exposes for HMIS dashboards, surveillance monitoring, service KPIs, and Grafana clinical metric panels. It is configured under Analytics → HMIS → Measure Builder.
Create programme indicators such as births, death notifications, reportable laboratory results, and referral counts as AQL or saved-query definitions. Administrators can then update national, regional, facility, and programme reporting rules without changing platform code.
When an indicator depends on operational state created from a clinical template, configure the template workflow projection first. See Workflow Foundation Bindings for the openEHR-to-foundation targets used by birth, NICU, admission, transfer, discharge, emergency, and death workflows. If the indicator depends on derived facts or rule outcomes, configure the rule process under Clinical Fact and Guideline Guardrail Workflows.
Definition governance
Each metric has a stable key, display name, source type, refresh interval, unit, status, labels, sensitivity policy, and sample history.
Fast monitoring path
Prometheus scrapes stored aggregate samples. It does not execute AQL and does not receive patient-level rows.
Safe clinical labels
Labels are bounded administrative dimensions such as domain, indicator set, or facility group. Patient identifiers and composition identifiers must not be labels.
Measure Builder UI
Measure Builder supports search, status/source filtering, create/edit, manual refresh, due processing, sample review, privacy suppression, and source review.
Registry Workflow
- Open Analytics → HMIS → Measure Builder.
- Review existing definitions and built-in collectors.
- Create a measure from a built-in collector, openEHR AQL aggregate, saved AQL aggregate, or governed operational workflow calculation.
- Add bounded static labels such as
domain=laboratory,indicator_set=hmis, orprogramme=maternal_child_health. - Set sensitivity and minimum group size where small counts risk exposing sensitive information.
- Save as
draft, refresh manually, review samples, then activate when validated. - Use Process due to run due metrics immediately, or allow the scheduler to collect samples on interval.
- Confirm values appear in the AMCDR Clinical Metrics Grafana folder through
amcdr_clinical_metric_value,amcdr_clinical_metric_status, andamcdr_clinical_metric_updated_age_seconds.
Definition Types
| Source kind | Use when | Configuration |
|---|---|---|
builtin | The value is a stable platform-wide aggregate such as EHR records, active patients, active visits, open encounters, active alerts, or open critical lab alerts. | Select a built-in source. Add labels, unit, refresh interval, and status. |
aql | The metric depends on openEHR composition content, templates, archetypes, or clinical facts. | Write an aggregate AQL query that returns one numeric value as the first result. Add parameters for template IDs or date windows. |
saved_query | The metric reuses a governed saved query that is already reviewed and versioned. | Enter the saved query key. The saved query must return one numeric aggregate value. |
operational | The measure uses governed visit/encounter workflow times or a distinct-patient coded cohort. | Select admission stay, outpatient facility time, encounter cycle time, or coded patient count; set aggregation and named period/facility/code parameters. |
Label Policy
Metric labels determine how Grafana groups values. They must be stable, low-cardinality, and non-identifying. AMCDR always includes the metric key and unit. Administrators add static labels that describe the metric domain or reporting set.
| Allowed label pattern | Examples |
|---|---|
| Clinical or operational domain | domain=laboratory, domain=encounter, domain=vital_events |
| Indicator set | indicator_set=hmis, indicator_set=civil_registration |
| Programme or reporting family | programme=maternal_child_health, programme=surveillance |
Do not use patient names, MRNs, EHR IDs, encounter IDs, accession numbers, composition UIDs, raw query text, or clinical result values as labels. High-cardinality or identifying labels make monitoring unsafe and slow.
Sensitivity and Suppression
Some clinical aggregate counts are sensitive even when no patient identifiers are exposed. Use Sensitive metric and Minimum group size for domains such as HIV, mental health, genetics, safeguarding, pregnancy, rare disease, violence, and small-population surveillance. When a non-zero value is below the configured minimum group size, AMCDR suppresses the sample instead of exporting a misleading or privacy-risking value.
Sample AQL Definitions
The repository includes sample definition data in examples/clinical_metrics/clinical_metric_definitions.json for implementers who import seed definitions. In the application UI, administrators configure the same information through standard fields and name/value rows.
| Field | Example value |
|---|---|
| Metric key | birth_records |
| Name | Birth records |
| Status | Draft until validated, then Active |
| Source kind | AQL |
| AQL aggregate query | SELECT COUNT(c/uid/value) AS value FROM EHR e CONTAINS COMPOSITION c WHERE c/archetype_details/template_id/value = $birth_template_id |
| Query parameter | birth_template_id = neonatal_birth_record.v1 |
| Metric labels | domain=vital_events; indicator_set=civil_registration |
| Unit and refresh | count; refresh every 300 seconds |
Operational States
| Status | Meaning |
|---|---|
draft | The definition is being prepared or validated. It must not be treated as production evidence. |
active | The scheduler processes the definition and Prometheus exports the latest sample. |
paused | The definition is retained but not processed automatically. |
retired | The definition is no longer operational. Keep it for audit/history when needed. |
API Surface
Clinical metric management is an administrator function. The standard dashboard scrape remains GET /metrics.
| Route | Purpose |
|---|---|
GET /clinical-metrics/builtin | List built-in aggregate collectors. |
GET /clinical-metrics/definitions | List configured definitions and latest sample summaries. |
POST /clinical-metrics/definitions | Create a governed definition. |
PATCH /clinical-metrics/definitions/{metric_key} | Update a definition’s source, labels, status, interval, sensitivity, or metadata. |
DELETE /clinical-metrics/definitions/{metric_key} | Retire a definition. |
POST /clinical-metrics/definitions/{metric_key}/refresh | Run one metric immediately and store a sample. |
GET /clinical-metrics/definitions/{metric_key}/samples | Review recent samples and failures. |
POST /clinical-metrics/process-due | Process due active definitions. |
GET /clinical-metrics/prometheus-preview | Preview registry metric lines included in /metrics. |
Production Guidance
- Keep clinical metric definitions versioned and reviewed like other reporting assets.
- Use draft status while validating AQL, saved queries, labels, units, and suppression rules.
- Keep refresh intervals realistic. High-frequency AQL metrics increase database load.
- Use saved queries when an indicator definition is shared by HMIS, printable reports, and dashboard metrics.
- Do not create duplicate definitions for the same KPI unless the reporting policy intentionally requires separate scopes or labels.
- Review failed, stale, or suppressed samples before using metric values in operational decisions.