Skip to content

Commit bb86045

Browse files
krishyfishyMike Krahulec
authored andcommitted
Add testing to check for overlap between medical claim / pharmacy claim and eligibility (#943)
* first pass at overlap checks * update checks * linting * gitkeep * refactor testing, update severity level * lint * database compatibility * swap coalesce for case when * fix join
1 parent 535ad68 commit bb86045

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

tests/.gitkeep

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{{ config(
2+
enabled = var('claims_preprocessing_enabled',var('claims_enabled',var('tuva_marts_enabled',False)))
3+
| as_bool,
4+
tags = ['dqi', 'tuva_dqi_sev_2', 'dqi_service_categories', 'dqi_ccsr', 'dqi_cms_chronic_conditions',
5+
'dqi_tuva_chronic_conditions', 'dqi_cms_hccs', 'dqi_ed_classification',
6+
'dqi_financial_pmpm', 'dqi_quality_measures', 'dqi_readmission'],
7+
severity = 'warn'
8+
)
9+
}}
10+
11+
with eligibility as (
12+
select distinct
13+
person_id
14+
, data_source
15+
from {{ ref('input_layer__eligibility') }}
16+
)
17+
18+
, medical_claims as (
19+
select distinct
20+
person_id
21+
, data_source
22+
from {{ ref('input_layer__medical_claim') }}
23+
)
24+
25+
, mc_records_check as (
26+
select
27+
data_source
28+
, count(*) as n_rows
29+
from medical_claims
30+
group by data_source
31+
)
32+
33+
, elig_records_check as (
34+
select
35+
data_source
36+
, count(*) as n_rows
37+
from eligibility
38+
group by data_source
39+
)
40+
41+
, overlap_check as (
42+
select
43+
m.data_source
44+
, count(e.person_id) as n_rows
45+
from medical_claims as m
46+
left outer join eligibility as e
47+
on m.person_id = e.person_id
48+
and m.data_source = e.data_source
49+
group by m.data_source
50+
)
51+
52+
, final as (
53+
select
54+
oc.data_source
55+
, oc.n_rows as n_overlapping_records
56+
, case when (mc.n_rows = 0 or mc.n_rows is null) then 1 else 0 end as is_mc_empty
57+
, case when (ec.n_rows = 0 or ec.n_rows is null) then 1 else 0 end as is_elig_empty
58+
from overlap_check as oc
59+
left outer join mc_records_check as mc
60+
on oc.data_source = mc.data_source
61+
left outer join elig_records_check as ec
62+
on oc.data_source = ec.data_source
63+
)
64+
65+
select
66+
data_source
67+
, n_overlapping_records
68+
from final
69+
where not (is_mc_empty = 1 or is_elig_empty = 1)
70+
and n_overlapping_records = 0
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{{ config(
2+
enabled = var('claims_preprocessing_enabled',var('claims_enabled',var('tuva_marts_enabled',False)))
3+
| as_bool,
4+
tags = ['dqi', 'tuva_dqi_sev_2', 'dqi_service_categories', 'dqi_ccsr', 'dqi_cms_chronic_conditions',
5+
'dqi_tuva_chronic_conditions', 'dqi_cms_hccs', 'dqi_ed_classification',
6+
'dqi_financial_pmpm', 'dqi_quality_measures', 'dqi_readmission'],
7+
severity = 'warn'
8+
)
9+
}}
10+
11+
with eligibility as (
12+
select distinct
13+
person_id
14+
, data_source
15+
from {{ ref('input_layer__eligibility') }}
16+
)
17+
18+
, pharmacy_claims as (
19+
select distinct
20+
person_id
21+
, data_source
22+
from {{ ref('input_layer__pharmacy_claim') }}
23+
)
24+
25+
, pc_records_check as (
26+
select
27+
data_source
28+
, count(*) as n_rows
29+
from pharmacy_claims
30+
group by data_source
31+
)
32+
33+
, elig_records_check as (
34+
select
35+
data_source
36+
, count(*) as n_rows
37+
from eligibility
38+
group by data_source
39+
)
40+
41+
, overlap_check as (
42+
select
43+
p.data_source
44+
, count(e.person_id) as n_rows
45+
from pharmacy_claims as p
46+
left outer join eligibility as e
47+
on p.person_id = e.person_id
48+
and p.data_source = e.data_source
49+
group by p.data_source
50+
)
51+
52+
, final as (
53+
select
54+
oc.data_source
55+
, oc.n_rows as n_overlapping_records
56+
, case when (pc.n_rows = 0 or pc.n_rows is null) then 1 else 0 end as is_pc_empty
57+
, case when (ec.n_rows = 0 or ec.n_rows is null) then 1 else 0 end as is_elig_empty
58+
from overlap_check as oc
59+
left outer join pc_records_check as pc
60+
on oc.data_source = pc.data_source
61+
left outer join elig_records_check as ec
62+
on oc.data_source = ec.data_source
63+
)
64+
65+
select
66+
data_source
67+
, n_overlapping_records
68+
from final
69+
where not (is_pc_empty = 1 or is_elig_empty = 1)
70+
and n_overlapping_records = 0

0 commit comments

Comments
 (0)