-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from tuva-health/add-hcc-suspecting
Add HCC Suspecting mart
- Loading branch information
Showing
15 changed files
with
12,213 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.