diff --git a/backend/src/main/resources/measures/audiogram.cql b/backend/src/main/resources/measures/audiogram.cql index 5a219fe..f8fb93e 100644 --- a/backend/src/main/resources/measures/audiogram.cql +++ b/backend/src/main/resources/measures/audiogram.cql @@ -11,14 +11,17 @@ parameter "Measurement Period" Interval context Patient define "In Hearing Conservation Program": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:hearing-enrollment' and x.code = 'hearing-enrollment')) define "Has Active Waiver": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:audiogram-waiver' and x.code = 'audiogram-waiver')) define "Most Recent Audiogram Date": Last( [Procedure] P + where exists(P.code.coding C where C.system = 'urn:workwell:vs:audiogram-procedures' and C.code = 'audiogram-procedure') sort by (performed as FHIR.dateTime) ).performed as FHIR.dateTime diff --git a/backend/src/main/resources/measures/cholesterol_ldl.cql b/backend/src/main/resources/measures/cholesterol_ldl.cql index 473df74..101c6ed 100644 --- a/backend/src/main/resources/measures/cholesterol_ldl.cql +++ b/backend/src/main/resources/measures/cholesterol_ldl.cql @@ -10,14 +10,17 @@ parameter "Measurement Period" Interval context Patient define "In Cholesterol Program": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:cholesterol-program' and x.code = 'cholesterol-enrolled')) define "Has Medical Exemption": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:cholesterol-exemption' and x.code = 'cholesterol-exempt')) define "Most Recent LDL Screening Date": Last( [Procedure] P + where exists(P.code.coding C where C.system = 'urn:workwell:vs:ldl-labs' and C.code = 'ldl-lab') sort by (performed as FHIR.dateTime) ).performed as FHIR.dateTime diff --git a/backend/src/main/resources/measures/diabetes_hba1c.cql b/backend/src/main/resources/measures/diabetes_hba1c.cql index ea40be9..e753a5e 100644 --- a/backend/src/main/resources/measures/diabetes_hba1c.cql +++ b/backend/src/main/resources/measures/diabetes_hba1c.cql @@ -10,14 +10,17 @@ parameter "Measurement Period" Interval context Patient define "In Diabetes Program": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:diabetes-program' and x.code = 'diabetes-enrolled')) define "Has Medical Exemption": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:diabetes-exemption' and x.code = 'diabetes-exempt')) define "Most Recent HbA1c Date": Last( [Procedure] P + where exists(P.code.coding C where C.system = 'urn:workwell:vs:hba1c-labs' and C.code = 'hba1c-lab') sort by (performed as FHIR.dateTime) ).performed as FHIR.dateTime diff --git a/backend/src/main/resources/measures/flu_vaccine.cql b/backend/src/main/resources/measures/flu_vaccine.cql index 5269f82..7e20f75 100644 --- a/backend/src/main/resources/measures/flu_vaccine.cql +++ b/backend/src/main/resources/measures/flu_vaccine.cql @@ -10,18 +10,22 @@ parameter "Measurement Period" Interval context Patient define "Clinical Facing Employee": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:clinical-roles' and x.code = 'clinical-role')) define "Has Valid Exemption": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:flu-exemption' and x.code = 'flu-exemption')) define "Flu Vaccine This Season": exists([Immunization] I - where (I.occurrence as FHIR.dateTime) during "Measurement Period") + where exists(I.vaccineCode.coding C where C.system = 'urn:workwell:vs:flu-vaccines' and C.code = 'flu-vaccine') + and (I.occurrence as FHIR.dateTime) during "Measurement Period") define "Most Recent Flu Vaccine Date": Last( [Immunization] I + where exists(I.vaccineCode.coding C where C.system = 'urn:workwell:vs:flu-vaccines' and C.code = 'flu-vaccine') sort by (occurrence as FHIR.dateTime) ).occurrence as FHIR.dateTime diff --git a/backend/src/main/resources/measures/hypertension.cql b/backend/src/main/resources/measures/hypertension.cql index 131cda5..12fe932 100644 --- a/backend/src/main/resources/measures/hypertension.cql +++ b/backend/src/main/resources/measures/hypertension.cql @@ -10,14 +10,17 @@ parameter "Measurement Period" Interval context Patient define "In Wellness Program": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:wellness-enrollment' and x.code = 'wellness-enrolled')) define "Has Medical Exemption": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:wellness-exemption' and x.code = 'wellness-exempt')) define "Most Recent BP Screening Date": Last( [Procedure] P + where exists(P.code.coding C where C.system = 'urn:workwell:vs:bp-screening' and C.code = 'bp-screen') sort by (performed as FHIR.dateTime) ).performed as FHIR.dateTime diff --git a/backend/src/main/resources/measures/obesity_bmi.cql b/backend/src/main/resources/measures/obesity_bmi.cql index 3e858db..992d308 100644 --- a/backend/src/main/resources/measures/obesity_bmi.cql +++ b/backend/src/main/resources/measures/obesity_bmi.cql @@ -10,14 +10,17 @@ parameter "Measurement Period" Interval context Patient define "In Wellness Program": - exists([Condition]) + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:wellness-enrollment' and x.code = 'wellness-enrolled')) define "Has Medical Exemption": - Count([Condition]) > 1 + exists([Condition] C + where exists(C.code.coding x where x.system = 'urn:workwell:vs:wellness-exemption' and x.code = 'wellness-exempt')) define "Most Recent BMI Screening Date": Last( [Procedure] P + where exists(P.code.coding C where C.system = 'urn:workwell:vs:bmi-screening' and C.code = 'bmi-screen') sort by (performed as FHIR.dateTime) ).performed as FHIR.dateTime diff --git a/docs/MEASURES.md b/docs/MEASURES.md index b20a766..f3d785d 100644 --- a/docs/MEASURES.md +++ b/docs/MEASURES.md @@ -196,6 +196,6 @@ Each outcome evidence payload includes: ## Implementation Notes -- TB and HAZWOPER recency checks use explicit procedure-code filtering in CQL so the seeded in-memory CQF evaluator can resolve the most recent exam date without relying on unsupported value-set token retrieval. +- All 8 active CQL measures now use inline code-filter expressions on both the qualifying event (Procedure or Immunization) and the enrollment/exemption Conditions, matching the system/code stamped by `SyntheticFhirBundleBuilder`. This replaces the earlier `exists([Condition])` / `Count([Condition]) > 1` pattern that was semantically correct but not code-scoped. True ValueSet token expansion (resolving `urn:workwell:vs:*` OIDs via the VSAC or a local expansion service) is a known evaluator limitation of the in-memory CQF path; the inline-code pattern is the stable workaround until a resolver is wired. - All four HEDIS wellness measures are seeded via `ensureInstanceSeeds()` when `WORKWELL_INSTANCE=ecqm` or `twh`. - All 49 CMS eCQM catalog entries (2026 performance period) are seeded via `ensureCmsEcqmCatalogSeed()` for the same instance values. They are Draft-only and do not participate in CQL evaluation runs until CQL is authored and compiled. On re-seed, existing measures are looked up by CMS ID prefix (`LIKE 'CMSNNNv%'`) and updated in-place so version bumps (e.g., v13→v14) do not create duplicate DB rows.