A quality measure is a rate with three parts, written down before any SQL. Cedar Ridge's own diabetes measure, used for practice here (not a HEDIS specification), reads:
- Denominator: patients with type 2 diabetes, meaning an E11 code on any encounter from January to June 2026.
- Exclusions: patients aged 76 or older on 30 June 2026 come out of the denominator; the measure covers adults up to 75.
- Numerator: patients left in the denominator whose latest A1c in the half-year is below 8.0%.
Measures count patients, not encounters or lab rows, so build one row per patient first:
SELECT DISTINCT e.patient_id
FROM hd_diagnoses d
JOIN hd_encounters e ON e.encounter_id = d.encounter_id
WHERE d.icd10_code LIKE 'E11%';
The pitfalls: counting diagnosis rows instead of patients, applying an exclusion to the numerator only, and taking any A1c below 8.0 instead of the latest one. The course sets no clinical targets: 8.0 is part of this measure's definition.
Patients, not diagnosis rows, with an E11 code.