From 6e63fab4ae1edbe2bc989a44dce5d58b3b3f86ad Mon Sep 17 00:00:00 2001 From: Phil Fehlinger Date: Thu, 25 Apr 2024 20:59:59 -0400 Subject: [PATCH 1/3] Adding member months from financial_pmpm and using that to weight payment_risk_score by member months --- .../final/cms_hcc__patient_risk_scores.sql | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql index 01cbc8a8..b68172e1 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql @@ -24,6 +24,18 @@ with seed_adjustment_rates as ( ) +, member_months as ( + + select + patient_id + , cast(substr(year_month, 1, 4) as integer) as eligible_year + , COUNT(1) as member_months + from {{ ref('financial_pmpm__member_months') }} + group by + patient_id + , cast(substr(year_month, 1, 4) as integer) +) + , raw_score as ( select @@ -135,6 +147,24 @@ with seed_adjustment_rates as ( ) +, weighted_score as ( + + select + payment.patient_id + , payment.v24_risk_score + , payment.v28_risk_score + , payment.blended_risk_score + , payment.normalized_risk_score + , payment.payment_risk_score + , member_months.member_months + , payment.payment_risk_score * member_months.member_months as payment_risk_score_weighted_by_months + , payment.payment_year + from payment + left join member_months + on payment.patient_id = member_months.patient_id + and payment.payment_year = member_months.eligible_year +) + , add_data_types as ( select @@ -144,8 +174,10 @@ with seed_adjustment_rates as ( , round(cast(blended_risk_score as {{ dbt.type_numeric() }}),3) as blended_risk_score , round(cast(normalized_risk_score as {{ dbt.type_numeric() }}),3) as normalized_risk_score , round(cast(payment_risk_score as {{ dbt.type_numeric() }}),3) as payment_risk_score + , round(cast(payment_risk_score_weighted_by_months as {{ dbt.type_numeric() }}),3) as payment_risk_score_weighted_by_months + , cast(member_months as integer) as member_months , cast(payment_year as integer) as payment_year - from payment + from weighted_score ) @@ -156,6 +188,8 @@ select , blended_risk_score , normalized_risk_score , payment_risk_score + , payment_risk_score_weighted_by_months + , member_months , payment_year , '{{ var('tuva_last_run')}}' as tuva_last_run from add_data_types \ No newline at end of file From a0b19a7fa89ac158060c2280e9b80b2ebb38ddfc Mon Sep 17 00:00:00 2001 From: Phil Fehlinger Date: Mon, 3 Jun 2024 17:06:36 -0400 Subject: [PATCH 2/3] Added substring macro to support cross platform nature of the project. Added ephemeral staging for member months in cms_hcc --- macros/substring.sql | 31 +++++++++++++++++++ models/cms_hcc/cms_hcc_models.yml | 28 ++++++++++++++++- .../final/cms_hcc__patient_risk_scores.sql | 6 ++-- ...hcc__stg_financial_pmpm__member_months.sql | 12 +++++++ 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 macros/substring.sql create mode 100644 models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql diff --git a/macros/substring.sql b/macros/substring.sql new file mode 100644 index 00000000..64cf63e9 --- /dev/null +++ b/macros/substring.sql @@ -0,0 +1,31 @@ +{% macro substring(string, start, length) %} + {{ return(adapter.dispatch('substring', 'macros')(string, start, length)) }} +{% endmacro %} + +{% macro default__substring(string, start, length) %} + substring({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} + +{% macro postgres__substring(string, start, length) %} + substring({{ string }} from {{ start }} for {{ length }}) +{% endmacro %} + +{% macro snowflake__substring(string, start, length) %} + substr({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} + +{% macro bigquery__substring(string, start, length) %} + substr({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} + +{% macro redshift__substring(string, start, length) %} + substring({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} + +{% macro databricks__substring(string, start, length) %} + substring({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} + +{% macro duckdb__substring(string, start, length) %} + substring({{ string }}, {{ start }}, {{ length }}) +{% endmacro %} \ No newline at end of file diff --git a/models/cms_hcc/cms_hcc_models.yml b/models/cms_hcc/cms_hcc_models.yml index 01e1ffad..2013718b 100644 --- a/models/cms_hcc/cms_hcc_models.yml +++ b/models/cms_hcc/cms_hcc_models.yml @@ -536,4 +536,30 @@ models: - name: birth_date description: Date the patient was born. - name: death_date - description: The death date of the patient if there is one. \ No newline at end of file + description: The death date of the patient if there is one. + - name: cms_hcc__stg_financial_pmpm__member_months + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_cms_hcc{% else %}cms_hcc{%- endif -%} + alias: _stg_member_months + tags: cms_hcc + materialized: ephemeral + description: Staging member months from financial_pmpm + columns: + - name: patient_id + description: Unique identifier for each patient in the dataset. + - name: year_month + description: Unique year-month of in the dataset computed from eligibility. + - name: payer + description: Name of the payer (i.e. health insurer) providing coverage. + - name: plan + description: Name of the plan (i.e. sub contract) providing coverage. + - name: data_source + description: > + User-configured field that indicates the data source (e.g. typically + named after the payer and state "BCBS Tennessee"). + - name: tuva_last_run + description: > + The last time the data was refreshed. Generated by + `dbt_utils.pretty_time` as the local time of the `dbt run` + environment. Timezone is configurable via the `tuva_last_run` var. \ No newline at end of file diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql index b68172e1..08ab66e3 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql @@ -28,12 +28,12 @@ with seed_adjustment_rates as ( select patient_id - , cast(substr(year_month, 1, 4) as integer) as eligible_year + , cast({{ substring('year_month', 1, 4) }} as integer) as eligible_year , COUNT(1) as member_months - from {{ ref('financial_pmpm__member_months') }} + from {{ ref('cms_hcc__stg_financial_pmpm__member_months') }} group by patient_id - , cast(substr(year_month, 1, 4) as integer) + , cast({{ substring('year_month', 1, 4) }} as integer) ) , raw_score as ( diff --git a/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql b/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql new file mode 100644 index 00000000..b9531f9f --- /dev/null +++ b/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql @@ -0,0 +1,12 @@ +{{ config( + enabled = var('cms_hcc_enabled',var('financial_pmpm_enabled', var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))))) | as_bool + ) +}} +select + patient_id + , year_month + , payer + , plan + , data_source + , '{{ var('tuva_last_run')}}' as tuva_last_run +from {{ ref('financial_pmpm__member_months') }} \ No newline at end of file From 1036f2a9c7bf4443239a7c9786708862155fd220 Mon Sep 17 00:00:00 2001 From: Phil Fehlinger Date: Tue, 4 Jun 2024 15:13:10 -0400 Subject: [PATCH 3/3] Removed dependency on clinical models being enabled --- .../staging/cms_hcc__stg_financial_pmpm__member_months.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql b/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql index b9531f9f..8daa8d46 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_financial_pmpm__member_months.sql @@ -1,5 +1,5 @@ {{ config( - enabled = var('cms_hcc_enabled',var('financial_pmpm_enabled', var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))))) | as_bool + enabled = var('cms_hcc_enabled',var('financial_pmpm_enabled', var('claims_enabled',var('tuva_marts_enabled',False)))) | as_bool ) }} select