Skip to content

Commit 9524a23

Browse files
bradmontierthMike Krahulec
authored andcommitted
Adding risk adjusted benchmark mart (#938)
Adding mart used for training models and bringing predictions back into the tuva project
1 parent 47dbfdb commit 9524a23

17 files changed

Lines changed: 2556 additions & 0 deletions

models/benchmarks/models.yml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
version: 2
2+
3+
models:
4+
- name: benchmarks__person_year
5+
description: |
6+
flat table for training ml models on
7+
config:
8+
schema: |
9+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
10+
{%- else -%}benchmarks{%- endif -%}
11+
alias: person_year
12+
materialized: table
13+
tags:
14+
- benchmarks_train
15+
- benchmarks
16+
data_tests:
17+
- dbt_utils.unique_combination_of_columns:
18+
combination_of_columns:
19+
- person_id
20+
- payer
21+
- "{{ '\"plan\"' if (target.type == 'fabric') else 'plan' }}"
22+
- year_nbr
23+
24+
- name: benchmarks__pivot_condition
25+
description: |
26+
flat table for training ml models on
27+
config:
28+
schema: |
29+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
30+
{%- else -%}benchmarks{%- endif -%}
31+
alias: int_pivot_condition
32+
materialized: table
33+
tags:
34+
- benchmarks_train
35+
- benchmarks
36+
37+
38+
- name: benchmarks__predict_member_month
39+
description: |
40+
member_month grain table for data viz with expected values
41+
config:
42+
schema: |
43+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
44+
{%- else -%}benchmarks{%- endif -%}
45+
alias: predict_member_month
46+
materialized: table
47+
tags:
48+
- benchmarks_analysis
49+
- benchmarks
50+
51+
- name: benchmarks__predict_inpatient
52+
description: |
53+
joining inpatient predicts to encounter table actuals
54+
config:
55+
schema: |
56+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
57+
{%- else -%}benchmarks{%- endif -%}
58+
alias: predict_inpatient
59+
materialized: table
60+
tags:
61+
- benchmarks_analysis
62+
- benchmarks
63+
64+
65+
- name: benchmarks__inpatient_input
66+
description: |
67+
unpivot for viz
68+
config:
69+
schema: |
70+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
71+
{%- else -%}benchmarks{%- endif -%}
72+
alias: benchmarks_inpatient_input
73+
materialized: table
74+
tags:
75+
- benchmarks_train
76+
- benchmarks
77+
data_tests:
78+
- dbt_utils.unique_combination_of_columns:
79+
combination_of_columns:
80+
- encounter_id
81+
82+
- name: benchmarks__unpivot_inpatient
83+
description: |
84+
unpivot for viz
85+
config:
86+
schema: |
87+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
88+
{%- else -%}benchmarks{%- endif -%}
89+
alias: benchmarks_unpivot_inpatient
90+
materialized: table
91+
tags:
92+
- benchmarks_analysis
93+
- benchmarks
94+
95+
- name: benchmarks__unpivot_member_month
96+
description: |
97+
unpivot for viz
98+
config:
99+
schema: |
100+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
101+
{%- else -%}benchmarks{%- endif -%}
102+
alias: benchmarks_unpivot_member_month
103+
materialized: table
104+
tags:
105+
- benchmarks_analysis
106+
- benchmarks
107+
108+
109+
- name: benchmarks__pivot_hcc
110+
description: |
111+
hcc_person_year
112+
config:
113+
schema: |
114+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
115+
{%- else -%}benchmarks{%- endif -%}
116+
alias: int_pivot_hcc
117+
materialized: table
118+
tags:
119+
- benchmarks_train
120+
- benchmarks
121+
122+
- name: benchmarks__pivot_cms_condition
123+
description: |
124+
hcc_person_year
125+
config:
126+
schema: |
127+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
128+
{%- else -%}benchmarks{%- endif -%}
129+
alias: int_pivot_cms_condition
130+
materialized: table
131+
tags:
132+
- benchmarks_train
133+
- benchmarks
134+
135+
# Staging models
136+
- name: benchmarks__stg_core__condition
137+
description: Staging model for core condition data used in benchmarks
138+
config:
139+
materialized: view
140+
tags:
141+
- benchmarks_train
142+
- benchmarks
143+
schema: |
144+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
145+
{%- else -%}benchmarks{%- endif -%}
146+
147+
148+
- name: benchmarks__stg_core__member_months
149+
description: Staging model for core member months data used in benchmarks
150+
config:
151+
materialized: view
152+
tags:
153+
- benchmarks_train
154+
- benchmarks
155+
schema: |
156+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
157+
{%- else -%}benchmarks{%- endif -%}
158+
159+
- name: benchmarks__stg_core__medical_claim
160+
description: Staging model for core medical claim data used in benchmarks
161+
config:
162+
materialized: view
163+
tags:
164+
- benchmarks_train
165+
- benchmarks
166+
schema: |
167+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
168+
{%- else -%}benchmarks{%- endif -%}
169+
170+
- name: benchmarks__stg_core__encounter
171+
description: Staging model for core encounter data used in benchmarks
172+
config:
173+
materialized: view
174+
tags:
175+
- benchmarks_train
176+
- benchmarks
177+
schema: |
178+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
179+
{%- else -%}benchmarks{%- endif -%}
180+
181+
- name: benchmarks__stg_core__patient
182+
description: Staging model for core patient data used in benchmarks
183+
config:
184+
materialized: view
185+
tags:
186+
- benchmarks_train
187+
- benchmarks
188+
schema: |
189+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
190+
{%- else -%}benchmarks{%- endif -%}
191+
192+
- name: benchmarks__stg_reference_data__calendar
193+
description: Staging model for reference calendar data used in benchmarks
194+
config:
195+
materialized: view
196+
tags:
197+
- benchmarks_train
198+
- benchmarks
199+
schema: |
200+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
201+
{%- else -%}benchmarks{%- endif -%}
202+
203+
- name: benchmarks__stg_cms_hcc__int_disease_factors
204+
description: Staging model for CMS HCC disease factors data used in benchmarks
205+
config:
206+
materialized: view
207+
tags:
208+
- benchmarks_train
209+
- benchmarks
210+
schema: |
211+
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
212+
{%- else -%}benchmarks{%- endif -%}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{
2+
config(
3+
enabled = var('benchmarks_already_created', False) | as_bool
4+
)
5+
}}
6+
7+
WITH inpatient_pred AS (
8+
SELECT
9+
p.encounter_id
10+
, p.length_of_stay_pred
11+
, p.readmission_pred
12+
, p.discharge_location_pred
13+
, p.discharge_pred_proba_expired
14+
, p.discharge_pred_proba_home
15+
, p.discharge_pred_proba_home_health
16+
, p.discharge_pred_proba_hospice
17+
, p.discharge_pred_proba_ipt_rehab
18+
, p.discharge_pred_proba_other
19+
, p.discharge_pred_proba_snf
20+
, p.discharge_pred_proba_transfer_other_facility
21+
FROM {{ var('predictions_inpatient') }} p
22+
23+
)
24+
25+
,enrollment_flag as (
26+
select encounter_id
27+
,max(enrollment_flag) as max_enrollment_flag
28+
from {{ ref('benchmarks__stg_core__medical_claim') }} e
29+
group by encounter_id
30+
)
31+
32+
33+
select e.encounter_id
34+
, ce.data_source
35+
, ce.encounter_start_date
36+
, cal.first_day_of_month
37+
, ce.person_id
38+
, i.length_of_stay_pred as expected_los
39+
, e.length_of_stay as actual_los
40+
, e.readmission_numerator as actual_readmission
41+
, i.readmission_pred as expected_readmission
42+
, e.readmission_denominator
43+
, e.discharge_location as actual_discharge_location
44+
, i.discharge_location_pred as expected_discharge_location
45+
, ce.facility_id
46+
, ce.facility_name
47+
, case when ce.drg_code_type = 'ms-drg' then concat(ce.drg_code,' ',ce.drg_description) else null end as ms_drg_code
48+
, ce.paid_amount
49+
, i.discharge_pred_proba_expired
50+
, i.discharge_pred_proba_home
51+
, i.discharge_pred_proba_home_health
52+
, i.discharge_pred_proba_hospice
53+
, i.discharge_pred_proba_ipt_rehab
54+
, i.discharge_pred_proba_other
55+
, i.discharge_pred_proba_snf
56+
, i.discharge_pred_proba_transfer_other_facility
57+
, ef.max_enrollment_flag as enrolled_encounter_flag
58+
FROM {{ ref('benchmarks__inpatient_input') }} e
59+
inner join inpatient_pred i on e.encounter_id = i.encounter_id
60+
inner join {{ ref('benchmarks__stg_core__encounter') }} ce on e.encounter_id = ce.encounter_id
61+
inner join {{ ref('benchmarks__stg_reference_data__calendar') }} cal on ce.encounter_start_date = cal.full_date
62+
left join enrollment_flag ef on e.encounter_id = ef.encounter_id

0 commit comments

Comments
 (0)