Skip to content

Commit 84f4657

Browse files
author
Alexandra Pavlyshina
committed
measure-evaluate/evidence: strict ip_evidence in all 12 measures, add for CMS143/153/155, plus ip_pathway/ip_source_cte aliases for SoF cte-tag display
1 parent 523565f commit 84f4657

13 files changed

Lines changed: 327 additions & 35 deletions

File tree

aidbox-custom-operations/measure-evaluate/demo/measure-sql.json

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

aidbox-custom-operations/measure-evaluate/sql/measures/cms1154/03-cms1154-evidence.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ ip_evidence AS (
1818
FROM encounter_flat e
1919
JOIN initial_population ip ON ip.patient_id = e.patient_id
2020
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
21+
AND vs.valueset_url IN (
22+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1160.24', -- OfficeVisits
23+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1160.13' -- PreventiveCare
24+
)
2125
CROSS JOIN mp
2226
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
2327
),
@@ -116,6 +120,8 @@ SELECT
116120
ee.exclusion_pathway,
117121
ee.exc_resource_type,
118122
ee.exc_resource_id,
123+
ie.pathway AS ip_pathway,
124+
ie.source_cte AS ip_source_cte,
119125
ie.resource_type AS ip_resource_type,
120126
ie.resource_id AS ip_resource_id,
121127
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms124/03-cms124-evidence.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ ip_evidence AS (
2222
FROM encounter_flat e
2323
JOIN initial_population ip ON ip.patient_id = e.patient_id
2424
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
25+
AND vs.valueset_url IN (
26+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001',
27+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025',
28+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023',
29+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016',
30+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080',
31+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089'
32+
)
2533
CROSS JOIN mp
2634
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
2735
),
@@ -183,6 +191,8 @@ SELECT
183191
ee.exclusion_pathway,
184192
ee.exc_resource_type,
185193
ee.exc_resource_id,
194+
ie.pathway AS ip_pathway,
195+
ie.source_cte AS ip_source_cte,
186196
ie.resource_type AS ip_resource_type,
187197
ie.resource_id AS ip_resource_id,
188198
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms125/03-cms125-evidence.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ ip_evidence AS (
2121
FROM encounter_flat e
2222
JOIN initial_population ip ON ip.patient_id = e.patient_id
2323
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
24+
AND vs.valueset_url IN (
25+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001',
26+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1240',
27+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025',
28+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023',
29+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016',
30+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089',
31+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080'
32+
)
2433
CROSS JOIN mp
2534
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
2635
),
@@ -169,6 +178,8 @@ SELECT
169178
ee.exclusion_pathway,
170179
ee.exc_resource_type,
171180
ee.exc_resource_id,
181+
ie.pathway AS ip_pathway,
182+
ie.source_cte AS ip_source_cte,
172183
ie.resource_type AS ip_resource_type,
173184
ie.resource_id AS ip_resource_id,
174185
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms130/03-cms130-evidence.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ ip_evidence AS (
2323
FROM encounter_flat e
2424
JOIN initial_population ip ON ip.patient_id = e.patient_id
2525
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
26+
AND vs.valueset_url IN (
27+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001',
28+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1240',
29+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025',
30+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023',
31+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016',
32+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089',
33+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080'
34+
)
2635
CROSS JOIN mp
2736
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
2837
),
@@ -224,6 +233,8 @@ SELECT
224233
ee.exclusion_pathway,
225234
ee.exc_resource_type,
226235
ee.exc_resource_id,
236+
ie.pathway AS ip_pathway,
237+
ie.source_cte AS ip_source_cte,
227238
ie.resource_type AS ip_resource_type,
228239
ie.resource_id AS ip_resource_id,
229240
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms131/03-cms131-evidence.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ ip_evidence AS (
2727
FROM encounter_flat e
2828
JOIN initial_population ip ON ip.patient_id = e.patient_id
2929
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
30+
AND vs.valueset_url IN (
31+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001',
32+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1240',
33+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025',
34+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023',
35+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016',
36+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1285',
37+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080'
38+
)
3039
CROSS JOIN mp
3140
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
3241
),
@@ -252,6 +261,8 @@ SELECT
252261
ee.exclusion_pathway,
253262
ee.exc_resource_type,
254263
ee.exc_resource_id,
264+
ie.pathway AS ip_pathway,
265+
ie.source_cte AS ip_source_cte,
255266
ie.resource_type AS ip_resource_type,
256267
ie.resource_id AS ip_resource_id,
257268
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms139/03-cms139-evidence.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ ip_evidence AS (
2121
FROM encounter_flat e
2222
JOIN initial_population ip ON ip.patient_id = e.patient_id
2323
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
24+
AND vs.valueset_url IN (
25+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001',
26+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1240',
27+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025',
28+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023',
29+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016',
30+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080',
31+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089',
32+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1285',
33+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1026',
34+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1013',
35+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1012',
36+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1014',
37+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1066',
38+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1022',
39+
'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1011'
40+
)
2441
CROSS JOIN mp
2542
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
2643
),
@@ -108,6 +125,8 @@ SELECT
108125
ee.exclusion_pathway,
109126
ee.exc_resource_type,
110127
ee.exc_resource_id,
128+
ie.pathway AS ip_pathway,
129+
ie.source_cte AS ip_source_cte,
111130
ie.resource_type AS ip_resource_type,
112131
ie.resource_id AS ip_resource_id,
113132
ie.code_display AS ip_code_display,

aidbox-custom-operations/measure-evaluate/sql/measures/cms143/03-cms143-evidence.sql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ exclusion_evidence AS (
6161
AND vs.valueset_url = 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1334'
6262
WHERE o.resource->>'status' = 'cancelled'
6363
AND o.resource#>>'{subject,id}' IN (SELECT patient_id FROM medical_reason_optic_disc)
64+
),
65+
66+
-- ============================================================
67+
-- EVIDENCE: Initial Population — POAG encounter (encounter WITH active POAG diagnosis)
68+
-- ============================================================
69+
ip_evidence AS (
70+
SELECT DISTINCT pe.patient_id, 'poag_encounter' AS pathway,
71+
'Encounter' AS resource_type, pe.encounter_id AS resource_id,
72+
e.type_code AS code, vs.display AS code_display,
73+
pe.period_start AS event_date, 'initial_population' AS source_cte
74+
FROM poag_encounters pe
75+
JOIN initial_population ip ON ip.patient_id = pe.patient_id
76+
JOIN encounter_flat e ON e.id = pe.encounter_id AND e.patient_id = pe.patient_id
77+
LEFT JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
6478
)
6579

6680
-- ============================================================
@@ -81,8 +95,15 @@ SELECT
8195
ne.source_cte,
8296
ee.exclusion_pathway,
8397
ee.exc_resource_type,
84-
ee.exc_resource_id
98+
ee.exc_resource_id,
99+
ie.pathway AS ip_pathway,
100+
ie.source_cte AS ip_source_cte,
101+
ie.resource_type AS ip_resource_type,
102+
ie.resource_id AS ip_resource_id,
103+
ie.code_display AS ip_code_display,
104+
ie.event_date AS ip_event_date
85105
FROM measure_results mr
106+
LEFT JOIN ip_evidence ie ON ie.patient_id = mr.patient_id
86107
LEFT JOIN numerator_evidence ne ON ne.patient_id = mr.patient_id
87108
LEFT JOIN exclusion_evidence ee ON ee.patient_id = mr.patient_id
88109
ORDER BY mr.patient_id, pathway;

aidbox-custom-operations/measure-evaluate/sql/measures/cms149/03-cms149-evidence.sql

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
-- EVIDENCE: Initial Population qualifying encounters
1212
-- ============================================================
1313
ip_evidence AS (
14-
SELECT DISTINCT e.patient_id, 'dementia_encounter' AS pathway,
15-
'Encounter' AS resource_type, e.id AS resource_id,
14+
-- Source from dementia_encounter (encounter WITH overlapping active dementia condition)
15+
-- — that's the joint condition that makes a patient IP-eligible.
16+
SELECT DISTINCT de.patient_id, 'dementia_encounter' AS pathway,
17+
'Encounter' AS resource_type, de.encounter_id AS resource_id,
1618
e.type_code AS code, vs.display AS code_display,
17-
e.period_start AS event_date, 'initial_population' AS source_cte
18-
FROM encounter_flat e
19-
JOIN initial_population ip ON ip.patient_id = e.patient_id
20-
JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
21-
CROSS JOIN mp
22-
WHERE e.period_start >= mp.mp_start AND e.period_end <= mp.mp_end
19+
de.period_start AS event_date, 'initial_population' AS source_cte
20+
FROM dementia_encounter de
21+
JOIN initial_population ip ON ip.patient_id = de.patient_id
22+
JOIN encounter_flat e ON e.id = de.encounter_id AND e.patient_id = de.patient_id
23+
LEFT JOIN concepts vs ON vs.system = e.type_system AND vs.code = e.type_code
2324
),
2425

2526
numerator_evidence AS (
@@ -96,6 +97,8 @@ SELECT
9697
ee.exclusion_pathway,
9798
ee.exc_resource_type,
9899
ee.exc_resource_id,
100+
ie.pathway AS ip_pathway,
101+
ie.source_cte AS ip_source_cte,
99102
ie.resource_type AS ip_resource_type,
100103
ie.resource_id AS ip_resource_id,
101104
ie.code_display AS ip_code_display,

0 commit comments

Comments
 (0)