Skip to content

Commit

Permalink
Add comorbidity suspecting logic for HCC 37 - Diabetes with Chronic C…
Browse files Browse the repository at this point in the history
…omplications (#426)

* Add new value sets seed

* Add new comorbidity model

* Add list rollup model

* Update seed name

* Rename column

* Fix hcc

* Update dbt docs

* Add function to cast string to resolve redshift error

* Bump package version

* Refactor comorbidity table

* update dbt docs
  • Loading branch information
sarah-tuva authored Mar 27, 2024
1 parent ec0c800 commit 85a5b71
Show file tree
Hide file tree
Showing 10 changed files with 1,047 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'the_tuva_project'
version: '0.7.12'
version: '0.7.13'
config-version: 2
require-dbt-version: ">=1.3.0"

Expand Down
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.

35 changes: 34 additions & 1 deletion models/hcc_suspecting/final/hcc_suspecting__list.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,52 @@ with hcc_history_suspects as (
, data_source
, hcc_code
, hcc_description
, 'Prior coding history' as reason
, cast('Prior coding history' as {{ dbt.type_string() }}) 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
, coalesce(last_billed, last_recorded) as condition_date
from {{ ref('hcc_suspecting__int_patient_hcc_history') }}
where current_year_billed = false

)

, comorbidity_suspects as (

select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, cast('Comorbidity suspect' as {{ dbt.type_string() }}) as reason
, condition_1_concept_name
|| ' ('
|| condition_1_code
|| ' on '
|| condition_1_recorded_date
|| ')'
|| ' and '
|| condition_2_concept_name
|| ' ('
|| condition_2_code
|| ' on '
|| condition_2_recorded_date
|| ')'
as contributing_factor
, condition_1_recorded_date as condition_date
from {{ ref('hcc_suspecting__int_comorbidity_suspects') }}
where current_year_billed = false

)

, unioned as (

select * from hcc_history_suspects
union all
select * from comorbidity_suspects

)

Expand All @@ -37,6 +68,7 @@ with hcc_history_suspects as (
, 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
, cast(condition_date as date) as condition_date
from unioned

)
Expand All @@ -48,5 +80,6 @@ select
, hcc_description
, reason
, contributing_factor
, condition_date
, '{{ var('tuva_last_run')}}' as tuva_last_run
from add_data_types
61 changes: 61 additions & 0 deletions models/hcc_suspecting/final/hcc_suspecting__list_rollup.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)))) | as_bool
)
}}

with list as (

select
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, condition_date
, row_number() over (
partition by
patient_id
, hcc_code
order by condition_date desc
) as row_num
from {{ ref('hcc_suspecting__list') }}

)

, list_dedupe as (

select
patient_id
, hcc_code
, hcc_description
, reason
, contributing_factor
, condition_date as latest_condition_date
from list
where row_num = 1

)

, add_data_types as (

select
cast(patient_id as {{ dbt.type_string() }}) as patient_id
, 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
, cast(latest_condition_date as date) as latest_condition_date
from list_dedupe

)

select
patient_id
, hcc_code
, hcc_description
, reason
, contributing_factor
, latest_condition_date
, '{{ var('tuva_last_run')}}' as tuva_last_run
from add_data_types
78 changes: 74 additions & 4 deletions models/hcc_suspecting/hcc_suspecting_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ models:
tags: hcc_suspecting
materialized: table
description: >
This final model displays the list of suspecting conditions per patient
with the reason and contributing factors.
This final model displays the list of suspecting conditions per patient,
data_source, hcc, and diagnosis code with the reason and contributing
factors.
columns:
- name: patient_id
description: Unique ID for the patient.
Expand All @@ -32,6 +33,39 @@ models:
- name: contributing_factor
description: >
Description of the contributing factor(s) for the suspecting condition.
- name: condition_date
description: Date when the condition was recorded or billed.
- name: tuva_last_run
description: The date the model was run.

- name: hcc_suspecting__list_rollup
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: list_rollup
tags: hcc_suspecting
materialized: table
description: >
This final model displays the list of suspecting conditions per patient
and hcc with the latest contributing factor rolled up.
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/tuva/blob/main/seeds/value_sets/hcc_suspecting/hcc_suspecting__hcc_descriptions.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: latest_condition_date
description: Date when the condition was recorded or billed.
- name: tuva_last_run
description: The date the model was run.

Expand Down Expand Up @@ -91,6 +125,42 @@ models:
- name: tuva_last_run
description: The date the model was run.

- name: hcc_suspecting__int_comorbidity_suspects
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_hcc_suspecting{% else %}hcc_suspecting{%- endif -%}
alias: _int_comorbidity_suspects
tags: hcc_suspecting
materialized: table
description: Comorbidity suspecting conditions.
columns:
- name: patient_id
description: Unique ID for the patient.
- name: data_source
description: >
User-configured field that indicates the data source (e.g. typically
named after the payer and state "BCBS Tennessee").
- name: hcc_code
description: >
HCC code from the latest CMS HCC model available in the mart.
meta:
terminology: https://github.com/tuva-health/tuva/blob/main/seeds/value_sets/hcc_suspecting/hcc_suspecting__hcc_descriptions.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: condition_date
description: Date when the condition was recorded or billed.
- name: current_year_billed
description: >
Flag indicating that the HCC has been billed during the payment year.
- name: tuva_last_run
description: The date the model was run.

- name: hcc_suspecting__int_patient_hcc_history
config:
schema: |
Expand Down Expand Up @@ -134,8 +204,8 @@ models:
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.
Flag indicating that the ICD-10-CM code mapped to the HCC has been
billed during the payment year.
- name: tuva_last_run
description: The date the model was run.

Expand Down
Loading

0 comments on commit 85a5b71

Please sign in to comment.