Skip to content

Commit

Permalink
Merge pull request #354 from tuva-health/add-hcc-suspecting
Browse files Browse the repository at this point in the history
Add HCC Suspecting mart
  • Loading branch information
eldon-tuva authored Jan 23, 2024
2 parents ba17a66 + 1194012 commit 6fa8c04
Show file tree
Hide file tree
Showing 15 changed files with 12,213 additions and 122 deletions.
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/run_results.json

Large diffs are not rendered by default.

76 changes: 0 additions & 76 deletions models/cms_hcc/cms_hcc_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,6 @@ version: 2

models:
## Final
- name: cms_hcc__patient_hcc_history
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_cms_hcc{% else %}cms_hcc{%- endif -%}
alias: patient_hcc_history
tags: cms_hcc
materialized: table
description: >
This final model displays the full history of a patient's recorded HCCs
with a flag for recorded during the payment year.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: recorded_date
description: Date in which the ICD-10-CM condition was recorded.
- name: condition_type
description: The type of condition.
- name: icd_10_cm_code
description: The ICD-10-CM condition code.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/cms_hcc/cms_hcc__icd_10_cm_mappings.csv
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/cms_hcc/cms_hcc__icd_10_cm_mappings.csv
- name: hcc_description
description: >
HCC description from the latest CMS HCC model available in the mart.
- name: first_recorded
description: Date the HCC was first recorded in the patient's record.
- name: last_recorded
description: Date the HCC was last recorded in the patient's record.
- name: payment_year_recorded
description: >
Flag indicating that the ICD-10-CM code mapped to the HCC was recorded
during the payment year.
- name: model_version
description: CMS HCC model version.
- name: payment_year
description: >
The payment year the HCC and risk scores are being calculated for.
- name: tuva_last_run
description: The date the model was run.

- name: cms_hcc__patient_risk_factors
config:
schema: |
Expand Down Expand Up @@ -125,37 +80,6 @@ models:
description: The date the model was run.

## Intermediate
- name: cms_hcc__int_all_conditions
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_cms_hcc{% else %}cms_hcc{%- endif -%}
alias: _int_all_conditions
tags: cms_hcc
materialized: table
description: All historical conditions mapped to HCCs.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: recorded_date
description: Date in which the condition was recorded.
- name: condition_type
description: The type of condition.
- name: icd_10_cm_code
description: The ICD-10-CM condition code.
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
- name: hcc_description
description: >
HCC description from the latest CMS HCC model available in the mart.
- name: model_version
description: CMS HCC model version.
- name: payment_year
description: >
The payment year the HCC and risk scores are being calculated for.
- name: tuva_last_run
description: The date the model was run.

- name: cms_hcc__int_demographic_factors
config:
schema: |
Expand Down
2 changes: 1 addition & 1 deletion models/cms_hcc/staging/cms_hcc__stg_core__condition.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ config(
enabled = var('cms_hcc_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))))
enabled = var('cms_hcc_enabled',var('claims_enabled',var('tuva_marts_enabled',False)))
)
}}
select
Expand Down
52 changes: 52 additions & 0 deletions models/hcc_suspecting/final/hcc_suspecting__list.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{ config(
enabled = var('hcc_suspecting_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))))
)
}}

with hcc_history_suspects as (

select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, 'Prior coding history' as reason
, icd_10_cm_code
|| case
when last_billed is not null then ' last billed on ' || last_billed
when last_billed is null and last_recorded is not null then ' last recorded on ' || last_recorded
else ' (missing recorded and billing dates) '
end as contributing_factor
from {{ ref('hcc_suspecting__int_patient_hcc_history') }}
where current_year_billed = false

)

, unioned as (

select * from hcc_history_suspects

)

, add_data_types as (

select
cast(patient_id as {{ dbt.type_string() }}) as patient_id
, cast(data_source as {{ dbt.type_string() }}) as data_source
, cast(hcc_code as {{ dbt.type_string() }}) as hcc_code
, cast(hcc_description as {{ dbt.type_string() }}) as hcc_description
, cast(reason as {{ dbt.type_string() }}) as reason
, cast(contributing_factor as {{ dbt.type_string() }}) as contributing_factor
from unioned

)

select
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, '{{ var('tuva_last_run')}}' as tuva_last_run
from add_data_types
61 changes: 61 additions & 0 deletions models/hcc_suspecting/final/hcc_suspecting__summary.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{ config(
enabled = var('hcc_suspecting_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))))
)
}}

with patients as (

select
patient_id
, sex
, birth_date
, floor({{ datediff('birth_date', 'current_date', 'hour') }} / 8766.0) as age
from {{ ref('hcc_suspecting__stg_core__patient') }}
where death_date is null

)

, suspecting_list as (

select
patient_id
, count(*) as gaps
from {{ ref('hcc_suspecting__list') }}
group by patient_id

)

, joined as (

select
patients.patient_id
, patients.sex
, patients.birth_date
, patients.age
, suspecting_list.gaps
from patients
inner join suspecting_list
on patients.patient_id = suspecting_list.patient_id

)

, add_data_types as (

select
cast(patient_id as {{ dbt.type_string() }}) as patient_id
, cast(sex as {{ dbt.type_string() }}) as patient_sex
, cast(birth_date as date) as patient_birth_date
, cast(age as integer) as patient_age
, cast(gaps as integer) as suspecting_gaps
from joined

)

select
patient_id
, patient_sex
, patient_birth_date
, patient_age
, suspecting_gaps
, '{{ var('tuva_last_run')}}' as tuva_last_run
from add_data_types
159 changes: 159 additions & 0 deletions models/hcc_suspecting/hcc_suspecting_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
version: 2

models:
## Final
- name: hcc_suspecting__list
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: list
tags: hcc_suspecting
materialized: table
description: >
This final model displays the list of suspecting conditions per patient
with the reason and contributing factors.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/cms_hcc/cms_hcc__icd_10_cm_mappings.csv
- name: hcc_description
description: >
HCC description from the latest CMS HCC model available in the mart.
- name: reason
description: Standardized reason for the suspecting condition.
- name: contributing_factor
description: >
Description of the contributing factor(s) for the suspecting condition.
- name: tuva_last_run
description: The date the model was run.

- name: hcc_suspecting__summary
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: summary
tags: hcc_suspecting
materialized: table
description: >
This final model displays a rollup of suspecting conditions per patient.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: patient_sex
description: The gender of the patient.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__gender.csv
- name: patient_birth_date
description: The birth date of the patient.
- name: patient_age
description: The patient's current age.
- name: suspecting_gaps
description: Count of suspecting conditions.
- name: tuva_last_run
description: The date the model was run.

## Intermediate
- name: hcc_suspecting__int_all_conditions
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: _int_all_conditions
tags: hcc_suspecting
materialized: table
description: All historical conditions mapped to HCCs.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: recorded_date
description: Date in which the condition was recorded.
- name: condition_type
description: The type of condition.
- name: icd_10_cm_code
description: The ICD-10-CM condition code.
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
- name: hcc_description
description: >
HCC description from the latest CMS HCC model available in the mart.
- name: tuva_last_run
description: The date the model was run.

- name: hcc_suspecting__int_patient_hcc_history
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: _int_patient_hcc_history
tags: hcc_suspecting
materialized: table
description: >
This intermediate model displays the full history of a patient's recorded HCCs
with a flag for recorded during the current year.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: recorded_date
description: Date in which the ICD-10-CM condition was recorded.
- name: condition_type
description: The type of condition.
- name: icd_10_cm_code
description: The ICD-10-CM condition code.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/cms_hcc/cms_hcc__icd_10_cm_mappings.csv
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/cms_hcc/cms_hcc__icd_10_cm_mappings.csv
- name: hcc_description
description: >
HCC description from the latest CMS HCC model available in the mart.
- name: first_recorded
description: Date the HCC was first recorded in the patient's record.
- name: last_recorded
description: Date the HCC was last recorded in the patient's record.
- name: last_billed
description: >
Date the HCC was last billed in the patient's record (where
condition_type <> 'problem').
- name: current_year_billed
description: >
Flag indicating that the ICD-10-CM code mapped to the HCC was billed
during the payment year.
- name: tuva_last_run
description: The date the model was run.

## Staging
- name: hcc_suspecting__stg_core__condition
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: _stg_condition
tags: hcc_suspecting
materialized: ephemeral
description: Staging conditions from core.
columns:
- name: claim_id
- name: patient_id
- name: recorded_date
- name: condition_type
- name: code_type
- name: code

- name: hcc_suspecting__stg_core__patient
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: _stg_patient
tags: hcc_suspecting
materialized: ephemeral
description: Staging patients from core.
columns:
- name: patient_id
- name: sex
- name: birth_date
- name: death_date
Loading

0 comments on commit 6fa8c04

Please sign in to comment.