Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMS HCC Payment Risk Score Weighting by Member Months #453

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions macros/substring.sql
Original file line number Diff line number Diff line change
@@ -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 %}
28 changes: 27 additions & 1 deletion models/cms_hcc/cms_hcc_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
36 changes: 35 additions & 1 deletion models/cms_hcc/final/cms_hcc__patient_risk_scores.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ with seed_adjustment_rates as (

)

, member_months as (

select
patient_id
, cast({{ substring('year_month', 1, 4) }} as integer) as eligible_year
, COUNT(1) as member_months
from {{ ref('cms_hcc__stg_financial_pmpm__member_months') }}
group by
sarah-tuva marked this conversation as resolved.
Show resolved Hide resolved
patient_id
, cast({{ substring('year_month', 1, 4) }} as integer)
)

, raw_score as (

select
Expand Down Expand Up @@ -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
Expand All @@ -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

)

Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ config(
enabled = var('cms_hcc_enabled',var('financial_pmpm_enabled', var('claims_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') }}