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

Refactor code and description columns #508

Merged
merged 8 commits into from
Jun 21, 2024
4 changes: 3 additions & 1 deletion ci_testing/models/encounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ cast(null as {{ dbt.type_string() }} ) as encounter_id
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_code
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_description
, cast(null as {{ dbt.type_string() }} ) as attending_provider_id
, cast(null as {{ dbt.type_string() }} ) as facility_npi
, cast(null as {{ dbt.type_string() }} ) as attending_provider_name
, cast(null as {{ dbt.type_string() }} ) as facility_id
, cast(null as {{ dbt.type_string() }} ) as facility_name
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code_type
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_description
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ seeds:
+post-hook: "{{ load_seed('tuva-public-resources/versioned_value_sets/0.8.7','cms_hcc_payment_hcc_count_factors.csv',compression=true,null_marker=true) }}"
data_quality:
data_quality__test_catalog:
+post-hook: "{{ load_seed('tuva-public-resources/versioned_value_sets/0.8.7','data_quality_test_catalog.csv',compression=true,null_marker=true) }}"
+post-hook: "{{ load_seed('tuva-public-resources/versioned_value_sets/0.9.0','data_quality_test_catalog.csv',compression=true,null_marker=true) }}"
ed_classification:
ed_classification__categories:
+post-hook: "{{ load_seed('tuva-public-resources/versioned_value_sets/0.8.7','ed_classification_categories.csv',compression=true,null_marker=true) }}"
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vars:
error_empty_seeds: true
## Use this variable to run the project with synthetic data loaded as seeds
# otherwise set to false and set the input vars below
use_synthetic_data: true
use_synthetic_data: false

## Update these vars to use your own data as input, do not comment out
# enabled logic has been added to the sources config
Expand Down
20 changes: 17 additions & 3 deletions integration_tests/docs_generate/models/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The eligibility table includes information about a patient's health
insurance coverage and demographics (note: we use the word patient as a
Expand Down Expand Up @@ -98,6 +99,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The medical_claim table contains information on healthcare services and
supplies provided to patients, billed by providers, and paid for by health
Expand Down Expand Up @@ -696,6 +698,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The pharmacy_claim table includes information about retail and specialty
drug prescriptions that have been filled by a patient, billed by a
Expand Down Expand Up @@ -772,6 +775,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The condition table contains information related to medical conditions
patients have, including problems, admitting diagnosis codes, and billable
Expand Down Expand Up @@ -851,6 +855,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The encounter table contains information about patients visits (i.e.
encounters). This includes acute inpatient, emergency department, office
Expand Down Expand Up @@ -898,10 +903,13 @@ models:
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__provider.csv
terminology_note: "**Note: this terminology set is too large to be loaded as a seed and is instead loaded from public cloud storage for supported adapters."
- name: facility_npi
- name: facility_id
description: >
Facility identifier for the encounter (typically represents the facility where services were performed). Can
be an NPI or source code.
- name: facility_name
description: >
Facility NPI for the encounter (typically represents the facility
where services were performed).
Facility name for the encounter (typically represents the facility where services were performed).
meta:
terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__provider.csv
terminology_note: "**Note: this terminology set is too large to be loaded as a seed and is instead loaded from public cloud storage for supported adapters."
Expand Down Expand Up @@ -957,6 +965,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The lab result table contains information about lab test results,
including the LOINC code and description, units, reference range, and
Expand Down Expand Up @@ -1052,6 +1061,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The location table contains information on practice and facility locations
where patients receive medical care.
Expand Down Expand Up @@ -1167,6 +1177,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The observation table contains information on measurements other than lab
tests e.g. blood pressure, height, and weight.
Expand Down Expand Up @@ -1226,6 +1237,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The patient table contains demographic and geographic information on
patients.
Expand Down Expand Up @@ -1282,6 +1294,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The practitioner table contains information on the providers in the
dataset e.g. physicians, physicians assistants, etc.
Expand Down Expand Up @@ -1321,6 +1334,7 @@ models:
database: tuva
schema: input_layer
tags: input_layer
materialized: table
description: >
The procedure table contains information on procedures that were performed
on patients in the dataset.
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/docs_generate/models/encounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ select
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_code
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_description
, cast(null as {{ dbt.type_string() }} ) as attending_provider_id
, cast(null as {{ dbt.type_string() }} ) as facility_npi
, cast(null as {{ dbt.type_string() }} ) as attending_provider_name
, cast(null as {{ dbt.type_string() }} ) as facility_id
, cast(null as {{ dbt.type_string() }} ) as facility_name
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code_type
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_description
Expand Down
1 change: 1 addition & 0 deletions integration_tests/docs_generate/models/medical_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ select
, procedure_date_24
, procedure_date_25
, data_source
, in_network_flag
, file_name
, ingest_datetime
from {{ ref('medical_claim_seed') }}
1 change: 1 addition & 0 deletions integration_tests/docs_generate/models/pharmacy_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ select
, copayment_amount
, deductible_amount
, data_source
, in_network_flag
, file_name
, ingest_datetime
from {{ ref('pharmacy_claim_seed') }}
4 changes: 3 additions & 1 deletion integration_tests/models/encounter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ cast(null as {{ dbt.type_string() }} ) as encounter_id
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_code
, cast(null as {{ dbt.type_string() }} ) as discharge_disposition_description
, cast(null as {{ dbt.type_string() }} ) as attending_provider_id
, cast(null as {{ dbt.type_string() }} ) as facility_npi
, cast(null as {{ dbt.type_string() }} ) as attending_provider_name
, cast(null as {{ dbt.type_string() }} ) as facility_id
, cast(null as {{ dbt.type_string() }} ) as facility_name
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code_type
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_code
, cast(null as {{ dbt.type_string() }} ) as primary_diagnosis_description
Expand Down
8 changes: 4 additions & 4 deletions models/ahrq_measures/pqi/final/ahrq_measures__pqi_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ select p.pqi_number
, e.encounter_id
, e.data_source
, e.patient_id
, e.facility_npi
, e.facility_id
, e.ms_drg_code
, e.ms_drg_description
, e.encounter_start_date
Expand All @@ -17,7 +17,7 @@ select p.pqi_number
, e.paid_amount
, '{{ var('tuva_last_run')}}' as tuva_last_run
from {{ref('ahrq_measures__pqi_num_long')}} p
inner join {{ref('ahrq_measures__stg_pqi_inpatient_encounter')}} e on p.encounter_id = e.encounter_id
and
p.data_source = e.data_source
inner join {{ref('ahrq_measures__stg_pqi_inpatient_encounter')}} e
on p.encounter_id = e.encounter_id
and p.data_source = e.data_source
inner join {{ ref('pqi__measures') }} m on cast(p.pqi_number as {{ dbt.type_string() }}) = m.pqi_number
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ select
, length_of_stay
, primary_diagnosis_code
, patient_id
, facility_npi
, facility_id
, paid_amount
, {{ date_part('YEAR', 'encounter_start_date') }} as year_number
from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inner join {{ ref('acute_inpatient__encounter_start_and_end_dates') }} b
b.encounter_id
, first.diagnosis_code_1
, first.diagnosis_code_type
, first.facility_npi as facility_npi
, first.facility_id as facility_id
, first.ms_drg_code as ms_drg_code
, first.apr_drg_code as apr_drg_code
, first.admit_source_code as admit_source_code
Expand All @@ -44,7 +44,7 @@ inner join {{ ref('acute_inpatient__encounter_start_and_end_dates') }} b
b.encounter_id
, first.diagnosis_code_1
, first.diagnosis_code_type
, first.facility_npi
, first.facility_id
, first.ms_drg_code
, first.apr_drg_code
, first.admit_source_code
Expand Down Expand Up @@ -75,17 +75,16 @@ group by 1
from {{ ref('acute_inpatient__stg_eligibility') }}
)

, provider as (
, facility as (
select
a.encounter_id
, max(a.facility_npi) as facility_npi
, b.provider_first_name
, b.provider_last_name
, count(distinct facility_npi) as npi_count
, max(a.facility_id) as facility_id
, b.provider_organization_name
, count(distinct facility_id) as npi_count
from {{ ref('acute_inpatient__institutional_encounter_id') }} a
left join {{ ref('terminology__provider') }} b
on a.facility_npi = b.npi
group by 1,3,4
on a.facility_id = b.npi
group by 1,3
)

select
Expand All @@ -99,9 +98,8 @@ select
, c.diagnosis_code_type as primary_diagnosis_code_type
, c.diagnosis_code_1 as primary_diagnosis_code
, coalesce(icd10cm.long_description, icd9cm.long_description) as primary_diagnosis_description
, f.facility_npi
, f.provider_first_name
, f.provider_last_name
, f.facility_id as facility_id
, f.provider_organization_name as facility_name
, c.ms_drg_code
, j.ms_drg_description
, j.medical_surgical
Expand Down Expand Up @@ -130,7 +128,7 @@ left join professional_claim_details d
on a.encounter_id = d.encounter_id
left join patient e
on a.patient_id = e.patient_id
left join provider f
left join facility f
on a.encounter_id = f.encounter_id
left join {{ ref('terminology__discharge_disposition') }} g
on c.discharge_disposition_code = g.discharge_disposition_code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ from {{ ref('acute_inpatient__institutional_claims') }}
),


facility_npi_not_unique as (
facility_id_not_unique as (
select
'22 facility_npi_not_unique' as field,
sum(facility_npi_not_unique) as total_count
'22 facility_id_not_unique' as field,
sum(facility_id_not_unique) as total_count
from {{ ref('acute_inpatient__institutional_claims') }}
),


facility_npi_missing as (
facility_id_missing as (
select
'23 facility_npi_missing' as field,
sum(facility_npi_missing) as total_count
'23 facility_id_missing' as field,
sum(facility_id_missing) as total_count
from {{ ref('acute_inpatient__institutional_claims') }}
),

Expand Down Expand Up @@ -378,12 +378,12 @@ from discharge_disposition_code_missing
union all

select *
from facility_npi_not_unique
from facility_id_not_unique

union all

select *
from facility_npi_missing
from facility_id_missing

union all

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{{ config(
enabled = var('claims_preprocessing_enabled',var('claims_enabled',var('tuva_marts_enabled',False))) | as_bool
)
}}

with first_claim_values as(
select distinct
e.encounter_id
, coalesce(claim_start_date, admission_date) as claim_start
, diagnosis_code_1
, diagnosis_code_type
, admit_source_code
, admit_type_code
, facility_npi
, ms_drg_code
, apr_drg_code
from {{ ref('acute_inpatient__encounter_id')}} e
inner join {{ ref('acute_inpatient__stg_medical_claim') }} m
on e.claim_id = m.claim_id
where claim_type = 'institutional'
)

select
encounter_id
, claim_start
, diagnosis_code_1
, diagnosis_code_type
, admit_source_code
, admit_type_code
, facility_npi
, ms_drg_code
, apr_drg_code
, row_number() over (partition by encounter_id order by claim_start) as claim_row
from first_claim_values
{{ config(
enabled = var('claims_preprocessing_enabled',var('claims_enabled',var('tuva_marts_enabled',False)))
| as_bool
)
}}

with first_claim_values as(
select distinct
e.encounter_id
, coalesce(claim_start_date, admission_date) as claim_start
, diagnosis_code_1
, diagnosis_code_type
, admit_source_code
, admit_type_code
, facility_id
, ms_drg_code
, apr_drg_code
from {{ ref('acute_inpatient__encounter_id')}} e
inner join {{ ref('acute_inpatient__stg_medical_claim') }} m
on e.claim_id = m.claim_id
where claim_type = 'institutional'
)

select
encounter_id
, claim_start
, diagnosis_code_1
, diagnosis_code_type
, admit_source_code
, admit_type_code
, facility_id
, ms_drg_code
, apr_drg_code
, row_number() over (partition by encounter_id order by claim_start) as claim_row
from first_claim_values
Loading
Loading