Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7b441df
initial commit bringing in benchmarks to run with tuva project
bradmontierth May 1, 2025
2175d88
fabric fixes
bradmontierth May 19, 2025
9cbf7f2
remove old models from yml
bradmontierth May 19, 2025
5eaf48f
null state and race values when not match
bradmontierth May 20, 2025
8857292
adding vars for benchmarks
bradmontierth May 22, 2025
24cd493
updating plan syntax for fabric
bradmontierth May 23, 2025
34892d5
fix drg code syntax
bradmontierth May 23, 2025
5b20aee
Merge tag 'v0.14.11' into benchmarks
bradmontierth May 23, 2025
b33815d
fixing ambiguous reference
bradmontierth May 23, 2025
2e9f9b6
adding inpatient predict tables
bradmontierth May 28, 2025
775138f
missing age imputation for inpatient models
bradmontierth May 28, 2025
9181539
adding year to inpatient table
bradmontierth May 28, 2025
ef9286e
handling both state formats
bradmontierth May 28, 2025
ff62dd1
fixing ref
bradmontierth May 28, 2025
46271fd
adding inpatient views for dashboard
bradmontierth May 29, 2025
3b4c777
fixing inpatient table syntax
bradmontierth May 29, 2025
23aaaa5
updating member months with additional fields
bradmontierth May 29, 2025
b65f1d0
fix typos
bradmontierth May 29, 2025
72a5641
adding unpivot metric table for data viz
bradmontierth May 29, 2025
a551ada
fixing syntax
bradmontierth May 29, 2025
21fa198
removing pkpy calc for consistancy
bradmontierth May 29, 2025
93c88c4
fix grain of encounter predictions
bradmontierth May 29, 2025
50716b4
add config to new model
bradmontierth May 30, 2025
4aa26f8
Merge tag 'v0.14.13' into benchmarks
bradmontierth Jun 4, 2025
84d307b
adding condition flags to inpatient
bradmontierth Jun 11, 2025
faf68bd
fixing joins
bradmontierth Jun 11, 2025
1e0fc7e
Merge remote-tracking branch 'origin/main' into benchmarks
bradmontierth Jun 11, 2025
e26f82b
adding sex and setting null values to string for non xgboost models
bradmontierth Jun 12, 2025
68f9467
fix patient to person
bradmontierth Jun 12, 2025
9514179
adding last run var
bradmontierth Jun 12, 2025
755fb22
adding test to inpatient table
bradmontierth Jun 12, 2025
010ade4
moving test to correct table
bradmontierth Jun 12, 2025
aa173a4
fixing state join
bradmontierth Jun 13, 2025
1702afe
fixing string
bradmontierth Jun 13, 2025
fb8ac32
adding alias
bradmontierth Jun 13, 2025
b810bbb
null case for drg
bradmontierth Jun 13, 2025
dc198f7
predicting inpatient location probabilities directly
bradmontierth Jun 16, 2025
356adf9
fixing column refs
bradmontierth Jun 16, 2025
b3c407f
fixing other facility category
bradmontierth Jun 16, 2025
7454989
changing prediction grain to pmpm
bradmontierth Jun 17, 2025
e27f84b
adding first and last month columns for aligning with mssp in training
bradmontierth Jun 17, 2025
456340c
fixing syntax
bradmontierth Jun 17, 2025
ef1ff0a
adding first and last enrollment month to inpatient
bradmontierth Jun 17, 2025
63cd7de
add missing column
bradmontierth Jun 17, 2025
de81a94
fixing syntax
bradmontierth Jun 17, 2025
cf52e1d
fixing grain to join enrollment to encounter
bradmontierth Jun 17, 2025
cce7030
adding enrollment start logic for mssp comparison
bradmontierth Jun 17, 2025
300732a
Merge tag 'v0.14.14' into benchmarks
bradmontierth Jun 17, 2025
37664c4
adding enrollment flag to encounter
bradmontierth Jun 17, 2025
0dc328e
fixing plan keyword reservation
bradmontierth Jun 18, 2025
1f62125
fixing table ref
bradmontierth Jun 18, 2025
ffb841f
updating with all fields for predict member month
bradmontierth Jun 23, 2025
1199e41
adding placeholder for missing models
bradmontierth Jun 23, 2025
4b75c78
var to true for ci testing
bradmontierth Jun 23, 2025
0552991
linting
bradmontierth Jun 23, 2025
865f147
fixing big query syntax and clinical var error
bradmontierth Jun 23, 2025
3163d1b
linting fix
bradmontierth Jun 24, 2025
1e76da6
logic for big query string literals
bradmontierth Jun 24, 2025
0773d95
syntax fix and linting
bradmontierth Jun 24, 2025
63dde53
this is the last big query syntax fix
bradmontierth Jun 24, 2025
f6511d3
one more data type fix for bq
bradmontierth Jun 24, 2025
ff1b30c
fixing sql syntax
bradmontierth Jun 24, 2025
a0bf30e
more bq syntax
bradmontierth Jun 25, 2025
a38063c
fixing macro
bradmontierth Jun 25, 2025
862aa89
setting back to original var after ci testing passed
bradmontierth Jun 25, 2025
8a693ba
revert integ test files
bradmontierth Jun 25, 2025
6292cc0
trailing new line
bradmontierth Jun 25, 2025
983062e
delete tabs
bradmontierth Jun 25, 2025
720b483
adding staging models and referencing them downstream
bradmontierth Jun 26, 2025
b00b9a7
linting
bradmontierth Jun 26, 2025
d3d1201
adding config to new staging models
bradmontierth Jun 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions models/benchmarks/models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
version: 2

models:
- name: benchmarks__person_year
description: |
flat table for training ml models on
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: person_year
materialized: table
tags:
- benchmarks_train
- benchmarks
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- person_id
- payer
- "{{ '\"plan\"' if (target.type == 'fabric') else 'plan' }}"
- year_nbr

- name: benchmarks__pivot_condition
description: |
flat table for training ml models on
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: int_pivot_condition
materialized: table
tags:
- benchmarks_train
- benchmarks


- name: benchmarks__predict_member_month
description: |
member_month grain table for data viz with expected values
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: predict_member_month
materialized: table
tags:
- benchmarks_analysis
- benchmarks

- name: benchmarks__predict_inpatient
description: |
joining inpatient predicts to encounter table actuals
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: predict_inpatient
materialized: table
tags:
- benchmarks_analysis
- benchmarks


- name: benchmarks__inpatient_input
description: |
unpivot for viz
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: benchmarks_inpatient_input
materialized: table
tags:
- benchmarks_train
- benchmarks
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- encounter_id

- name: benchmarks__unpivot_inpatient
description: |
unpivot for viz
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: benchmarks_unpivot_inpatient
materialized: table
tags:
- benchmarks_analysis
- benchmarks

- name: benchmarks__unpivot_member_month
description: |
unpivot for viz
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: benchmarks_unpivot_member_month
materialized: table
tags:
- benchmarks_analysis
- benchmarks


- name: benchmarks__pivot_hcc
description: |
hcc_person_year
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: int_pivot_hcc
materialized: table
tags:
- benchmarks_train
- benchmarks

- name: benchmarks__pivot_cms_condition
description: |
hcc_person_year
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
alias: int_pivot_cms_condition
materialized: table
tags:
- benchmarks_train
- benchmarks

# Staging models
- name: benchmarks__stg_core__condition
description: Staging model for core condition data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}


- name: benchmarks__stg_core__member_months
description: Staging model for core member months data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}

- name: benchmarks__stg_core__medical_claim
description: Staging model for core medical claim data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}

- name: benchmarks__stg_core__encounter
description: Staging model for core encounter data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}

- name: benchmarks__stg_core__patient
description: Staging model for core patient data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}

- name: benchmarks__stg_reference_data__calendar
description: Staging model for reference calendar data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}

- name: benchmarks__stg_cms_hcc__int_disease_factors
description: Staging model for CMS HCC disease factors data used in benchmarks
config:
materialized: view
tags:
- benchmarks_train
- benchmarks
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_benchmarks
{%- else -%}benchmarks{%- endif -%}
62 changes: 62 additions & 0 deletions models/benchmarks/post_predict/benchmarks__predict_inpatient.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{
config(
enabled = var('benchmarks_already_created', False) | as_bool
)
}}

WITH inpatient_pred AS (
SELECT
p.encounter_id
, p.length_of_stay_pred
, p.readmission_pred
, p.discharge_location_pred
, p.discharge_pred_proba_expired
, p.discharge_pred_proba_home
, p.discharge_pred_proba_home_health
, p.discharge_pred_proba_hospice
, p.discharge_pred_proba_ipt_rehab
, p.discharge_pred_proba_other
, p.discharge_pred_proba_snf
, p.discharge_pred_proba_transfer_other_facility
FROM {{ var('predictions_inpatient') }} p

)

,enrollment_flag as (
select encounter_id
,max(enrollment_flag) as max_enrollment_flag
from {{ ref('benchmarks__stg_core__medical_claim') }} e
group by encounter_id
)


select e.encounter_id
, ce.data_source
, ce.encounter_start_date
, cal.first_day_of_month
, ce.person_id
, i.length_of_stay_pred as expected_los
, e.length_of_stay as actual_los
, e.readmission_numerator as actual_readmission
, i.readmission_pred as expected_readmission
, e.readmission_denominator
, e.discharge_location as actual_discharge_location
, i.discharge_location_pred as expected_discharge_location
, ce.facility_id
, ce.facility_name
, case when ce.drg_code_type = 'ms-drg' then concat(ce.drg_code,' ',ce.drg_description) else null end as ms_drg_code
, ce.paid_amount
, i.discharge_pred_proba_expired
, i.discharge_pred_proba_home
, i.discharge_pred_proba_home_health
, i.discharge_pred_proba_hospice
, i.discharge_pred_proba_ipt_rehab
, i.discharge_pred_proba_other
, i.discharge_pred_proba_snf
, i.discharge_pred_proba_transfer_other_facility
, ef.max_enrollment_flag as enrolled_encounter_flag
FROM {{ ref('benchmarks__inpatient_input') }} e
inner join inpatient_pred i on e.encounter_id = i.encounter_id
inner join {{ ref('benchmarks__stg_core__encounter') }} ce on e.encounter_id = ce.encounter_id
inner join {{ ref('benchmarks__stg_reference_data__calendar') }} cal on ce.encounter_start_date = cal.full_date
left join enrollment_flag ef on e.encounter_id = ef.encounter_id
Loading