diff --git a/ci_testing/dbt_project.yml b/ci_testing/dbt_project.yml index 82030ae8e..d891c33dd 100644 --- a/ci_testing/dbt_project.yml +++ b/ci_testing/dbt_project.yml @@ -12,7 +12,7 @@ vars: ## Update these vars to use your own data as input, do not comment out # enabled logic has been added to the sources config - input_database: dev-ci-testing + input_database: dev_ci_testing input_schema: input_layer tuva_last_run: '{{ run_started_at.astimezone(modules.pytz.timezone("UTC")) }}' @@ -62,14 +62,14 @@ dispatch: seeds: ci_testing: eligibility_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/tuva_synthetic_data','eligibility.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','eligibility.csv',headers=true) }}" lab_result_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/tuva_synthetic_data','lab_result.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','lab_result.csv',headers=true) }}" medical_claim_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/tuva_synthetic_data','medical_claim.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','medical_claim.csv',headers=true) }}" observation_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/tuva_synthetic_data','observation.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','observation.csv',headers=true) }}" pharmacy_claim_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/tuva_synthetic_data','pharmacy_claim.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','pharmacy_claim.csv',headers=true) }}" provider_attribution_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','provider_attribution.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','provider_attribution.csv',headers=true) }}" diff --git a/ci_testing/macros/quote_column.sql b/ci_testing/macros/quote_column.sql new file mode 100644 index 000000000..32a490d8d --- /dev/null +++ b/ci_testing/macros/quote_column.sql @@ -0,0 +1,7 @@ +{% macro quote_column(column_name) %} + {%- if target.type == 'fabric' -%} + "{{ column_name }}" + {%- else -%} + {{ column_name }} + {%- endif -%} +{% endmacro %} diff --git a/ci_testing/models/condition.sql b/ci_testing/models/condition.sql index 664742aa8..93c2a105a 100644 --- a/ci_testing/models/condition.sql +++ b/ci_testing/models/condition.sql @@ -1,6 +1,6 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as condition_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id @@ -19,28 +19,7 @@ select top 0 , cast(null as {{ dbt.type_string() }} ) as present_on_admit_code , cast(null as {{ dbt.type_string() }} ) as present_on_admit_description , cast(null as {{ dbt.type_string() }} ) as data_source +, cast(null as {{ dbt.type_string() }} ) as file_name +, cast(null as {{ dbt.type_timestamp() }} ) as ingest_datetime , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select - cast(null as {{ dbt.type_string() }} ) as condition_id -, cast(null as {{ dbt.type_string() }} ) as patient_id -, cast(null as {{ dbt.type_string() }} ) as encounter_id -, cast(null as {{ dbt.type_string() }} ) as claim_id -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as recorded_date -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as onset_date -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as resolved_date -, cast(null as {{ dbt.type_string() }} ) as status -, cast(null as {{ dbt.type_string() }} ) as condition_type -, cast(null as {{ dbt.type_string() }} ) as source_code_type -, cast(null as {{ dbt.type_string() }} ) as source_code -, cast(null as {{ dbt.type_string() }} ) as source_description -, cast(null as {{ dbt.type_string() }} ) as normalized_code_type -, cast(null as {{ dbt.type_string() }} ) as normalized_code -, cast(null as {{ dbt.type_string() }} ) as normalized_description -, cast(null as {{ dbt.type_int() }} ) as condition_rank -, cast(null as {{ dbt.type_string() }} ) as present_on_admit_code -, cast(null as {{ dbt.type_string() }} ) as present_on_admit_description -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/encounter.sql b/ci_testing/models/encounter.sql index f5f85db8b..5e666f4d7 100644 --- a/ci_testing/models/encounter.sql +++ b/ci_testing/models/encounter.sql @@ -1,6 +1,6 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as encounter_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_type , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as encounter_start_date @@ -27,36 +27,7 @@ cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_float() }} ) as allowed_amount , cast(null as {{ dbt.type_float() }} ) as charge_amount , cast(null as {{ dbt.type_string() }} ) as data_source +, cast(null as {{ dbt.type_string() }} ) as file_name +, cast(null as {{ dbt.type_timestamp() }} ) as ingest_datetime , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select -cast(null as {{ dbt.type_string() }} ) as encounter_id -, cast(null as {{ dbt.type_string() }} ) as patient_id -, cast(null as {{ dbt.type_string() }} ) as encounter_type -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as encounter_start_date -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as encounter_end_date -, cast(null as {{ dbt.type_int() }} ) as length_of_stay -, cast(null as {{ dbt.type_string() }} ) as admit_source_code -, cast(null as {{ dbt.type_string() }} ) as admit_source_description -, cast(null as {{ dbt.type_string() }} ) as admit_type_code -, cast(null as {{ dbt.type_string() }} ) as admit_type_description -, 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 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 -, cast(null as {{ dbt.type_string() }} ) as ms_drg_code -, cast(null as {{ dbt.type_string() }} ) as ms_drg_description -, cast(null as {{ dbt.type_string() }} ) as apr_drg_code -, cast(null as {{ dbt.type_string() }} ) as apr_drg_description -, cast(null as {{ dbt.type_float() }} ) as paid_amount -, cast(null as {{ dbt.type_float() }} ) as allowed_amount -, cast(null as {{ dbt.type_float() }} ) as charge_amount -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/lab_result.sql b/ci_testing/models/lab_result.sql index 34213e5c5..c1916394b 100644 --- a/ci_testing/models/lab_result.sql +++ b/ci_testing/models/lab_result.sql @@ -6,9 +6,9 @@ select * from {{ ref('lab_result_seed') }} {%- else -%} - {% if target.type == 'fabric' %} - select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as lab_result_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as accession_number @@ -36,37 +36,6 @@ select * from {{ ref('lab_result_seed') }} , cast(null as {{ dbt.type_string() }} ) as ordering_practitioner_id , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run - {% else %} - select - cast(null as {{ dbt.type_string() }} ) as lab_result_id - , cast(null as {{ dbt.type_string() }} ) as patient_id - , cast(null as {{ dbt.type_string() }} ) as encounter_id - , cast(null as {{ dbt.type_string() }} ) as accession_number - , cast(null as {{ dbt.type_string() }} ) as source_code_type - , cast(null as {{ dbt.type_string() }} ) as source_code - , cast(null as {{ dbt.type_string() }} ) as source_description - , cast(null as {{ dbt.type_string() }} ) as source_component - , cast(null as {{ dbt.type_string() }} ) as normalized_code_type - , cast(null as {{ dbt.type_string() }} ) as normalized_code - , cast(null as {{ dbt.type_string() }} ) as normalized_description - , cast(null as {{ dbt.type_string() }} ) as normalized_component - , cast(null as {{ dbt.type_string() }} ) as status - , cast(null as {{ dbt.type_string() }} ) as result - , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as result_date - , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as collection_date - , cast(null as {{ dbt.type_string() }} ) as source_units - , cast(null as {{ dbt.type_string() }} ) as normalized_units - , cast(null as {{ dbt.type_string() }} ) as source_reference_range_low - , cast(null as {{ dbt.type_string() }} ) as source_reference_range_high - , cast(null as {{ dbt.type_string() }} ) as normalized_reference_range_low - , cast(null as {{ dbt.type_string() }} ) as normalized_reference_range_high - , cast(null as {{ dbt.type_int() }} ) as source_abnormal_flag - , cast(null as {{ dbt.type_int() }} ) as normalized_abnormal_flag - , cast(null as {{ dbt.type_string() }} ) as specimen - , cast(null as {{ dbt.type_string() }} ) as ordering_practitioner_id - , cast(null as {{ dbt.type_string() }} ) as data_source - , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run - limit 0 - {%- endif %} + {% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} {%- endif %} diff --git a/ci_testing/models/location.sql b/ci_testing/models/location.sql index 498cd5019..07353bec1 100644 --- a/ci_testing/models/location.sql +++ b/ci_testing/models/location.sql @@ -1,5 +1,4 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as location_id , cast(null as {{ dbt.type_string() }} ) as npi , cast(null as {{ dbt.type_string() }} ) as name @@ -13,20 +12,4 @@ cast(null as {{ dbt.type_string() }} ) as location_id , cast(null as {{ dbt.type_float() }} ) as longitude , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select -cast(null as {{ dbt.type_string() }} ) as location_id -, cast(null as {{ dbt.type_string() }} ) as npi -, cast(null as {{ dbt.type_string() }} ) as name -, cast(null as {{ dbt.type_string() }} ) as facility_type -, cast(null as {{ dbt.type_string() }} ) as parent_organization -, cast(null as {{ dbt.type_string() }} ) as address -, cast(null as {{ dbt.type_string() }} ) as city -, cast(null as {{ dbt.type_string() }} ) as state -, cast(null as {{ dbt.type_string() }} ) as zip_code -, cast(null as {{ dbt.type_float() }} ) as latitude -, cast(null as {{ dbt.type_float() }} ) as longitude -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/medication.sql b/ci_testing/models/medication.sql index 3317878a7..755578a0f 100644 --- a/ci_testing/models/medication.sql +++ b/ci_testing/models/medication.sql @@ -1,6 +1,6 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as medication_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date @@ -22,29 +22,4 @@ cast(null as {{ dbt.type_string() }} ) as medication_id , cast(null as {{ dbt.type_string() }} ) as practitioner_id , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select -cast(null as {{ dbt.type_string() }} ) as medication_id -, cast(null as {{ dbt.type_string() }} ) as patient_id -, cast(null as {{ dbt.type_string() }} ) as encounter_id -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as prescribing_date -, cast(null as {{ dbt.type_string() }} ) as source_code_type -, cast(null as {{ dbt.type_string() }} ) as source_code -, cast(null as {{ dbt.type_string() }} ) as source_description -, cast(null as {{ dbt.type_string() }} ) as ndc_code -, cast(null as {{ dbt.type_string() }} ) as ndc_description -, cast(null as {{ dbt.type_string() }} ) as rxnorm_code -, cast(null as {{ dbt.type_string() }} ) as rxnorm_description -, cast(null as {{ dbt.type_string() }} ) as atc_code -, cast(null as {{ dbt.type_string() }} ) as atc_description -, cast(null as {{ dbt.type_string() }} ) as route -, cast(null as {{ dbt.type_string() }} ) as strength -, cast(null as {{ dbt.type_int() }} ) as quantity -, cast(null as {{ dbt.type_string() }} ) as quantity_unit -, cast(null as {{ dbt.type_int() }} ) as days_supply -, cast(null as {{ dbt.type_string() }} ) as practitioner_id -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/observation.sql b/ci_testing/models/observation.sql index 7d9090d83..ce0c47461 100644 --- a/ci_testing/models/observation.sql +++ b/ci_testing/models/observation.sql @@ -6,9 +6,9 @@ select * from {{ ref('observation_seed') }} {%- else -%} -{% if target.type == 'fabric' %} - select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as observation_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as panel_id @@ -29,30 +29,6 @@ select * from {{ ref('observation_seed') }} , cast(null as {{ dbt.type_string() }} ) as normalized_reference_range_high , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run - {% else %} - select - cast(null as {{ dbt.type_string() }} ) as observation_id - , cast(null as {{ dbt.type_string() }} ) as patient_id - , cast(null as {{ dbt.type_string() }} ) as encounter_id - , cast(null as {{ dbt.type_string() }} ) as panel_id - , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as observation_date - , cast(null as {{ dbt.type_string() }} ) as observation_type - , cast(null as {{ dbt.type_string() }} ) as source_code_type - , cast(null as {{ dbt.type_string() }} ) as source_code - , cast(null as {{ dbt.type_string() }} ) as source_description - , cast(null as {{ dbt.type_string() }} ) as normalized_code_type - , cast(null as {{ dbt.type_string() }} ) as normalized_code - , cast(null as {{ dbt.type_string() }} ) as normalized_description - , cast(null as {{ dbt.type_string() }} ) as result - , cast(null as {{ dbt.type_string() }} ) as source_units - , cast(null as {{ dbt.type_string() }} ) as normalized_units - , cast(null as {{ dbt.type_string() }} ) as source_reference_range_low - , cast(null as {{ dbt.type_string() }} ) as source_reference_range_high - , cast(null as {{ dbt.type_string() }} ) as normalized_reference_range_low - , cast(null as {{ dbt.type_string() }} ) as normalized_reference_range_high - , cast(null as {{ dbt.type_string() }} ) as data_source - , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run - limit 0 - {% endif %} + {% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} {%- endif %} diff --git a/ci_testing/models/patient.sql b/ci_testing/models/patient.sql index 22b50e531..a6dc1cb37 100644 --- a/ci_testing/models/patient.sql +++ b/ci_testing/models/patient.sql @@ -1,6 +1,6 @@ -{% if target.type == 'fabric' %} -select top 0 -cast(null as {{ dbt.type_string() }} ) as patient_id +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} +cast(null as {{ dbt.type_string() }} ) as person_id +, cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as first_name , cast(null as {{ dbt.type_string() }} ) as last_name , cast(null as {{ dbt.type_string() }} ) as sex @@ -16,27 +16,7 @@ cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as county , cast(null as {{ dbt.type_float() }} ) as latitude , cast(null as {{ dbt.type_float() }} ) as longitude +, cast(null as {{ dbt.type_string() }}) as phone , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select -cast(null as {{ dbt.type_string() }} ) as patient_id -, cast(null as {{ dbt.type_string() }} ) as first_name -, cast(null as {{ dbt.type_string() }} ) as last_name -, cast(null as {{ dbt.type_string() }} ) as sex -, cast(null as {{ dbt.type_string() }} ) as race -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as birth_date -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as death_date -, cast(null as {{ dbt.type_int() }} ) as death_flag -, cast(null as {{ dbt.type_string() }} ) as social_security_number -, cast(null as {{ dbt.type_string() }} ) as address -, cast(null as {{ dbt.type_string() }} ) as city -, cast(null as {{ dbt.type_string() }} ) as state -, cast(null as {{ dbt.type_string() }} ) as zip_code -, cast(null as {{ dbt.type_string() }} ) as county -, cast(null as {{ dbt.type_float() }} ) as latitude -, cast(null as {{ dbt.type_float() }} ) as longitude -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/practitioner.sql b/ci_testing/models/practitioner.sql index 279b62f9b..f1f0ebf1f 100644 --- a/ci_testing/models/practitioner.sql +++ b/ci_testing/models/practitioner.sql @@ -1,5 +1,4 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as practitioner_id , cast(null as {{ dbt.type_string() }} ) as npi , cast(null as {{ dbt.type_string() }} ) as first_name @@ -9,16 +8,4 @@ select top 0 , cast(null as {{ dbt.type_string() }} ) as sub_specialty , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select - cast(null as {{ dbt.type_string() }} ) as practitioner_id -, cast(null as {{ dbt.type_string() }} ) as npi -, cast(null as {{ dbt.type_string() }} ) as first_name -, cast(null as {{ dbt.type_string() }} ) as last_name -, cast(null as {{ dbt.type_string() }} ) as practice_affiliation -, cast(null as {{ dbt.type_string() }} ) as specialty -, cast(null as {{ dbt.type_string() }} ) as sub_specialty -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/procedure.sql b/ci_testing/models/procedure.sql index e827e5930..ca01da316 100644 --- a/ci_testing/models/procedure.sql +++ b/ci_testing/models/procedure.sql @@ -1,6 +1,6 @@ -{% if target.type == 'fabric' %} -select top 0 +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as procedure_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id @@ -19,26 +19,4 @@ select top 0 , cast(null as {{ dbt.type_string() }} ) as practitioner_id , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -{% else %} -select - cast(null as {{ dbt.type_string() }} ) as procedure_id -, cast(null as {{ dbt.type_string() }} ) as patient_id -, cast(null as {{ dbt.type_string() }} ) as encounter_id -, cast(null as {{ dbt.type_string() }} ) as claim_id -, {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as procedure_date -, cast(null as {{ dbt.type_string() }} ) as source_code_type -, cast(null as {{ dbt.type_string() }} ) as source_code -, cast(null as {{ dbt.type_string() }} ) as source_description -, cast(null as {{ dbt.type_string() }} ) as normalized_code_type -, cast(null as {{ dbt.type_string() }} ) as normalized_code -, cast(null as {{ dbt.type_string() }} ) as normalized_description -, cast(null as {{ dbt.type_string() }} ) as modifier_1 -, cast(null as {{ dbt.type_string() }} ) as modifier_2 -, cast(null as {{ dbt.type_string() }} ) as modifier_3 -, cast(null as {{ dbt.type_string() }} ) as modifier_4 -, cast(null as {{ dbt.type_string() }} ) as modifier_5 -, cast(null as {{ dbt.type_string() }} ) as practitioner_id -, cast(null as {{ dbt.type_string() }} ) as data_source -, cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run -limit 0 -{% endif %} +{% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} \ No newline at end of file diff --git a/ci_testing/models/provider_attribution.sql b/ci_testing/models/provider_attribution.sql index 2bf7e6bcd..58b13355e 100644 --- a/ci_testing/models/provider_attribution.sql +++ b/ci_testing/models/provider_attribution.sql @@ -4,8 +4,29 @@ ) }} +{# logic to use the seed data or an empty table -#} +{% if var('test_data_override') == true -%} +select * from {{ ref('provider_attribution_seed') }} +{%- else -%} -select * from {{ ref('provider_attribution_seed') }} +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} + cast(null as {{ dbt.type_string() }} ) as person_id + , cast(null as {{ dbt.type_string() }} ) as patient_id + , cast(null as {{ dbt.type_string() }} ) as year_month + , cast(null as {{ dbt.type_string() }} ) as payer + , cast(null as {{ dbt.type_string() }} ) as {{ quote_column('plan') }} + , cast(null as {{ dbt.type_string() }} ) as data_source + , cast(null as {{ dbt.type_string() }} ) as payer_attributed_provider + , cast(null as {{ dbt.type_string() }} ) as payer_attributed_provider_practice + , cast(null as {{ dbt.type_string() }} ) as payer_attributed_provider_organization + , cast(null as {{ dbt.type_string() }} ) as payer_attributed_provider_lob + , cast(null as {{ dbt.type_string() }} ) as custom_attributed_provider + , cast(null as {{ dbt.type_string() }} ) as custom_attributed_provider_practice + , cast(null as {{ dbt.type_string() }} ) as custom_attributed_provider_organization + , cast(null as {{ dbt.type_string() }} ) as custom_attributed_provider_lob + {% if target.type == 'fabric' %} {% else %} limit 0 {% endif %} + +{%- endif %} diff --git a/ci_testing/seeds/_seeds.yml b/ci_testing/seeds/_seeds.yml index 227779929..877eaa003 100644 --- a/ci_testing/seeds/_seeds.yml +++ b/ci_testing/seeds/_seeds.yml @@ -9,7 +9,7 @@ seeds: enabled: | {% if var('test_data_override') == true -%} {{ true|as_bool }} {%- else -%} {{ false|as_bool }} {%- endif -%} column_types: - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -67,6 +67,8 @@ seeds: column_types: lab_result_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} + person_id: | + {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} patient_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} encounter_id: | @@ -131,7 +133,7 @@ seeds: claim_line_number: integer claim_type: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -380,6 +382,8 @@ seeds: column_types: observation_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} + person_id: | + {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} patient_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} encounter_id: | @@ -429,7 +433,7 @@ seeds: claim_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} claim_line_number: integer - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -452,15 +456,16 @@ seeds: allowed_amount: float data_source: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} - - name: provider_attribution_seed config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_tuva_synthetic {% else %}_tuva_synthetic{%- endif -%} + enabled: | + {% if var('test_data_override') == true -%} {{ true|as_bool }} {%- else -%} {{ false|as_bool }} {%- endif -%} column_types: - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} year_month: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} diff --git a/ci_testing/seeds/eligibility_seed.csv b/ci_testing/seeds/eligibility_seed.csv index 766b48e44..0dbc37868 100644 --- a/ci_testing/seeds/eligibility_seed.csv +++ b/ci_testing/seeds/eligibility_seed.csv @@ -1 +1 @@ -patient_id,member_id,subscriber_id,gender,race,birth_date,death_date,death_flag,enrollment_start_date,enrollment_end_date,payer,payer_type,plan,original_reason_entitlement_code,dual_status_code,medicare_status_code,first_name,last_name,social_security_number,subscriber_relation,address,city,state,zip_code,phone,data_source \ No newline at end of file +person_id,member_id,subscriber_id,gender,race,birth_date,death_date,death_flag,enrollment_start_date,enrollment_end_date,payer,payer_type,plan,original_reason_entitlement_code,dual_status_code,medicare_status_code,first_name,last_name,social_security_number,subscriber_relation,address,city,state,zip_code,phone,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/ci_testing/seeds/lab_result_seed.csv b/ci_testing/seeds/lab_result_seed.csv index 232fda69b..61b183b90 100644 --- a/ci_testing/seeds/lab_result_seed.csv +++ b/ci_testing/seeds/lab_result_seed.csv @@ -1 +1 @@ -lab_result_id,patient_id,encounter_id,accession_number,source_code_type,source_code,source_description,source_component,normalized_code_type,normalized_code,normalized_description,normalized_component,status,result,result_date,collection_date,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,source_abnormal_flag,normalized_abnormal_flag,specimen,ordering_practitioner_id,data_source \ No newline at end of file +lab_result_id,person_id,patient_id,encounter_id,accession_number,source_code_type,source_code,source_description,source_component,normalized_code_type,normalized_code,normalized_description,normalized_component,status,result,result_date,collection_date,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,source_abnormal_flag,normalized_abnormal_flag,specimen,ordering_practitioner_id,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/ci_testing/seeds/medical_claim_seed.csv b/ci_testing/seeds/medical_claim_seed.csv index dfe13102e..1a86bde2d 100644 --- a/ci_testing/seeds/medical_claim_seed.csv +++ b/ci_testing/seeds/medical_claim_seed.csv @@ -1 +1 @@ -claim_id,claim_line_number,claim_type,patient_id,member_id,payer,plan,claim_start_date,claim_end_date,claim_line_start_date,claim_line_end_date,admission_date,discharge_date,admit_source_code,admit_type_code,discharge_disposition_code,place_of_service_code,bill_type_code,ms_drg_code,apr_drg_code,revenue_center_code,service_unit_quantity,hcpcs_code,hcpcs_modifier_1,hcpcs_modifier_2,hcpcs_modifier_3,hcpcs_modifier_4,hcpcs_modifier_5,rendering_npi,billing_npi,facility_npi,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,total_cost_amount,diagnosis_code_type,diagnosis_code_1,diagnosis_code_2,diagnosis_code_3,diagnosis_code_4,diagnosis_code_5,diagnosis_code_6,diagnosis_code_7,diagnosis_code_8,diagnosis_code_9,diagnosis_code_10,diagnosis_code_11,diagnosis_code_12,diagnosis_code_13,diagnosis_code_14,diagnosis_code_15,diagnosis_code_16,diagnosis_code_17,diagnosis_code_18,diagnosis_code_19,diagnosis_code_20,diagnosis_code_21,diagnosis_code_22,diagnosis_code_23,diagnosis_code_24,diagnosis_code_25,diagnosis_poa_1,diagnosis_poa_2,diagnosis_poa_3,diagnosis_poa_4,diagnosis_poa_5,diagnosis_poa_6,diagnosis_poa_7,diagnosis_poa_8,diagnosis_poa_9,diagnosis_poa_10,diagnosis_poa_11,diagnosis_poa_12,diagnosis_poa_13,diagnosis_poa_14,diagnosis_poa_15,diagnosis_poa_16,diagnosis_poa_17,diagnosis_poa_18,diagnosis_poa_19,diagnosis_poa_20,diagnosis_poa_21,diagnosis_poa_22,diagnosis_poa_23,diagnosis_poa_24,diagnosis_poa_25,procedure_code_type,procedure_code_1,procedure_code_2,procedure_code_3,procedure_code_4,procedure_code_5,procedure_code_6,procedure_code_7,procedure_code_8,procedure_code_9,procedure_code_10,procedure_code_11,procedure_code_12,procedure_code_13,procedure_code_14,procedure_code_15,procedure_code_16,procedure_code_17,procedure_code_18,procedure_code_19,procedure_code_20,procedure_code_21,procedure_code_22,procedure_code_23,procedure_code_24,procedure_code_25,procedure_date_1,procedure_date_2,procedure_date_3,procedure_date_4,procedure_date_5,procedure_date_6,procedure_date_7,procedure_date_8,procedure_date_9,procedure_date_10,procedure_date_11,procedure_date_12,procedure_date_13,procedure_date_14,procedure_date_15,procedure_date_16,procedure_date_17,procedure_date_18,procedure_date_19,procedure_date_20,procedure_date_21,procedure_date_22,procedure_date_23,procedure_date_24,procedure_date_25,data_source +claim_id,claim_line_number,claim_type,person_id,member_id,payer,plan,claim_start_date,claim_end_date,claim_line_start_date,claim_line_end_date,admission_date,discharge_date,admit_source_code,admit_type_code,discharge_disposition_code,place_of_service_code,bill_type_code,ms_drg_code,apr_drg_code,revenue_center_code,service_unit_quantity,hcpcs_code,hcpcs_modifier_1,hcpcs_modifier_2,hcpcs_modifier_3,hcpcs_modifier_4,hcpcs_modifier_5,rendering_npi,rendering_tin,billing_npi,billing_tin,facility_npi,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,total_cost_amount,diagnosis_code_type,diagnosis_code_1,diagnosis_code_2,diagnosis_code_3,diagnosis_code_4,diagnosis_code_5,diagnosis_code_6,diagnosis_code_7,diagnosis_code_8,diagnosis_code_9,diagnosis_code_10,diagnosis_code_11,diagnosis_code_12,diagnosis_code_13,diagnosis_code_14,diagnosis_code_15,diagnosis_code_16,diagnosis_code_17,diagnosis_code_18,diagnosis_code_19,diagnosis_code_20,diagnosis_code_21,diagnosis_code_22,diagnosis_code_23,diagnosis_code_24,diagnosis_code_25,diagnosis_poa_1,diagnosis_poa_2,diagnosis_poa_3,diagnosis_poa_4,diagnosis_poa_5,diagnosis_poa_6,diagnosis_poa_7,diagnosis_poa_8,diagnosis_poa_9,diagnosis_poa_10,diagnosis_poa_11,diagnosis_poa_12,diagnosis_poa_13,diagnosis_poa_14,diagnosis_poa_15,diagnosis_poa_16,diagnosis_poa_17,diagnosis_poa_18,diagnosis_poa_19,diagnosis_poa_20,diagnosis_poa_21,diagnosis_poa_22,diagnosis_poa_23,diagnosis_poa_24,diagnosis_poa_25,procedure_code_type,procedure_code_1,procedure_code_2,procedure_code_3,procedure_code_4,procedure_code_5,procedure_code_6,procedure_code_7,procedure_code_8,procedure_code_9,procedure_code_10,procedure_code_11,procedure_code_12,procedure_code_13,procedure_code_14,procedure_code_15,procedure_code_16,procedure_code_17,procedure_code_18,procedure_code_19,procedure_code_20,procedure_code_21,procedure_code_22,procedure_code_23,procedure_code_24,procedure_code_25,procedure_date_1,procedure_date_2,procedure_date_3,procedure_date_4,procedure_date_5,procedure_date_6,procedure_date_7,procedure_date_8,procedure_date_9,procedure_date_10,procedure_date_11,procedure_date_12,procedure_date_13,procedure_date_14,procedure_date_15,procedure_date_16,procedure_date_17,procedure_date_18,procedure_date_19,procedure_date_20,procedure_date_21,procedure_date_22,procedure_date_23,procedure_date_24,procedure_date_25,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/ci_testing/seeds/observation_seed.csv b/ci_testing/seeds/observation_seed.csv index 2029a03a1..f47b4ead2 100644 --- a/ci_testing/seeds/observation_seed.csv +++ b/ci_testing/seeds/observation_seed.csv @@ -1 +1 @@ -observation_id,patient_id,encounter_id,panel_id,observation_date,observation_type,source_code_type,source_code,source_description,normalized_code_type,normalized_code,normalized_description,result,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,data_source \ No newline at end of file +observation_id,person_id,patient_id,encounter_id,panel_id,observation_date,observation_type,source_code_type,source_code,source_description,normalized_code_type,normalized_code,normalized_description,result,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/ci_testing/seeds/pharmacy_claim_seed.csv b/ci_testing/seeds/pharmacy_claim_seed.csv index 80d793e55..1283733ce 100644 --- a/ci_testing/seeds/pharmacy_claim_seed.csv +++ b/ci_testing/seeds/pharmacy_claim_seed.csv @@ -1 +1 @@ -claim_id,claim_line_number,patient_id,member_id,payer,plan,prescribing_provider_npi,dispensing_provider_npi,dispensing_date,ndc_code,quantity,days_supply,refills,paid_date,paid_amount,allowed_amount,coinsurance_amount,copayment_amount,deductible_amount,data_source \ No newline at end of file +claim_id,claim_line_number,person_id,member_id,payer,plan,prescribing_provider_npi,dispensing_provider_npi,dispensing_date,ndc_code,quantity,days_supply,refills,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/ci_testing/seeds/provider_attribution_seed.csv b/ci_testing/seeds/provider_attribution_seed.csv index 58fdb2ae2..642638fe0 100644 --- a/ci_testing/seeds/provider_attribution_seed.csv +++ b/ci_testing/seeds/provider_attribution_seed.csv @@ -1 +1 @@ -patient_id,year_month,payer,plan,data_source,payer_attributed_provider,payer_attributed_provider_practice,payer_attributed_provider_organization,payer_attributed_provider_lob,custom_attributed_provider,custom_attributed_provider_practice,custom_attributed_provider_organization,custom_attributed_provider_lob \ No newline at end of file +person_id,patient_id,year_month,payer,plan,data_source,payer_attributed_provider,payer_attributed_provider_practice,payer_attributed_provider_organization,payer_attributed_provider_lob,custom_attributed_provider,custom_attributed_provider_practice,custom_attributed_provider_organization,custom_attributed_provider_lob \ No newline at end of file diff --git a/dbt_doc_blocks/column_descriptions.md b/dbt_doc_blocks/column_descriptions.md index 9fe25b505..243501bc3 100644 --- a/dbt_doc_blocks/column_descriptions.md +++ b/dbt_doc_blocks/column_descriptions.md @@ -374,6 +374,10 @@ Facility name. Facility NPI for the claim (typically represents the facility where services were performed). {% enddocs %} +{% docs file_name %} +The file name of the source file. +{% enddocs %} + {% docs facility_type %} The type of facility e.g. acute care hospital. {% enddocs %} @@ -414,6 +418,10 @@ The CPT or HCPCS code representing the procedure or service provided. These code Flag indicating if the claim was in or out of network. {% enddocs %} +{% docs ingest_datetime %} +The date and time the source file was ingested into the data warehouse or landed in cloud storage. +{% enddocs %} + {% docs inferred_claim_end_column_used %} The column used to infer the claim end date. {% enddocs %} @@ -647,7 +655,7 @@ Identifier for the source system from which patient data originated. {% enddocs %} {% docs patient_id %} -Unique identifier for each patient in the dataset. +Identifier that links a patient to a particular clinical source system. {% enddocs %} {% docs patient_row_num %} @@ -678,6 +686,10 @@ Name of the line of business for the payer attributed provider (e.g. medicare, m Type of payer (e.g. commercial, medicare, medicaid, etc.). {% enddocs %} +{% docs person_id %} +Unique identifier for each person in the dataset. +{% enddocs %} + {% docs pharmacy_claim_id %} Unique identifier for each row in the table. {% enddocs %} diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index 1e2a3804c..8f96bc42e 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -73,17 +73,17 @@ dispatch: seeds: integration_tests: eligibility_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','eligibility.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','eligibility.csv',headers=true) }}" lab_result_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','lab_result.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','lab_result.csv',headers=true) }}" medical_claim_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','medical_claim.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','medical_claim.csv',headers=true) }}" observation_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','observation.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','observation.csv',headers=true) }}" pharmacy_claim_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','pharmacy_claim.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','pharmacy_claim.csv',headers=true) }}" provider_attribution_seed: - +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.12.0','provider_attribution.csv',headers=true) }}" + +post-hook: "{{ the_tuva_project.load_seed('tuva-public-resources/versioned_tuva_synthetic_data/0.13.0','provider_attribution.csv',headers=true) }}" models: integration_tests: diff --git a/integration_tests/docs_generate/models/_models.yml b/integration_tests/docs_generate/models/_models.yml index a8ce786f8..dd5e1fbd4 100644 --- a/integration_tests/docs_generate/models/_models.yml +++ b/integration_tests/docs_generate/models/_models.yml @@ -15,84 +15,75 @@ models: eligibility data, otherwise it's impossible to calculate member months, which are needed to calculate measures like PMPM. columns: - - name: patient_id - description: Unique identifier for each patient in the dataset. + - name: person_id + description: '{{ doc("person_id") }}' - name: member_id - description: > - Identifier that links a patient to a particular insurance product or - health plan. A patient can have more than one member_id because they - can have more than one insurance product/plan. + description: '{{ doc("member_id") }}' - name: subscriber_id - description: Identifier that links a patient to a particular insurance product or health plan. + description: '{{ doc("subscriber_id") }}' - name: gender - description: Biological sex of the patient. + description: '{{ doc("sex") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__gender.csv - name: race - description: Race of the patient. + description: '{{ doc("race") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__race.csv - name: birth_date - description: Date the patient was born. + description: '{{ doc("birth_date") }}' - name: death_date - description: Date the patient died. + description: '{{ doc("death_date") }}' - name: death_flag - description: Indicates whether the patient has died. + description: '{{ doc("death_flag") }}' data_type: boolean - name: enrollment_start_date - description: Date the patient's insurance eligibility began. + description: '{{ doc("enrollment_start_date") }}' - name: enrollment_end_date - description: Date the patient's insurance eligibility ended. + description: '{{ doc("enrollment_end_date") }}' - name: payer - description: Name of the payer (i.e. health insurer) providing coverage. + description: '{{ doc("payer") }}' - name: payer_type - description: Type of payer (e.g. commercial, medicare, medicaid, etc.). + description: '{{ doc("payer_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__payer_type.csv - name: plan - description: Name of the plan (i.e. sub contract) providing coverage. + description: '{{ doc("plan") }}' - name: original_reason_entitlement_code - description: Original reason for Medicare entitlement code. + description: '{{ doc("original_reason_entitlement_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_orec.csv - name: dual_status_code - description: > - Indicates whether the patient is dually eligible for Medicare and - Medicaid. + description: '{{ doc("dual_status_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_dual_eligibility.csv - name: medicare_status_code - description: Indicates how the patient became eligible for Medicare. + description: '{{ doc("medicare_status_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_status.csv - name: first_name - description: Patient's first name. + description: '{{ doc("first_name") }}' - name: last_name - description: Patient's last name. + description: '{{ doc("last_name") }}' - name: social_security_number - description: Patient's social security number. + description: '{{ doc("social_security_number") }}' - name: subscriber_relation - description: Relationship to the policy holder (self, spouse, dependent, etc) + description: '{{ doc("subscriber_relation") }}' - name: address - description: Patient's street address. + description: '{{ doc("address") }}' - name: city - description: Patient's city of address. + description: '{{ doc("city") }}' - name: state - description: State the patient lives in (most recent known address) + description: '{{ doc("state") }}' - name: zip_code - description: Zip code the patient lives in (most recent known address). + description: '{{ doc("zip_code") }}' - name: phone - description: Patient's phone number. + description: '{{ doc("phone") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file from the payer + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: medical_claim config: @@ -108,103 +99,91 @@ models: underlying reason for the service (i.e. diagnosis). columns: - name: claim_id - description: Unique identifier for each claim. + description: '{{ doc("claim_id") }}' - name: claim_line_number - description: > - Indicates the line number for the particular line of the claim. + description: '{{ doc("claim_line_number") }}' data_type: integer - name: claim_type - description: > - Indicates whether the claim is professional (CMS-1500), institutional - (UB-04), dental, or vision. + description: '{{ doc("claim_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__claim_type.csv - - name: patient_id - description: Unique identifier for each patient in the dataset. + - name: person_id + description: '{{ doc("person_id") }}' - name: member_id - description: > - Identifier that links a patient to a particular insurance product or - health plan. A patient can have more than one member_id because they - can have more than one insurance product/plan. + description: '{{ doc("member_id") }}' - name: payer - description: Name of the payer (i.e. health insurer) providing coverage. + description: '{{ doc("payer") }}' - name: plan - description: Name of the plan + description: '{{ doc("plan") }}' - name: claim_start_date - description: Start date for the claim. + description: '{{ doc("claim_start_date") }}' - name: claim_end_date - description: End date for the claim. + description: '{{ doc("claim_end_date") }}' - name: claim_line_start_date - description: Start date for the claim line. + description: '{{ doc("claim_line_start_date") }}' - name: claim_line_end_date - description: End date for the claim line. + description: '{{ doc("claim_line_end_date") }}' - name: admission_date - description: Admission date for the claim (inpatient claims only). + description: '{{ doc("admission_date") }}' - name: discharge_date - description: Discharge date for the claim (inpatient claims only). + description: '{{ doc("discharge_date") }}' - name: admit_source_code - description: > - Indicates where the patient was before the healthcare encounter - (inpatient claims only). + description: '{{ doc("admit_source_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv - name: admit_type_code - description: Indicates the type of admission (inpatient claims only). + description: '{{ doc("admit_type_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv - name: discharge_disposition_code - description: > - Indicates the type of setting the patient was discharged to - (institutional inpatient claims only). + description: '{{ doc("discharge_disposition_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv - name: place_of_service_code - description: Place of service for the claim (professional claims only). + description: '{{ doc("place_of_service_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__place_of_service.csv - name: bill_type_code - description: Bill type code for the claim (institutional claims only). + description: '{{ doc("bill_type_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__bill_type.csv - name: ms_drg_code - description: MS-DRG for the claim (inpatient claims only). + description: '{{ doc("ms_drg_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv - name: apr_drg_code - description: APR-DRG for the claim (inpatient claims only). + description: '{{ doc("apr_drg_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv - name: revenue_center_code - description: > - Revenue center code for the claim line (institutional only and - typically multiple codes per claim). + description: '{{ doc("revenue_center_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__revenue_center.csv - name: service_unit_quantity - description: The number of units for the particular revenue center code. + description: '{{ doc("service_unit_quantity") }}' data_type: integer - name: hcpcs_code - description: HCPCS level 1 or level 2 code for the claim line. + description: '{{ doc("hcpcs_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: hcpcs_modifier_1 - description: 1st modifier for HCPCS code. + description: '{{ doc("hcpcs_modifier_1") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: hcpcs_modifier_2 - description: 2nd modifier for HCPCS code. + description: '{{ doc("hcpcs_modifier_2") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: hcpcs_modifier_3 - description: 3rd modifier for HCPCS code. + description: '{{ doc("hcpcs_modifier_3") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: hcpcs_modifier_4 - description: 4th modifier for HCPCS code. + description: '{{ doc("hcpcs_modifier_4") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: hcpcs_modifier_5 - description: 5th modifier for HCPCS code. + description: '{{ doc("hcpcs_modifier_5") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: rendering_npi @@ -215,8 +194,7 @@ models: 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: rendering_tin - description: > - Rendering provider tax identification number (TIN). + description: '{{ doc("rendering_tin") }}' - name: billing_npi description: > Billing NPI for the claim (typically represents organization billing @@ -225,8 +203,7 @@ models: 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: billing_tin - description: > - Billing provider tax identification number (TIN). + description: '{{ doc("billing_tin") }}' - name: facility_npi description: > Facility NPI for the claim (typically represents the facility where @@ -235,27 +212,25 @@ models: 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: paid_date - description: The date the claim was paid. + description: '{{ doc("paid_date") }}' - name: paid_amount - description: The total amount paid on the claim by the insurer. + description: '{{ doc("paid_amount") }}' - name: allowed_amount - description: > - The total amount allowed (includes amount paid by the insurer and - patient) on the claim. + description: '{{ doc("allowed_amount") }}' - name: charge_amount - description: The total amount charged on the claim by the provider. + description: '{{ doc("charge_amount") }}' - name: coinsurance_amount - description: The total coinsurance charged on the claim by the provider. + description: '{{ doc("coinsurance_amount") }}' - name: copayment_amount - description: The total copayment charged on the claim by the provider. + description: '{{ doc("copayment_amount") }}' - name: deductible_amount - description: The total amount paid by the patient that applies towards their deductible. + description: '{{ doc("deductible_amount") }}' - name: total_cost_amount - description: The total amount paid on the claim by different parties. + description: '{{ doc("total_cost_amount") }}' - name: diagnosis_code_type meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - description: Indicates the type of diagnosis code (e.g. ICD-10-CM). + description: '{{ doc("diagnosis_code_type") }}' - name: diagnosis_code_1 meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.csv @@ -686,17 +661,13 @@ models: - name: procedure_date_25 description: Date of the 25th procedure on the claim. - name: in_network_flag - description: Flag indicating if the claim was in or out of network. + description: '{{ doc("in_network_flag") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file from the payer + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: pharmacy_claim config: @@ -710,22 +681,18 @@ models: pharmacy, and paid by an insurer. columns: - name: claim_id - description: Unique identifier for each claim. + description: '{{ doc("claim_id") }}' - name: claim_line_number - description: > - Indicates the line number for the particular line of the claim. + description: '{{ doc("claim_line_number") }}' data_type: integer - - name: patient_id - description: Unique identifier for each patient in the dataset. + - name: person_id + description: '{{ doc("person_id") }}' - name: member_id - description: > - Identifier that links a patient to a particular insurance product or - health plan. A patient can have more than one member_id because they - can have more than one insurance product/plan. + description: '{{ doc("member_id") }}' - name: payer - description: Name of the payer (i.e. health insurer) providing coverage. + description: '{{ doc("payer") }}' - name: plan - description: Name of the plan + description: '{{ doc("plan") }}' - name: prescribing_provider_npi description: > NPI for the provider that wrote the prescription (e.g. priamry care @@ -740,51 +707,42 @@ models: 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: dispensing_date - description: Date the prescription was filled. + description: '{{ doc("dispensing_date") }}' - name: ndc_code - description: National drug code on the claim. + description: '{{ doc("ndc_code") }}' meta: terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory - name: quantity - description: Number of doses. + description: '{{ doc("quantity") }}' data_type: integer - name: days_supply - description: Number of days supply. + description: '{{ doc("days_supply") }}' data_type: integer - name: refills - description: Number of refills for the prescription. + description: '{{ doc("refills") }}' data_type: integer - name: paid_date - description: Date the claim was paid. + description: '{{ doc("paid_date") }}' - name: paid_amount - description: Amount paid by the health insurer for the claim. + description: '{{ doc("paid_amount") }}' - name: allowed_amount - description: > - Contractual amount allowed to be paid by the payer + patient. + description: '{{ doc("allowed_amount") }}' - name: charge_amount - description: > - The total amount charged on the claim by the provider. + description: '{{ doc("charge_amount") }}' - name: coinsurance_amount - description: The total coinsurance charged on the claim by the provider. + description: '{{ doc("coinsurance_amount") }}' - name: copayment_amount - description: > - The total copayment charged on the claim by the provider. + description: '{{ doc("copayment_amount") }}' - name: deductible_amount - description: > - The total amount charged on the claim by the provider. + description: '{{ doc("deductible_amount") }}' - name: in_network_flag - description: Flag indicating if the claim was in or out of network. + description: '{{ doc("in_network_flag") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file from the payer + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file was ingested into the data warehouse or - landed in cloud storage - + description: '{{ doc("ingest_datetime") }}' - name: provider_attribution config: @@ -800,49 +758,32 @@ models: Fields related to each attributed provider (practice, organization, line of business)are also present. columns: - - name: patient_id - description: Unique identifier for each patient in the dataset. + - name: person_id + description: '{{ doc("person_id") }}' - name: year_month - description: > - Unique year-month of in the dataset as a 6 character string (yyyymm, e.g. 202401). + description: '{{ doc("year_month") }}' - name: payer - description: Name of the payer (i.e. health insurer) providing coverage. + description: '{{ doc("payer") }}' - name: plan - description: Name of the plan + description: '{{ doc("plan") }}' - name: payer_attributed_provider - description: > - Unique identifier for the provider assigned to this patient-year_month - by the payer. + description: '{{ doc("payer_attributed_provider") }}' - name: payer_attributed_provider_practice - description: > - Name of the practice for the payer attributed provider. + description: '{{ doc("payer_attributed_provider_practice") }}' - name: payer_attributed_provider_organization - description: > - Name of the organization for the payer attributed provider. + description: '{{ doc("payer_attributed_provider_organization") }}' - name: payer_attributed_provider_lob - description: > - Name of the line of business for the payer attributed provider - (e.g. medicare, medicaid, commercial). + description: '{{ doc("payer_attributed_provider_lob") }}' - name: custom_attributed_provider - description: > - Unique identifier for the provider assigned to this patient-year_month - by the user. + description: '{{ doc("custom_attributed_provider") }}' - name: custom_attributed_provider_practice - description: > - Name of the practice for the attributed provider assigned by the user. + description: '{{ doc("custom_attributed_provider_practice") }}' - name: custom_attributed_provider_organization - description: > - Name of the organization for the attributed provider assigned by the user. + description: '{{ doc("custom_attributed_provider_organization") }}' - name: custom_attributed_provider_lob - description: > - Name of the line of business for the attributed provider assigned by the user - (e.g. medicare, medicaid, commercial). + description: '{{ doc("custom_attributed_provider_lob") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). - - + description: '{{ doc("data_source") }}' # Clinical input - name: condition @@ -857,72 +798,62 @@ models: diagnosis codes. columns: - name: condition_id - description: Unique identifier for each condition in the table. + description: '{{ doc("condition_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each patient in the dataset. + description: '{{ doc("patient_id") }}' - name: encounter_id - description: Unique identifier for each encounter. + description: '{{ doc("encounter_id") }}' - name: claim_id - description: Unique identifier for each claim. + description: '{{ doc("claim_id") }}' - name: recorded_date - description: Date when the condition was recorded. + description: '{{ doc("recorded_date") }}' - name: onset_date - description: Date when the condition first occurred. + description: '{{ doc("onset_date") }}' - name: resolved_date - description: Date when the condition was resolved. + description: '{{ doc("resolved_date") }}' - name: status - description: Status of the condition. + description: '{{ doc("status") }}' - name: condition_type - description: The type of condition i.e. problem, admitting, or billing. + description: '{{ doc("condition_type") }}' - name: source_code_type - description: > - The type of condition code reported in the source system e.g. - ICD-10-CM. + description: '{{ doc("source_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: source_code - description: > - The condition code in the source system e.g. the ICD-10 code. + description: '{{ doc("source_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: source_description - description: Description of the condition code in the source system. + description: '{{ doc("source_description") }}' - name: normalized_code_type - description: The normalized type of condition code. + description: '{{ doc("normalized_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: normalized_code - description: The normalized condition code. + description: '{{ doc("normalized_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: normalized_description - description: Normalized description of the condition code. + description: '{{ doc("normalized_description") }}' - name: condition_rank - description: > - The numerical ranking of a diagnosis code in a claim. Principle - diagnosis code is given a ranking of 1. Claims data typically has a - strict ranking of conditions whereas medical records will often not - have this information or the information won't be accurate. + description: '{{ doc("condition_rank") }}' data_type: integer - name: present_on_admit_code - description: The present_on_admit_code related to the condition. + description: '{{ doc("present_on_admit_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__present_on_admission.csv - name: present_on_admit_description - description: > - The description of the present_on_admit_code for the condition. + description: '{{ doc("present_on_admit_description") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file from the payer + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: encounter config: @@ -936,105 +867,88 @@ models: visits, SNF stays, etc. columns: - name: encounter_id - description: Unique identifier for each encounter. + description: '{{ doc("encounter_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for a patient. + description: '{{ doc("patient_id") }}' - name: encounter_type - description: > - Indicates the type of encounter e.g. acute inpatient, emergency - department, etc. + description: '{{ doc("encounter_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__encounter_type.csv - name: encounter_start_date - description: Date when the encounter started. + description: '{{ doc("encounter_start_date") }}' - name: encounter_end_date - description: Date when the encounter ended. + description: '{{ doc("encounter_end_date") }}' - name: length_of_stay - description: > - Length of the encounter calculated as encounter_end_date - - encounter_start_date. + description: '{{ doc("length_of_stay") }}' - name: admit_source_code - description: Admission source code for the encounter. + description: '{{ doc("admit_source_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv - name: admit_source_description - description: Description of the admit_source_code for the encounter. + description: '{{ doc("admit_source_description") }}' - name: admit_type_code - description: Admission type code for the encounter. + description: '{{ doc("admit_type_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv - name: admit_type_description - description: Description of the admit_type_code for the encounter. + description: '{{ doc("admit_type_description") }}' - name: discharge_disposition_code - description: Discharge disposition code for the encounter. + description: '{{ doc("discharge_disposition_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv - name: discharge_disposition_description - description: > - Description of the discharge_disposition_code for the encounter. + description: '{{ doc("discharge_disposition_description") }}' - name: attending_provider_id - description: Attending provider ID for the encounter. + description: '{{ doc("attending_provider_id") }}' 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: attending_provider_name - description: Attending provider name for the encounter. + description: '{{ doc("attending_provider_name") }}' - name: facility_id - description: > - Facility identifier for the encounter (typically represents the facility where services were performed). Can - be an NPI or source code. + description: '{{ doc("facility_id") }}' - name: facility_name - description: > - Facility name for the encounter (typically represents the facility where services were performed). + description: '{{ doc("facility_name") }}' 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: primary_diagnosis_code_type - description: > - The type of condition code reported in the source system e.g. - ICD-10-CM. + description: '{{ doc("primary_diagnosis_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: primary_diagnosis_code - description: > - Primary diagnosis code for the encounter. If from claims the primary - diagnosis code comes from the institutional claim. + description: '{{ doc("primary_diagnosis_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: primary_diagnosis_description - description: Description of the primary diagnosis code. + description: '{{ doc("primary_diagnosis_description") }}' - name: ms_drg_code - description: MS-DRG code for the encounter. + description: '{{ doc("ms_drg_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv - name: ms_drg_description - description: Description of the ms_drg_code. + description: '{{ doc("ms_drg_description") }}' - name: apr_drg_code - description: APR-DRG code for the encounter. + description: '{{ doc("apr_drg_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv - name: apr_drg_description - description: Description of the APR-DRG code. + description: '{{ doc("apr_drg_description") }}' - name: paid_amount - description: The total amount paid for the encounter by the insurer. + description: '{{ doc("paid_amount") }}' - name: allowed_amount - description: > - The total amount allowed (includes amount paid by the insurer and - patient) on the encounter. + description: '{{ doc("allowed_amount") }}' - name: charge_amount - description: > - The total amount charged on the encounter by the provider. + description: '{{ doc("charge_amount") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: lab_result config: @@ -1048,88 +962,84 @@ models: result. columns: - name: lab_result_id - description: Unique identifier for the lab test. + description: '{{ doc("lab_result_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each patient. + description: '{{ doc("patient_id") }}' - name: encounter_id - description: > - Unique identifier for each encounter. Included in this table if the - lab test can be linked to an encounter. + description: '{{ doc("encounter_id") }}' - name: accession_number - description: The lab order number from the source system. + description: '{{ doc("accession_number") }}' - name: source_code_type - description: The code type from the source system. + description: '{{ doc("source_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: source_code - description: The code for the lab from the source system. + description: '{{ doc("source_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: source_description - description: The description for the lab test from the source system. + description: '{{ doc("source_description") }}' - name: source_component - description: > - The description for the component of the test from the source system. + description: '{{ doc("source_component") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_code_type - description: The normalized code type. + description: '{{ doc("normalized_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: normalized_code - description: The normalized code e.g. LOINC. + description: '{{ doc("normalized_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_description - description: The normalized description for the code. + description: '{{ doc("normalized_description") }}' - name: normalized_component - description: The normalized component. + description: '{{ doc("normalized_component") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: status - description: The status of the lab test. + description: '{{ doc("status") }}' - name: result - description: The result of the lab test. + description: '{{ doc("result") }}' - name: result_date - description: Date of the test result. + description: '{{ doc("result_date") }}' - name: collection_date - description: Date the test was collected. + description: '{{ doc("collection_date") }}' - name: source_units - description: Source units of the lab test. + description: '{{ doc("source_units") }}' - name: normalized_units - description: Normalized units of the lab test. + description: '{{ doc("normalized_units") }}' - name: source_reference_range_low - description: The low end of the reference range from the source system. + description: '{{ doc("source_reference_range_low") }}' - name: source_reference_range_high - description: The high end of the reference range from the source system. + description: '{{ doc("source_reference_range_high") }}' - name: normalized_reference_range_low - description: The normalized low end of the reference range. + description: '{{ doc("normalized_reference_range_low") }}' - name: normalized_reference_range_high - description: The normalized high end of the reference range. + description: '{{ doc("normalized_reference_range_high") }}' - name: source_abnormal_flag - description: Indicates whether the result is abnormal or normal. + description: '{{ doc("source_abnormal_flag") }}' - name: normalized_abnormal_flag - description: Normalized abnormal flag. + description: '{{ doc("normalized_abnormal_flag") }}' - name: specimen - description: The type of specimen e.g. blood, plasma, urine. + description: '{{ doc("specimen") }}' - name: ordering_practitioner_id - description: > - Unique identifier for the practitioner who ordered the lab test. + description: '{{ doc("ordering_practitioner_id") }}' 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: data_source - description: Custom description of the source system e.g. Epic. + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: location config: @@ -1142,40 +1052,36 @@ models: where patients receive medical care. columns: - name: location_id - description: Unique identifier for each location. + description: '{{ doc("location_id") }}' - name: npi - description: > - The national provider identifier associated with the location e.g. - facility_npi. + description: '{{ doc("npi") }}' 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: name - description: The name of the location. + description: '{{ doc("name") }}' - name: facility_type - description: The type of facility e.g. acute care hospital. + description: '{{ doc("facility_type") }}' - name: parent_organization - description: The parent organization associated with the facility. + description: '{{ doc("parent_organization") }}' - name: address - description: The street address of the location. + description: '{{ doc("address") }}' - name: city - description: The city of the location. + description: '{{ doc("city") }}' - name: state - description: The state of the location. + description: '{{ doc("state") }}' - name: zip_code - description: The zip code of the location. + description: '{{ doc("zip_code") }}' - name: latitude - description: The latitude of the location. + description: '{{ doc("latitude") }}' - name: longitude - description: The longitude of the location. + description: '{{ doc("longitude") }}' - name: data_source - description: Custom description of the source system e.g. Epic. + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: medication config: @@ -1187,62 +1093,61 @@ models: administered during a patient encounter. columns: - name: medication_id - description: Unique identifier for each medication in the table. + description: '{{ doc("medication_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each patient in the dataset. + description: '{{ doc("patient_id") }}' - name: encounter_id - description: Unique identifier for each encounter in the dataset. + description: '{{ doc("encounter_id") }}' - name: dispensing_date - description: Date the medication was dispensed. + description: '{{ doc("dispensing_date") }}' - name: prescribing_date - description: Date the medication was prescribed. + description: '{{ doc("prescribing_date") }}' - name: source_code_type - description: The source code type of the medication. + description: '{{ doc("source_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: source_code - description: The source code for the medication. + description: '{{ doc("source_code") }}' - name: source_description - description: The source description of the medication. + description: '{{ doc("source_description") }}' - name: ndc_code - description: National drug code associated with the medication. + description: '{{ doc("ndc_code") }}' - name: ndc_description - description: Description for the NDC. + description: '{{ doc("ndc_description") }}' meta: terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory - name: rxnorm_code - description: RxNorm code associated with the medication. + description: '{{ doc("rxnorm_code") }}' meta: terminology: https://www.nlm.nih.gov/research/umls/rxnorm/index.html - name: rxnorm_description - description: Description for the RxNorm code. + description: '{{ doc("rxnorm_description") }}' - name: atc_code - description: ATC code for the medication. + description: '{{ doc("atc_code") }}' meta: terminology: https://www.who.int/tools/atc-ddd-toolkit/atc-classification - name: atc_description - description: Description for the ATC code. + description: '{{ doc("atc_description") }}' - name: route - description: The route used to administer the medication. + description: '{{ doc("route") }}' - name: strength - description: The strength of the medication. + description: '{{ doc("strength") }}' - name: quantity - description: The quantity of the medication. + description: '{{ doc("quantity") }}' - name: quantity_unit - description: The units for the quantity. + description: '{{ doc("quantity_unit") }}' - name: days_supply - description: The number of days supply included. + description: '{{ doc("days_supply") }}' - name: practitioner_id - description: > - Unique identifier for the practitioner who ordered the medication. + description: '{{ doc("practitioner_id") }}' - name: data_source - description: Custom description of the source system e.g. Epic. + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: observation config: @@ -1255,53 +1160,53 @@ models: tests e.g. blood pressure, height, and weight. columns: - name: observation_id - description: Unique identifier for each observation in the dataset. + description: '{{ doc("observation_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each patient in the dataset. + description: '{{ doc("patient_id") }}' - name: encounter_id - description: Unique identifier for each encounter in the dataset. + description: '{{ doc("encounter_id") }}' - name: panel_id - description: Unique identifier for the panel. + description: '{{ doc("panel_id") }}' - name: observation_date - description: Date the observation was recorded. + description: '{{ doc("observation_date") }}' - name: observation_type - description: Type of observation. + description: '{{ doc("observation_type") }}' - name: source_code_type - description: Source code type of the observation. + description: '{{ doc("source_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: source_code - description: Source code of the observation. + description: '{{ doc("source_code") }}' - name: source_description - description: Source description of the observation. + description: '{{ doc("source_description") }}' - name: normalized_code_type - description: Normalized code type of the observation. + description: '{{ doc("normalized_code_type") }}' - name: normalized_code - description: Normalized code of the observation. + description: '{{ doc("normalized_code") }}' - name: normalized_description - description: Normalized description of the observatino. + description: '{{ doc("normalized_description") }}' - name: result - description: The result of the observation. + description: '{{ doc("result") }}' - name: source_units - description: Source units of the lab test. + description: '{{ doc("source_units") }}' - name: normalized_units - description: Normalized units of the lab test. + description: '{{ doc("normalized_units") }}' - name: source_reference_range_low - description: The low end of the reference range from the source system. + description: '{{ doc("source_reference_range_low") }}' - name: source_reference_range_high - description: The high end of the reference range from the source system. + description: '{{ doc("source_reference_range_high") }}' - name: normalized_reference_range_low - description: The normalized low end of the reference range. + description: '{{ doc("normalized_reference_range_low") }}' - name: normalized_reference_range_high - description: The normalized high end of the reference range. + description: '{{ doc("normalized_reference_range_high") }}' - name: data_source - description: Custom description of the source system e.g. Epic. + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: patient config: @@ -1313,53 +1218,53 @@ models: The patient table contains demographic and geographic information on patients. columns: + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each person across all datasets. + description: '{{ doc("patient_id") }}' - name: first_name - description: The first name of the patient. + description: '{{ doc("first_name") }}' - name: last_name - description: The last name of the patient. + description: '{{ doc("last_name") }}' - name: sex - description: The gender of the patient. + description: '{{ doc("sex") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__gender.csv - name: race - description: The race of the patient. + description: '{{ doc("race") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__race.csv - name: birth_date - description: The birth date of the patient. + description: '{{ doc("birth_date") }}' - name: death_date - description: The death date of the patient if there is one. + description: '{{ doc("death_date") }}' - name: death_flag - description: A flag indicating if the patient has died. + description: '{{ doc("death_flag") }}' data_type: boolean - name: social_security_number - description: Patient's social security number. + description: '{{ doc("social_security_number") }}' - name: address - description: The address of the patient. + description: '{{ doc("address") }}' - name: city - description: The city where the patient lives. + description: '{{ doc("city") }}' - name: state - description: The state where the patient lives. + description: '{{ doc("state") }}' - name: zip_code - description: The zip code for the patient. + description: '{{ doc("zip_code") }}' - name: county - description: The county for the patient. + description: '{{ doc("county") }}' - name: latitude - description: The latitude for the patient. + description: '{{ doc("county") }}' - name: longitude - description: The longitude for the patient. + description: '{{ doc("longitude") }}' + - name: phone + description: '{{ doc("phone") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: practitioner config: @@ -1372,32 +1277,28 @@ models: dataset e.g. physicians, physicians assistants, etc. columns: - name: practitioner_id - description: Unique ID for the provider. + description: '{{ doc("practitioner_id") }}' - name: npi - description: NPI for the provider. + description: '{{ doc("npi") }}' 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: first_name - description: First name of the provider. + description: '{{ doc("provider_first_name") }}' - name: last_name - description: Last name of the provider. + description: '{{ doc("provider_last_name") }}' - name: practice_affiliation - description: Practice affiliation of the provider. + description: '{{ doc("practice_affiliation") }}' - name: specialty - description: Specialty of the provider. + description: '{{ doc("specialty") }}' - name: sub_specialty - description: Sub specialty of the provider. + description: '{{ doc("sub_specialty") }}' - name: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage + description: '{{ doc("ingest_datetime") }}' - name: procedure config: @@ -1410,72 +1311,67 @@ models: on patients in the dataset. columns: - name: procedure_id - description: The unique identifier for the performed procedure. + description: '{{ doc("procedure_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: patient_id - description: Unique identifier for each person across all datasets. + description: '{{ doc("patient_id") }}' - name: encounter_id - description: > - The encounter_id for the encounter where this procedure was performed. + description: '{{ doc("encounter_id") }}' - name: claim_id - description: The claim on which the procedure was recorded. + description: '{{ doc("claim_id") }}' - name: procedure_date - description: Date when the procedure was performed. + description: '{{ doc("procedure_date") }}' - name: source_code_type - description: > - Type of procedure code for the procedure in the source system. + description: '{{ doc("source_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: source_code - description: The procedure code in the source system. + description: '{{ doc("source_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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: source_description - description: Description of the procedure code. + description: '{{ doc("source_description") }}' - name: normalized_code_type - description: Normalized type of procedure code for the procedure. + description: '{{ doc("normalized_code_type") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - name: normalized_code - description: The normalized procedure code. + description: '{{ doc("normalized_code") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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." - 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: normalized_description - description: Description of the procedure code. + description: '{{ doc("normalized_description") }}' - name: modifier_1 - description: First modifier for the procedure code. + description: '{{ doc("modifier_1") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: modifier_2 - description: Second modifier for the procedure code. + description: '{{ doc("modifier_2") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: modifier_3 - description: Third modifier for the procedure code. + description: '{{ doc("modifier_3") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: modifier_4 - description: Fourth modifier for the procedure code. + description: '{{ doc("modifier_4") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: modifier_5 - description: Fifth modifier for the procedure code. + description: '{{ doc("modifier_5") }}' meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - name: practitioner_id - description: ID of the provider who performed the procedure. + description: '{{ doc("practitioner_id") }}' 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: data_source - description: > - User-configured field that indicates the data source (e.g. typically - named after the payer and state "BCBS Tennessee"). + description: '{{ doc("data_source") }}' - name: file_name - description: The file name of the source file + description: '{{ doc("file_name") }}' - name: ingest_datetime - description: > - The date and time the source file/data was ingested into the data warehouse or - landed in cloud storage \ No newline at end of file + description: '{{ doc("ingest_datetime") }}' diff --git a/integration_tests/docs_generate/models/condition.sql b/integration_tests/docs_generate/models/condition.sql index fa55dbde8..83c887453 100644 --- a/integration_tests/docs_generate/models/condition.sql +++ b/integration_tests/docs_generate/models/condition.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as condition_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id diff --git a/integration_tests/docs_generate/models/eligibility.sql b/integration_tests/docs_generate/models/eligibility.sql index 59f8a34de..9d5a28186 100644 --- a/integration_tests/docs_generate/models/eligibility.sql +++ b/integration_tests/docs_generate/models/eligibility.sql @@ -1,5 +1,5 @@ select - patient_id + person_id , member_id , subscriber_id , gender diff --git a/integration_tests/docs_generate/models/encounter.sql b/integration_tests/docs_generate/models/encounter.sql index 26035e233..db7c05b39 100644 --- a/integration_tests/docs_generate/models/encounter.sql +++ b/integration_tests/docs_generate/models/encounter.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as encounter_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_type , cast(null as date) as encounter_start_date diff --git a/integration_tests/docs_generate/models/lab_result.sql b/integration_tests/docs_generate/models/lab_result.sql index 0f05adf2b..f28553a0b 100644 --- a/integration_tests/docs_generate/models/lab_result.sql +++ b/integration_tests/docs_generate/models/lab_result.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as lab_result_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as accession_number diff --git a/integration_tests/docs_generate/models/medical_claim.sql b/integration_tests/docs_generate/models/medical_claim.sql index f28df1576..79e958b8e 100644 --- a/integration_tests/docs_generate/models/medical_claim.sql +++ b/integration_tests/docs_generate/models/medical_claim.sql @@ -2,7 +2,7 @@ select claim_id , claim_line_number , claim_type - , patient_id + , person_id , member_id , payer , plan diff --git a/integration_tests/docs_generate/models/medication.sql b/integration_tests/docs_generate/models/medication.sql index c2348c3d9..cccb8bce5 100644 --- a/integration_tests/docs_generate/models/medication.sql +++ b/integration_tests/docs_generate/models/medication.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as medication_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as date) as dispensing_date diff --git a/integration_tests/docs_generate/models/observation.sql b/integration_tests/docs_generate/models/observation.sql index b119ceba0..377b2f305 100644 --- a/integration_tests/docs_generate/models/observation.sql +++ b/integration_tests/docs_generate/models/observation.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as observation_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as panel_id diff --git a/integration_tests/docs_generate/models/patient.sql b/integration_tests/docs_generate/models/patient.sql index 36db26ae8..e22ba053c 100644 --- a/integration_tests/docs_generate/models/patient.sql +++ b/integration_tests/docs_generate/models/patient.sql @@ -1,5 +1,6 @@ select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id + , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as first_name , cast(null as {{ dbt.type_string() }} ) as last_name , cast(null as {{ dbt.type_string() }} ) as sex @@ -15,6 +16,7 @@ select , cast(null as {{ dbt.type_string() }} ) as county , cast(null as {{ dbt.type_float() }} ) as latitude , cast(null as {{ dbt.type_float() }} ) as longitude + , cast(null as {{ dbt.type_string() }} ) as phone , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_string() }} ) as file_name , cast(null as {{ dbt.type_timestamp() }} ) as ingest_datetime diff --git a/integration_tests/docs_generate/models/pharmacy_claim.sql b/integration_tests/docs_generate/models/pharmacy_claim.sql index 5310f3583..21c0a0f5f 100644 --- a/integration_tests/docs_generate/models/pharmacy_claim.sql +++ b/integration_tests/docs_generate/models/pharmacy_claim.sql @@ -1,7 +1,7 @@ select claim_id , claim_line_number - , patient_id + , person_id , member_id , payer , plan diff --git a/integration_tests/docs_generate/models/procedure.sql b/integration_tests/docs_generate/models/procedure.sql index 3e812a49f..0c7e5c5b3 100644 --- a/integration_tests/docs_generate/models/procedure.sql +++ b/integration_tests/docs_generate/models/procedure.sql @@ -1,5 +1,6 @@ select cast(null as {{ dbt.type_string() }} ) as procedure_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id diff --git a/integration_tests/docs_generate/models/provider_attribution.sql b/integration_tests/docs_generate/models/provider_attribution.sql index 8d6915b0f..ee8eadda5 100644 --- a/integration_tests/docs_generate/models/provider_attribution.sql +++ b/integration_tests/docs_generate/models/provider_attribution.sql @@ -1,7 +1,7 @@ select - patient_id + person_id , year_month , payer , plan diff --git a/integration_tests/models/condition.sql b/integration_tests/models/condition.sql index c83074e0a..16445c3cc 100644 --- a/integration_tests/models/condition.sql +++ b/integration_tests/models/condition.sql @@ -4,12 +4,11 @@ ) }} - - {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as condition_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id @@ -33,10 +32,8 @@ select , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {{ limit_zero()}} - {%- else -%} - select * from {{ source('source_input', 'condition') }} {%- endif %} \ No newline at end of file diff --git a/integration_tests/models/encounter.sql b/integration_tests/models/encounter.sql index c085a5bc2..321eef686 100644 --- a/integration_tests/models/encounter.sql +++ b/integration_tests/models/encounter.sql @@ -4,11 +4,11 @@ ) }} - {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as encounter_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_type , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as encounter_start_date diff --git a/integration_tests/models/lab_result.sql b/integration_tests/models/lab_result.sql index f6751adbb..06621e7b4 100644 --- a/integration_tests/models/lab_result.sql +++ b/integration_tests/models/lab_result.sql @@ -10,7 +10,6 @@ select * from {{ ref('lab_result_seed') }} {%- else -%} - select * from {{ source('source_input', 'lab_result') }} {%- endif %} \ No newline at end of file diff --git a/integration_tests/models/location.sql b/integration_tests/models/location.sql index 5d24c825d..b2b7fb9d5 100644 --- a/integration_tests/models/location.sql +++ b/integration_tests/models/location.sql @@ -6,7 +6,7 @@ {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as location_id , cast(null as {{ dbt.type_string() }} ) as npi , cast(null as {{ dbt.type_string() }} ) as name diff --git a/integration_tests/models/medication.sql b/integration_tests/models/medication.sql index 6a53a8a7d..5fd792b9b 100644 --- a/integration_tests/models/medication.sql +++ b/integration_tests/models/medication.sql @@ -6,8 +6,9 @@ {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as medication_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date diff --git a/integration_tests/models/patient.sql b/integration_tests/models/patient.sql index b9c85afea..039f5896a 100644 --- a/integration_tests/models/patient.sql +++ b/integration_tests/models/patient.sql @@ -4,12 +4,11 @@ ) }} - {% if var('use_synthetic_data') == true -%} - -select -cast(null as {{ dbt.type_string() }} ) as patient_id +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} +cast(null as {{ dbt.type_string() }} ) as person_id +, cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as first_name , cast(null as {{ dbt.type_string() }} ) as last_name , cast(null as {{ dbt.type_string() }} ) as sex @@ -25,13 +24,13 @@ cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as county , cast(null as {{ dbt.type_float() }} ) as latitude , cast(null as {{ dbt.type_float() }} ) as longitude +, cast(null as {{ dbt.type_string() }} ) as phone , cast(null as {{ dbt.type_string() }} ) as data_source , cast(null as {{ dbt.type_string() }} ) as file_name , cast(null as {{ dbt.type_timestamp() }} ) as ingest_datetime , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {{ limit_zero()}} - {%- else -%} select * from {{ source('source_input', 'patient') }} diff --git a/integration_tests/models/practitioner.sql b/integration_tests/models/practitioner.sql index e3f937aa9..56e7661af 100644 --- a/integration_tests/models/practitioner.sql +++ b/integration_tests/models/practitioner.sql @@ -4,10 +4,9 @@ ) }} - {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as practitioner_id , cast(null as {{ dbt.type_string() }} ) as npi , cast(null as {{ dbt.type_string() }} ) as first_name diff --git a/integration_tests/models/procedure.sql b/integration_tests/models/procedure.sql index 5f409eb6f..2a5d792b8 100644 --- a/integration_tests/models/procedure.sql +++ b/integration_tests/models/procedure.sql @@ -6,8 +6,9 @@ {% if var('use_synthetic_data') == true -%} -select +select {% if target.type == 'fabric' %} top 0 {% else %}{% endif %} cast(null as {{ dbt.type_string() }} ) as procedure_id +, cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as claim_id diff --git a/integration_tests/seeds/_seeds.yml b/integration_tests/seeds/_seeds.yml index f26c34b4b..8879f3613 100644 --- a/integration_tests/seeds/_seeds.yml +++ b/integration_tests/seeds/_seeds.yml @@ -9,7 +9,7 @@ seeds: enabled: | {% if var('use_synthetic_data') == true -%} {{ true|as_bool }} {%- else -%} {{ false|as_bool }} {%- endif -%} column_types: - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -60,7 +60,6 @@ seeds: {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} ingest_datetime: | {%- if target.type in ("fabric") -%} datetime2(0) {%- else -%} datetime {%- endif -%} - - name: lab_result_seed config: @@ -72,6 +71,8 @@ seeds: column_types: lab_result_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} + person_id: | + {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} patient_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} encounter_id: | @@ -127,7 +128,6 @@ seeds: tuva_last_run: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} - - name: medical_claim_seed config: schema: | @@ -141,7 +141,7 @@ seeds: claim_line_number: integer claim_type: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -385,7 +385,6 @@ seeds: ingest_datetime: | {%- if target.type in ("fabric") -%} datetime2(0) {%- else -%} datetime {%- endif -%} - - name: observation_seed config: schema: | @@ -396,6 +395,8 @@ seeds: column_types: observation_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} + person_id: | + {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} patient_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} encounter_id: | @@ -438,8 +439,6 @@ seeds: ingest_datetime: | {%- if target.type in ("fabric") -%} datetime2(0) {%- else -%} datetime {%- endif -%} - - - name: pharmacy_claim_seed config: schema: | @@ -451,7 +450,7 @@ seeds: claim_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} claim_line_number: integer - patient_id: | + person_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} member_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} @@ -481,7 +480,6 @@ seeds: ingest_datetime: | {%- if target.type in ("fabric") -%} datetime2(0) {%- else -%} datetime {%- endif -%} - - name: provider_attribution_seed config: schema: | @@ -490,6 +488,8 @@ seeds: enabled: | {% if var('use_synthetic_data') == true -%} {{ true|as_bool }} {%- else -%} {{ false|as_bool }} {%- endif -%} column_types: + person_id: | + {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} patient_id: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} year_month: | @@ -516,4 +516,3 @@ seeds: {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} custom_attributed_provider_lob: | {%- if target.type in ("bigquery", "databricks") -%} string {%- else -%} varchar(255) {%- endif -%} - diff --git a/integration_tests/seeds/eligibility_seed.csv b/integration_tests/seeds/eligibility_seed.csv index 24ad0ef4f..0dbc37868 100644 --- a/integration_tests/seeds/eligibility_seed.csv +++ b/integration_tests/seeds/eligibility_seed.csv @@ -1 +1 @@ -patient_id,member_id,subscriber_id,gender,race,birth_date,death_date,death_flag,enrollment_start_date,enrollment_end_date,payer,payer_type,plan,original_reason_entitlement_code,dual_status_code,medicare_status_code,first_name,last_name,social_security_number,subscriber_relation,address,city,state,zip_code,phone,data_source,file_name,ingest_datetime \ No newline at end of file +person_id,member_id,subscriber_id,gender,race,birth_date,death_date,death_flag,enrollment_start_date,enrollment_end_date,payer,payer_type,plan,original_reason_entitlement_code,dual_status_code,medicare_status_code,first_name,last_name,social_security_number,subscriber_relation,address,city,state,zip_code,phone,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/integration_tests/seeds/lab_result_seed.csv b/integration_tests/seeds/lab_result_seed.csv index 3d2d9949e..61b183b90 100644 --- a/integration_tests/seeds/lab_result_seed.csv +++ b/integration_tests/seeds/lab_result_seed.csv @@ -1 +1 @@ -lab_result_id,patient_id,encounter_id,accession_number,source_code_type,source_code,source_description,source_component,normalized_code_type,normalized_code,normalized_description,normalized_component,status,result,result_date,collection_date,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,source_abnormal_flag,normalized_abnormal_flag,specimen,ordering_practitioner_id,data_source,file_name,ingest_datetime \ No newline at end of file +lab_result_id,person_id,patient_id,encounter_id,accession_number,source_code_type,source_code,source_description,source_component,normalized_code_type,normalized_code,normalized_description,normalized_component,status,result,result_date,collection_date,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,source_abnormal_flag,normalized_abnormal_flag,specimen,ordering_practitioner_id,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/integration_tests/seeds/medical_claim_seed.csv b/integration_tests/seeds/medical_claim_seed.csv index f74e97154..1a86bde2d 100644 --- a/integration_tests/seeds/medical_claim_seed.csv +++ b/integration_tests/seeds/medical_claim_seed.csv @@ -1 +1 @@ -claim_id,claim_line_number,claim_type,patient_id,member_id,payer,plan,claim_start_date,claim_end_date,claim_line_start_date,claim_line_end_date,admission_date,discharge_date,admit_source_code,admit_type_code,discharge_disposition_code,place_of_service_code,bill_type_code,ms_drg_code,apr_drg_code,revenue_center_code,service_unit_quantity,hcpcs_code,hcpcs_modifier_1,hcpcs_modifier_2,hcpcs_modifier_3,hcpcs_modifier_4,hcpcs_modifier_5,rendering_npi,rendering_tin,billing_npi,billing_tin,facility_npi,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,total_cost_amount,diagnosis_code_type,diagnosis_code_1,diagnosis_code_2,diagnosis_code_3,diagnosis_code_4,diagnosis_code_5,diagnosis_code_6,diagnosis_code_7,diagnosis_code_8,diagnosis_code_9,diagnosis_code_10,diagnosis_code_11,diagnosis_code_12,diagnosis_code_13,diagnosis_code_14,diagnosis_code_15,diagnosis_code_16,diagnosis_code_17,diagnosis_code_18,diagnosis_code_19,diagnosis_code_20,diagnosis_code_21,diagnosis_code_22,diagnosis_code_23,diagnosis_code_24,diagnosis_code_25,diagnosis_poa_1,diagnosis_poa_2,diagnosis_poa_3,diagnosis_poa_4,diagnosis_poa_5,diagnosis_poa_6,diagnosis_poa_7,diagnosis_poa_8,diagnosis_poa_9,diagnosis_poa_10,diagnosis_poa_11,diagnosis_poa_12,diagnosis_poa_13,diagnosis_poa_14,diagnosis_poa_15,diagnosis_poa_16,diagnosis_poa_17,diagnosis_poa_18,diagnosis_poa_19,diagnosis_poa_20,diagnosis_poa_21,diagnosis_poa_22,diagnosis_poa_23,diagnosis_poa_24,diagnosis_poa_25,procedure_code_type,procedure_code_1,procedure_code_2,procedure_code_3,procedure_code_4,procedure_code_5,procedure_code_6,procedure_code_7,procedure_code_8,procedure_code_9,procedure_code_10,procedure_code_11,procedure_code_12,procedure_code_13,procedure_code_14,procedure_code_15,procedure_code_16,procedure_code_17,procedure_code_18,procedure_code_19,procedure_code_20,procedure_code_21,procedure_code_22,procedure_code_23,procedure_code_24,procedure_code_25,procedure_date_1,procedure_date_2,procedure_date_3,procedure_date_4,procedure_date_5,procedure_date_6,procedure_date_7,procedure_date_8,procedure_date_9,procedure_date_10,procedure_date_11,procedure_date_12,procedure_date_13,procedure_date_14,procedure_date_15,procedure_date_16,procedure_date_17,procedure_date_18,procedure_date_19,procedure_date_20,procedure_date_21,procedure_date_22,procedure_date_23,procedure_date_24,procedure_date_25,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file +claim_id,claim_line_number,claim_type,person_id,member_id,payer,plan,claim_start_date,claim_end_date,claim_line_start_date,claim_line_end_date,admission_date,discharge_date,admit_source_code,admit_type_code,discharge_disposition_code,place_of_service_code,bill_type_code,ms_drg_code,apr_drg_code,revenue_center_code,service_unit_quantity,hcpcs_code,hcpcs_modifier_1,hcpcs_modifier_2,hcpcs_modifier_3,hcpcs_modifier_4,hcpcs_modifier_5,rendering_npi,rendering_tin,billing_npi,billing_tin,facility_npi,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,total_cost_amount,diagnosis_code_type,diagnosis_code_1,diagnosis_code_2,diagnosis_code_3,diagnosis_code_4,diagnosis_code_5,diagnosis_code_6,diagnosis_code_7,diagnosis_code_8,diagnosis_code_9,diagnosis_code_10,diagnosis_code_11,diagnosis_code_12,diagnosis_code_13,diagnosis_code_14,diagnosis_code_15,diagnosis_code_16,diagnosis_code_17,diagnosis_code_18,diagnosis_code_19,diagnosis_code_20,diagnosis_code_21,diagnosis_code_22,diagnosis_code_23,diagnosis_code_24,diagnosis_code_25,diagnosis_poa_1,diagnosis_poa_2,diagnosis_poa_3,diagnosis_poa_4,diagnosis_poa_5,diagnosis_poa_6,diagnosis_poa_7,diagnosis_poa_8,diagnosis_poa_9,diagnosis_poa_10,diagnosis_poa_11,diagnosis_poa_12,diagnosis_poa_13,diagnosis_poa_14,diagnosis_poa_15,diagnosis_poa_16,diagnosis_poa_17,diagnosis_poa_18,diagnosis_poa_19,diagnosis_poa_20,diagnosis_poa_21,diagnosis_poa_22,diagnosis_poa_23,diagnosis_poa_24,diagnosis_poa_25,procedure_code_type,procedure_code_1,procedure_code_2,procedure_code_3,procedure_code_4,procedure_code_5,procedure_code_6,procedure_code_7,procedure_code_8,procedure_code_9,procedure_code_10,procedure_code_11,procedure_code_12,procedure_code_13,procedure_code_14,procedure_code_15,procedure_code_16,procedure_code_17,procedure_code_18,procedure_code_19,procedure_code_20,procedure_code_21,procedure_code_22,procedure_code_23,procedure_code_24,procedure_code_25,procedure_date_1,procedure_date_2,procedure_date_3,procedure_date_4,procedure_date_5,procedure_date_6,procedure_date_7,procedure_date_8,procedure_date_9,procedure_date_10,procedure_date_11,procedure_date_12,procedure_date_13,procedure_date_14,procedure_date_15,procedure_date_16,procedure_date_17,procedure_date_18,procedure_date_19,procedure_date_20,procedure_date_21,procedure_date_22,procedure_date_23,procedure_date_24,procedure_date_25,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/integration_tests/seeds/observation_seed.csv b/integration_tests/seeds/observation_seed.csv index 0b5d1d841..f47b4ead2 100644 --- a/integration_tests/seeds/observation_seed.csv +++ b/integration_tests/seeds/observation_seed.csv @@ -1 +1 @@ -observation_id,patient_id,encounter_id,panel_id,observation_date,observation_type,source_code_type,source_code,source_description,normalized_code_type,normalized_code,normalized_description,result,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,data_source,file_name,ingest_datetime \ No newline at end of file +observation_id,person_id,patient_id,encounter_id,panel_id,observation_date,observation_type,source_code_type,source_code,source_description,normalized_code_type,normalized_code,normalized_description,result,source_units,normalized_units,source_reference_range_low,source_reference_range_high,normalized_reference_range_low,normalized_reference_range_high,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/integration_tests/seeds/pharmacy_claim_seed.csv b/integration_tests/seeds/pharmacy_claim_seed.csv index 1b615da7f..1283733ce 100644 --- a/integration_tests/seeds/pharmacy_claim_seed.csv +++ b/integration_tests/seeds/pharmacy_claim_seed.csv @@ -1 +1 @@ -claim_id,claim_line_number,patient_id,member_id,payer,plan,prescribing_provider_npi,dispensing_provider_npi,dispensing_date,ndc_code,quantity,days_supply,refills,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file +claim_id,claim_line_number,person_id,member_id,payer,plan,prescribing_provider_npi,dispensing_provider_npi,dispensing_date,ndc_code,quantity,days_supply,refills,paid_date,paid_amount,allowed_amount,charge_amount,coinsurance_amount,copayment_amount,deductible_amount,in_network_flag,data_source,file_name,ingest_datetime \ No newline at end of file diff --git a/integration_tests/seeds/provider_attribution_seed.csv b/integration_tests/seeds/provider_attribution_seed.csv index 58fdb2ae2..642638fe0 100644 --- a/integration_tests/seeds/provider_attribution_seed.csv +++ b/integration_tests/seeds/provider_attribution_seed.csv @@ -1 +1 @@ -patient_id,year_month,payer,plan,data_source,payer_attributed_provider,payer_attributed_provider_practice,payer_attributed_provider_organization,payer_attributed_provider_lob,custom_attributed_provider,custom_attributed_provider_practice,custom_attributed_provider_organization,custom_attributed_provider_lob \ No newline at end of file +person_id,patient_id,year_month,payer,plan,data_source,payer_attributed_provider,payer_attributed_provider_practice,payer_attributed_provider_organization,payer_attributed_provider_lob,custom_attributed_provider,custom_attributed_provider_practice,custom_attributed_provider_organization,custom_attributed_provider_lob \ No newline at end of file diff --git a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_denom_long.sql b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_denom_long.sql index 790d512d2..083c18115 100644 --- a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_denom_long.sql +++ b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_denom_long.sql @@ -4,7 +4,7 @@ select d.year_number - , d.patient_id + , d.person_id , d.data_source , '01' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '03' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -24,7 +24,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '05' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -34,7 +34,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '07' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -44,7 +44,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '08' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -54,7 +54,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '11' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -64,7 +64,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '12' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -74,7 +74,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '14' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -84,7 +84,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '15' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -94,7 +94,7 @@ union all select d.year_number - , d.patient_id + , d.person_id , d.data_source , '16' as pqi_number , '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_num_long.sql b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_num_long.sql index c89a134b0..ab1944bb5 100644 --- a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_num_long.sql +++ b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_num_long.sql @@ -4,7 +4,7 @@ select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '01' as pqi_number @@ -15,7 +15,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '03' as pqi_number @@ -26,7 +26,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '05' as pqi_number @@ -37,7 +37,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '07' as pqi_number @@ -48,7 +48,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '08' as pqi_number @@ -59,7 +59,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '11' as pqi_number @@ -70,7 +70,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '12' as pqi_number @@ -81,7 +81,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '14' as pqi_number @@ -92,7 +92,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '15' as pqi_number @@ -103,7 +103,7 @@ union all select n.data_source - , n.patient_id + , n.person_id , n.year_number , n.encounter_id , '16' as pqi_number diff --git a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_rate.sql b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_rate.sql index 907d6b428..0aa43da16 100644 --- a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_rate.sql +++ b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_rate.sql @@ -20,7 +20,7 @@ with num as ( data_source , year_number , pqi_number - , count(patient_id) as denom_count + , count(person_id) as denom_count from {{ ref('ahrq_measures__pqi_denom_long') }} as d group by data_source diff --git a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_summary.sql b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_summary.sql index ff872bc26..409cf7c5c 100644 --- a/models/ahrq_measures/pqi/final/ahrq_measures__pqi_summary.sql +++ b/models/ahrq_measures/pqi/final/ahrq_measures__pqi_summary.sql @@ -7,7 +7,7 @@ select p.pqi_number , e.year_number , e.encounter_id , e.data_source - , e.patient_id + , e.person_id , e.facility_id , e.ms_drg_code , e.ms_drg_description diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_num.sql index b4fdcbba5..57821e592 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_01_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as pqi and pqi.value_set_name = 'diabetes_with_short-term_complications_diagnosis_codes' and pqi.pqi_number = '01' inner join {{ ref('ahrq_measures__int_pqi_01_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_01_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_num.sql index 9a90ca9ae..e9fea3b88 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_03_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as pqi and pqi.value_set_name = 'diabetes_with_long-term_complications_diagnosis_codes' and pqi.pqi_number = '03' inner join {{ ref('ahrq_measures__int_pqi_03_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_03_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_denom.sql index d789aa5a6..65cbef89d 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 40 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_num.sql index 27da641de..d50c80ac7 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_05_num.sql @@ -4,13 +4,13 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_inpatient_encounter') }} as e inner join {{ ref('ahrq_measures__int_pqi_05_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('pqi__value_sets') }} as copd diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_num.sql index cf6eb0285..57265a28e 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_07_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'hypertension_diagnosis_codes' and hyp.pqi_number = '07' inner join {{ ref('ahrq_measures__int_pqi_07_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_07_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_num.sql index f84ba354f..e2208803f 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_08_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'heart_failure_diagnosis_codes' and hyp.pqi_number = '08' inner join {{ ref('ahrq_measures__int_pqi_08_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_08_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_num.sql index 2e5e4c7b4..96fe1ffd4 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_11_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'community_acquired_bacterial_pneumonia_diagnosis_codes' and hyp.pqi_number = '11' inner join {{ ref('ahrq_measures__int_pqi_11_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_11_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_num.sql index 00baa4a0e..95f4c17d9 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_12_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'urinary_tract_infection_diagnosis_codes' and hyp.pqi_number = '12' inner join {{ ref('ahrq_measures__int_pqi_12_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_12_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_num.sql index b9b769c9c..9cb96ac53 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_14_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'uncontrolled_diabetes_diagnosis_codes' and hyp.pqi_number = '14' inner join {{ ref('ahrq_measures__int_pqi_14_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_14_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_denom.sql index fe4e58042..ce4c55612 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_num.sql index 22671f994..5408743b0 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_15_num.sql @@ -4,7 +4,7 @@ select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run')}}' as tuva_last_run @@ -14,7 +14,7 @@ inner join {{ ref('pqi__value_sets') }} as hyp and hyp.value_set_name = 'asthma_diagnosis_codes' and hyp.pqi_number = '15' inner join {{ ref('ahrq_measures__int_pqi_15_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number left join {{ ref('ahrq_measures__int_pqi_15_exclusions') }} as shared diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_denom.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_denom.sql index 2e9717365..aec218c34 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_denom.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_denom.sql @@ -4,13 +4,13 @@ select distinct cast(substring(e.year_month, 1, 4) as int) AS year_number - , e.patient_id + , e.person_id , e.data_source , {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} as age , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_member_months') }} as e inner join {{ ref('ahrq_measures__stg_pqi_patient') }} as p - on e.patient_id = p.patient_id + on e.person_id = p.person_id and p.data_source = e.data_source where {{ datediff('p.birth_date', 'e.first_day_of_month', 'year') }} >= 18 diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_num.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_num.sql index 0f2f74d3f..538aa95ae 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_num.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_16_num.sql @@ -33,13 +33,13 @@ procedures as ( select e.data_source - , e.patient_id + , e.person_id , e.year_number , e.encounter_id , '{{ var('tuva_last_run') }}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_inpatient_encounter') }} as e inner join {{ ref('ahrq_measures__int_pqi_16_denom') }} as denom - on e.patient_id = denom.patient_id + on e.person_id = denom.person_id and e.data_source = denom.data_source and e.year_number = denom.year_number inner join procedures as p diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_age.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_age.sql index 9cd5c2265..8a9cf0e35 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_age.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_age.sql @@ -5,7 +5,7 @@ /* Exclude patients with missing age */ select data_source - , patient_id + , person_id , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_patient') }} where birth_date is null \ No newline at end of file diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_gender.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_gender.sql index 8be31439b..e5ece639b 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_gender.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_missing_gender.sql @@ -5,7 +5,7 @@ -- Exclude patients with undefined or missing gender select data_source - , patient_id + , person_id , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_patient') }} where diff --git a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_union.sql b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_union.sql index a33ec4e14..7543f0f6d 100644 --- a/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_union.sql +++ b/models/ahrq_measures/pqi/intermediate/ahrq_measures__int_pqi_shared_exclusion_union.sql @@ -10,7 +10,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_inpatient_encounter') }} as denom inner join {{ ref('ahrq_measures__int_pqi_shared_exclusion_missing_age') }} as age - on denom.patient_id = age.patient_id + on denom.person_id = age.person_id and denom.data_source = age.data_source union all @@ -23,7 +23,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ahrq_measures__stg_pqi_inpatient_encounter') }} as denom inner join {{ ref('ahrq_measures__int_pqi_shared_exclusion_missing_gender') }} as gender - on denom.patient_id = gender.patient_id + on denom.person_id = gender.person_id and denom.data_source = gender.data_source union all diff --git a/models/ahrq_measures/pqi/pqi_models.yml b/models/ahrq_measures/pqi/pqi_models.yml index c930fd4a0..c3379ccb8 100644 --- a/models/ahrq_measures/pqi/pqi_models.yml +++ b/models/ahrq_measures/pqi/pqi_models.yml @@ -17,7 +17,7 @@ models: columns: - name: year_number description: the year the patient qualified for the corresponding denominator - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: data_source description: > @@ -77,7 +77,7 @@ models: description: > User-configured field that indicates the data source (e.g. typically named after the payer and state "BCBS Tennessee"). - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: year_number description: the year the patient qualified for the corresponding numerator @@ -151,7 +151,7 @@ models: named after the payer and state "BCBS Tennessee"). - name: year_number description: the year the patient qualified for the corresponding numerator - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: facility_id description: > diff --git a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_inpatient_encounter.sql b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_inpatient_encounter.sql index bc4e1c1d6..c1b03005e 100644 --- a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_inpatient_encounter.sql +++ b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_inpatient_encounter.sql @@ -12,7 +12,7 @@ select , encounter_end_date , length_of_stay , primary_diagnosis_code - , patient_id + , person_id , facility_id , paid_amount , {{ date_part('year', 'encounter_start_date') }} as year_number diff --git a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_member_months.sql b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_member_months.sql index dd30d2da1..aaf984f88 100644 --- a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_member_months.sql +++ b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_member_months.sql @@ -13,7 +13,7 @@ date_int as ( select data_source - , patient_id + , person_id , first_day_of_month , d.yyyymm as year_month diff --git a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_patient.sql b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_patient.sql index cb3a707c9..642c93f04 100644 --- a/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_patient.sql +++ b/models/ahrq_measures/pqi/staging/ahrq_measures__stg_pqi_patient.sql @@ -5,7 +5,7 @@ select data_source , birth_date - , patient_id + , person_id , sex from {{ ref('core__patient') }} diff --git a/models/ccsr/ccsr_models.yml b/models/ccsr/ccsr_models.yml index 84563e01d..6dbd55397 100644 --- a/models/ccsr/ccsr_models.yml +++ b/models/ccsr/ccsr_models.yml @@ -25,7 +25,7 @@ models: description: Unique identifier for each the encounter. - name: claim_id description: Unique identifier for each claim. - - name: patient_id + - name: person_id description: Unique identifier for each patient. - name: normalized_code description: "The ICD-10-CM code for the diagnosis." @@ -101,7 +101,7 @@ models: description: Unique identifier for an encounter. - name: claim_id description: Unique claim_id for each claim. - - name: patient_id + - name: person_id description: Unique identifier for each patient. - name: body_system description: > @@ -154,7 +154,7 @@ models: The encounter_id for the encounter where this procedure was performed. - name: claim_id description: Unique identifier for each claim. - - name: patient_id + - name: person_id description: Unique identifier for each patient. - name: normalized_code description: The ICD-10-PCS code for the procedure. @@ -295,7 +295,7 @@ models: columns: - name: encounter_id - name: claim_id - - name: patient_id + - name: person_id - name: normalized_code - name: condition_rank @@ -307,5 +307,5 @@ models: columns: - name: encounter_id - name: claim_id - - name: patient_id + - name: person_id - name: normalized_code \ No newline at end of file diff --git a/models/ccsr/final/ccsr__long_condition_category.sql b/models/ccsr/final/ccsr__long_condition_category.sql index bc1c1601e..f7435ddbf 100644 --- a/models/ccsr/final/ccsr__long_condition_category.sql +++ b/models/ccsr/final/ccsr__long_condition_category.sql @@ -7,36 +7,38 @@ with ccsr__dx_vertical_pivot as ( select * from {{ ref('ccsr__dx_vertical_pivot') }} -), condition as ( +) + +, condition as ( select * from {{ ref('ccsr__stg_core__condition') }} -), dxccsr_body_systems as ( +) + +, dxccsr_body_systems as ( select * from {{ ref('ccsr__dxccsr_v2023_1_body_systems') }} ) select - condition.encounter_id, - condition.claim_id, - condition.patient_id, - condition.normalized_code, - ccsr__dx_vertical_pivot.code_description, - condition.condition_rank, - ccsr__dx_vertical_pivot.ccsr_parent_category, - dxccsr_body_systems.body_system, - dxccsr_body_systems.parent_category_description, - ccsr__dx_vertical_pivot.ccsr_category, - ccsr__dx_vertical_pivot.ccsr_category_description, - ccsr__dx_vertical_pivot.ccsr_category_rank, - ccsr__dx_vertical_pivot.is_ip_default_category, - ccsr__dx_vertical_pivot.is_op_default_category, - {{ var('dxccsr_version') }} as dxccsr_version, - '{{ var('tuva_last_run')}}' as tuva_last_run + condition.encounter_id + , condition.claim_id + , condition.person_id + , condition.normalized_code + , ccsr__dx_vertical_pivot.code_description + , condition.condition_rank + , ccsr__dx_vertical_pivot.ccsr_parent_category + , dxccsr_body_systems.body_system + , dxccsr_body_systems.parent_category_description + , ccsr__dx_vertical_pivot.ccsr_category + , ccsr__dx_vertical_pivot.ccsr_category_description + , ccsr__dx_vertical_pivot.ccsr_category_rank + , ccsr__dx_vertical_pivot.is_ip_default_category + , ccsr__dx_vertical_pivot.is_op_default_category + , {{ var('dxccsr_version') }} as dxccsr_version + , '{{ var('tuva_last_run')}}' as tuva_last_run from condition left join ccsr__dx_vertical_pivot on condition.normalized_code = ccsr__dx_vertical_pivot.code -left join dxccsr_body_systems on ccsr__dx_vertical_pivot.ccsr_parent_category = dxccsr_body_systems.ccsr_parent_category - - +left join dxccsr_body_systems on ccsr__dx_vertical_pivot.ccsr_parent_category = dxccsr_body_systems.ccsr_parent_category \ No newline at end of file diff --git a/models/ccsr/final/ccsr__long_procedure_category.sql b/models/ccsr/final/ccsr__long_procedure_category.sql index 2465674eb..c6d60443c 100644 --- a/models/ccsr/final/ccsr__long_procedure_category.sql +++ b/models/ccsr/final/ccsr__long_procedure_category.sql @@ -18,7 +18,7 @@ with procedures as ( select distinct procedures.encounter_id , procedures.claim_id - , procedures.patient_id + , procedures.person_id , procedures.normalized_code , ccsr__procedure_category_map.code_description , ccsr__procedure_category_map.ccsr_parent_category diff --git a/models/ccsr/final/ccsr__singular_condition_category.sql b/models/ccsr/final/ccsr__singular_condition_category.sql index 54ebbb78d..399f0369e 100644 --- a/models/ccsr/final/ccsr__singular_condition_category.sql +++ b/models/ccsr/final/ccsr__singular_condition_category.sql @@ -4,17 +4,16 @@ }} select - encounter_id, - claim_id, - patient_id, - ccsr_category, - ccsr_category_description, - ccsr_parent_category, - parent_category_description, - body_system, - {{ var('dxccsr_version') }} as dxccsr_version, - '{{ var('tuva_last_run')}}' as tuva_last_run + encounter_id + , claim_id + , person_id + , ccsr_category + , ccsr_category_description + , ccsr_parent_category + , parent_category_description + , body_system + , {{ var('dxccsr_version') }} as dxccsr_version + , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ref('ccsr__long_condition_category')}} -where - is_{{ var('record_type', 'ip') }}_default_category = 1 - and condition_rank = 1 \ No newline at end of file +where is_{{ var('record_type', 'ip') }}_default_category = 1 +and condition_rank = 1 \ No newline at end of file diff --git a/models/ccsr/intermediate/ccsr__dx_vertical_pivot.sql b/models/ccsr/intermediate/ccsr__dx_vertical_pivot.sql index bd98b178d..38aefb6d2 100644 --- a/models/ccsr/intermediate/ccsr__dx_vertical_pivot.sql +++ b/models/ccsr/intermediate/ccsr__dx_vertical_pivot.sql @@ -6,29 +6,31 @@ with codes as ( select - icd_10_cm_code as code, - icd_10_cm_code_description as code_description, + icd_10_cm_code as code + , icd_10_cm_code_description as code_description -- loop to generate columns for CCSR categories 1-6 {%- for i in range(1,7) %} - ccsr_category_{{ i }}, - ccsr_category_{{ i }}_description, + , ccsr_category_{{ i }} + , ccsr_category_{{ i }}_description {%- endfor %} - default_ccsr_category_ip, - default_ccsr_category_op + , default_ccsr_category_ip + , default_ccsr_category_op from {{ ref('ccsr__dxccsr_v2023_1_cleaned_map') }} -), long_union as ( +) + +, long_union as ( -- generate select & union statements to pivot category columns to rows {% for i in range(1,7,1) %} select - code, - code_description, - substring(ccsr_category_{{ i }}, 1, 3) as ccsr_parent_category, - ccsr_category_{{ i }} as ccsr_category, - ccsr_category_{{ i }}_description as ccsr_category_description, - {{ i }} as ccsr_category_rank, - CASE WHEN ccsr_category_{{ i }} = default_ccsr_category_ip THEN 1 ELSE 0 END as is_ip_default_category, - CASE WHEN ccsr_category_{{ i }} = default_ccsr_category_op THEN 1 ELSE 0 END as is_op_default_category + code + , code_description + , substring(ccsr_category_{{ i }}, 1, 3) as ccsr_parent_category + , ccsr_category_{{ i }} as ccsr_category + , ccsr_category_{{ i }}_description as ccsr_category_description + , {{ i }} as ccsr_category_rank + , CASE WHEN ccsr_category_{{ i }} = default_ccsr_category_ip THEN 1 ELSE 0 END as is_ip_default_category + , CASE WHEN ccsr_category_{{ i }} = default_ccsr_category_op THEN 1 ELSE 0 END as is_op_default_category from codes {{ "union all" if not loop.last else "" }} {%- endfor %} diff --git a/models/ccsr/intermediate/ccsr__procedure_category_map.sql b/models/ccsr/intermediate/ccsr__procedure_category_map.sql index 8eb17f468..a1788ca07 100644 --- a/models/ccsr/intermediate/ccsr__procedure_category_map.sql +++ b/models/ccsr/intermediate/ccsr__procedure_category_map.sql @@ -4,11 +4,11 @@ }} select - icd_10_pcs as code, - icd_10_pcs_description as code_description, - prccsr as ccsr_category, - substring(prccsr, 1, 3) as ccsr_parent_category, - prccsr_description as ccsr_category_description, - clinical_domain, - '{{ var('tuva_last_run')}}' as tuva_last_run + icd_10_pcs as code + , icd_10_pcs_description as code_description + , prccsr as ccsr_category + , substring(prccsr, 1, 3) as ccsr_parent_category + , prccsr_description as ccsr_category_description + , clinical_domain + , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('ccsr__prccsr_v2023_1_cleaned_map')}} \ No newline at end of file diff --git a/models/ccsr/staging/ccsr__stg_core__condition.sql b/models/ccsr/staging/ccsr__stg_core__condition.sql index c23bd395c..03bc0b2d6 100644 --- a/models/ccsr/staging/ccsr__stg_core__condition.sql +++ b/models/ccsr/staging/ccsr__stg_core__condition.sql @@ -6,7 +6,7 @@ select encounter_id , claim_id - , patient_id + , person_id , normalized_code , condition_rank , '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/ccsr/staging/ccsr__stg_core__procedure.sql b/models/ccsr/staging/ccsr__stg_core__procedure.sql index 20ad2d02c..f1df90da4 100644 --- a/models/ccsr/staging/ccsr__stg_core__procedure.sql +++ b/models/ccsr/staging/ccsr__stg_core__procedure.sql @@ -6,7 +6,7 @@ select encounter_id , claim_id - , patient_id + , person_id , normalized_code , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('core__procedure') }} \ No newline at end of file diff --git a/models/chronic_conditions/cms_chronic_conditions_models.yml b/models/chronic_conditions/cms_chronic_conditions_models.yml index 5556fb686..852aa2c30 100644 --- a/models/chronic_conditions/cms_chronic_conditions_models.yml +++ b/models/chronic_conditions/cms_chronic_conditions_models.yml @@ -16,7 +16,7 @@ models: This model pivots conditions on the patient level (i.e. one record per patient) with flags for each chronic condition. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - unique @@ -247,8 +247,10 @@ models: description: flag indicating if the condition is present data_type: boolean - name: tuva_last_run - description: The time at with the model was materialized. Generated by `dbt_utils.pretty_time` as the local time of the `dbt run` environment. Timezone is configurable via the `tuva_last_run` var. - + description: > + The time at with the model was materialized. Generated by + `dbt_utils.pretty_time` as the local time of the `dbt run` + environment. Timezone is configurable via the `tuva_last_run` var. - name: chronic_conditions__cms_chronic_conditions_long config: @@ -266,13 +268,12 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - claim_id - start_date - condition - columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - not_null @@ -324,7 +325,7 @@ models: and maps ICD-10-CM diagnosis codes, ICD-10-PCS procedure codes, HCPCS codes, and MS DRG codes to chronic conditions. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - not_null @@ -367,7 +368,7 @@ models: (HIV/AIDS). This model maps ICD-10-CM diagnosis codes and MS DRG codes to the chronic condition. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - not_null @@ -410,7 +411,7 @@ models: (OUD). This model maps ICD-10-CM diagnosis codes, ICD-10-PCS procedure codes, HCPCS codes, and NDC codes to the chronic condition. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - not_null diff --git a/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_long.sql b/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_long.sql index a6e4b8972..472afe271 100644 --- a/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_long.sql +++ b/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_long.sql @@ -26,7 +26,7 @@ with conditions_unioned as ( {% endif %} select - patient_id + person_id , claim_id , start_date , chronic_condition_type diff --git a/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_wide.sql b/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_wide.sql index ec40b1427..250ea40b3 100644 --- a/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_wide.sql +++ b/models/chronic_conditions/final/chronic_conditions__cms_chronic_conditions_wide.sql @@ -15,7 +15,7 @@ with chronic_conditions as ( , conditions as ( select - chronic_conditions_unioned.patient_id + chronic_conditions_unioned.person_id , chronic_conditions.condition_column_name , 1 as condition_count from {{ ref('chronic_conditions__cms_chronic_conditions_long') }} as chronic_conditions_unioned @@ -25,7 +25,7 @@ with chronic_conditions as ( ) select - p.patient_id + p.person_id , {{ dbt_utils.pivot( column='condition_column_name' , values=dbt_utils.get_column_values( @@ -41,6 +41,6 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('cms_chronic_conditions__stg_core__patient') }} p left join conditions - on p.patient_id = conditions.patient_id + on p.person_id = conditions.person_id group by - p.patient_id \ No newline at end of file + p.person_id \ No newline at end of file diff --git a/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_long.sql b/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_long.sql index 60ea37fd1..746ba9c13 100644 --- a/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_long.sql +++ b/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_long.sql @@ -5,7 +5,7 @@ with all_conditions as ( select - patient_id, + person_id, normalized_code, recorded_date from {{ ref('tuva_chronic_conditions__stg_core__condition') }} @@ -14,18 +14,18 @@ select conditions_with_first_and_last_diagnosis_date as ( select - patient_id, + person_id, normalized_code as icd_10_cm, min(recorded_date) as first_diagnosis_date, max(recorded_date) as last_diagnosis_date from all_conditions -group by patient_id, normalized_code +group by person_id, normalized_code ) select - aa.patient_id, + aa.person_id, bb.concept_name as condition, min(first_diagnosis_date) as first_diagnosis_date, max(last_diagnosis_date) as last_diagnosis_date, @@ -33,4 +33,4 @@ select from conditions_with_first_and_last_diagnosis_date aa inner join {{ ref('clinical_concept_library__value_set_member_relevant_fields') }} bb on aa.icd_10_cm = bb.code -group by aa.patient_id, bb.concept_name +group by aa.person_id, bb.concept_name diff --git a/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_wide.sql b/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_wide.sql index ff7f63d2d..883fa7844 100644 --- a/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_wide.sql +++ b/models/chronic_conditions/final/chronic_conditions__tuva_chronic_conditions_wide.sql @@ -4,277 +4,277 @@ }} with patients as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} ), obesity as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Obesity' ), osteoarthritis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Osteoarthritis' ), copd as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Chronic Obstructive Pulmonary Disease' ), anxiety_disorders as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Anxiety Disorders' ), ckd as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Chronic Kidney Disease' ), t2d as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Type 2 Diabetes Mellitus' ), cll as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Chronic Lymphocytic Leukemia' ), dysplipidemias as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Dyslipidemias' ), hypertension as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Hypertension' ), atherosclerosis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Atherosclerosis' ), dementia as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Dementia' ), rheumatoid_arthritis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Rheumatoid Arthritis' ), celiac as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Celiac Disease' ), hip_fracture as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Hip Fracture' ), immunodeficiencies_and_white_blood_cell_disorders as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Specified Immunodeficiencies and White Blood Cell Disorders (HCC v28 concept #115)' ), asthma as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Asthma' ), t1d as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Type 1 Diabetes Mellitus' ), ulcerative_colitis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Ulcerative colitis' ), chrohns as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Crohns Disease' ), holicobacter as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Helicobacter pylori Infection' ), bipolar as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Bipolar Affective Disorder' ), heart_failure as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Heart Failure' ), tabacco as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Tobacco Use' ), lyme as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Lyme Disease' ), breast_cancer as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Breast Cancer' ), osteoporosis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Osteoporosis' ), pulmonary_embolism as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Pulmonary Embolism, Thrombotic or Unspecified' ), schizophrenia as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Schizophrenia' ), atrial_fibrillation as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Atrial Fibrillation' ), colorectal_cancer as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Colorectal Cancer' ), depression as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Major Depressive Disorder' ), deep_vein_thrombosis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Deep Vein Thrombosis of Extremities or Central Veins' ), alzheimer as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Alzheimer Disease' ), stroke as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Stroke' ), myocardial_infraction as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Myocardial Infarction' ), opiod_use_disorder as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Opioid Use Disorder' ), lung_cancer as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Lung cancer, primary or unspecified' ), herpes as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Herpes Simplex Infection' ), rickettsiosis as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Rickettsiosis' ), ms as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Multiple Sclerosis' ), alchohol as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Alcohol Use Disorder' ), adhd as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Attention Deficit-Hyperactivity Disorder' ), hiv as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'HIV/AIDS (HCC v28 concept #1)' ), ptsd as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Post-Traumatic Stress Disorder' ), lupus as ( -select distinct patient_id +select distinct person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} where condition = 'Systemic Lupus Erythematosus' ) @@ -283,140 +283,140 @@ where condition = 'Systemic Lupus Erythematosus' select - patient_id, - case when patient_id in (select * from obesity) then 1 + person_id, + case when person_id in (select * from obesity) then 1 else 0 end as obesity, - case when patient_id in (select * from osteoarthritis) then 1 + case when person_id in (select * from osteoarthritis) then 1 else 0 end as osteoarthritis, - case when patient_id in (select * from copd) then 1 + case when person_id in (select * from copd) then 1 else 0 end as copd, - case when patient_id in (select * from anxiety_disorders) then 1 + case when person_id in (select * from anxiety_disorders) then 1 else 0 end as anxiety_disorders, - case when patient_id in (select * from ckd) then 1 + case when person_id in (select * from ckd) then 1 else 0 end as ckd, - case when patient_id in (select * from t2d) then 1 + case when person_id in (select * from t2d) then 1 else 0 end as t2d, - case when patient_id in (select * from cll) then 1 + case when person_id in (select * from cll) then 1 else 0 end as cll, - case when patient_id in (select * from dysplipidemias) then 1 + case when person_id in (select * from dysplipidemias) then 1 else 0 end as dysplipidemias, - case when patient_id in (select * from hypertension) then 1 + case when person_id in (select * from hypertension) then 1 else 0 end as hypertension, - case when patient_id in (select * from atherosclerosis) then 1 + case when person_id in (select * from atherosclerosis) then 1 else 0 end as atherosclerosis, - case when patient_id in (select * from dementia) then 1 + case when person_id in (select * from dementia) then 1 else 0 end as dementia, - case when patient_id in (select * from rheumatoid_arthritis) then 1 + case when person_id in (select * from rheumatoid_arthritis) then 1 else 0 end as rheumatoid_arthritis, - case when patient_id in (select * from celiac) then 1 + case when person_id in (select * from celiac) then 1 else 0 end as celiac, - case when patient_id in (select * from hip_fracture) then 1 + case when person_id in (select * from hip_fracture) then 1 else 0 end as hip_fracture, - case when patient_id in (select * from immunodeficiencies_and_white_blood_cell_disorders) then 1 + case when person_id in (select * from immunodeficiencies_and_white_blood_cell_disorders) then 1 else 0 end as immunodeficiencies_and_white_blood_cell_disorders, - case when patient_id in (select * from asthma) then 1 + case when person_id in (select * from asthma) then 1 else 0 end asthma, - case when patient_id in (select * from t1d) then 1 + case when person_id in (select * from t1d) then 1 else 0 end as t1d, - case when patient_id in (select * from ulcerative_colitis) then 1 + case when person_id in (select * from ulcerative_colitis) then 1 else 0 end as ulcerative_colitis, - case when patient_id in (select * from chrohns) then 1 + case when person_id in (select * from chrohns) then 1 else 0 end as chrohns, - case when patient_id in (select * from holicobacter) then 1 + case when person_id in (select * from holicobacter) then 1 else 0 end as holicobacter, - case when patient_id in (select * from bipolar) then 1 + case when person_id in (select * from bipolar) then 1 else 0 end as bipolar, - case when patient_id in (select * from heart_failure) then 1 + case when person_id in (select * from heart_failure) then 1 else 0 end as heart_failure, - case when patient_id in (select * from tabacco) then 1 + case when person_id in (select * from tabacco) then 1 else 0 end as tabacco, - case when patient_id in (select * from lyme) then 1 + case when person_id in (select * from lyme) then 1 else 0 end as lyme, - case when patient_id in (select * from breast_cancer) then 1 + case when person_id in (select * from breast_cancer) then 1 else 0 end as breast_cancer, - case when patient_id in (select * from osteoporosis) then 1 + case when person_id in (select * from osteoporosis) then 1 else 0 end as osteoporosis, - case when patient_id in (select * from pulmonary_embolism) then 1 + case when person_id in (select * from pulmonary_embolism) then 1 else 0 end as pulmonary_embolism, - case when patient_id in (select * from schizophrenia) then 1 + case when person_id in (select * from schizophrenia) then 1 else 0 end as schizophrenia, - case when patient_id in (select * from atrial_fibrillation) then 1 + case when person_id in (select * from atrial_fibrillation) then 1 else 0 end as atrial_fibrillation, - case when patient_id in (select * from colorectal_cancer) then 1 + case when person_id in (select * from colorectal_cancer) then 1 else 0 end as colorectal_cancer, - case when patient_id in (select * from depression) then 1 + case when person_id in (select * from depression) then 1 else 0 end as depression, - case when patient_id in (select * from deep_vein_thrombosis) then 1 + case when person_id in (select * from deep_vein_thrombosis) then 1 else 0 end as deep_vein_thrombosis, - case when patient_id in (select * from alzheimer) then 1 + case when person_id in (select * from alzheimer) then 1 else 0 end as alzheimer, - case when patient_id in (select * from stroke) then 1 + case when person_id in (select * from stroke) then 1 else 0 end as stroke, - case when patient_id in (select * from myocardial_infraction) then 1 + case when person_id in (select * from myocardial_infraction) then 1 else 0 end as myocardial_infraction, - case when patient_id in (select * from opiod_use_disorder) then 1 + case when person_id in (select * from opiod_use_disorder) then 1 else 0 end as opiod_use_disorder, - case when patient_id in (select * from lung_cancer) then 1 + case when person_id in (select * from lung_cancer) then 1 else 0 end as lung_cancer, - case when patient_id in (select * from herpes) then 1 + case when person_id in (select * from herpes) then 1 else 0 end as herpes, - case when patient_id in (select * from rickettsiosis) then 1 + case when person_id in (select * from rickettsiosis) then 1 else 0 end as rickettsiosis, - case when patient_id in (select * from ms) then 1 + case when person_id in (select * from ms) then 1 else 0 end as ms, - case when patient_id in (select * from alchohol) then 1 + case when person_id in (select * from alchohol) then 1 else 0 end as alchohol, - case when patient_id in (select * from adhd) then 1 + case when person_id in (select * from adhd) then 1 else 0 end as adhd, - case when patient_id in (select * from hiv) then 1 + case when person_id in (select * from hiv) then 1 else 0 end as hiv, - case when patient_id in (select * from ptsd) then 1 + case when person_id in (select * from ptsd) then 1 else 0 end as ptsd, - case when patient_id in (select * from lupus) then 1 + case when person_id in (select * from lupus) then 1 else 0 end as lupus, '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_all.sql b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_all.sql index 3f30ace4a..4d4936a54 100644 --- a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_all.sql +++ b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_all.sql @@ -12,7 +12,7 @@ with chronic_conditions as ( , patient_conditions as ( select - patient_id + person_id , claim_id , recorded_date as start_date , normalized_code_type as code_type @@ -25,7 +25,7 @@ with chronic_conditions as ( , patient_ms_drgs as ( select - patient_id + person_id , claim_id , claim_start_date as start_date , 'MS-DRG' as code_type @@ -38,7 +38,7 @@ with chronic_conditions as ( , patient_procedures as ( select - patient_id + person_id , claim_id , procedure_date as start_date , normalized_code_type as code_type @@ -51,7 +51,7 @@ with chronic_conditions as ( , inclusions_diagnosis as ( select - patient_conditions.patient_id + patient_conditions.person_id , patient_conditions.claim_id , patient_conditions.start_date , patient_conditions.data_source @@ -70,7 +70,7 @@ with chronic_conditions as ( , inclusions_ms_drg as ( select - patient_ms_drgs.patient_id + patient_ms_drgs.person_id , patient_ms_drgs.claim_id , patient_ms_drgs.start_date , patient_ms_drgs.data_source @@ -89,7 +89,7 @@ with chronic_conditions as ( , inclusions_procedure as ( select - patient_procedures.patient_id + patient_procedures.person_id , patient_procedures.claim_id , patient_procedures.start_date , patient_procedures.data_source @@ -141,7 +141,7 @@ with chronic_conditions as ( {% endif %} select distinct - cast(inclusions_unioned.patient_id as {{ dbt.type_string() }}) as patient_id + cast(inclusions_unioned.person_id as {{ dbt.type_string() }}) as person_id , cast(inclusions_unioned.claim_id as {{ dbt.type_string() }}) as claim_id , cast(inclusions_unioned.start_date as date) as start_date , cast(inclusions_unioned.chronic_condition_type as {{ dbt.type_string() }}) as chronic_condition_type diff --git a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_hiv_aids.sql b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_hiv_aids.sql index 8be90302a..38d653bc9 100644 --- a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_hiv_aids.sql +++ b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_hiv_aids.sql @@ -15,7 +15,7 @@ with chronic_conditions as ( , patient_conditions as ( select - patient_id + person_id , claim_id , recorded_date as start_date , normalized_code_type as code_type @@ -28,7 +28,7 @@ with chronic_conditions as ( , patient_ms_drgs as ( select - patient_id + person_id , claim_id , claim_start_date as start_date , 'MS-DRG' as code_type @@ -48,7 +48,7 @@ with chronic_conditions as ( , inclusions_diagnosis as ( select - patient_conditions.patient_id + patient_conditions.person_id , patient_conditions.claim_id , patient_conditions.start_date , patient_conditions.data_source @@ -67,7 +67,7 @@ with chronic_conditions as ( , inclusions_ms_drg as ( select - patient_ms_drgs.patient_id + patient_ms_drgs.person_id , patient_ms_drgs.claim_id , patient_ms_drgs.start_date , patient_ms_drgs.data_source @@ -92,7 +92,7 @@ with chronic_conditions as ( , exception_diagnosis as ( select - patient_conditions.patient_id + patient_conditions.person_id , patient_conditions.claim_id , patient_conditions.start_date , patient_conditions.data_source @@ -103,7 +103,7 @@ with chronic_conditions as ( inner join chronic_conditions on patient_conditions.code = chronic_conditions.code inner join inclusions_diagnosis - on patient_conditions.patient_id = inclusions_diagnosis.patient_id + on patient_conditions.person_id = inclusions_diagnosis.person_id where chronic_conditions.inclusion_type = 'Include' and chronic_conditions.code_system = 'ICD-10-CM' and chronic_conditions.code = 'R75' @@ -133,7 +133,7 @@ with chronic_conditions as ( {% endif %} select distinct - cast(inclusions_unioned.patient_id as {{ dbt.type_string() }}) as patient_id + cast(inclusions_unioned.person_id as {{ dbt.type_string() }}) as person_id , cast(inclusions_unioned.claim_id as {{ dbt.type_string() }}) as claim_id , cast(inclusions_unioned.start_date as date) as start_date , cast(inclusions_unioned.chronic_condition_type as {{ dbt.type_string() }}) as chronic_condition_type diff --git a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_oud.sql b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_oud.sql index df02d0266..a9134a295 100644 --- a/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_oud.sql +++ b/models/chronic_conditions/intermediate/chronic_conditions__cms_chronic_conditions_oud.sql @@ -28,7 +28,7 @@ with chronic_conditions as ( , patient_conditions as ( select - patient_id + person_id , claim_id , recorded_date as start_date , normalized_code_type as code_type @@ -41,7 +41,7 @@ with chronic_conditions as ( , patient_medications as ( select - patient_id + person_id , claim_id , paid_date as start_date , replace(ndc_code,'.','') as code @@ -53,7 +53,7 @@ with chronic_conditions as ( , patient_procedures as ( select - patient_id + person_id , claim_id , procedure_date as start_date , normalized_code_type as code_type @@ -66,7 +66,7 @@ with chronic_conditions as ( , inclusions_diagnosis as ( select - patient_conditions.patient_id + patient_conditions.person_id , patient_conditions.claim_id , patient_conditions.start_date , patient_conditions.data_source @@ -84,7 +84,7 @@ with chronic_conditions as ( , inclusions_procedure as ( select - patient_procedures.patient_id + patient_procedures.person_id , patient_procedures.claim_id , patient_procedures.start_date , patient_procedures.data_source @@ -109,7 +109,7 @@ with chronic_conditions as ( , inclusions_medication as ( select - patient_medications.patient_id + patient_medications.person_id , patient_medications.claim_id , patient_medications.start_date , patient_medications.data_source @@ -134,7 +134,7 @@ with chronic_conditions as ( */ , exclusions_other_chronic_conditions as ( - select distinct patient_id + select distinct person_id from {{ ref('chronic_conditions__cms_chronic_conditions_all') }} where condition in ( 'Alcohol Use Disorders' @@ -153,18 +153,18 @@ with chronic_conditions as ( */ , exclusions_medication as ( select distinct - patient_medications.patient_id + patient_medications.person_id from patient_medications inner join chronic_conditions on patient_medications.code = chronic_conditions.code inner join exclusions_other_chronic_conditions - on patient_medications.patient_id = exclusions_other_chronic_conditions.patient_id + on patient_medications.person_id = exclusions_other_chronic_conditions.person_id left join inclusions_diagnosis - on patient_medications.patient_id = inclusions_diagnosis.patient_id + on patient_medications.person_id = inclusions_diagnosis.person_id where chronic_conditions.inclusion_type = 'Include' and chronic_conditions.code_system = 'NDC' and chronic_conditions.code in {{ naltrexone_ndcs }} - and inclusions_diagnosis.patient_id is null + and inclusions_diagnosis.person_id is null ) @@ -191,7 +191,7 @@ with chronic_conditions as ( {% endif %} select distinct - cast(inclusions_unioned.patient_id as {{ dbt.type_string() }}) as patient_id + cast(inclusions_unioned.person_id as {{ dbt.type_string() }}) as person_id , cast(inclusions_unioned.claim_id as {{ dbt.type_string() }}) as claim_id , cast(inclusions_unioned.start_date as date) as start_date , cast(inclusions_unioned.chronic_condition_type as {{ dbt.type_string() }}) as chronic_condition_type @@ -201,5 +201,5 @@ select distinct , '{{ var('tuva_last_run')}}' as tuva_last_run from inclusions_unioned left join exclusions_medication - on inclusions_unioned.patient_id = exclusions_medication.patient_id -where exclusions_medication.patient_id is null \ No newline at end of file + on inclusions_unioned.person_id = exclusions_medication.person_id +where exclusions_medication.person_id is null \ No newline at end of file diff --git a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__condition.sql b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__condition.sql index f82a16ed8..19a3d01f7 100644 --- a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__condition.sql +++ b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__condition.sql @@ -5,7 +5,7 @@ select claim_id - , patient_id + , person_id , recorded_date , normalized_code_type , normalized_code diff --git a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__medical_claim.sql b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__medical_claim.sql index 377fe3d87..3f4b066ee 100644 --- a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__medical_claim.sql +++ b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__medical_claim.sql @@ -5,7 +5,7 @@ select claim_id - , patient_id + , person_id , claim_start_date , ms_drg_code , data_source diff --git a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__patient.sql b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__patient.sql index 2493d966d..580fc19b8 100644 --- a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__patient.sql +++ b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__patient.sql @@ -4,6 +4,6 @@ }} select - patient_id + person_id , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('core__patient') }} \ No newline at end of file diff --git a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__pharmacy_claim.sql b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__pharmacy_claim.sql index ae2ab424c..82a291d34 100644 --- a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__pharmacy_claim.sql +++ b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__pharmacy_claim.sql @@ -5,7 +5,7 @@ select claim_id - , patient_id + , person_id , paid_date , ndc_code , data_source diff --git a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__procedure.sql b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__procedure.sql index dcca1d1e1..dad6307c1 100644 --- a/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__procedure.sql +++ b/models/chronic_conditions/staging/cms_chronic_conditions__stg_core__procedure.sql @@ -5,7 +5,7 @@ select claim_id - , patient_id + , person_id , procedure_date , normalized_code_type , normalized_code diff --git a/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__condition.sql b/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__condition.sql index ea0063a8a..febdb40e2 100644 --- a/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__condition.sql +++ b/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__condition.sql @@ -4,7 +4,7 @@ }} select - patient_id + person_id , normalized_code , recorded_date , '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__patient.sql b/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__patient.sql index 1d9f850bd..dda067800 100644 --- a/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__patient.sql +++ b/models/chronic_conditions/staging/tuva_chronic_conditions__stg_core__patient.sql @@ -4,6 +4,6 @@ }} select - patient_id + person_id , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('core__patient') }} \ No newline at end of file diff --git a/models/chronic_conditions/tuva_chronic_conditions_models.yml b/models/chronic_conditions/tuva_chronic_conditions_models.yml index 37829f8a0..109eae9fa 100644 --- a/models/chronic_conditions/tuva_chronic_conditions_models.yml +++ b/models/chronic_conditions/tuva_chronic_conditions_models.yml @@ -21,17 +21,11 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - condition columns: - - name: patient_id + - name: person_id description: The unique identifier for a patient -# - name: condition_family -# description: > -# A higher level rollup grouping of conditions from the condition -# column -# meta: -# terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/chronic_conditions/chronic_conditions__tuva_chronic_conditions_hierarchy.csv - name: condition description: > The name of the condition that each diagnosis code rolls up to @@ -46,8 +40,10 @@ models: The last date when a diagnosis code that rolls up to this condition was coded to this patient - name: tuva_last_run - description: The time at with the model was materialized. Generated by `dbt_utils.pretty_time` as the local time of the `dbt run` environment. Timezone is configurable via the `tuva_last_run` var. - + description: > + The time at with the model was materialized. Generated by + `dbt_utils.pretty_time` as the local time of the `dbt run` + environment. Timezone is configurable via the `tuva_last_run` var. - name: chronic_conditions__tuva_chronic_conditions_wide description: > @@ -66,11 +62,11 @@ models: materialized: table tests: - unique: - column_name: patient_id + column_name: person_id - not_null: - column_name: patient_id + column_name: person_id columns: - - name: patient_id + - name: person_id description: ID of the patient - name: obesity description: flag indicating if the condition is present @@ -163,7 +159,10 @@ models: - name: lupus description: flag indicating if the condition is present - name: tuva_last_run - description: The time at with the model was materialized. Generated by `dbt_utils.pretty_time` as the local time of the `dbt run` environment. Timezone is configurable via the `tuva_last_run` var. + description: > + The time at with the model was materialized. Generated by + `dbt_utils.pretty_time` as the local time of the `dbt run` + environment. Timezone is configurable via the `tuva_last_run` var. ## Staging - name: tuva_chronic_conditions__stg_core__condition diff --git a/models/claims_preprocessing/claims_enrollment/claims_enrollment__flag_claims_with_enrollment.sql b/models/claims_preprocessing/claims_enrollment/claims_enrollment__flag_claims_with_enrollment.sql index 7a3f6fa98..1243d5967 100644 --- a/models/claims_preprocessing/claims_enrollment/claims_enrollment__flag_claims_with_enrollment.sql +++ b/models/claims_preprocessing/claims_enrollment/claims_enrollment__flag_claims_with_enrollment.sql @@ -9,7 +9,8 @@ with claim_dates as( select claim_id , claim_line_number - , patient_id + , person_id + , member_id , payer , {{ quote_column('plan') }} , coalesce(claim_line_start_date, claim_start_date, admission_date) as inferred_claim_start_date @@ -31,7 +32,8 @@ with claim_dates as( select claim_id , claim_line_number - , patient_id + , person_id + , member_id , payer , {{ quote_column('plan') }} , inferred_claim_start_date @@ -68,7 +70,8 @@ from claim_dates select distinct claim.claim_id , claim.claim_line_number - , claim.patient_id + , claim.person_id + , claim.member_id , claim.payer , claim.{{ quote_column('plan') }} , claim.inferred_claim_start_year_month @@ -78,7 +81,8 @@ select distinct , cast('{{ var('tuva_last_run')}}' as {{ dbt.type_timestamp() }} ) as tuva_last_run from {{ ref('core__member_months')}} mm inner join claim_year_month claim - on mm.patient_id = claim.patient_id + on mm.person_id = claim.person_id + and mm.member_id = claim.member_id and mm.payer = claim.payer and mm.{{ quote_column('plan') }} = claim.{{ quote_column('plan') }} and mm.year_month >= claim.inferred_claim_start_year_month diff --git a/models/claims_preprocessing/claims_preprocessing_models.yml b/models/claims_preprocessing/claims_preprocessing_models.yml index 15a01892c..42cabf6d1 100644 --- a/models/claims_preprocessing/claims_preprocessing_models.yml +++ b/models/claims_preprocessing/claims_preprocessing_models.yml @@ -20,7 +20,7 @@ models: - name: claim_line_number description: > Indicates the line number for the particular line of the claim. - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: payer description: Name of the payer. @@ -57,7 +57,7 @@ models: - normalized_input - claims_preprocessing columns: - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: member_id description: > @@ -166,7 +166,7 @@ models: (UB-04), dental, or vision. meta: terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__claim_type.csv - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: member_id description: > @@ -769,7 +769,7 @@ models: - name: claim_line_number description: Indicates the line number for the particular line of the claim. data_type: integer - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: member_id description: > diff --git a/models/claims_preprocessing/encounters/encounter_models.yml b/models/claims_preprocessing/encounters/encounter_models.yml index 5425d8148..53ac2aa58 100644 --- a/models/claims_preprocessing/encounters/encounter_models.yml +++ b/models/claims_preprocessing/encounters/encounter_models.yml @@ -29,8 +29,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -160,8 +160,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -292,8 +292,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -423,8 +423,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -554,8 +554,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -685,8 +685,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -816,8 +816,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -944,8 +944,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1072,8 +1072,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1200,8 +1200,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1328,8 +1328,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1456,8 +1456,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1584,8 +1584,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1712,8 +1712,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1840,8 +1840,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -1968,8 +1968,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2096,8 +2096,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2224,8 +2224,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2352,8 +2352,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2480,8 +2480,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2608,8 +2608,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2736,8 +2736,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2864,8 +2864,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -2992,8 +2992,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -3120,8 +3120,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender @@ -3249,8 +3249,8 @@ models: description: '{{ doc("encounter_type") }}' - name: encounter_group description: '{{ doc("encounter_group") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' - name: admit_age description: '{{ doc("admit_age") }}' - name: gender diff --git a/models/claims_preprocessing/encounters/staging/encounters__patient_data_source_id.sql b/models/claims_preprocessing/encounters/staging/encounters__patient_data_source_id.sql index be66bf2a0..5a392104e 100644 --- a/models/claims_preprocessing/encounters/staging/encounters__patient_data_source_id.sql +++ b/models/claims_preprocessing/encounters/staging/encounters__patient_data_source_id.sql @@ -4,7 +4,7 @@ }} with multiple_sources as ( -select distinct patient_id +select distinct person_id ,data_source from {{ ref('normalized_input__medical_claim') }} @@ -14,13 +14,13 @@ union union distinct {% endif %} -select distinct patient_id +select distinct person_id ,data_source from {{ ref('normalized_input__eligibility')}} ) select -patient_id +person_id ,data_source -,dense_rank() over (order by concat(patient_id,data_source)) as patient_data_source_id +,dense_rank() over (order by concat(person_id,data_source)) as patient_data_source_id from multiple_sources diff --git a/models/claims_preprocessing/encounters/staging/encounters__stg_eligibility.sql b/models/claims_preprocessing/encounters/staging/encounters__stg_eligibility.sql index 7bed2a83f..968887cfc 100644 --- a/models/claims_preprocessing/encounters/staging/encounters__stg_eligibility.sql +++ b/models/claims_preprocessing/encounters/staging/encounters__stg_eligibility.sql @@ -4,7 +4,7 @@ }} select - e.patient_id + e.person_id , e.birth_date , e.gender , e.race @@ -12,6 +12,6 @@ select , row_number() over (partition by d.patient_data_source_id order by e.enrollment_start_date desc) patient_row_num , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('normalized_input__eligibility') }} e -inner join {{ ref('encounters__patient_data_source_id') }} d on e.patient_id = d.patient_id +inner join {{ ref('encounters__patient_data_source_id') }} d on e.person_id = d.person_id and e.data_source = d.data_source \ No newline at end of file diff --git a/models/claims_preprocessing/encounters/staging/encounters__stg_medical_claim.sql b/models/claims_preprocessing/encounters/staging/encounters__stg_medical_claim.sql index 638a31e2a..700f264eb 100644 --- a/models/claims_preprocessing/encounters/staging/encounters__stg_medical_claim.sql +++ b/models/claims_preprocessing/encounters/staging/encounters__stg_medical_claim.sql @@ -6,7 +6,7 @@ select m.apr_drg_code - , m.patient_id + , m.person_id , d.patient_data_source_id , m.claim_id , m.claim_line_number @@ -65,7 +65,7 @@ inner join {{ ref('service_category__service_category_grouper') }} g on m.claim_ and m.claim_line_number = g.claim_line_number and g.duplicate_row_number = 1 -inner join {{ ref('encounters__patient_data_source_id') }} d on m.patient_id = d.patient_id +inner join {{ ref('encounters__patient_data_source_id') }} d on m.person_id = d.person_id and m.data_source = d.data_source left join {{ ref('ccsr__dxccsr_v2023_1_cleaned_map') }} dx on m.diagnosis_code_1 = dx.icd_10_cm_code diff --git a/models/claims_preprocessing/normalized_input/final/normalized_input__eligibility.sql b/models/claims_preprocessing/normalized_input/final/normalized_input__eligibility.sql index 2a778c237..f9eca7736 100644 --- a/models/claims_preprocessing/normalized_input/final/normalized_input__eligibility.sql +++ b/models/claims_preprocessing/normalized_input/final/normalized_input__eligibility.sql @@ -6,7 +6,7 @@ select - cast(elig.patient_id as {{ dbt.type_string() }} ) as patient_id + cast(elig.person_id as {{ dbt.type_string() }} ) as person_id , cast(elig.member_id as {{ dbt.type_string() }} ) as member_id , cast(elig.subscriber_id as {{ dbt.type_string() }} ) as subscriber_id , cast(elig.gender as {{ dbt.type_string() }} ) as gender @@ -35,4 +35,4 @@ select , cast('{{ var('tuva_last_run')}}' as {{ dbt.type_string() }} ) as tuva_last_run from {{ ref('normalized_input__stg_eligibility') }} elig left join {{ ref('normalized_input__int_eligibility_dates_normalize') }} date_norm - on elig.patient_id_key = date_norm.patient_id_key + on elig.person_id_key = date_norm.person_id_key diff --git a/models/claims_preprocessing/normalized_input/final/normalized_input__medical_claim.sql b/models/claims_preprocessing/normalized_input/final/normalized_input__medical_claim.sql index 77a3642c9..6a2b632bf 100644 --- a/models/claims_preprocessing/normalized_input/final/normalized_input__medical_claim.sql +++ b/models/claims_preprocessing/normalized_input/final/normalized_input__medical_claim.sql @@ -9,7 +9,7 @@ select cast(med.claim_id as {{ dbt.type_string() }} ) as claim_id , cast(med.claim_line_number as int ) as claim_line_number , cast(med.claim_type as {{ dbt.type_string() }} ) as claim_type - , cast(med.patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(med.person_id as {{ dbt.type_string() }} ) as person_id , cast(med.member_id as {{ dbt.type_string() }} ) as member_id , cast(med.payer as {{ dbt.type_string() }} ) as payer , cast(med.{{ quote_column('plan') }} as {{ dbt.type_string() }} ) as {{ quote_column('plan') }} diff --git a/models/claims_preprocessing/normalized_input/final/normalized_input__pharmacy_claim.sql b/models/claims_preprocessing/normalized_input/final/normalized_input__pharmacy_claim.sql index 1b3b7e83e..e6a5a72a6 100644 --- a/models/claims_preprocessing/normalized_input/final/normalized_input__pharmacy_claim.sql +++ b/models/claims_preprocessing/normalized_input/final/normalized_input__pharmacy_claim.sql @@ -8,7 +8,7 @@ select cast(claim_id as {{ dbt.type_string() }} ) as claim_id , cast(claim_line_number as int ) as claim_line_number - , cast(patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(member_id as {{ dbt.type_string() }} ) as member_id , cast(payer as {{ dbt.type_string() }} ) as payer , cast({{ quote_column('plan') }} as {{ dbt.type_string() }} ) as {{ quote_column('plan') }} diff --git a/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_eligibility_dates_normalize.sql b/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_eligibility_dates_normalize.sql index 434f28bdf..759ef3641 100644 --- a/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_eligibility_dates_normalize.sql +++ b/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_eligibility_dates_normalize.sql @@ -6,15 +6,15 @@ select distinct - elig.patient_id + elig.person_id , {{ dbt.concat([ - "elig.patient_id", + "elig.person_id", "coalesce(elig.data_source,'')", "coalesce(elig.payer,'')", "coalesce(elig." ~ quote_column('plan') ~ ",'')", "coalesce(cast(elig.enrollment_start_date as " ~ dbt.type_string() ~ "),'')", "coalesce(cast(elig.enrollment_end_date as " ~ dbt.type_string() ~ "),'')" - ]) }} as patient_id_key + ]) }} as person_id_key , cal_dob.full_date as normalized_birth_date , cal_death.full_date as normalized_death_date , cal_enroll_start.full_date as normalized_enrollment_start_date diff --git a/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_undetermined_claim_type.sql b/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_undetermined_claim_type.sql index cdba14f3e..670dd8f02 100644 --- a/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_undetermined_claim_type.sql +++ b/models/claims_preprocessing/normalized_input/intermediate/normalized_input__int_undetermined_claim_type.sql @@ -9,7 +9,7 @@ select claim_id , claim_line_number , claim_type - , patient_id + , person_id , member_id , payer , {{ quote_column('plan') }} diff --git a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_eligibility.sql b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_eligibility.sql index 6b507725c..8f8bf7c3a 100644 --- a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_eligibility.sql +++ b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_eligibility.sql @@ -6,15 +6,15 @@ select - patient_id + person_id , {{ dbt.concat([ - "patient_id", + "person_id", "coalesce(data_source,'')", "coalesce(payer,'')", "coalesce(" ~ quote_column('plan') ~ ",'')", "coalesce(cast(enrollment_start_date as " ~ dbt.type_string() ~ "),'')", "coalesce(cast(enrollment_end_date as " ~ dbt.type_string() ~ "),'')" - ]) }} as patient_id_key + ]) }} as person_id_key , member_id , subscriber_id , gender diff --git a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_medical_claim.sql b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_medical_claim.sql index 467788919..9c706aca1 100644 --- a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_medical_claim.sql +++ b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_medical_claim.sql @@ -8,7 +8,7 @@ select claim_id , claim_line_number , claim_type - , patient_id + , person_id , member_id , payer , {{ quote_column('plan') }} diff --git a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_pharmacy_claim.sql b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_pharmacy_claim.sql index 414f3a1d0..c74a2fdc0 100644 --- a/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_pharmacy_claim.sql +++ b/models/claims_preprocessing/normalized_input/staging/normalized_input__stg_pharmacy_claim.sql @@ -8,7 +8,7 @@ select claim_id , claim_line_number - , patient_id + , person_id , member_id , payer , {{ quote_column('plan') }} diff --git a/models/claims_preprocessing/service_category/service_category_models.yml b/models/claims_preprocessing/service_category/service_category_models.yml index 5c113abdb..9b8ab035d 100644 --- a/models/claims_preprocessing/service_category/service_category_models.yml +++ b/models/claims_preprocessing/service_category/service_category_models.yml @@ -730,6 +730,8 @@ models: - name: service_category__stg_medical_claim description: Staging med claims for sc grouper config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing{%- else %}claims_preprocessing{%- endif -%} materialized: view tags: - service_category_grouper_base @@ -737,6 +739,8 @@ models: - name: service_category__stg_inpatient_institutional config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing{%- else %}claims_preprocessing{%- endif -%} materialized: view tags: - service_category_grouper @@ -744,6 +748,8 @@ models: - name: service_category__stg_outpatient_institutional config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing{%- else %}claims_preprocessing{%- endif -%} materialized: view tags: - service_category_grouper @@ -751,6 +757,8 @@ models: - name: service_category__stg_professional config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing{%- else %}claims_preprocessing{%- endif -%} materialized: view tags: - service_category_grouper @@ -758,6 +766,8 @@ models: - name: service_category__stg_office_based config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing{%- else %}claims_preprocessing{%- endif -%} materialized: view tags: - service_category_grouper diff --git a/models/cms_hcc/cms_hcc_models.yml b/models/cms_hcc/cms_hcc_models.yml index 28430fb6b..9148352c0 100644 --- a/models/cms_hcc/cms_hcc_models.yml +++ b/models/cms_hcc/cms_hcc_models.yml @@ -13,7 +13,7 @@ models: This final model displays the contributing demographic and disease risk factors, interactions, and HCCs for each enrollee in the payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: enrollment_status_default description: > @@ -56,7 +56,7 @@ models: factors, interactions, and HCCs for each enrollee in the payment year and collection period. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: enrollment_status_default description: > @@ -105,7 +105,7 @@ models: normalized risk score, and payment risk score for each enrollee in the payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - unique @@ -158,11 +158,11 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - payment_year - collection_end_date columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: v24_risk_score description: > @@ -219,11 +219,11 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - model_version - collection_end_date columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: enrollment_status description: > @@ -286,7 +286,7 @@ models: Disabled and disease interaction factor values for the corresponding HCC model version and payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: description description: Description of the disabled and disease interaction. @@ -317,7 +317,7 @@ models: after the hierarchy has been applied and necessary HCCs dropped for the corresponding HCC model version and payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: hcc_code description: HCC code. @@ -350,7 +350,7 @@ models: after the hierarchy has been applied and necessary HCCs dropped for the corresponding HCC model version and payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: hcc_code_1 description: HCC code 1 of the interaction. @@ -384,7 +384,7 @@ models: Conditions from eligible risk-adjustable claims per claim type for the collection year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: condition_code description: The condition code. @@ -409,7 +409,7 @@ models: Enrollment interaction factor values for the corresponding HCC model version and payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: description description: Description of the enrollment interaction. @@ -439,7 +439,7 @@ models: Final payment-eligible HCC count factor values for the corresponding HCC model version and payment year. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: description description: HCC counts. @@ -469,7 +469,7 @@ models: HCC hierarchy for the corresponding HCC model version and payment year applied to the mapped payment-eligible HCCs. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: model_version description: CMS HCC model version. @@ -492,7 +492,7 @@ models: Eligible conditions mapped to HCC codes for the corresponding HCC model version and payment year columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: condition_code description: Condition code. @@ -516,13 +516,13 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - collection_end_date description: > Transformed eligibility data into the demographic risk segments required for the CMS HCC and risk calculations. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. tests: - not_null @@ -604,8 +604,8 @@ models: columns: - name: claim_id description: Unique claim_id for each claim. - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: recorded_date description: Date in which the condition was recorded. - name: condition_type @@ -624,7 +624,7 @@ models: materialized: ephemeral description: Staging eligibility from core. columns: - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: enrollment_start_date description: Date the patient's insurance eligibility began. @@ -655,7 +655,7 @@ models: description: > Indicates whether the claim is professional (CMS-1500), institutional (UB-04), dental, or vision. - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: claim_start_date description: Start date for the claim. @@ -675,7 +675,7 @@ models: materialized: ephemeral description: Staging patient from core. columns: - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: sex description: Biological sex of the patient. @@ -692,7 +692,7 @@ models: materialized: ephemeral description: Staging member months from financial_pmpm columns: - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: year_month description: Unique year-month of in the dataset computed from eligibility. diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_factors.sql b/models/cms_hcc/final/cms_hcc__patient_risk_factors.sql index 185c83a28..abb0595e6 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_factors.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_factors.sql @@ -4,7 +4,7 @@ }} select - patient_id + person_id , enrollment_status_default , medicaid_dual_status_default , orec_default @@ -15,9 +15,4 @@ select , model_version , payment_year , '{{ var('tuva_last_run')}}' as tuva_last_run -from {{ ref('cms_hcc__patient_risk_factors_monthly') }} -where collection_end_date = ( - select max(collection_end_date) - from {{ ref('cms_hcc__patient_risk_factors_monthly') }} - where payment_year = {{ var('cms_hcc_payment_year') }} - ) \ No newline at end of file +from {{ ref('cms_hcc__patient_risk_factors_monthly') }} \ No newline at end of file diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_factors_monthly.sql b/models/cms_hcc/final/cms_hcc__patient_risk_factors_monthly.sql index bb5306b46..dd3fceece 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_factors_monthly.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_factors_monthly.sql @@ -5,7 +5,7 @@ with demographic_factors as ( select - patient_id + person_id /* concatenate demographic risk factors */ , {{ dbt.concat( @@ -48,7 +48,7 @@ with demographic_factors as ( , demographic_defaults as ( select - patient_id + person_id , model_version , enrollment_status_default , medicaid_dual_status_default @@ -64,7 +64,7 @@ with demographic_factors as ( , disease_factors as ( select - patient_id + person_id , {{ dbt.concat(["hcc_description", "' (HCC '", "hcc_code", "')'"]) }} as description , coefficient , factor_type @@ -79,7 +79,7 @@ with demographic_factors as ( , enrollment_interactions as ( select - patient_id + person_id , description , coefficient , factor_type @@ -94,7 +94,7 @@ with demographic_factors as ( , disabled_interactions as ( select - patient_id + person_id , description , coefficient , factor_type @@ -109,7 +109,7 @@ with demographic_factors as ( , disease_interactions as ( select - patient_id + person_id , description , coefficient , factor_type @@ -124,7 +124,7 @@ with demographic_factors as ( , hcc_counts as ( select - patient_id + person_id , description , coefficient , factor_type @@ -155,7 +155,7 @@ with demographic_factors as ( , add_defaults as ( select - unioned.patient_id + unioned.person_id , demographic_defaults.enrollment_status_default , demographic_defaults.medicaid_dual_status_default , demographic_defaults.orec_default @@ -169,7 +169,7 @@ with demographic_factors as ( , unioned.collection_end_date from unioned left join demographic_defaults - on unioned.patient_id = demographic_defaults.patient_id + on unioned.person_id = demographic_defaults.person_id and unioned.model_version = demographic_defaults.model_version and unioned.payment_year = demographic_defaults.payment_year and unioned.collection_end_date = demographic_defaults.collection_end_date @@ -179,7 +179,7 @@ with demographic_factors as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id {% if target.type == 'fabric' %} , cast(enrollment_status_default as bit) as enrollment_status_default , cast(medicaid_dual_status_default as bit) as medicaid_dual_status_default @@ -203,7 +203,7 @@ with demographic_factors as ( ) select - patient_id + person_id , enrollment_status_default , medicaid_dual_status_default , orec_default diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql index c5cf6a40d..fe5e9cbc9 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_scores.sql @@ -4,7 +4,7 @@ }} select - patient_id + person_id , v24_risk_score , v28_risk_score , blended_risk_score diff --git a/models/cms_hcc/final/cms_hcc__patient_risk_scores_monthly.sql b/models/cms_hcc/final/cms_hcc__patient_risk_scores_monthly.sql index 856a3f1c0..6d1b6f93c 100644 --- a/models/cms_hcc/final/cms_hcc__patient_risk_scores_monthly.sql +++ b/models/cms_hcc/final/cms_hcc__patient_risk_scores_monthly.sql @@ -16,7 +16,7 @@ with seed_adjustment_rates as ( , risk_factors as ( select - patient_id + person_id , coefficient , model_version , payment_year @@ -29,19 +29,19 @@ with seed_adjustment_rates as ( , member_months as ( select - patient_id + person_id , cast({{ substring('year_month', 1, 4) }} as integer) as eligible_year , COUNT(1) as member_months from {{ ref('cms_hcc__stg_core__member_months') }} group by - patient_id + person_id , cast({{ substring('year_month', 1, 4) }} as integer) ) , raw_score as ( select - patient_id + person_id , sum(coefficient) as risk_score , model_version , payment_year @@ -49,7 +49,7 @@ with seed_adjustment_rates as ( , collection_end_date from risk_factors group by - patient_id + person_id , model_version , payment_year , collection_start_date @@ -73,7 +73,7 @@ with seed_adjustment_rates as ( , transition_scores as ( select - patient_id + person_id , risk_score , case when payment_year <= 2023 and model_version = 'CMS-HCC-V24' then risk_score @@ -101,7 +101,7 @@ with seed_adjustment_rates as ( , transition_scores_grouped as ( select - patient_id + person_id , max(v24_risk_score) as v24_risk_score , max(v28_risk_score) as v28_risk_score , payment_year @@ -109,7 +109,7 @@ with seed_adjustment_rates as ( , collection_end_date from transition_scores group by - patient_id + person_id , payment_year , collection_start_date , collection_end_date @@ -119,7 +119,7 @@ with seed_adjustment_rates as ( , blended as ( select - patient_id + person_id , v24_risk_score , v28_risk_score , v24_risk_score + v28_risk_score as blended_risk_score @@ -133,7 +133,7 @@ with seed_adjustment_rates as ( , normalized as ( select - blended.patient_id + blended.person_id , blended.v24_risk_score , blended.v28_risk_score , blended.blended_risk_score @@ -150,7 +150,7 @@ with seed_adjustment_rates as ( , payment as ( select - normalized.patient_id + normalized.person_id , normalized.v24_risk_score , normalized.v28_risk_score , normalized.blended_risk_score @@ -168,7 +168,7 @@ with seed_adjustment_rates as ( , weighted_score as ( select - payment.patient_id + payment.person_id , payment.v24_risk_score , payment.v28_risk_score , payment.blended_risk_score @@ -181,14 +181,14 @@ with seed_adjustment_rates as ( , payment.collection_end_date from payment left join member_months - on payment.patient_id = member_months.patient_id + on payment.person_id = member_months.person_id and payment.payment_year = member_months.eligible_year ) , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , round(cast(v24_risk_score as {{ dbt.type_numeric() }}),3) as v24_risk_score , round(cast(v28_risk_score as {{ dbt.type_numeric() }}),3) as v28_risk_score , round(cast(blended_risk_score as {{ dbt.type_numeric() }}),3) as blended_risk_score @@ -204,7 +204,7 @@ with seed_adjustment_rates as ( ) select - patient_id + person_id , v24_risk_score , v28_risk_score , blended_risk_score diff --git a/models/cms_hcc/intermediate/cms_hcc__int_demographic_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_demographic_factors.sql index 2c5c1073b..f7d04026b 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_demographic_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_demographic_factors.sql @@ -6,7 +6,7 @@ with members as ( select - patient_id + person_id , enrollment_status , gender , age_group @@ -46,7 +46,7 @@ with members as ( , v24_new_enrollees as ( select - members.patient_id + members.person_id , members.enrollment_status , members.gender , members.age_group @@ -79,7 +79,7 @@ with members as ( , v24_continuining_enrollees as ( select - members.patient_id + members.person_id , members.enrollment_status , members.gender , members.age_group @@ -114,7 +114,7 @@ with members as ( , v28_new_enrollees as ( select - members.patient_id + members.person_id , members.enrollment_status , members.gender , members.age_group @@ -147,7 +147,7 @@ with members as ( , v28_continuining_enrollees as ( select - members.patient_id + members.person_id , members.enrollment_status , members.gender , members.age_group @@ -194,7 +194,7 @@ with members as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(enrollment_status as {{ dbt.type_string() }}) as enrollment_status , cast(gender as {{ dbt.type_string() }}) as gender , cast(age_group as {{ dbt.type_string() }}) as age_group @@ -224,7 +224,7 @@ with members as ( ) select - patient_id + person_id , enrollment_status , gender , age_group diff --git a/models/cms_hcc/intermediate/cms_hcc__int_disabled_interaction_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_disabled_interaction_factors.sql index a374850f0..14ac294a6 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_disabled_interaction_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_disabled_interaction_factors.sql @@ -6,7 +6,7 @@ with demographics as ( select - patient_id + person_id , enrollment_status , institutional_status , model_version @@ -20,7 +20,7 @@ with demographics as ( , hcc_hierarchy as ( select - patient_id + person_id , hcc_code , model_version , payment_year @@ -48,7 +48,7 @@ with demographics as ( , demographics_with_hccs as ( select - demographics.patient_id + demographics.person_id , demographics.enrollment_status , demographics.institutional_status , demographics.model_version @@ -58,7 +58,7 @@ with demographics as ( , hcc_hierarchy.hcc_code from demographics inner join hcc_hierarchy - on demographics.patient_id = hcc_hierarchy.patient_id + on demographics.person_id = hcc_hierarchy.person_id and demographics.model_version = hcc_hierarchy.model_version and demographics.payment_year = hcc_hierarchy.payment_year and demographics.collection_end_date = hcc_hierarchy.collection_end_date @@ -68,7 +68,7 @@ with demographics as ( , interactions as ( select - demographics_with_hccs.patient_id + demographics_with_hccs.person_id , demographics_with_hccs.model_version , demographics_with_hccs.payment_year , demographics_with_hccs.collection_start_date @@ -88,7 +88,7 @@ with demographics as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(description as {{ dbt.type_string() }}) as description , round(cast(coefficient as {{ dbt.type_numeric() }}),3) as coefficient , cast(factor_type as {{ dbt.type_string() }}) as factor_type @@ -101,7 +101,7 @@ from interactions ) select - patient_id + person_id , description , coefficient , factor_type diff --git a/models/cms_hcc/intermediate/cms_hcc__int_disease_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_disease_factors.sql index 06f13754f..0461f129d 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_disease_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_disease_factors.sql @@ -6,7 +6,7 @@ with demographics as ( select - patient_id + person_id , enrollment_status , gender , age_group @@ -25,7 +25,7 @@ with demographics as ( , hcc_hierarchy as ( select - patient_id + person_id , hcc_code , model_version , payment_year @@ -55,7 +55,7 @@ with demographics as ( , demographics_with_hccs as ( select - demographics.patient_id + demographics.person_id , demographics.enrollment_status , demographics.gender , demographics.age_group @@ -70,7 +70,7 @@ with demographics as ( , hcc_hierarchy.hcc_code from demographics inner join hcc_hierarchy - on demographics.patient_id = hcc_hierarchy.patient_id + on demographics.person_id = hcc_hierarchy.person_id and demographics.model_version = hcc_hierarchy.model_version and demographics.payment_year = hcc_hierarchy.payment_year and demographics.collection_end_date = hcc_hierarchy.collection_end_date @@ -80,7 +80,7 @@ with demographics as ( , disease_factors as ( select - demographics_with_hccs.patient_id + demographics_with_hccs.person_id , demographics_with_hccs.hcc_code , demographics_with_hccs.model_version , demographics_with_hccs.payment_year @@ -104,7 +104,7 @@ with demographics as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(hcc_code as {{ dbt.type_string() }}) as hcc_code , cast(description as {{ dbt.type_string() }}) as hcc_description , round(cast(coefficient as {{ dbt.type_numeric() }}),3) as coefficient @@ -118,7 +118,7 @@ with demographics as ( ) select - patient_id + person_id , hcc_code , hcc_description , coefficient diff --git a/models/cms_hcc/intermediate/cms_hcc__int_disease_interaction_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_disease_interaction_factors.sql index a456d8cdd..7a0b0caa7 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_disease_interaction_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_disease_interaction_factors.sql @@ -6,7 +6,7 @@ with demographics as ( select - patient_id + person_id , enrollment_status , gender , age_group @@ -25,7 +25,7 @@ with demographics as ( , hcc_hierarchy as ( select - patient_id + person_id , hcc_code , model_version , payment_year @@ -57,7 +57,7 @@ with demographics as ( , demographics_with_hccs as ( select - demographics.patient_id + demographics.person_id , demographics.enrollment_status , demographics.medicaid_status , demographics.dual_status @@ -70,7 +70,7 @@ with demographics as ( , hcc_hierarchy.hcc_code from demographics inner join hcc_hierarchy - on demographics.patient_id = hcc_hierarchy.patient_id + on demographics.person_id = hcc_hierarchy.person_id and demographics.model_version = hcc_hierarchy.model_version and demographics.payment_year = hcc_hierarchy.payment_year and demographics.collection_end_date = hcc_hierarchy.collection_end_date @@ -80,7 +80,7 @@ with demographics as ( , demographics_with_interactions as ( select - demographics_with_hccs.patient_id + demographics_with_hccs.person_id , demographics_with_hccs.model_version , demographics_with_hccs.payment_year , demographics_with_hccs.collection_start_date @@ -105,7 +105,7 @@ with demographics as ( , disease_interactions as ( select - demographics_with_interactions.patient_id + demographics_with_interactions.person_id , demographics_with_interactions.factor_type , demographics_with_interactions.hcc_code_1 , demographics_with_interactions.hcc_code_2 @@ -117,7 +117,7 @@ with demographics as ( , demographics_with_interactions.collection_end_date from demographics_with_interactions inner join demographics_with_hccs as interactions_code_2 - on demographics_with_interactions.patient_id = interactions_code_2.patient_id + on demographics_with_interactions.person_id = interactions_code_2.person_id and demographics_with_interactions.hcc_code_2 = interactions_code_2.hcc_code and demographics_with_interactions.model_version = interactions_code_2.model_version and demographics_with_interactions.payment_year = interactions_code_2.payment_year @@ -127,7 +127,7 @@ with demographics as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(hcc_code_1 as {{ dbt.type_string() }}) as hcc_code_1 , cast(hcc_code_2 as {{ dbt.type_string() }}) as hcc_code_2 , cast(description as {{ dbt.type_string() }}) as description @@ -142,7 +142,7 @@ with demographics as ( ) select - patient_id + person_id , hcc_code_1 , hcc_code_2 , description diff --git a/models/cms_hcc/intermediate/cms_hcc__int_eligible_conditions.sql b/models/cms_hcc/intermediate/cms_hcc__int_eligible_conditions.sql index 166b13008..80ec9db0a 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_eligible_conditions.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_eligible_conditions.sql @@ -28,7 +28,7 @@ with medical_claims as ( claim_id , claim_line_number , claim_type - , patient_id + , person_id , claim_start_date , claim_end_date , bill_type_code @@ -41,7 +41,7 @@ with medical_claims as ( select claim_id - , patient_id + , person_id , code from {{ ref('cms_hcc__stg_core__condition') }} where code_type = 'icd-10-cm' @@ -60,10 +60,10 @@ with medical_claims as ( , professional_claims as ( select - medical_claims.claim_id + medical_claims.claim_id , medical_claims.claim_line_number , medical_claims.claim_type - , medical_claims.patient_id + , medical_claims.person_id , medical_claims.claim_start_date , medical_claims.claim_end_date , medical_claims.bill_type_code @@ -84,10 +84,10 @@ with medical_claims as ( , inpatient_claims as ( select - medical_claims.claim_id + medical_claims.claim_id , medical_claims.claim_line_number , medical_claims.claim_type - , medical_claims.patient_id + , medical_claims.person_id , medical_claims.claim_start_date , medical_claims.claim_end_date , medical_claims.bill_type_code @@ -106,10 +106,10 @@ with medical_claims as ( , outpatient_claims as ( select - medical_claims.claim_id + medical_claims.claim_id , medical_claims.claim_line_number , medical_claims.claim_type - , medical_claims.patient_id + , medical_claims.person_id , medical_claims.claim_start_date , medical_claims.claim_end_date , medical_claims.bill_type_code @@ -142,7 +142,7 @@ with medical_claims as ( select distinct eligible_claims.claim_id - , eligible_claims.patient_id + , eligible_claims.person_id , eligible_claims.payment_year , eligible_claims.collection_start_date , eligible_claims.collection_end_date @@ -150,14 +150,14 @@ with medical_claims as ( from eligible_claims inner join conditions on eligible_claims.claim_id = conditions.claim_id - and eligible_claims.patient_id = conditions.patient_id + and eligible_claims.person_id = conditions.person_id ) , add_data_types as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(code as {{ dbt.type_string() }}) as condition_code , cast(payment_year as integer) as payment_year , cast(collection_start_date as date) as collection_start_date @@ -167,7 +167,7 @@ with medical_claims as ( ) select - patient_id + person_id , condition_code , payment_year , collection_start_date diff --git a/models/cms_hcc/intermediate/cms_hcc__int_enrollment_interaction_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_enrollment_interaction_factors.sql index 0e4930fde..44cfb1007 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_enrollment_interaction_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_enrollment_interaction_factors.sql @@ -6,7 +6,7 @@ with demographics as ( select - patient_id + person_id , enrollment_status , gender , age_group @@ -44,7 +44,7 @@ with demographics as ( , non_institutional_interactions as ( select - demographics.patient_id + demographics.person_id , demographics.model_version , demographics.payment_year , demographics.collection_start_date @@ -80,7 +80,7 @@ with demographics as ( , institutional_interactions as ( select - demographics.patient_id + demographics.person_id , demographics.model_version , demographics.payment_year , demographics.collection_start_date @@ -109,7 +109,7 @@ with demographics as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(description as {{ dbt.type_string() }}) as description , round(cast(coefficient as {{ dbt.type_numeric() }}),3) as coefficient , cast(factor_type as {{ dbt.type_string() }}) as factor_type @@ -122,7 +122,7 @@ with demographics as ( ) select - patient_id + person_id , description , coefficient , factor_type diff --git a/models/cms_hcc/intermediate/cms_hcc__int_hcc_count_factors.sql b/models/cms_hcc/intermediate/cms_hcc__int_hcc_count_factors.sql index 2e92d374d..33fdd3032 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_hcc_count_factors.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_hcc_count_factors.sql @@ -6,7 +6,7 @@ with demographics as ( select - patient_id + person_id , enrollment_status , medicaid_status , dual_status @@ -40,7 +40,7 @@ with demographics as ( , hcc_hierarchy as ( select - patient_id + person_id , hcc_code , model_version , payment_year @@ -53,7 +53,7 @@ with demographics as ( , demographics_with_hcc_counts as ( select - demographics.patient_id + demographics.person_id , demographics.enrollment_status , demographics.medicaid_status , demographics.dual_status @@ -66,12 +66,12 @@ with demographics as ( , count(hcc_hierarchy.hcc_code) as hcc_count from demographics inner join hcc_hierarchy - on demographics.patient_id = hcc_hierarchy.patient_id + on demographics.person_id = hcc_hierarchy.person_id and demographics.model_version = hcc_hierarchy.model_version and demographics.payment_year = hcc_hierarchy.payment_year and demographics.collection_end_date = hcc_hierarchy.collection_end_date group by - demographics.patient_id + demographics.person_id , demographics.enrollment_status , demographics.medicaid_status , demographics.dual_status @@ -87,7 +87,7 @@ with demographics as ( , hcc_counts_normalized as ( select - patient_id + person_id , enrollment_status , medicaid_status , dual_status @@ -108,7 +108,7 @@ with demographics as ( , hcc_counts as ( select - hcc_counts_normalized.patient_id + hcc_counts_normalized.person_id , hcc_counts_normalized.model_version , hcc_counts_normalized.payment_year , hcc_counts_normalized.collection_start_date @@ -131,7 +131,7 @@ with demographics as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(description as {{ dbt.type_string() }}) as description , round(cast(coefficient as {{ dbt.type_numeric() }}),3) as coefficient , cast(factor_type as {{ dbt.type_string() }}) as factor_type @@ -144,7 +144,7 @@ with demographics as ( ) select - patient_id + person_id , description , coefficient , factor_type diff --git a/models/cms_hcc/intermediate/cms_hcc__int_hcc_hierarchy.sql b/models/cms_hcc/intermediate/cms_hcc__int_hcc_hierarchy.sql index c3f3f1b1a..f3813d7f5 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_hcc_hierarchy.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_hcc_hierarchy.sql @@ -13,7 +13,7 @@ with hcc_mapping as ( select distinct - patient_id + person_id , hcc_code , model_version , payment_year @@ -41,7 +41,7 @@ with hcc_mapping as ( , hccs_without_hierarchy as ( select distinct - hcc_mapping.patient_id + hcc_mapping.person_id , hcc_mapping.model_version , hcc_mapping.payment_year , hcc_mapping.collection_start_date @@ -65,7 +65,7 @@ with hcc_mapping as ( , hccs_with_hierarchy as ( select - hcc_mapping.patient_id + hcc_mapping.person_id , hcc_mapping.model_version , hcc_mapping.payment_year , hcc_mapping.collection_start_date @@ -87,7 +87,7 @@ with hcc_mapping as ( , hierarchy_applied as ( select - hccs_with_hierarchy.patient_id + hccs_with_hierarchy.person_id , hccs_with_hierarchy.model_version , hccs_with_hierarchy.payment_year , hccs_with_hierarchy.collection_start_date @@ -96,13 +96,13 @@ with hcc_mapping as ( , min(hcc_mapping.hcc_code) as top_level_hcc from hccs_with_hierarchy left join hcc_mapping - on hcc_mapping.patient_id = hccs_with_hierarchy.patient_id + on hcc_mapping.person_id = hccs_with_hierarchy.person_id and hcc_mapping.hcc_code = hccs_with_hierarchy.top_level_hcc and hcc_mapping.model_version = hccs_with_hierarchy.model_version and hcc_mapping.payment_year = hccs_with_hierarchy.payment_year and hcc_mapping.collection_end_date = hccs_with_hierarchy.collection_end_date group by - hccs_with_hierarchy.patient_id + hccs_with_hierarchy.person_id , hccs_with_hierarchy.model_version , hccs_with_hierarchy.payment_year , hccs_with_hierarchy.collection_start_date @@ -118,7 +118,7 @@ with hcc_mapping as ( , lower_level_inclusions as ( select distinct - patient_id + person_id , model_version , payment_year , collection_start_date @@ -138,7 +138,7 @@ with hcc_mapping as ( , top_level_inclusions as ( select distinct - hcc_mapping.patient_id + hcc_mapping.person_id , hcc_mapping.model_version , hcc_mapping.payment_year , hcc_mapping.collection_start_date @@ -149,13 +149,13 @@ with hcc_mapping as ( on hcc_mapping.hcc_code = seed_hcc_hierarchy.hcc_code and hcc_mapping.model_version = seed_hcc_hierarchy.model_version left join lower_level_inclusions - on hcc_mapping.patient_id = lower_level_inclusions.patient_id + on hcc_mapping.person_id = lower_level_inclusions.person_id and hcc_mapping.hcc_code = lower_level_inclusions.hcc_code and hcc_mapping.model_version = lower_level_inclusions.model_version and hcc_mapping.payment_year = lower_level_inclusions.payment_year and hcc_mapping.collection_end_date = lower_level_inclusions.collection_end_date left join hierarchy_applied - on hcc_mapping.patient_id = hierarchy_applied.patient_id + on hcc_mapping.person_id = hierarchy_applied.person_id and hcc_mapping.hcc_code = hierarchy_applied.hcc_code and hcc_mapping.model_version = hierarchy_applied.model_version and hcc_mapping.payment_year = hierarchy_applied.payment_year @@ -178,7 +178,7 @@ with hcc_mapping as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(model_version as {{ dbt.type_string() }}) as model_version , cast(payment_year as integer) as payment_year , cast(collection_start_date as date) as collection_start_date @@ -189,7 +189,7 @@ with hcc_mapping as ( ) select - patient_id + person_id , model_version , payment_year , collection_start_date diff --git a/models/cms_hcc/intermediate/cms_hcc__int_hcc_mapping.sql b/models/cms_hcc/intermediate/cms_hcc__int_hcc_mapping.sql index 4ff2ec5b5..c039ef832 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_hcc_mapping.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_hcc_mapping.sql @@ -14,7 +14,7 @@ Steps for staging the medical claim data: with conditions as ( select - patient_id + person_id , condition_code , payment_year , collection_start_date @@ -40,7 +40,7 @@ with conditions as ( , v24_mapped as ( select distinct - conditions.patient_id + conditions.person_id , conditions.condition_code , conditions.payment_year , conditions.collection_start_date @@ -58,7 +58,7 @@ with conditions as ( , v28_mapped as ( select distinct - conditions.patient_id + conditions.person_id , conditions.condition_code , conditions.payment_year , conditions.collection_start_date @@ -84,7 +84,7 @@ with conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(condition_code as {{ dbt.type_string() }}) as condition_code , cast(hcc_code as {{ dbt.type_string() }}) as hcc_code , cast(model_version as {{ dbt.type_string() }}) as model_version @@ -96,7 +96,7 @@ with conditions as ( ) select - patient_id + person_id , condition_code , hcc_code , model_version diff --git a/models/cms_hcc/intermediate/cms_hcc__int_members.sql b/models/cms_hcc/intermediate/cms_hcc__int_members.sql index ecb53a86e..0d6c465df 100644 --- a/models/cms_hcc/intermediate/cms_hcc__int_members.sql +++ b/models/cms_hcc/intermediate/cms_hcc__int_members.sql @@ -18,7 +18,7 @@ Jinja is used to set payment year variable. with stg_eligibility as ( select - elig.patient_id + elig.person_id , elig.enrollment_start_date , elig.enrollment_end_date , elig.original_reason_entitlement_code @@ -30,7 +30,7 @@ with stg_eligibility as ( , dates.collection_end_date , {{ dbt.concat(['dates.payment_year', "'-12-31'"]) }} as payment_year_end_date , row_number() over( - partition by elig.patient_id, dates.collection_end_date + partition by elig.person_id, dates.collection_end_date order by elig.enrollment_end_date desc ) as row_num /* used to dedupe eligibility */ from {{ ref('cms_hcc__stg_core__eligibility') }} as elig @@ -53,7 +53,7 @@ with stg_eligibility as ( , stg_patient as ( select - patient.patient_id + patient.person_id , patient.sex , patient.birth_date , dates.payment_year @@ -68,7 +68,7 @@ with stg_eligibility as ( , cap_collection_start_end_dates as ( select - patient_id + person_id , enrollment_start_date , enrollment_end_date , payment_year @@ -85,18 +85,18 @@ with stg_eligibility as ( else enrollment_end_date end as proxy_enrollment_end_date from stg_eligibility - + ) , calculate_prior_coverage as ( - select patient_id + select person_id , payment_year , collection_end_date , sum({{ datediff('proxy_enrollment_start_date', 'proxy_enrollment_end_date', 'month') }} + 1) as coverage_months /* include starting month */ , min({{ datediff('collection_start_date', 'collection_end_date', 'month') }} + 1) as collection_months from cap_collection_start_end_dates - group by patient_id + group by person_id , payment_year , collection_end_date @@ -109,7 +109,7 @@ with stg_eligibility as ( , add_enrollment as ( select - patient_id + person_id , payment_year , collection_end_date , case @@ -123,7 +123,7 @@ with stg_eligibility as ( , latest_eligibility as ( select - stg_eligibility.patient_id + stg_eligibility.person_id , stg_eligibility.payment_year , stg_eligibility.collection_start_date , stg_eligibility.collection_end_date @@ -150,11 +150,11 @@ with stg_eligibility as ( {% endif %} from stg_eligibility left join add_enrollment - on stg_eligibility.patient_id = add_enrollment.patient_id + on stg_eligibility.person_id = add_enrollment.person_id and stg_eligibility.payment_year = add_enrollment.payment_year and stg_eligibility.collection_end_date = add_enrollment.collection_end_date left join stg_patient - on stg_eligibility.patient_id = stg_patient.patient_id + on stg_eligibility.person_id = stg_patient.person_id and stg_eligibility.payment_year = stg_patient.payment_year where stg_eligibility.row_num = 1 @@ -163,7 +163,7 @@ with stg_eligibility as ( , add_age_group as ( select - patient_id + person_id , payment_year , collection_start_date , collection_end_date @@ -211,7 +211,7 @@ with stg_eligibility as ( , add_status_logic as ( select - patient_id + person_id , payment_year , collection_start_date , collection_end_date @@ -282,7 +282,7 @@ with stg_eligibility as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(enrollment_status as {{ dbt.type_string() }}) as enrollment_status , cast(gender as {{ dbt.type_string() }}) as gender , cast(age_group as {{ dbt.type_string() }}) as age_group @@ -309,7 +309,7 @@ with stg_eligibility as ( ) select - patient_id + person_id , enrollment_status , gender , age_group diff --git a/models/cms_hcc/staging/cms_hcc__stg_core__condition.sql b/models/cms_hcc/staging/cms_hcc__stg_core__condition.sql index a6e90a163..1c335093d 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_core__condition.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_core__condition.sql @@ -4,7 +4,7 @@ }} select claim_id - , patient_id + , person_id , recorded_date , condition_type , normalized_code_type as code_type diff --git a/models/cms_hcc/staging/cms_hcc__stg_core__eligibility.sql b/models/cms_hcc/staging/cms_hcc__stg_core__eligibility.sql index d07f283e6..80781a929 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_core__eligibility.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_core__eligibility.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , enrollment_start_date , enrollment_end_date , original_reason_entitlement_code diff --git a/models/cms_hcc/staging/cms_hcc__stg_core__medical_claim.sql b/models/cms_hcc/staging/cms_hcc__stg_core__medical_claim.sql index 885709e1d..8f3d37ddc 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_core__medical_claim.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_core__medical_claim.sql @@ -6,7 +6,7 @@ select claim_id , claim_line_number , claim_type - , patient_id + , person_id , claim_start_date , claim_end_date , bill_type_code diff --git a/models/cms_hcc/staging/cms_hcc__stg_core__member_months.sql b/models/cms_hcc/staging/cms_hcc__stg_core__member_months.sql index ec9df4eb8..580a39b11 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_core__member_months.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_core__member_months.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/cms_hcc/staging/cms_hcc__stg_core__patient.sql b/models/cms_hcc/staging/cms_hcc__stg_core__patient.sql index 5632c254b..f351b7a26 100644 --- a/models/cms_hcc/staging/cms_hcc__stg_core__patient.sql +++ b/models/cms_hcc/staging/cms_hcc__stg_core__patient.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , sex , birth_date , death_date diff --git a/models/core/core_models.yml b/models/core/core_models.yml index 5aac1397f..fb826238a 100644 --- a/models/core/core_models.yml +++ b/models/core/core_models.yml @@ -2,1068 +2,1125 @@ version: 2 models: ## Final -- name: core__condition - description: > - The core condition table contains information related to medical conditions - patients have, including problems, admitting diagnosis codes, and billable diagnosis - codes. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: condition - tags: core - materialized: table - columns: - - name: condition_id - description: '{{ doc("condition_id") }}' - tests: - - unique: - config: - severity: warn - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: claim_id - description: '{{ doc("claim_id") }}' - - name: recorded_date - description: '{{ doc("recorded_date") }}' - - name: onset_date - description: '{{ doc("onset_date") }}' - - name: resolved_date - description: '{{ doc("resolved_date") }}' - - name: status - description: '{{ doc("status") }}' - - name: condition_type - description: '{{ doc("condition_type") }}' - - name: source_code_type - description: '{{ doc("source_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: source_code - description: '{{ doc("source_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: source_description - description: '{{ doc("source_description") }}' - - name: normalized_code_type - description: '{{ doc("normalized_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: normalized_code - description: '{{ doc("normalized_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: normalized_description - description: '{{ doc("normalized_description") }}' - - name: mapping_method - description: '{{ doc("mapping_method") }}' - - name: condition_rank - description: '{{ doc("condition_rank") }}' - data_type: integer - - name: present_on_admit_code - description: '{{ doc("present_on_admit_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__present_on_admission.csv - - name: present_on_admit_description - description: '{{ doc("present_on_admit_description") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__eligibility - description: > - The eligibility table contains information on patient health plan - and supplemental insurance eligibility. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: eligibility - tags: core - materialized: table - columns: - - name: eligibility_id - description: '{{ doc("eligibility_id") }}' - tests: - - unique: - config: - severity: warn - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: member_id - description: '{{ doc("member_id") }}' - - name: subscriber_id - description: '{{ doc("subscriber_id") }}' - - name: birth_date - description: '{{ doc("birth_date") }}' - - name: death_date - description: '{{ doc("death_date") }}' - - name: enrollment_start_date - description: '{{ doc("enrollment_start_date") }}' - - name: enrollment_end_date - description: '{{ doc("enrollment_end_date") }}' - - name: payer - description: '{{ doc("payer") }}' - - name: payer_type - description: '{{ doc("payer_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__payer_type.csv - - name: plan - description: '{{ doc("plan") }}' - - name: original_reason_entitlement_code - description: '{{ doc("original_reason_entitlement_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_orec.csv - - name: dual_status_code - description: '{{ doc("dual_status_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_dual_eligibility.csv - - name: medicare_status_code - description: '{{ doc("medicare_status_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_status.csv - - name: subscriber_relation - description: '{{ doc("subscriber_relation") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__encounter - description: > - The encounter table contains information about patients visits (i.e. encounters). This - includes acute inpatient, emergency department, office visits, SNF stays, etc. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: encounter - tags: - - core - - encounters - materialized: table - columns: - - name: encounter_id - description: '{{ doc("encounter_id") }}' - tests: - - unique - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: patient_data_source_id - description: '{{ doc("patient_data_source_id") }}' - - name: encounter_type - description: '{{ doc("encounter_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__encounter_type.csv - - name: encounter_group - description: '{{ doc("encounter_group") }}' - - name: encounter_start_date - description: '{{ doc("encounter_start_date") }}' - - name: encounter_end_date - description: '{{ doc("encounter_end_date") }}' - - name: length_of_stay - description: '{{ doc("length_of_stay") }}' - - name: admit_source_code - description: '{{ doc("admit_source_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv - - name: admit_source_description - description: '{{ doc("admit_source_description") }}' - - name: admit_type_code - description: '{{ doc("admit_type_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv - - name: admit_type_description - description: '{{ doc("admit_type_description") }}' - - name: discharge_disposition_code - description: '{{ doc("discharge_disposition_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv - - name: discharge_disposition_description - description: '{{ doc("discharge_disposition_description") }}' - - name: attending_provider_id - description: '{{ doc("attending_provider_id") }}' - - name: attending_provider_name - description: '{{ doc("attending_provider_name") }}' - - name: facility_id - description: '{{ doc("facility_id") }}' - - name: facility_name - description: '{{ doc("facility_name") }}' - - name: facility_type - description: '{{ doc("facility_type") }}' - - name: observation_flag - description: '{{ doc("observation_flag") }}' - - name: lab_flag - description: '{{ doc("lab_flag") }}' - - name: dme_flag - description: '{{ doc("dme_flag") }}' - - name: ambulance_flag - description: '{{ doc("ambulance_flag") }}' - - name: pharmacy_flag - description: '{{ doc("pharmacy_flag") }}' - - name: ed_flag - description: '{{ doc("ed_flag") }}' - - name: delivery_flag - description: '{{ doc("delivery_flag") }}' - - name: delivery_type - description: '{{ doc("delivery_type") }}' - - name: newborn_flag - description: '{{ doc("newborn_flag") }}' - - name: nicu_flag - description: '{{ doc("nicu_flag") }}' - - name: primary_diagnosis_code_type - description: '{{ doc("primary_diagnosis_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: primary_diagnosis_code - description: '{{ doc("primary_diagnosis_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: primary_diagnosis_description - description: '{{ doc("primary_diagnosis_description") }}' - - name: ms_drg_code - description: '{{ doc("ms_drg_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv - - name: ms_drg_description - description: '{{ doc("ms_drg_description") }}' - - name: apr_drg_code - description: '{{ doc("apr_drg_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv - - name: apr_drg_description - description: '{{ doc("apr_drg_description") }}' - - name: paid_amount - description: '{{ doc("paid_amount") }}' - - name: allowed_amount - description: '{{ doc("allowed_amount") }}' - - name: charge_amount - description: '{{ doc("charge_amount") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: claim_count - description: '{{ doc("claim_count") }}' - - name: inst_claim_count - description: '{{ doc("inst_claim_count") }}' - - name: prof_claim_count - description: '{{ doc("prof_claim_count") }}' - - name: source_model - description: '{{ doc("source_model") }}' - - name: encounter_source_type - description: '{{ doc("encounter_source_type") }}' - - name: attending_provider_id - description: '{{ doc("attending_provider_id") }}' - - name: attending_provider_name - description: '{{ doc("attending_provider_name") }}' - - name: facility_id - description: '{{ doc("facility_id") }}' - - name: facility_name - description: '{{ doc("facility_name") }}' - - name: facility_type - description: '{{ doc("facility_type") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__lab_result - description: > - The lab result table contains information about lab test results, - including the LOINC code and description, units, reference range, and result. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: lab_result - tags: core - materialized: table - columns: - - name: lab_result_id - description: '{{ doc("lab_result_id") }}' - tests: - - unique: - config: - severity: warn - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: accession_number - description: '{{ doc("accession_number") }}' - - name: source_code_type - description: '{{ doc("source_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: source_code - description: '{{ doc("source_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: source_description - description: '{{ doc("source_description") }}' - - name: source_component - description: '{{ doc("source_component") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_code_type - description: '{{ doc("normalized_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: normalized_code - description: '{{ doc("normalized_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_description - description: '{{ doc("normalized_description") }}' - - name: mapping_method - description: '{{ doc("mapping_method") }}' - - name: normalized_component - description: '{{ doc("normalized_component") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: status - description: '{{ doc("status") }}' - - name: result - description: '{{ doc("result") }}' - - name: result_date - description: '{{ doc("result_date") }}' - - name: collection_date - description: '{{ doc("collection_date") }}' - - name: source_units - description: '{{ doc("source_units") }}' - - name: normalized_units - description: '{{ doc("normalized_units") }}' - - name: source_reference_range_low - description: '{{ doc("source_reference_range_low") }}' - - name: source_reference_range_high - description: '{{ doc("source_reference_range_high") }}' - - name: normalized_reference_range_low - description: '{{ doc("normalized_reference_range_low") }}' - - name: normalized_reference_range_high - description: '{{ doc("normalized_reference_range_high") }}' - - name: source_abnormal_flag - description: '{{ doc("source_abnormal_flag") }}' - - name: normalized_abnormal_flag - description: '{{ doc("normalized_abnormal_flag") }}' - - name: specimen - description: '{{ doc("specimen") }}' - - name: ordering_practitioner_id - description: '{{ doc("ordering_practitioner_id") }}' - 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: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__location - description: > - The location table contains information on practice and facility locations where - patients receive medical care. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: location - tags: core - materialized: table - columns: - - name: location_id - description: '{{ doc("location_id") }}' - tests: - - unique: - config: - severity: warn - - name: npi - description: '{{ doc("npi") }}' - 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: name - description: '{{ doc("name") }}' - - name: facility_type - description: '{{ doc("facility_type") }}' - - name: parent_organization - description: '{{ doc("parent_organization") }}' - - name: address - description: '{{ doc("address") }}' - - name: city - description: '{{ doc("city") }}' - - name: state - description: '{{ doc("state") }}' - - name: zip_code - description: '{{ doc("zip_code") }}' - - name: latitude - description: '{{ doc("latitude") }}' - - name: longitude - description: '{{ doc("longitude") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__medical_claim - description: > - The medical claim table contains information on services rendered - to patients and billed by the provider to the insurer as claims. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: medical_claim - tags: - - core - - encounters - materialized: table - columns: - - name: medical_claim_id - description: '{{ doc("medical_claim_id") }}' - tests: - - unique: - config: - severity: error - - name: claim_id - description: '{{ doc("claim_id") }}' - - name: claim_line_number - description: '{{ doc("claim_line_number") }}' - data_type: integer - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: encounter_type - description: '{{ doc("encounter_type") }}' - - name: encounter_group - description: '{{ doc("encounter_group") }}' - - name: claim_type - description: '{{ doc("claim_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__claim_type.csv - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: member_id - description: '{{ doc("member_id") }}' - - name: payer - description: '{{ doc("payer") }}' - - name: plan - description: '{{ doc("plan") }}' - - name: claim_start_date - description: '{{ doc("claim_start_date") }}' - - name: claim_end_date - description: '{{ doc("claim_end_date") }}' - - name: claim_line_start_date - description: '{{ doc("claim_line_start_date") }}' - - name: claim_line_end_date - description: '{{ doc("claim_line_end_date") }}' - - name: admission_date - description: '{{ doc("admission_date") }}' - - name: discharge_date - description: '{{ doc("discharge_date") }}' - - name: service_category_1 - description: '{{ doc("service_category_1") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/service_categories/service_category__service_categories.csv - - name: service_category_2 - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/service_categories/service_category__service_categories.csv - description: '{{ doc("service_category_2") }}' - - name: service_category_3 - description: '{{ doc("service_category_3") }}' - - name: admit_source_code - description: '{{ doc("admit_source_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv - - name: admit_source_description - description: '{{ doc("admit_source_description") }}' - - name: admit_type_code - description: '{{ doc("admit_type_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv - - name: admit_type_description - description: '{{ doc("admit_type_description") }}' - - name: discharge_disposition_code - description: '{{ doc("discharge_disposition_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv - - name: discharge_disposition_description - description: '{{ doc("discharge_disposition_description") }}' - - name: place_of_service_code - description: '{{ doc("place_of_service_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__place_of_service.csv - - name: place_of_service_description - description: '{{ doc("place_of_service_description") }}' - - name: bill_type_code - description: '{{ doc("bill_type_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__bill_type.csv - - name: bill_type_description - description: '{{ doc("bill_type_description") }}' - - name: ms_drg_code - description: '{{ doc("ms_drg_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv - - name: ms_drg_description - description: '{{ doc("ms_drg_description") }}' - - name: apr_drg_code - description: '{{ doc("apr_drg_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv - - name: apr_drg_description - description: '{{ doc("apr_drg_description") }}' - - name: revenue_center_code - description: '{{ doc("revenue_center_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__revenue_center.csv - - name: revenue_center_description - description: '{{ doc("revenue_center_description") }}' - - name: service_unit_quantity - description: '{{ doc("service_unit_quantity") }}' - data_type: integer - - name: hcpcs_code - description: '{{ doc("hcpcs_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: hcpcs_modifier_1 - description: '{{ doc("hcpcs_modifier_1") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: hcpcs_modifier_2 - description: '{{ doc("hcpcs_modifier_2") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: hcpcs_modifier_3 - description: '{{ doc("hcpcs_modifier_3") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: hcpcs_modifier_4 - description: '{{ doc("hcpcs_modifier_4") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: hcpcs_modifier_5 - description: '{{ doc("hcpcs_modifier_5") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: rendering_id - description: '{{ doc("rendering_id") }}' - 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: rendering_tin - description: '{{ doc("rendering_tin") }}' - - name: rendering_name - description: '{{ doc("rendering_name") }}' - - name: billing_id - description: '{{ doc("billing_id") }}' - 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: billing_tin - description: '{{ doc("billing_tin") }}' - - name: billing_name - description: '{{ doc("billing_name") }}' - - name: facility_id - description: '{{ doc("facility_id") }}' - 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_name - description: '{{ doc("facility_name") }}' - - name: paid_date - description: '{{ doc("paid_date") }}' - - name: paid_amount - description: '{{ doc("paid_amount") }}' - - name: allowed_amount - description: '{{ doc("allowed_amount") }}' - - name: charge_amount - description: '{{ doc("charge_amount") }}' - - name: coinsurance_amount - description: '{{ doc("coinsurance_amount") }}' - - name: copayment_amount - description: '{{ doc("copayment_amount") }}' - - name: deductible_amount - description: '{{ doc("deductible_amount") }}' - - name: total_cost_amount - description: '{{ doc("total_cost_amount") }}' - - name: in_network_flag - description: '{{ doc("in_network_flag") }}' - - name: enrollment_flag - description: '{{ doc("enrollment_flag") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - -- name: core__medication - description: > - The medication table contains information on medications ordered and/or - administered during a patient encounter. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: medication - tags: core - materialized: table - columns: - - name: medication_id - description: '{{ doc("medication_id") }}' - tests: - - unique: - config: - severity: warn - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: dispensing_date - description: '{{ doc("dispensing_date") }}' - - name: prescribing_date - description: '{{ doc("prescribing_date") }}' - - name: source_code_type - description: '{{ doc("source_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: source_code - description: '{{ doc("source_code") }}' - meta: - terminology: https://www.nlm.nih.gov/research/umls/rxnorm/index.html - - name: source_description - description: '{{ doc("source_description") }}' - - name: ndc_code - description: '{{ doc("ndc_code") }}' - meta: - terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory - - name: ndc_description - description: '{{ doc("ndc_description") }}' - - name: ndc_mapping_method - description: '{{ doc("ndc_mapping_method") }}' - - name: rxnorm_code - description: '{{ doc("rxnorm_code") }}' - meta: - terminology: https://www.nlm.nih.gov/research/umls/rxnorm/index.html - - name: rxnorm_description - description: '{{ doc("rxnorm_description") }}' - - name: rxnorm_mapping_method - description: '{{ doc("rxnorm_mapping_method") }}' - - name: atc_code - description: '{{ doc("atc_code") }}' - meta: - terminology: https://www.who.int/tools/atc-ddd-toolkit/atc-classification - - name: atc_description - description: '{{ doc("atc_description") }}' - - name: atc_mapping_method - description: '{{ doc("atc_mapping_method") }}' - - name: route - description: '{{ doc("route") }}' - - name: strength - description: '{{ doc("strength") }}' - - name: quantity - description: '{{ doc("quantity") }}' - - name: quantity_unit - description: '{{ doc("quantity_unit") }}' - - name: days_supply - description: '{{ doc("days_supply") }}' - - name: practitioner_id - description: '{{ doc("practitioner_id") }}' - 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: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - name: core__condition + description: > + The core condition table contains information related to medical conditions + patients have, including problems, admitting diagnosis codes, and billable diagnosis + codes. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: condition + tags: core + materialized: table + columns: + - name: condition_id + description: '{{ doc("condition_id") }}' + tests: + - unique: + config: + severity: warn + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: claim_id + description: '{{ doc("claim_id") }}' + - name: recorded_date + description: '{{ doc("recorded_date") }}' + - name: onset_date + description: '{{ doc("onset_date") }}' + - name: resolved_date + description: '{{ doc("resolved_date") }}' + - name: status + description: '{{ doc("status") }}' + - name: condition_type + description: '{{ doc("condition_type") }}' + - name: source_code_type + description: '{{ doc("source_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: source_code + description: '{{ doc("source_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: source_description + description: '{{ doc("source_description") }}' + - name: normalized_code_type + description: '{{ doc("normalized_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: normalized_code + description: '{{ doc("normalized_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: normalized_description + description: '{{ doc("normalized_description") }}' + - name: mapping_method + description: '{{ doc("mapping_method") }}' + - name: condition_rank + description: '{{ doc("condition_rank") }}' + data_type: integer + - name: present_on_admit_code + description: '{{ doc("present_on_admit_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__present_on_admission.csv + - name: present_on_admit_description + description: '{{ doc("present_on_admit_description") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__eligibility + description: > + The eligibility table contains information on patient health plan + and supplemental insurance eligibility. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: eligibility + tags: core + materialized: table + columns: + - name: eligibility_id + description: '{{ doc("eligibility_id") }}' + tests: + - unique: + config: + severity: warn + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: subscriber_id + description: '{{ doc("subscriber_id") }}' + - name: birth_date + description: '{{ doc("birth_date") }}' + - name: death_date + description: '{{ doc("death_date") }}' + - name: enrollment_start_date + description: '{{ doc("enrollment_start_date") }}' + - name: enrollment_end_date + description: '{{ doc("enrollment_end_date") }}' + - name: payer + description: '{{ doc("payer") }}' + - name: payer_type + description: '{{ doc("payer_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__payer_type.csv + - name: plan + description: '{{ doc("plan") }}' + - name: original_reason_entitlement_code + description: '{{ doc("original_reason_entitlement_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_orec.csv + - name: dual_status_code + description: '{{ doc("dual_status_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_dual_eligibility.csv + - name: medicare_status_code + description: '{{ doc("medicare_status_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__medicare_status.csv + - name: subscriber_relation + description: '{{ doc("subscriber_relation") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' -- name: core__member_months - description: Creates member months from eligibility data - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: member_months - tags: - - core - materialized: table - columns: - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: year_month - description: '{{ doc("year_month") }}' - - name: payer - description: '{{ doc("payer") }}' - - name: plan - description: '{{ doc("plan") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' - - name: payer_attributed_provider - description: '{{ doc("payer_attributed_provider") }}' - - name: payer_attributed_provider_practice - description: '{{ doc("payer_attributed_provider_practice") }}' - - name: payer_attributed_provider_organization - description: '{{ doc("payer_attributed_provider_organization") }}' - - name: payer_attributed_provider_lob - description: '{{ doc("payer_attributed_provider_lob") }}' - - name: custom_attributed_provider - description: '{{ doc("custom_attributed_provider") }}' - - name: custom_attributed_provider_practice - description: '{{ doc("custom_attributed_provider_practice") }}' - - name: custom_attributed_provider_organization - description: '{{ doc("custom_attributed_provider_organization") }}' - - name: custom_attributed_provider_lob - description: '{{ doc("custom_attributed_provider_lob") }}' + - name: core__encounter + description: > + The encounter table contains information about patients visits (i.e. encounters). This + includes acute inpatient, emergency department, office visits, SNF stays, etc. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: encounter + tags: + - core + - encounters + materialized: table + columns: + - name: encounter_id + description: '{{ doc("encounter_id") }}' + tests: + - unique + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: patient_data_source_id + description: '{{ doc("patient_data_source_id") }}' + - name: encounter_type + description: '{{ doc("encounter_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__encounter_type.csv + - name: encounter_group + description: '{{ doc("encounter_group") }}' + - name: encounter_start_date + description: '{{ doc("encounter_start_date") }}' + - name: encounter_end_date + description: '{{ doc("encounter_end_date") }}' + - name: length_of_stay + description: '{{ doc("length_of_stay") }}' + - name: admit_source_code + description: '{{ doc("admit_source_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv + - name: admit_source_description + description: '{{ doc("admit_source_description") }}' + - name: admit_type_code + description: '{{ doc("admit_type_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv + - name: admit_type_description + description: '{{ doc("admit_type_description") }}' + - name: discharge_disposition_code + description: '{{ doc("discharge_disposition_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv + - name: discharge_disposition_description + description: '{{ doc("discharge_disposition_description") }}' + - name: attending_provider_id + description: '{{ doc("attending_provider_id") }}' + - name: attending_provider_name + description: '{{ doc("attending_provider_name") }}' + - name: facility_id + description: '{{ doc("facility_id") }}' + - name: facility_name + description: '{{ doc("facility_name") }}' + - name: facility_type + description: '{{ doc("facility_type") }}' + - name: observation_flag + description: '{{ doc("observation_flag") }}' + - name: lab_flag + description: '{{ doc("lab_flag") }}' + - name: dme_flag + description: '{{ doc("dme_flag") }}' + - name: ambulance_flag + description: '{{ doc("ambulance_flag") }}' + - name: pharmacy_flag + description: '{{ doc("pharmacy_flag") }}' + - name: ed_flag + description: '{{ doc("ed_flag") }}' + - name: delivery_flag + description: '{{ doc("delivery_flag") }}' + - name: delivery_type + description: '{{ doc("delivery_type") }}' + - name: newborn_flag + description: '{{ doc("newborn_flag") }}' + - name: nicu_flag + description: '{{ doc("nicu_flag") }}' + - name: primary_diagnosis_code_type + description: '{{ doc("primary_diagnosis_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: primary_diagnosis_code + description: '{{ doc("primary_diagnosis_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_cm.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: primary_diagnosis_description + description: '{{ doc("primary_diagnosis_description") }}' + - name: ms_drg_code + description: '{{ doc("ms_drg_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv + - name: ms_drg_description + description: '{{ doc("ms_drg_description") }}' + - name: apr_drg_code + description: '{{ doc("apr_drg_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv + - name: apr_drg_description + description: '{{ doc("apr_drg_description") }}' + - name: paid_amount + description: '{{ doc("paid_amount") }}' + - name: allowed_amount + description: '{{ doc("allowed_amount") }}' + - name: charge_amount + description: '{{ doc("charge_amount") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: claim_count + description: '{{ doc("claim_count") }}' + - name: inst_claim_count + description: '{{ doc("inst_claim_count") }}' + - name: prof_claim_count + description: '{{ doc("prof_claim_count") }}' + - name: source_model + description: '{{ doc("source_model") }}' + - name: encounter_source_type + description: '{{ doc("encounter_source_type") }}' + - name: attending_provider_id + description: '{{ doc("attending_provider_id") }}' + - name: attending_provider_name + description: '{{ doc("attending_provider_name") }}' + - name: facility_id + description: '{{ doc("facility_id") }}' + - name: facility_name + description: '{{ doc("facility_name") }}' + - name: facility_type + description: '{{ doc("facility_type") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__lab_result + description: > + The lab result table contains information about lab test results, + including the LOINC code and description, units, reference range, and result. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: lab_result + tags: core + materialized: table + columns: + - name: lab_result_id + description: '{{ doc("lab_result_id") }}' + tests: + - unique: + config: + severity: warn + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: accession_number + description: '{{ doc("accession_number") }}' + - name: source_code_type + description: '{{ doc("source_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: source_code + description: '{{ doc("source_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: source_description + description: '{{ doc("source_description") }}' + - name: source_component + description: '{{ doc("source_component") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_code_type + description: '{{ doc("normalized_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: normalized_code + description: '{{ doc("normalized_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: normalized_description + description: '{{ doc("normalized_description") }}' + - name: mapping_method + description: '{{ doc("mapping_method") }}' + - name: normalized_component + description: '{{ doc("normalized_component") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__loinc.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: status + description: '{{ doc("status") }}' + - name: result + description: '{{ doc("result") }}' + - name: result_date + description: '{{ doc("result_date") }}' + - name: collection_date + description: '{{ doc("collection_date") }}' + - name: source_units + description: '{{ doc("source_units") }}' + - name: normalized_units + description: '{{ doc("normalized_units") }}' + - name: source_reference_range_low + description: '{{ doc("source_reference_range_low") }}' + - name: source_reference_range_high + description: '{{ doc("source_reference_range_high") }}' + - name: normalized_reference_range_low + description: '{{ doc("normalized_reference_range_low") }}' + - name: normalized_reference_range_high + description: '{{ doc("normalized_reference_range_high") }}' + - name: source_abnormal_flag + description: '{{ doc("source_abnormal_flag") }}' + - name: normalized_abnormal_flag + description: '{{ doc("normalized_abnormal_flag") }}' + - name: specimen + description: '{{ doc("specimen") }}' + - name: ordering_practitioner_id + description: '{{ doc("ordering_practitioner_id") }}' + 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: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' -- name: core__observation - description: > - The observation table contains information on measurements other than lab - tests e.g. blood pressure, height, and weight. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: observation - tags: core - materialized: table - columns: - - name: observation_id - description: '{{ doc("observation_id") }}' - tests: - - unique: - config: - severity: warn - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: panel_id - description: '{{ doc("panel_id") }}' - - name: observation_date - description: '{{ doc("observation_date") }}' - - name: observation_type - description: '{{ doc("observation_type") }}' - - name: source_code_type - description: '{{ doc("source_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: source_code - description: '{{ doc("source_code") }}' - - name: source_description - description: '{{ doc("source_description") }}' - - name: normalized_code_type - description: '{{ doc("normalized_code_type") }}' - - name: normalized_code - description: '{{ doc("normalized_code") }}' - - name: normalized_description - description: '{{ doc("normalized_description") }}' - - name: mapping_method - description: '{{ doc("mapping_method") }}' - - name: result - description: '{{ doc("result") }}' - - name: source_units - description: '{{ doc("source_units") }}' - - name: normalized_units - description: '{{ doc("normalized_units") }}' - - name: source_reference_range_low - description: '{{ doc("source_reference_range_low") }}' - - name: source_reference_range_high - description: '{{ doc("source_reference_range_high") }}' - - name: normalized_reference_range_low - description: '{{ doc("normalized_reference_range_low") }}' - - name: normalized_reference_range_high - description: '{{ doc("normalized_reference_range_high") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - name: core__location + description: > + The location table contains information on practice and facility locations where + patients receive medical care. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: location + tags: core + materialized: table + columns: + - name: location_id + description: '{{ doc("location_id") }}' + tests: + - unique: + config: + severity: warn + - name: npi + description: '{{ doc("npi") }}' + 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: name + description: '{{ doc("name") }}' + - name: facility_type + description: '{{ doc("facility_type") }}' + - name: parent_organization + description: '{{ doc("parent_organization") }}' + - name: address + description: '{{ doc("address") }}' + - name: city + description: '{{ doc("city") }}' + - name: state + description: '{{ doc("state") }}' + - name: zip_code + description: '{{ doc("zip_code") }}' + - name: latitude + description: '{{ doc("latitude") }}' + - name: longitude + description: '{{ doc("longitude") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__medical_claim + description: > + The medical claim table contains information on services rendered + to patients and billed by the provider to the insurer as claims. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: medical_claim + tags: + - core + - encounters + materialized: table + columns: + - name: medical_claim_id + description: '{{ doc("medical_claim_id") }}' + tests: + - unique: + config: + severity: error + - name: claim_id + description: '{{ doc("claim_id") }}' + - name: claim_line_number + description: '{{ doc("claim_line_number") }}' + data_type: integer + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: encounter_type + description: '{{ doc("encounter_type") }}' + - name: encounter_group + description: '{{ doc("encounter_group") }}' + - name: claim_type + description: '{{ doc("claim_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__claim_type.csv + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: payer + description: '{{ doc("payer") }}' + - name: plan + description: '{{ doc("plan") }}' + - name: claim_start_date + description: '{{ doc("claim_start_date") }}' + - name: claim_end_date + description: '{{ doc("claim_end_date") }}' + - name: claim_line_start_date + description: '{{ doc("claim_line_start_date") }}' + - name: claim_line_end_date + description: '{{ doc("claim_line_end_date") }}' + - name: admission_date + description: '{{ doc("admission_date") }}' + - name: discharge_date + description: '{{ doc("discharge_date") }}' + - name: service_category_1 + description: '{{ doc("service_category_1") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/service_categories/service_category__service_categories.csv + - name: service_category_2 + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/value_sets/service_categories/service_category__service_categories.csv + description: '{{ doc("service_category_2") }}' + - name: service_category_3 + description: '{{ doc("service_category_3") }}' + - name: admit_source_code + description: '{{ doc("admit_source_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_source.csv + - name: admit_source_description + description: '{{ doc("admit_source_description") }}' + - name: admit_type_code + description: '{{ doc("admit_type_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__admit_type.csv + - name: admit_type_description + description: '{{ doc("admit_type_description") }}' + - name: discharge_disposition_code + description: '{{ doc("discharge_disposition_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__discharge_disposition.csv + - name: discharge_disposition_description + description: '{{ doc("discharge_disposition_description") }}' + - name: place_of_service_code + description: '{{ doc("place_of_service_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__place_of_service.csv + - name: place_of_service_description + description: '{{ doc("place_of_service_description") }}' + - name: bill_type_code + description: '{{ doc("bill_type_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__bill_type.csv + - name: bill_type_description + description: '{{ doc("bill_type_description") }}' + - name: ms_drg_code + description: '{{ doc("ms_drg_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__ms_drg.csv + - name: ms_drg_description + description: '{{ doc("ms_drg_description") }}' + - name: apr_drg_code + description: '{{ doc("apr_drg_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__apr_drg.csv + - name: apr_drg_description + description: '{{ doc("apr_drg_description") }}' + - name: revenue_center_code + description: '{{ doc("revenue_center_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__revenue_center.csv + - name: revenue_center_description + description: '{{ doc("revenue_center_description") }}' + - name: service_unit_quantity + description: '{{ doc("service_unit_quantity") }}' + data_type: integer + - name: hcpcs_code + description: '{{ doc("hcpcs_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: hcpcs_modifier_1 + description: '{{ doc("hcpcs_modifier_1") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: hcpcs_modifier_2 + description: '{{ doc("hcpcs_modifier_2") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: hcpcs_modifier_3 + description: '{{ doc("hcpcs_modifier_3") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: hcpcs_modifier_4 + description: '{{ doc("hcpcs_modifier_4") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: hcpcs_modifier_5 + description: '{{ doc("hcpcs_modifier_5") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: rendering_id + description: '{{ doc("rendering_id") }}' + 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: rendering_tin + description: '{{ doc("rendering_tin") }}' + - name: rendering_name + description: '{{ doc("rendering_name") }}' + - name: billing_id + description: '{{ doc("billing_id") }}' + 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: billing_tin + description: '{{ doc("billing_tin") }}' + - name: billing_name + description: '{{ doc("billing_name") }}' + - name: facility_id + description: '{{ doc("facility_id") }}' + 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_name + description: '{{ doc("facility_name") }}' + - name: paid_date + description: '{{ doc("paid_date") }}' + - name: paid_amount + description: '{{ doc("paid_amount") }}' + - name: allowed_amount + description: '{{ doc("allowed_amount") }}' + - name: charge_amount + description: '{{ doc("charge_amount") }}' + - name: coinsurance_amount + description: '{{ doc("coinsurance_amount") }}' + - name: copayment_amount + description: '{{ doc("copayment_amount") }}' + - name: deductible_amount + description: '{{ doc("deductible_amount") }}' + - name: total_cost_amount + description: '{{ doc("total_cost_amount") }}' + - name: in_network_flag + description: '{{ doc("in_network_flag") }}' + - name: enrollment_flag + description: '{{ doc("enrollment_flag") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' -- name: core__patient - description: > - The patient table contains demographic and geographic information - on patients. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: patient - tags: core - materialized: table - columns: - - name: patient_id - description: '{{ doc("patient_id") }}' - tests: - - unique: - config: - severity: error - - name: sex - description: '{{ doc("sex") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__gender.csv - - name: race - description: '{{ doc("race") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__race.csv - - name: birth_date - description: '{{ doc("birth_date") }}' - - name: death_date - description: '{{ doc("death_date") }}' - - name: death_flag - description: '{{ doc("death_flag") }}' - data_type: boolean - - name: first_name - description: '{{ doc("first_name") }}' - - name: last_name - description: '{{ doc("last_name") }}' - - name: social_security_number - description: '{{ doc("social_security_number") }}' - - name: address - description: '{{ doc("address") }}' - - name: city - description: '{{ doc("city") }}' - - name: state - description: '{{ doc("state") }}' - - name: zip_code - description: '{{ doc("zip_code") }}' - - name: county - description: '{{ doc("county") }}' - - name: latitude - description: '{{ doc("latitude") }}' - - name: longitude - description: '{{ doc("longitude") }}' - - name: phone - description: '{{ doc("phone") }}' - - name: age - description: '{{ doc("age") }}' - - name: age_group - description: '{{ doc("age_group") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - name: core__medication + description: > + The medication table contains information on medications ordered and/or + administered during a patient encounter. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: medication + tags: core + materialized: table + columns: + - name: medication_id + description: '{{ doc("medication_id") }}' + tests: + - unique: + config: + severity: warn + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: dispensing_date + description: '{{ doc("dispensing_date") }}' + - name: prescribing_date + description: '{{ doc("prescribing_date") }}' + - name: source_code_type + description: '{{ doc("source_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: source_code + description: '{{ doc("source_code") }}' + meta: + terminology: https://www.nlm.nih.gov/research/umls/rxnorm/index.html + - name: source_description + description: '{{ doc("source_description") }}' + - name: ndc_code + description: '{{ doc("ndc_code") }}' + meta: + terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory + - name: ndc_description + description: '{{ doc("ndc_description") }}' + - name: ndc_mapping_method + description: '{{ doc("ndc_mapping_method") }}' + - name: rxnorm_code + description: '{{ doc("rxnorm_code") }}' + meta: + terminology: https://www.nlm.nih.gov/research/umls/rxnorm/index.html + - name: rxnorm_description + description: '{{ doc("rxnorm_description") }}' + - name: rxnorm_mapping_method + description: '{{ doc("rxnorm_mapping_method") }}' + - name: atc_code + description: '{{ doc("atc_code") }}' + meta: + terminology: https://www.who.int/tools/atc-ddd-toolkit/atc-classification + - name: atc_description + description: '{{ doc("atc_description") }}' + - name: atc_mapping_method + description: '{{ doc("atc_mapping_method") }}' + - name: route + description: '{{ doc("route") }}' + - name: strength + description: '{{ doc("strength") }}' + - name: quantity + description: '{{ doc("quantity") }}' + - name: quantity_unit + description: '{{ doc("quantity_unit") }}' + - name: days_supply + description: '{{ doc("days_supply") }}' + - name: practitioner_id + description: '{{ doc("practitioner_id") }}' + 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: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__member_months + description: Creates member months from eligibility data + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: member_months + tags: + - core + materialized: table + columns: + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: year_month + description: '{{ doc("year_month") }}' + - name: payer + description: '{{ doc("payer") }}' + - name: plan + description: '{{ doc("plan") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: payer_attributed_provider + description: '{{ doc("payer_attributed_provider") }}' + - name: payer_attributed_provider_practice + description: '{{ doc("payer_attributed_provider_practice") }}' + - name: payer_attributed_provider_organization + description: '{{ doc("payer_attributed_provider_organization") }}' + - name: payer_attributed_provider_lob + description: '{{ doc("payer_attributed_provider_lob") }}' + - name: custom_attributed_provider + description: '{{ doc("custom_attributed_provider") }}' + - name: custom_attributed_provider_practice + description: '{{ doc("custom_attributed_provider_practice") }}' + - name: custom_attributed_provider_organization + description: '{{ doc("custom_attributed_provider_organization") }}' + - name: custom_attributed_provider_lob + description: '{{ doc("custom_attributed_provider_lob") }}' -- name: core__pharmacy_claim - description: > - The pharmacy claim table contains information on prescription drugs - that were filled and billed to the insurer. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: pharmacy_claim - tags: core - materialized: table - columns: - - name: pharmacy_claim_id - description: '{{ doc("pharmacy_claim_id") }}' - tests: - - unique: - config: - severity: error - - name: claim_id - description: '{{ doc("claim_id") }}' - - name: claim_line_number - description: '{{ doc("claim_line_number") }}' - data_type: integer - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: member_id - description: '{{ doc("member_id") }}' - - name: payer - description: '{{ doc("payer") }}' - - name: plan - description: '{{ doc("plan") }}' - - name: prescribing_provider_id - description: '{{ doc("prescribing_provider_id") }}' - 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: prescribing_provider_name - description: '{{ doc("prescribing_provider_name") }}' - - name: dispensing_provider_id - description: '{{ doc("dispensing_provider_id") }}' - 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: dispensing_provider_name - description: '{{ doc("dispensing_provider_name") }}' - - name: dispensing_date - description: '{{ doc("dispensing_date") }}' - - name: ndc_code - description: '{{ doc("ndc_code") }}' - meta: - terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory - - name: ndc_description - description: '{{ doc("ndc_description") }}' - - name: quantity - description: '{{ doc("quantity") }}' - data_type: integer - - name: days_supply - description: '{{ doc("days_supply") }}' - data_type: integer - - name: refills - description: '{{ doc("refills") }}' - data_type: integer - - name: paid_date - description: '{{ doc("paid_date") }}' - - name: paid_amount - description: '{{ doc("paid_amount") }}' - - name: allowed_amount - description: '{{ doc("allowed_amount") }}' - - name: charge_amount - description: '{{ doc("charge_amount") }}' - - name: coinsurance_amount - description: '{{ doc("coinsurance_amount") }}' - - name: copayment_amount - description: '{{ doc("copayment_amount") }}' - - name: deductible_amount - description: '{{ doc("deductible_amount") }}' - - name: in_network_flag - description: '{{ doc("in_network_flag") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - name: core__observation + description: > + The observation table contains information on measurements other than lab + tests e.g. blood pressure, height, and weight. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: observation + tags: core + materialized: table + columns: + - name: observation_id + description: '{{ doc("observation_id") }}' + tests: + - unique: + config: + severity: warn + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: panel_id + description: '{{ doc("panel_id") }}' + - name: observation_date + description: '{{ doc("observation_date") }}' + - name: observation_type + description: '{{ doc("observation_type") }}' + - name: source_code_type + description: '{{ doc("source_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: source_code + description: '{{ doc("source_code") }}' + - name: source_description + description: '{{ doc("source_description") }}' + - name: normalized_code_type + description: '{{ doc("normalized_code_type") }}' + - name: normalized_code + description: '{{ doc("normalized_code") }}' + - name: normalized_description + description: '{{ doc("normalized_description") }}' + - name: mapping_method + description: '{{ doc("mapping_method") }}' + - name: result + description: '{{ doc("result") }}' + - name: source_units + description: '{{ doc("source_units") }}' + - name: normalized_units + description: '{{ doc("normalized_units") }}' + - name: source_reference_range_low + description: '{{ doc("source_reference_range_low") }}' + - name: source_reference_range_high + description: '{{ doc("source_reference_range_high") }}' + - name: normalized_reference_range_low + description: '{{ doc("normalized_reference_range_low") }}' + - name: normalized_reference_range_high + description: '{{ doc("normalized_reference_range_high") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__patient + description: > + The patient table contains demographic and geographic information + on patients. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: patient + tags: core + materialized: table + columns: + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - unique: + config: + severity: error + - name: sex + description: '{{ doc("sex") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__gender.csv + - name: race + description: '{{ doc("race") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__race.csv + - name: birth_date + description: '{{ doc("birth_date") }}' + - name: death_date + description: '{{ doc("death_date") }}' + - name: death_flag + description: '{{ doc("death_flag") }}' + data_type: boolean + - name: first_name + description: '{{ doc("first_name") }}' + - name: last_name + description: '{{ doc("last_name") }}' + - name: social_security_number + description: '{{ doc("social_security_number") }}' + - name: address + description: '{{ doc("address") }}' + - name: city + description: '{{ doc("city") }}' + - name: state + description: '{{ doc("state") }}' + - name: zip_code + description: '{{ doc("zip_code") }}' + - name: county + description: '{{ doc("county") }}' + - name: latitude + description: '{{ doc("county") }}' + - name: longitude + description: '{{ doc("longitude") }}' + - name: phone + description: '{{ doc("phone") }}' + - name: age + description: '{{ doc("age") }}' + - name: age_group + description: '{{ doc("age_group") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' -- name: core__practitioner - description: > - The practitioner table contains information on the providers in the dataset - e.g. physicians, physicians assistants, etc. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: practitioner - tags: core - materialized: table - columns: - - name: practitioner_id - description: '{{ doc("practitioner_id") }}' + - name: core__person_id_crosswalk + description: > + The person id crosswalk table contains all source patient identifiers from + the input layer eligibility (claims) and patient (clinical). + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: person_id_crosswalk + tags: core + materialized: table tests: - - unique: - config: - severity: warn - - name: npi - description: '{{ doc("npi") }}' - 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: provider_first_name - description: '{{ doc("provider_first_name") }}' - - name: provider_last_name - description: '{{ doc("provider_last_name") }}' - - name: practice_affiliation - description: '{{ doc("practice_affiliation") }}' - - name: specialty - description: '{{ doc("specialty") }}' - - name: sub_specialty - description: '{{ doc("sub_specialty") }}' - - name: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - person_id + - patient_id + - member_id + - payer + - '{{ quote_column("plan") }}' + - data_source + columns: + - name: person_id + description: '{{ doc("person_id") }}' + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: member_id + description: '{{ doc("member_id") }}' + - name: payer + description: '{{ doc("payer") }}' + - name: plan + description: '{{ doc("plan") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: core__pharmacy_claim + description: > + The pharmacy claim table contains information on prescription drugs + that were filled and billed to the insurer. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: pharmacy_claim + tags: core + materialized: table + columns: + - name: pharmacy_claim_id + description: '{{ doc("pharmacy_claim_id") }}' + tests: + - unique: + config: + severity: error + - name: claim_id + description: '{{ doc("claim_id") }}' + - name: claim_line_number + description: '{{ doc("claim_line_number") }}' + data_type: integer + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: payer + description: '{{ doc("payer") }}' + - name: plan + description: '{{ doc("plan") }}' + - name: prescribing_provider_id + description: '{{ doc("prescribing_provider_id") }}' + 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: prescribing_provider_name + description: '{{ doc("prescribing_provider_name") }}' + - name: dispensing_provider_id + description: '{{ doc("dispensing_provider_id") }}' + 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: dispensing_provider_name + description: '{{ doc("dispensing_provider_name") }}' + - name: dispensing_date + description: '{{ doc("dispensing_date") }}' + - name: ndc_code + description: '{{ doc("ndc_code") }}' + meta: + terminology: https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory + - name: ndc_description + description: '{{ doc("ndc_description") }}' + - name: quantity + description: '{{ doc("quantity") }}' + data_type: integer + - name: days_supply + description: '{{ doc("days_supply") }}' + data_type: integer + - name: refills + description: '{{ doc("refills") }}' + data_type: integer + - name: paid_date + description: '{{ doc("paid_date") }}' + - name: paid_amount + description: '{{ doc("paid_amount") }}' + - name: allowed_amount + description: '{{ doc("allowed_amount") }}' + - name: charge_amount + description: '{{ doc("charge_amount") }}' + - name: coinsurance_amount + description: '{{ doc("coinsurance_amount") }}' + - name: copayment_amount + description: '{{ doc("copayment_amount") }}' + - name: deductible_amount + description: '{{ doc("deductible_amount") }}' + - name: in_network_flag + description: '{{ doc("in_network_flag") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' -- name: core__procedure - description: > - The procedure table contains information on procedures that were performed on - patients in the dataset. - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core - {% else %}core{%- endif -%} - alias: procedure - tags: core - materialized: table - columns: - - name: procedure_id - description: '{{ doc("procedure_id") }}' - tests: - - unique: - config: - severity: warn - - name: encounter_id - description: '{{ doc("encounter_id") }}' - - name: claim_id - description: '{{ doc("claim_id") }}' - - name: patient_id - description: '{{ doc("patient_id") }}' - - name: procedure_date - description: '{{ doc("procedure_date") }}' - - name: source_code_type - description: '{{ doc("source_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: source_code - description: '{{ doc("source_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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: source_description - description: '{{ doc("source_description") }}' - - name: normalized_code_type - description: '{{ doc("normalized_code_type") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv - - name: normalized_code - description: '{{ doc("normalized_code") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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: normalized_description - description: '{{ doc("normalized_description") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: mapping_method - description: '{{ doc("mapping_method") }}' - - name: modifier_1 - description: '{{ doc("modifier_1") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: modifier_2 - description: '{{ doc("modifier_2") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: modifier_3 - description: '{{ doc("modifier_3") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: modifier_4 - description: '{{ doc("modifier_4") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: modifier_5 - description: '{{ doc("modifier_5") }}' - meta: - terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv - - name: practitioner_id - description: '{{ doc("practitioner_id") }}' - 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: data_source - description: '{{ doc("data_source") }}' - - name: tuva_last_run - description: '{{ doc("tuva_last_run") }}' + - name: core__practitioner + description: > + The practitioner table contains information on the providers in the dataset + e.g. physicians, physicians assistants, etc. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: practitioner + tags: core + materialized: table + columns: + - name: practitioner_id + description: '{{ doc("practitioner_id") }}' + tests: + - unique: + config: + severity: warn + - name: npi + description: '{{ doc("npi") }}' + 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: provider_first_name + description: '{{ doc("provider_first_name") }}' + - name: provider_last_name + description: '{{ doc("provider_last_name") }}' + - name: practice_affiliation + description: '{{ doc("practice_affiliation") }}' + - name: specialty + description: '{{ doc("specialty") }}' + - name: sub_specialty + description: '{{ doc("sub_specialty") }}' + - name: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' + - name: core__procedure + description: > + The procedure table contains information on procedures that were performed on + patients in the dataset. + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_core + {% else %}core{%- endif -%} + alias: procedure + tags: core + materialized: table + columns: + - name: procedure_id + description: '{{ doc("procedure_id") }}' + tests: + - unique: + config: + severity: warn + - name: encounter_id + description: '{{ doc("encounter_id") }}' + - name: claim_id + description: '{{ doc("claim_id") }}' + - name: person_id + description: '{{ doc("person_id") }}' + tests: + - not_null + - name: member_id + description: '{{ doc("member_id") }}' + - name: patient_id + description: '{{ doc("patient_id") }}' + - name: procedure_date + description: '{{ doc("procedure_date") }}' + - name: source_code_type + description: '{{ doc("source_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: source_code + description: '{{ doc("source_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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: source_description + description: '{{ doc("source_description") }}' + - name: normalized_code_type + description: '{{ doc("normalized_code_type") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__code_type.csv + - name: normalized_code + description: '{{ doc("normalized_code") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__icd_10_pcs.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: normalized_description + description: '{{ doc("normalized_description") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: mapping_method + description: '{{ doc("mapping_method") }}' + - name: modifier_1 + description: '{{ doc("modifier_1") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: modifier_2 + description: '{{ doc("modifier_2") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: modifier_3 + description: '{{ doc("modifier_3") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: modifier_4 + description: '{{ doc("modifier_4") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: modifier_5 + description: '{{ doc("modifier_5") }}' + meta: + terminology: https://github.com/tuva-health/the_tuva_project/blob/main/seeds/terminology/terminology__hcpcs_level_2.csv + - name: practitioner_id + description: '{{ doc("practitioner_id") }}' + 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: data_source + description: '{{ doc("data_source") }}' + - name: tuva_last_run + description: '{{ doc("tuva_last_run") }}' - ## Staging - Claims - name: core__stg_claims_medical_claim description: Staging core medical claims diff --git a/models/core/final/core__condition.sql b/models/core/final/core__condition.sql index 35c5d63a2..e2e080367 100644 --- a/models/core/final/core__condition.sql +++ b/models/core/final/core__condition.sql @@ -6,27 +6,24 @@ with all_conditions as ( - {% if var('clinical_enabled' - , var('tuva_marts_enabled' - , False)) == true and var('claims_enabled' - , var('tuva_marts_enabled' - , False)) == true -%} +{% if var('clinical_enabled', var('tuva_marts_enabled', False)) == true + and var('claims_enabled', var('tuva_marts_enabled', False)) == true -%} -select * -from {{ ref('core__stg_claims_condition') }} -union all -select * -from {{ ref('core__stg_clinical_condition') }} + select * + from {{ ref('core__stg_claims_condition') }} + union all + select * + from {{ ref('core__stg_clinical_condition') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} -select * -from {{ ref('core__stg_clinical_condition') }} + select * + from {{ ref('core__stg_clinical_condition') }} {% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} -select * -from {{ ref('core__stg_claims_condition') }} + select * + from {{ ref('core__stg_claims_condition') }} {%- endif %} ) @@ -36,6 +33,8 @@ from {{ ref('core__stg_claims_condition') }} {% if var('enable_normalize_engine',false) != true %} select all_conditions.condition_id + , all_conditions.person_id + , all_conditions.member_id , all_conditions.patient_id , all_conditions.encounter_id , all_conditions.claim_id @@ -90,6 +89,8 @@ left join {{ ref('terminology__snomed_ct') }} snomed_ct {% else %} select all_conditions.condition_id + , all_conditions.person_id + , all_conditions.member_id , all_conditions.patient_id , all_conditions.encounter_id , all_conditions.claim_id diff --git a/models/core/final/core__eligibility.sql b/models/core/final/core__eligibility.sql index 4054fc25a..9a995b078 100644 --- a/models/core/final/core__eligibility.sql +++ b/models/core/final/core__eligibility.sql @@ -1,7 +1,7 @@ -{{ config( - enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool - ) -}} - - -select * from {{ ref('core__stg_claims_eligibility')}} \ No newline at end of file +{{ config( + enabled = var('claims_enabled',var('tuva_marts_enabled',False)) + | as_bool + ) +}} + +select * from {{ ref('core__stg_claims_eligibility') }} \ No newline at end of file diff --git a/models/core/final/core__encounter.sql b/models/core/final/core__encounter.sql index db86b32a6..bb86a4097 100644 --- a/models/core/final/core__encounter.sql +++ b/models/core/final/core__encounter.sql @@ -6,26 +6,22 @@ {% if var('clinical_enabled', false) == true and var('claims_enabled', false) == true -%} -select * -,'claim' as encounter_source_type - from {{ ref('core__stg_claims_encounter') }} -union all + select *,'claim' as encounter_source_type + from {{ ref('core__stg_claims_encounter') }} -select * -,'clinical' as encounter_source_type - from {{ ref('core__stg_clinical_encounter') }} + union all + + select *,'clinical' as encounter_source_type + from {{ ref('core__stg_clinical_encounter') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} -select * -,'clinical' as encounter_source_type - from {{ ref('core__stg_clinical_encounter') }} + select *, 'clinical' as encounter_source_type + from {{ ref('core__stg_clinical_encounter') }} {% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} -select * -,'claim' as encounter_source_type from {{ ref('core__stg_claims_encounter') }} - -{%- endif %} - + select *, 'claim' as encounter_source_type + from {{ ref('core__stg_claims_encounter') }} +{%- endif %} \ No newline at end of file diff --git a/models/core/final/core__lab_result.sql b/models/core/final/core__lab_result.sql index e16b1e8a6..635bf5937 100644 --- a/models/core/final/core__lab_result.sql +++ b/models/core/final/core__lab_result.sql @@ -9,6 +9,7 @@ select labs.lab_result_id + , labs.person_id , labs.patient_id , labs.encounter_id , labs.accession_number @@ -63,6 +64,7 @@ left join {{ref('terminology__snomed_ct')}} snomed_ct select labs.lab_result_id + , labs.person_id , labs.patient_id , labs.encounter_id , labs.accession_number diff --git a/models/core/final/core__medical_claim.sql b/models/core/final/core__medical_claim.sql index 7119ea298..f40be06d1 100644 --- a/models/core/final/core__medical_claim.sql +++ b/models/core/final/core__medical_claim.sql @@ -1,7 +1,7 @@ -{{ config( - enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool - ) -}} - - +{{ config( + enabled = var('claims_enabled',var('tuva_marts_enabled',False)) + | as_bool + ) +}} + select * from {{ ref('core__stg_claims_medical_claim')}} \ No newline at end of file diff --git a/models/core/final/core__medication.sql b/models/core/final/core__medication.sql index 6614ab67c..400681cfa 100644 --- a/models/core/final/core__medication.sql +++ b/models/core/final/core__medication.sql @@ -9,6 +9,7 @@ with source_mapping as ( {% if var('enable_normalize_engine',false) != true %} select meds.medication_id + , meds.person_id , meds.patient_id , meds.encounter_id , meds.dispensing_date @@ -74,6 +75,7 @@ from {{ ref('core__stg_clinical_medication')}} meds select meds.medication_id + , meds.person_id , meds.patient_id , meds.encounter_id , meds.dispensing_date @@ -188,7 +190,7 @@ from {{ ref('core__stg_clinical_medication')}} meds -- add auto rxnorm + atc select sm.medication_id - , sm.patient_id + , sm.person_id , sm.encounter_id , sm.dispensing_date , sm.prescribing_date diff --git a/models/core/final/core__member_months.sql b/models/core/final/core__member_months.sql index 6ea2497f9..f5d60120d 100644 --- a/models/core/final/core__member_months.sql +++ b/models/core/final/core__member_months.sql @@ -3,8 +3,6 @@ ) }} - - with month_start_and_end_dates as ( select {{ dbt.concat(["year", @@ -18,7 +16,8 @@ with month_start_and_end_dates as ( final_before_attribution_fields as ( select distinct - a.patient_id + a.person_id + , a.member_id , year_month , a.payer , a.{{ quote_column('plan') }} @@ -33,7 +32,8 @@ inner join month_start_and_end_dates b add_attribution_fields as ( select - a.patient_id + a.person_id + , a.member_id , a.year_month , a.payer , a.{{ quote_column('plan') }} @@ -51,13 +51,11 @@ select from final_before_attribution_fields a left join {{ ref('financial_pmpm__stg_provider_attribution') }} b -on a.patient_id = b.patient_id +on a.person_id = b.person_id and a.year_month = b.year_month and a.payer = b.payer and a.{{ quote_column('plan') }} = b.{{ quote_column('plan') }} and a.data_source = b.data_source ) - -select * -from add_attribution_fields +select * from add_attribution_fields \ No newline at end of file diff --git a/models/core/final/core__observation.sql b/models/core/final/core__observation.sql index 1efed5282..be51260d1 100644 --- a/models/core/final/core__observation.sql +++ b/models/core/final/core__observation.sql @@ -7,6 +7,7 @@ {% if var('enable_normalize_engine',false) != true %} select obs.observation_id + , obs.person_id , obs.patient_id , obs.encounter_id , obs.panel_id @@ -92,6 +93,7 @@ left join {{ ref('terminology__loinc') }} loinc select obs.observation_id + , obs.person_id , obs.patient_id , obs.encounter_id , obs.panel_id diff --git a/models/core/final/core__person_id_crosswalk.sql b/models/core/final/core__person_id_crosswalk.sql new file mode 100644 index 000000000..8613084c3 --- /dev/null +++ b/models/core/final/core__person_id_crosswalk.sql @@ -0,0 +1,49 @@ +{{ config( + enabled = var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False))) + | as_bool + ) +}} + +{% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} + +select distinct + cast(person_id as {{ dbt.type_string() }}) as person_id + , cast(null as {{ dbt.type_string() }}) as patient_id + , cast(member_id as {{ dbt.type_string() }}) as member_id + , cast(payer as {{ dbt.type_string() }}) as payer + , cast({{ quote_column('plan') }} as {{ dbt.type_string() }}) as {{ quote_column('plan') }} + , cast(data_source as {{ dbt.type_string() }}) as data_source +from {{ ref('normalized_input__eligibility')}} +union all +select distinct + cast(person_id as {{ dbt.type_string() }}) as person_id + , cast(patient_id as {{ dbt.type_string() }}) as patient_id + , cast(null as {{ dbt.type_string() }}) as member_id + , cast(null as {{ dbt.type_string() }}) as payer + , cast(null as {{ dbt.type_string() }}) as {{ quote_column('plan') }} + , cast(data_source as {{ dbt.type_string() }}) as data_source +from {{ ref('patient') }} + +{% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} + +select distinct + cast(person_id as {{ dbt.type_string() }}) as person_id + , cast(patient_id as {{ dbt.type_string() }}) as patient_id + , cast(null as {{ dbt.type_string() }}) as member_id + , cast(null as {{ dbt.type_string() }}) as payer + , cast(null as {{ dbt.type_string() }}) as {{ quote_column('plan') }} + , cast(data_source as {{ dbt.type_string() }}) as data_source +from {{ ref('patient') }} + +{% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} + +select distinct + cast(person_id as {{ dbt.type_string() }}) as person_id + , cast(null as {{ dbt.type_string() }}) as patient_id + , cast(member_id as {{ dbt.type_string() }}) as member_id + , cast(payer as {{ dbt.type_string() }}) as payer + , cast({{ quote_column('plan') }} as {{ dbt.type_string() }}) as {{ quote_column('plan') }} + , cast(data_source as {{ dbt.type_string() }}) as data_source +from {{ ref('normalized_input__eligibility') }} + +{%- endif %} \ No newline at end of file diff --git a/models/core/final/core__procedure.sql b/models/core/final/core__procedure.sql index 27ff07ebe..6b63e658b 100644 --- a/models/core/final/core__procedure.sql +++ b/models/core/final/core__procedure.sql @@ -27,6 +27,8 @@ select * from {{ ref('core__stg_claims_procedure') }} select all_procedures.procedure_id + , all_procedures.person_id + , all_procedures.member_id , all_procedures.patient_id , all_procedures.encounter_id , all_procedures.claim_id @@ -81,6 +83,8 @@ left join {{ ref('terminology__snomed_ct')}} snomed_ct select all_procedures.procedure_id + , all_procedures.person_id + , all_procedures.member_id , all_procedures.patient_id , all_procedures.encounter_id , all_procedures.claim_id diff --git a/models/core/staging/core__stg_claims_condition.sql b/models/core/staging/core__stg_claims_condition.sql index 55e15ce32..7a4da7063 100644 --- a/models/core/staging/core__stg_claims_condition.sql +++ b/models/core/staging/core__stg_claims_condition.sql @@ -1,4 +1,3 @@ - {{ config( enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool ) @@ -13,7 +12,8 @@ with unpivot_cte as ( select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -33,7 +33,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -53,7 +54,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -73,7 +75,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -93,7 +96,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -113,7 +117,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -133,7 +138,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -153,7 +159,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -173,7 +180,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -193,7 +201,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -213,7 +222,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -233,7 +243,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -253,7 +264,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -273,7 +285,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -293,7 +306,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -313,7 +327,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -333,7 +348,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -353,7 +369,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -373,7 +390,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -393,7 +411,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -413,7 +432,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -433,7 +453,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -453,7 +474,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -473,7 +495,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -493,7 +516,8 @@ union all select claim_id , claim_line_number - , patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -522,8 +546,9 @@ select distinct "CAST(unpivot_cte.source_code AS " ~ dbt.type_string() ~ ")", ]), api.Column.translate_type("string")) }} as condition_id - - , cast(unpivot_cte.patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(unpivot_cte.person_id as {{ dbt.type_string() }} ) as person_id + , cast(unpivot_cte.member_id as {{ dbt.type_string() }} ) as member_id + , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id --one claim can be on multiple encounters, so nulling out for now , cast(unpivot_cte.claim_id as {{ dbt.type_string() }} ) as claim_id , {{ try_to_cast_date('unpivot_cte.recorded_date', 'YYYY-MM-DD') }} as recorded_date @@ -555,4 +580,4 @@ from unpivot_cte left join {{ ref('terminology__icd_10_cm') }} icd on unpivot_cte.source_code = icd.icd_10_cm left join {{ ref('terminology__present_on_admission') }} as poa - on unpivot_cte.present_on_admit_code = poa.present_on_admit_code + on unpivot_cte.present_on_admit_code = poa.present_on_admit_code \ No newline at end of file diff --git a/models/core/staging/core__stg_claims_eligibility.sql b/models/core/staging/core__stg_claims_eligibility.sql index b7a335c70..05f1167f7 100644 --- a/models/core/staging/core__stg_claims_eligibility.sql +++ b/models/core/staging/core__stg_claims_eligibility.sql @@ -13,6 +13,8 @@ select {{ dbt.concat([ + "person_id", + "'-'", "member_id", "'-'", "enrollment_start_date", @@ -22,8 +24,10 @@ select "payer", "'-'", quote_column('plan'), + "'-'", + "data_source" ]) }} as eligibility_id - , cast(patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(member_id as {{ dbt.type_string() }} ) as member_id , cast(subscriber_id as {{ dbt.type_string() }} ) as subscriber_id , cast(birth_date as date) as birth_date diff --git a/models/core/staging/core__stg_claims_encounter.sql b/models/core/staging/core__stg_claims_encounter.sql index 32af8b0eb..d96e947fb 100644 --- a/models/core/staging/core__stg_claims_encounter.sql +++ b/models/core/staging/core__stg_claims_encounter.sql @@ -45,7 +45,7 @@ WITH base AS ( SELECT cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id - , cast(p.patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(p.person_id as {{ dbt.type_string() }} ) as person_id , cast(encounter_type as {{ dbt.type_string() }} ) as encounter_type , cast(encounter_group as {{ dbt.type_string() }} ) as encounter_group , {{ try_to_cast_date('encounter_start_date', 'YYYY-MM-DD') }} as encounter_start_date diff --git a/models/core/staging/core__stg_claims_medical_claim.sql b/models/core/staging/core__stg_claims_medical_claim.sql index 6c06de3af..eef95992a 100644 --- a/models/core/staging/core__stg_claims_medical_claim.sql +++ b/models/core/staging/core__stg_claims_medical_claim.sql @@ -1,4 +1,3 @@ - {{ config( enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool ) @@ -33,12 +32,13 @@ with all_encounters as ( from {{ ref('encounters__orphaned_claims') }} ) - select {{ dbt.concat([ - "med.claim_id", - "'-'", - "med.claim_line_number" + "med.claim_id", + "'-'", + "med.claim_line_number", + "'-'", + "med.data_source" ]) }} as medical_claim_id , cast(med.claim_id as {{ dbt.type_string() }} ) as claim_id , cast(med.claim_line_number as {{ dbt.type_int() }} ) as claim_line_number @@ -46,7 +46,7 @@ select , cast(x.encounter_type as {{ dbt.type_string() }} ) as encounter_type , cast(x.encounter_group as {{ dbt.type_string() }} ) as encounter_group , cast(med.claim_type as {{ dbt.type_string() }} ) as claim_type - , cast(med.patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(med.person_id as {{ dbt.type_string() }} ) as person_id , cast(med.member_id as {{ dbt.type_string() }} ) as member_id , cast(med.payer as {{ dbt.type_string() }} ) as payer , med.{{ quote_column('plan') }} @@ -116,5 +116,4 @@ inner join all_encounters as x and med.claim_line_number = x.claim_line_number left join {{ ref('claims_enrollment__flag_claims_with_enrollment') }} as enroll on med.claim_id = enroll.claim_id - and med.claim_line_number = enroll.claim_line_number - + and med.claim_line_number = enroll.claim_line_number \ No newline at end of file diff --git a/models/core/staging/core__stg_claims_patient.sql b/models/core/staging/core__stg_claims_patient.sql index fa1642aa2..4cf60eed5 100644 --- a/models/core/staging/core__stg_claims_patient.sql +++ b/models/core/staging/core__stg_claims_patient.sql @@ -3,13 +3,9 @@ ) }} --- ************************************************* --- This dbt model creates the patient table in core. --- ************************************************* - with patient_stage as( select - patient_id + person_id ,first_name ,last_name ,gender @@ -25,7 +21,7 @@ with patient_stage as( ,phone ,data_source ,row_number() over ( - partition by patient_id + partition by person_id order by case when enrollment_end_date is null then cast ('2050-01-01' as date) else enrollment_end_date end DESC) @@ -36,7 +32,7 @@ with patient_stage as( ) select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(first_name as {{ dbt.type_string() }}) as first_name , cast(last_name as {{ dbt.type_string() }}) as last_name , cast(gender as {{ dbt.type_string() }}) as sex @@ -52,6 +48,7 @@ select , cast(null as {{ dbt.type_string() }}) as county , cast(null as {{ dbt.type_float() }}) as latitude , cast(null as {{ dbt.type_float() }}) as longitude + , cast(phone as {{ dbt.type_string() }}) as phone , cast(data_source as {{ dbt.type_string() }}) as data_source , cast(floor({{ datediff('birth_date', 'tuva_last_run_date', 'hour') }} / 8760.0) as {{ dbt.type_int() }} ) as age , cast( diff --git a/models/core/staging/core__stg_claims_pharmacy_claim.sql b/models/core/staging/core__stg_claims_pharmacy_claim.sql index 4b0232536..0032cb89e 100644 --- a/models/core/staging/core__stg_claims_pharmacy_claim.sql +++ b/models/core/staging/core__stg_claims_pharmacy_claim.sql @@ -1,4 +1,3 @@ - {{ config( enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool ) @@ -9,18 +8,17 @@ -- table in core. -- ************************************************* - - - select {{ dbt.concat([ "cast(claim_id as " ~ dbt.type_string() ~ ")", "'-'", - "cast(claim_line_number as " ~ dbt.type_string() ~ ")" + "cast(claim_line_number as " ~ dbt.type_string() ~ ")", + "'-'", + "cast(data_source as " ~ dbt.type_string() ~ ")" ]) }} as pharmacy_claim_id , cast(claim_id as {{ dbt.type_string() }} ) as claim_id , cast(claim_line_number as integer ) as claim_line_number - , cast(patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(member_id as {{ dbt.type_string() }} ) as member_id , cast(payer as {{ dbt.type_string() }} ) as payer , {{ quote_column('plan') }} @@ -44,4 +42,4 @@ select , cast(in_network_flag as int ) as in_network_flag , cast(data_source as {{ dbt.type_string() }} ) as data_source , '{{ var('tuva_last_run')}}' as tuva_last_run -from {{ ref('normalized_input__pharmacy_claim') }} pharm +from {{ ref('normalized_input__pharmacy_claim') }} pharm \ No newline at end of file diff --git a/models/core/staging/core__stg_claims_procedure.sql b/models/core/staging/core__stg_claims_procedure.sql index a52d38f16..b0986aab3 100644 --- a/models/core/staging/core__stg_claims_procedure.sql +++ b/models/core/staging/core__stg_claims_procedure.sql @@ -1,4 +1,3 @@ - {{ config( enabled = var('claims_enabled',var('tuva_marts_enabled',False)) | as_bool ) @@ -13,7 +12,8 @@ with unpivot_cte as ( select claim_id as claim_id , claim_line_number as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , coalesce(admission_date , claim_start_date , discharge_date @@ -40,7 +40,8 @@ union distinct select claim_id as claim_id , 1 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_1 as procedure_date , procedure_code_type as source_code_type , procedure_code_1 as source_code @@ -63,7 +64,8 @@ union distinct select claim_id as claim_id , 2 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_2 as procedure_date , procedure_code_type as source_code_type , procedure_code_2 as source_code @@ -86,7 +88,8 @@ union distinct select claim_id as claim_id , 3 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_3 as procedure_date , procedure_code_type as source_code_type , procedure_code_3 as source_code @@ -109,7 +112,8 @@ union distinct select claim_id as claim_id , 4 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_4 as procedure_date , procedure_code_type as source_code_type , procedure_code_4 as source_code @@ -132,7 +136,8 @@ union distinct select claim_id as claim_id , 5 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_5 as procedure_date , procedure_code_type as source_code_type , procedure_code_5 as source_code @@ -155,7 +160,8 @@ union distinct select claim_id as claim_id , 6 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_6 as procedure_date , procedure_code_type as source_code_type , procedure_code_6 as source_code @@ -178,7 +184,8 @@ union distinct select claim_id as claim_id , 7 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_7 as procedure_date , procedure_code_type as source_code_type , procedure_code_7 as source_code @@ -201,7 +208,8 @@ union distinct select claim_id as claim_id , 8 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_8 as procedure_date , procedure_code_type as source_code_type , procedure_code_8 as source_code @@ -224,7 +232,8 @@ union distinct select claim_id as claim_id , 9 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_9 as procedure_date , procedure_code_type as source_code_type , procedure_code_9 as source_code @@ -247,7 +256,8 @@ union distinct select claim_id as claim_id , 10 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_10 as procedure_date , procedure_code_type as source_code_type , procedure_code_10 as source_code @@ -270,7 +280,8 @@ union distinct select claim_id as claim_id , 11 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_11 as procedure_date , procedure_code_type as source_code_type , procedure_code_11 as source_code @@ -293,7 +304,8 @@ union distinct select claim_id as claim_id , 12 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_12 as procedure_date , procedure_code_type as source_code_type , procedure_code_12 as source_code @@ -316,7 +328,8 @@ union distinct select claim_id as claim_id , 13 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_13 as procedure_date , procedure_code_type as source_code_type , procedure_code_13 as source_code @@ -339,7 +352,8 @@ union distinct select claim_id as claim_id , 14 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_14 as procedure_date , procedure_code_type as source_code_type , procedure_code_14 as source_code @@ -362,7 +376,8 @@ union distinct select claim_id as claim_id , 15 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_15 as procedure_date , procedure_code_type as source_code_type , procedure_code_15 as source_code @@ -385,7 +400,8 @@ union distinct select claim_id as claim_id , 16 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_16 as procedure_date , procedure_code_type as source_code_type , procedure_code_16 as source_code @@ -408,7 +424,8 @@ union distinct select claim_id as claim_id , 17 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_17 as procedure_date , procedure_code_type as source_code_type , procedure_code_17 as source_code @@ -431,7 +448,8 @@ union distinct select claim_id as claim_id , 18 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_18 as procedure_date , procedure_code_type as source_code_type , procedure_code_18 as source_code @@ -454,7 +472,8 @@ union distinct select claim_id as claim_id , 19 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_19 as procedure_date , procedure_code_type as source_code_type , procedure_code_19 as source_code @@ -477,7 +496,8 @@ union distinct select claim_id as claim_id , 20 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_20 as procedure_date , procedure_code_type as source_code_type , procedure_code_20 as source_code @@ -500,7 +520,8 @@ union distinct select claim_id as claim_id , 21 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_21 as procedure_date , procedure_code_type as source_code_type , procedure_code_21 as source_code @@ -523,7 +544,8 @@ union distinct select claim_id as claim_id , 22 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_22 as procedure_date , procedure_code_type as source_code_type , procedure_code_22 as source_code @@ -546,7 +568,8 @@ union distinct select claim_id as claim_id , 23 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_23 as procedure_date , procedure_code_type as source_code_type , procedure_code_23 as source_code @@ -569,7 +592,8 @@ union distinct select claim_id as claim_id , 24 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_24 as procedure_date , procedure_code_type as source_code_type , procedure_code_24 as source_code @@ -592,7 +616,8 @@ union distinct select claim_id as claim_id , 25 as procedure_sequence_id - , patient_id as patient_id + , person_id + , member_id , procedure_date_25 as procedure_date , procedure_code_type as source_code_type , procedure_code_25 as source_code @@ -626,7 +651,9 @@ select distinct "case when unpivot_cte.practitioner_npi is not null then CONCAT('_', unpivot_cte.practitioner_npi) else '' end" ]), api.Column.translate_type("string")) }} as procedure_id - , cast(unpivot_cte.patient_id as {{ dbt.type_string() }} ) as patient_id + , cast(unpivot_cte.person_id as {{ dbt.type_string() }} ) as person_id + , cast(unpivot_cte.member_id as {{ dbt.type_string() }} ) as member_id + , cast(null as {{ dbt.type_string() }} ) as patient_id , cast(null as {{ dbt.type_string() }} ) as encounter_id --one claim can be on multiple encounters, so nulling out for now , cast(unpivot_cte.claim_id as {{ dbt.type_string() }} ) as claim_id , {{ try_to_cast_date('unpivot_cte.procedure_date', 'YYYY-MM-DD') }} as procedure_date @@ -668,5 +695,4 @@ from unpivot_cte left join {{ ref('terminology__icd_10_pcs') }} as icd on unpivot_cte.source_code = icd.icd_10_pcs left join {{ ref('terminology__hcpcs_level_2') }} as hcpcs - on unpivot_cte.source_code = hcpcs.hcpcs - + on unpivot_cte.source_code = hcpcs.hcpcs \ No newline at end of file diff --git a/models/core/staging/core__stg_clinical_condition.sql b/models/core/staging/core__stg_clinical_condition.sql index 8c75f8673..f5618d36a 100644 --- a/models/core/staging/core__stg_clinical_condition.sql +++ b/models/core/staging/core__stg_clinical_condition.sql @@ -5,6 +5,8 @@ select cast(condition_id as {{ dbt.type_string() }} ) as condition_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id + , cast(null as {{ dbt.type_string() }} ) as member_id , cast(patient_id as {{ dbt.type_string() }} ) as patient_id , cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id , cast(claim_id as {{ dbt.type_string() }} ) as claim_id diff --git a/models/core/staging/core__stg_clinical_encounter.sql b/models/core/staging/core__stg_clinical_encounter.sql index a6262c1b6..9079c2fae 100644 --- a/models/core/staging/core__stg_clinical_encounter.sql +++ b/models/core/staging/core__stg_clinical_encounter.sql @@ -5,7 +5,7 @@ select cast(encounter_id as {{ dbt.type_string() }}) as encounter_id - , cast(patient_id as {{ dbt.type_string() }}) as patient_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(encounter_type as {{ dbt.type_string() }}) as encounter_type , cast('clinical' as {{ dbt.type_string() }}) as encounter_group , {{ try_to_cast_date('encounter_start_date', 'YYYY-MM-DD') }} as encounter_start_date diff --git a/models/core/staging/core__stg_clinical_lab_result.sql b/models/core/staging/core__stg_clinical_lab_result.sql index bfad5d677..b8b71ed24 100644 --- a/models/core/staging/core__stg_clinical_lab_result.sql +++ b/models/core/staging/core__stg_clinical_lab_result.sql @@ -5,6 +5,7 @@ select cast(lab_result_id as {{ dbt.type_string() }} ) as lab_result_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(patient_id as {{ dbt.type_string() }} ) as patient_id , cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id , cast(accession_number as {{ dbt.type_string() }} ) as accession_number @@ -32,4 +33,4 @@ select , cast(ordering_practitioner_id as {{ dbt.type_string() }} ) as ordering_practitioner_id , cast(data_source as {{ dbt.type_string() }} ) as data_source , cast('{{ var('tuva_last_run')}}' as {{ dbt.type_timestamp() }} ) as tuva_last_run -from {{ ref('lab_result') }} +from {{ ref('lab_result') }} \ No newline at end of file diff --git a/models/core/staging/core__stg_clinical_medication.sql b/models/core/staging/core__stg_clinical_medication.sql index 1d38b8d2c..4efb77260 100644 --- a/models/core/staging/core__stg_clinical_medication.sql +++ b/models/core/staging/core__stg_clinical_medication.sql @@ -5,6 +5,7 @@ select cast(medication_id as {{ dbt.type_string() }} ) as medication_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(patient_id as {{ dbt.type_string() }} ) as patient_id , cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('dispensing_date', 'YYYY-MM-DD') }} as dispensing_date diff --git a/models/core/staging/core__stg_clinical_observation.sql b/models/core/staging/core__stg_clinical_observation.sql index bcd951ff6..11bf3dd82 100644 --- a/models/core/staging/core__stg_clinical_observation.sql +++ b/models/core/staging/core__stg_clinical_observation.sql @@ -6,6 +6,7 @@ select cast(observation_id as {{ dbt.type_string() }} ) as observation_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(patient_id as {{ dbt.type_string() }} ) as patient_id , cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id , cast(panel_id as {{ dbt.type_string() }} ) as panel_id diff --git a/models/core/staging/core__stg_clinical_patient.sql b/models/core/staging/core__stg_clinical_patient.sql index 34b35c95c..2f83007ee 100644 --- a/models/core/staging/core__stg_clinical_patient.sql +++ b/models/core/staging/core__stg_clinical_patient.sql @@ -9,7 +9,7 @@ with tuva_last_run as( , cast(substring('{{ var('tuva_last_run')}}',1,10) as date ) as tuva_last_run_date ) SELECT - cast(patient_id as {{ dbt.type_string() }} ) as patient_id + cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(first_name as {{ dbt.type_string() }} ) as first_name , cast(last_name as {{ dbt.type_string() }} ) as last_name , cast(sex as {{ dbt.type_string() }} ) as sex @@ -25,6 +25,7 @@ SELECT , cast(county as {{ dbt.type_string() }} ) as county , cast(latitude as {{ dbt.type_float() }} ) as latitude , cast(longitude as {{ dbt.type_float() }} ) as longitude + , cast(phone as {{ dbt.type_string() }}) as phone , cast(data_source as {{ dbt.type_string() }} ) as data_source , cast(floor({{ datediff('birth_date', 'tuva_last_run_date', 'hour') }} / 8760.0) as {{ dbt.type_int() }} ) as age , cast( diff --git a/models/core/staging/core__stg_clinical_procedure.sql b/models/core/staging/core__stg_clinical_procedure.sql index 659248d57..f51b0c7c3 100644 --- a/models/core/staging/core__stg_clinical_procedure.sql +++ b/models/core/staging/core__stg_clinical_procedure.sql @@ -4,7 +4,9 @@ }} select - cast(procedure_id as {{ dbt.type_string() }} ) as procedure_id + cast(procedure_id as {{ dbt.type_string() }} ) as procedure_id + , cast(person_id as {{ dbt.type_string() }} ) as person_id + , cast(null as {{ dbt.type_string() }} ) as member_id , cast(patient_id as {{ dbt.type_string() }} ) as patient_id , cast(encounter_id as {{ dbt.type_string() }} ) as encounter_id , cast(claim_id as {{ dbt.type_string() }} ) as claim_id diff --git a/models/data_quality/data_quality_models.yml b/models/data_quality/data_quality_models.yml index 5b560bb81..e9b3dd980 100644 --- a/models/data_quality/data_quality_models.yml +++ b/models/data_quality/data_quality_models.yml @@ -98,12 +98,12 @@ models: description: '{{ doc("tuva_last_run") }}' -- name: data_quality__eligibility_missing_patient_id +- name: data_quality__eligibility_missing_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: eligibility_missing_patient_id + alias: eligibility_missing_person_id tags: - data_quality_audit materialized: table @@ -261,12 +261,12 @@ models: - name: tuva_last_run description: '{{ doc("tuva_last_run") }}' -- name: data_quality__pharmacy_claim_patient_id +- name: data_quality__pharmacy_claim_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: pharmacy_claim_patient_id + alias: pharmacy_claim_person_id tags: - data_quality_audit materialized: table @@ -341,12 +341,12 @@ models: - data_quality_audit materialized: table -- name: data_quality__medical_claim_patient_id +- name: data_quality__medical_claim_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: medical_claim_patient_id + alias: medical_claim_person_id tags: - data_quality_audit materialized: table diff --git a/models/data_quality/dqi/dqi_models.yml b/models/data_quality/dqi/dqi_models.yml index da5c78d45..7a5aae4ea 100644 --- a/models/data_quality/dqi/dqi_models.yml +++ b/models/data_quality/dqi/dqi_models.yml @@ -350,12 +350,12 @@ models: materialized: table -- name: data_quality__eligibility_patient_id +- name: data_quality__eligibility_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: eligibility_patient_id + alias: eligibility_person_id tags: - data_quality materialized: table @@ -629,12 +629,12 @@ models: materialized: table -- name: data_quality__claim_patient_id +- name: data_quality__claim_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: claim_patient_id + alias: claim_person_id tags: - data_quality materialized: table @@ -1229,12 +1229,12 @@ models: materialized: table -- name: data_quality__pharmacy_patient_id +- name: data_quality__pharmacy_person_id config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_data_quality {% else %}data_quality{%- endif -%} - alias: pharmacy_patient_id + alias: pharmacy_person_id tags: - data_quality materialized: table diff --git a/models/data_quality/dqi/final/data_quality__raw_summary.sql b/models/data_quality/dqi/final/data_quality__raw_summary.sql index dfdbd510c..7b8e17378 100644 --- a/models/data_quality/dqi/final/data_quality__raw_summary.sql +++ b/models/data_quality/dqi/final/data_quality__raw_summary.sql @@ -7,7 +7,7 @@ with cte as ( 'input_layer' as source , 'eligibility' as table_name , count(*) as row_count - , count(distinct patient_id) as unique_check + , count(distinct person_id) as unique_check , 'Unique Patient Count' as unique_check_desc , 2 as table_order from {{ ref('eligibility') }} diff --git a/models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_patient_id.sql b/models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_person_id.sql similarity index 75% rename from models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_patient_id.sql rename to models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_person_id.sql index 94b5ac32a..2bfe0b0de 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_patient_id.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/claims/eligibility/data_quality__eligibility_person_id.sql @@ -9,9 +9,9 @@ SELECT DISTINCT ,'Member ID | Enrollment Start Date' AS drill_down_key ,coalesce(m.member_id, 'NULL') as drill_down_value ,'ELIGIBILITY' AS claim_type - ,'PATIENT_ID' AS field_name - ,case when m.patient_id is not null then 'valid' else 'null' end as bucket_name + ,'PERSON_ID' AS field_name + ,case when m.person_id is not null then 'valid' else 'null' end as bucket_name ,cast(null as {{ dbt.type_string() }}) as invalid_reason - ,cast(patient_id as {{ dbt.type_string() }}) as field_value + ,cast(person_id as {{ dbt.type_string() }}) as field_value , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('eligibility')}} m \ No newline at end of file diff --git a/models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_patient_id.sql b/models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_person_id.sql similarity index 75% rename from models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_patient_id.sql rename to models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_person_id.sql index ea438da5e..9daac2fa6 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_patient_id.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/claims/medical/data_quality__claim_person_id.sql @@ -9,9 +9,9 @@ SELECT DISTINCT -- to bring to claim_ID grain ,'Claim ID' AS drill_down_key ,coalesce(claim_id, 'NULL') AS drill_down_value ,m.claim_type as claim_type - ,'PATIENT_ID' AS field_name - ,case when m.patient_id is not null then 'valid' else 'null' end as bucket_name + ,'PERSON_ID' AS field_name + ,case when m.person_id is not null then 'valid' else 'null' end as bucket_name ,cast(null as {{ dbt.type_string() }}) as invalid_reason - ,cast(patient_id as {{ dbt.type_string() }}) as field_value + ,cast(person_id as {{ dbt.type_string() }}) as field_value , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('medical_claim')}} m \ No newline at end of file diff --git a/models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_patient_id.sql b/models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_person_id.sql similarity index 80% rename from models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_patient_id.sql rename to models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_person_id.sql index e9fd090b5..82ea1f3f5 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_patient_id.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/claims/pharmacy/data_quality__pharmacy_person_id.sql @@ -11,10 +11,10 @@ SELECT "'|'", "coalesce(cast(m.claim_line_number as " ~ dbt.type_string() ~ "), 'null')"]) }} as drill_down_value , 'PHARMACY' AS claim_type - , 'PATIENT_ID' AS field_name + , 'PERSON_ID' AS field_name , case - when m.patient_id is null then 'null' else 'valid' end as bucket_name + when m.person_id is null then 'null' else 'valid' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason - , cast(patient_id as {{ dbt.type_string() }}) as field_value + , cast(person_id as {{ dbt.type_string() }}) as field_value , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('pharmacy_claim')}} m diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_address.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_address.sql index b287d8c35..ea0c4ba30 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_address.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_address.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'ADDRESS' as field_name , case when m.address is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_birth_date.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_birth_date.sql index 963dfd1f1..c998561be 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_birth_date.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_birth_date.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'BIRTH_DATE' AS field_name , case when m.birth_date > cast(substring('{{ var('tuva_last_run') }}',1,10) as date) then 'invalid' diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_city.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_city.sql index c75ad4d7a..e36444ffe 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_city.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_city.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} ,'PATIENT' AS table_name - ,'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + ,'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value ,'CITY' AS field_name ,case when m.city is not null then 'valid' else 'null' end as bucket_name ,cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_county.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_county.sql index a7306e948..a722ec4f5 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_county.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_county.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} ,'PATIENT' AS table_name - ,'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + ,'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value ,'COUNTY' as field_name ,case when m.county is not null then 'valid' else 'null' end as bucket_name ,cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_data_source.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_data_source.sql index 96da31039..a25ea48e0 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_data_source.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_data_source.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'DATA_SOURCE' as field_name , case when m.data_source is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_date.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_date.sql index d69408dbb..aee65ec75 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_date.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_date.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'DEATH_DATE' AS field_name , case when m.death_date > cast(substring('{{ var('tuva_last_run') }}',1,10) as date) then 'invalid' diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_flag.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_flag.sql index 758fc0f6a..bf7d30661 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_flag.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_death_flag.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'DEATH_FLAG' as field_name , case when m.death_flag is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_first_name.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_first_name.sql index c43ebca0a..829971f28 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_first_name.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_first_name.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'FIRST_NAME' as field_name , case when m.first_name is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_last_name.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_last_name.sql index b357210f7..d2e23b604 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_last_name.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_last_name.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'LAST_NAME' AS field_name , case when m.last_name is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_latitude.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_latitude.sql index 7639e43e7..3bf12deea 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_latitude.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_latitude.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'LATITUDE' as field_name , case when m.latitude is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_longitude.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_longitude.sql index da0311e78..82f0a0188 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_longitude.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_longitude.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'LONGITUDE' as field_name , case when m.longitude is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_patient_id.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_patient_id.sql index 4f6590e4f..3451aaed1 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_patient_id.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_patient_id.sql @@ -11,7 +11,7 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key + , 'Person ID' as drill_down_key , coalesce(patient_id, 'NULL') AS drill_down_value , 'PATIENT_ID' as field_name , case when m.patient_id is not null then 'valid' else 'null' end as bucket_name diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_race.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_race.sql index 8de0504c3..3b89c5734 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_race.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_race.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'RACE' as field_name , case when term.description is not null then 'valid' when m.race is not null then 'invalid' diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_sex.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_sex.sql index beff549a0..324761733 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_sex.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_sex.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'SEX' as field_name , case when term.gender is not null then 'valid' when m.sex is not null then 'invalid' diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_state.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_state.sql index 265554f74..39503aab3 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_state.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_state.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'STATE' as field_name , case when m.state is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_zip_code.sql b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_zip_code.sql index da8514ebb..47b23ad02 100644 --- a/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_zip_code.sql +++ b/models/data_quality/dqi/intermediate/atomic_checks/clinical/patient/data_quality__patient_zip_code.sql @@ -11,8 +11,8 @@ SELECT , cast(coalesce({{ dbt.current_timestamp() }}, cast('1900-01-01' as date)) as date) as source_date {% endif %} , 'PATIENT' AS table_name - , 'Patient ID' as drill_down_key - , coalesce(patient_id, 'NULL') AS drill_down_value + , 'Person ID' as drill_down_key + , coalesce(person_id, 'NULL') AS drill_down_value , 'ZIP_CODE' as field_name , case when m.zip_code is not null then 'valid' else 'null' end as bucket_name , cast(null as {{ dbt.type_string() }}) as invalid_reason diff --git a/models/data_quality/dqi/intermediate/union_processing/claims/data_quality__data_quality_claims_detail.sql b/models/data_quality/dqi/intermediate/union_processing/claims/data_quality__data_quality_claims_detail.sql index 45886191b..c541212c8 100644 --- a/models/data_quality/dqi/intermediate/union_processing/claims/data_quality__data_quality_claims_detail.sql +++ b/models/data_quality/dqi/intermediate/union_processing/claims/data_quality__data_quality_claims_detail.sql @@ -272,7 +272,7 @@ SELECT , cast(invalid_reason as {{ dbt.type_string() }}) as invalid_reason , cast(field_value as {{ dbt.type_string() }}) as field_value , cast(tuva_last_run as {{ dbt.type_string() }}) as tuva_last_run - FROM {{ ref('data_quality__claim_patient_id') }} + FROM {{ ref('data_quality__claim_person_id') }} union all @@ -553,7 +553,7 @@ SELECT cast(data_source as {{ dbt.type_string() }}) as data_source , cast(invalid_reason as {{ dbt.type_string() }}) as invalid_reason , cast(field_value as {{ dbt.type_string() }}) as field_value , cast(tuva_last_run as {{ dbt.type_string() }}) as tuva_last_run - FROM {{ ref('data_quality__eligibility_patient_id') }} + FROM {{ ref('data_quality__eligibility_person_id') }} union all @@ -1303,7 +1303,7 @@ SELECT cast(data_source as {{ dbt.type_string() }}) as data_source , cast(invalid_reason as {{ dbt.type_string() }}) as invalid_reason , cast(field_value as {{ dbt.type_string() }}) as field_value , cast(tuva_last_run as {{ dbt.type_string() }}) as tuva_last_run - FROM {{ ref('data_quality__pharmacy_patient_id') }} + FROM {{ ref('data_quality__pharmacy_person_id') }} union all diff --git a/models/data_quality/dqi/mart_review/final/mart_review__claims_with_enrollment.sql b/models/data_quality/dqi/mart_review/final/mart_review__claims_with_enrollment.sql index 6f73230d5..337bd74a5 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__claims_with_enrollment.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__claims_with_enrollment.sql @@ -8,11 +8,11 @@ with enrollment_stage as( SELECT mc.data_source, mc.year_month, - SUM(CASE WHEN mm.patient_id IS NOT NULL THEN 1 ELSE 0 END) AS claims_with_enrollment, + SUM(CASE WHEN mm.person_id IS NOT NULL THEN 1 ELSE 0 END) AS claims_with_enrollment, COUNT(*) AS claims FROM {{ ref('mart_review__stg_medical_claim') }} mc LEFT JOIN {{ ref('core__member_months')}} mm - ON mc.patient_id = mm.patient_id + ON mc.person_id = mm.person_id AND mc.data_source = mm.data_source AND mc.year_month = mm.year_month GROUP BY mc.data_source diff --git a/models/data_quality/dqi/mart_review/final/mart_review__ed_classification.sql b/models/data_quality/dqi/mart_review/final/mart_review__ed_classification.sql index 993225b7a..a240b79c8 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__ed_classification.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__ed_classification.sql @@ -45,7 +45,7 @@ SELECT "e.discharge_disposition_description" ]) }} as discharge_code_and_description, {{ dbt.concat([ - "e.patient_id", + "e.person_id", "'|'", "e.data_source" ]) }} as patient_source_key, diff --git a/models/data_quality/dqi/mart_review/final/mart_review__enrollment_change.sql b/models/data_quality/dqi/mart_review/final/mart_review__enrollment_change.sql index ead44f3dd..9bdfd57c0 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__enrollment_change.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__enrollment_change.sql @@ -6,17 +6,17 @@ WITH RankedMonths AS ( SELECT - patient_id, + person_id, year_month, data_source, - lag(year_month_date, 1) over (partition by patient_id, data_source order by year_month_date) as prev_year_month, - lead(year_month_date, 1) over (partition by patient_id, data_source order by year_month_date) as next_year_month, + lag(year_month_date, 1) over (partition by person_id, data_source order by year_month_date) as prev_year_month, + lead(year_month_date, 1) over (partition by person_id, data_source order by year_month_date) as next_year_month, year_month_date FROM {{ ref('mart_review__stg_member_month') }} ), Changes AS ( SELECT - patient_id, + person_id, data_source, year_month_date as change_month, case @@ -27,7 +27,7 @@ Changes AS ( FROM RankedMonths union all SELECT - patient_id, + person_id, data_source, {{ dateadd('month', 1, 'year_month_date') }} as change_month, case @@ -40,9 +40,9 @@ FROM RankedMonths ), Final AS ( SELECT - {{ dbt.concat(["patient_id", "'|'", "change_month"]) }} as membermonthkey, + {{ dbt.concat(["person_id", "'|'", "change_month"]) }} as membermonthkey, data_source, - patient_id, + person_id, change_month, change_type FROM Changes diff --git a/models/data_quality/dqi/mart_review/final/mart_review__inpatient.sql b/models/data_quality/dqi/mart_review/final/mart_review__inpatient.sql index 431b05f59..443e23a69 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__inpatient.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__inpatient.sql @@ -13,7 +13,7 @@ with cte as ( , final as ( select e.* - , {{ dbt.concat(['e.patient_id', "'|'", 'e.data_source']) }} as patient_source_key + , {{ dbt.concat(['e.person_id', "'|'", 'e.data_source']) }} as patient_source_key , {{ dbt.concat(['e.encounter_id', "'|'", 'e.data_source']) }} as encounter_source_key , {{ dbt.concat(['e.ms_drg_code', "'|'", 'e.ms_drg_description']) }} as drgwithdescription , {{ dbt.concat(['e.primary_diagnosis_code', "'|'", 'e.primary_diagnosis_description']) }} as primary_diagnosis_and_description diff --git a/models/data_quality/dqi/mart_review/final/mart_review__member_months.sql b/models/data_quality/dqi/mart_review/final/mart_review__member_months.sql index 5ef5811f5..c338dce43 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__member_months.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__member_months.sql @@ -9,18 +9,18 @@ SELECT m.*, COALESCE(p.medical_paid, 0) AS medical_paid, COALESCE(p.pharmacy_paid, 0) AS pharmacy_paid, {{ dbt.concat([ - 'm.patient_id', + 'm.person_id', "'|'", 'm.data_source' ]) }} AS patient_data_source_key, {{ dbt.concat([ - 'm.patient_id', + 'm.person_id', "'|'", 'm.data_source', "'|'", 'm.year_month' ]) }} AS member_month_key FROM {{ ref('core__member_months')}} m -LEFT JOIN {{ ref('financial_pmpm__pmpm_prep') }} p ON m.patient_id = p.patient_id +LEFT JOIN {{ ref('financial_pmpm__pmpm_prep') }} p ON m.person_id = p.person_id AND m.data_source = p.data_source AND m.year_month = p.year_month diff --git a/models/data_quality/dqi/mart_review/final/mart_review__members_with_claims.sql b/models/data_quality/dqi/mart_review/final/mart_review__members_with_claims.sql index 47e54ead6..358653a5b 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__members_with_claims.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__members_with_claims.sql @@ -7,43 +7,43 @@ WITH medical_claim AS ( SELECT data_source, - patient_id, + person_id, year_month, SUM(paid_amount) AS paid_amount FROM {{ ref('mart_review__stg_medical_claim') }} GROUP BY data_source - , patient_id + , person_id , year_month ) ,pharmacy_claim AS ( SELECT data_source, - patient_id, + person_id, year_month, SUM(paid_amount) AS paid_amount FROM {{ ref('mart_review__stg_pharmacy_claim') }} GROUP BY data_source - , patient_id + , person_id , year_month ) , final as( SELECT mm.data_source, mm.year_month, - SUM(CASE WHEN mc.patient_id IS NOT NULL THEN 1 ELSE 0 END) AS members_with_medical_claims, - SUM(CASE WHEN pc.patient_id IS NOT NULL THEN 1 ELSE 0 END) AS members_with_pharmacy_claims, - SUM(CASE WHEN pc.patient_id IS NOT NULL THEN 1 - WHEN mc.patient_id is not null THEN 1 ELSE 0 END) AS members_with_claims, + SUM(CASE WHEN mc.person_id IS NOT NULL THEN 1 ELSE 0 END) AS members_with_medical_claims, + SUM(CASE WHEN pc.person_id IS NOT NULL THEN 1 ELSE 0 END) AS members_with_pharmacy_claims, + SUM(CASE WHEN pc.person_id IS NOT NULL THEN 1 + WHEN mc.person_id is not null THEN 1 ELSE 0 END) AS members_with_claims, COUNT(*) AS total_member_months , '{{ var('tuva_last_run')}}' as tuva_last_run FROM {{ ref('core__member_months')}} mm LEFT JOIN medical_claim mc - ON mm.patient_id = mc.patient_id + ON mm.person_id = mc.person_id AND mm.data_source = mc.data_source AND mm.year_month = mc.year_month LEFT JOIN pharmacy_claim pc - ON mm.patient_id = pc.patient_id + ON mm.person_id = pc.person_id AND mm.data_source = pc.data_source AND mm.year_month = pc.year_month GROUP BY mm.data_source, mm.year_month diff --git a/models/data_quality/dqi/mart_review/final/mart_review__number_of_conditions.sql b/models/data_quality/dqi/mart_review/final/mart_review__number_of_conditions.sql index f55ca6a55..5610820bf 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__number_of_conditions.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__number_of_conditions.sql @@ -5,24 +5,24 @@ }} with xwalk as ( - select distinct patient_id, data_source + select distinct person_id, data_source from {{ ref('core__patient')}} ), cte as ( - select l.patient_id, + select l.person_id, x.data_source, count(*) as numofconditions from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} l - left join xwalk x on l.patient_id = x.patient_id - group by l.patient_id, x.data_source + left join xwalk x on l.person_id = x.person_id + group by l.person_id, x.data_source ) -select p.patient_id, +select p.person_id, p.data_source, {{ dbt.concat([ - 'p.patient_id', + 'p.person_id', "'|'", 'p.data_source']) }} as patient_source_key, coalesce(cte.numofconditions, 0) as numofconditions , '{{ var('tuva_last_run')}}' as tuva_last_run from {{ ref('core__patient')}} p -left join cte on p.patient_id = cte.patient_id and p.data_source = cte.data_source +left join cte on p.person_id = cte.person_id and p.data_source = cte.data_source diff --git a/models/data_quality/dqi/mart_review/final/mart_review__patient.sql b/models/data_quality/dqi/mart_review/final/mart_review__patient.sql index 4ebaecf91..d55a616ae 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__patient.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__patient.sql @@ -6,7 +6,7 @@ SELECT *, {{ dbt.concat([ - 'patient_id', + 'person_id', "'|'", 'data_source']) }} as patient_data_source_key FROM {{ ref('core__patient')}} diff --git a/models/data_quality/dqi/mart_review/final/mart_review__patient_risk.sql b/models/data_quality/dqi/mart_review/final/mart_review__patient_risk.sql index 661cc4171..3a0751608 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__patient_risk.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__patient_risk.sql @@ -8,13 +8,13 @@ WITH cte AS ( SELECT payment_year, - patient_id, + person_id, model_version, patient_risk_sk, SUM(coefficient) AS risk_score FROM {{ ref('mart_review__patient_risk_factors') }} GROUP BY payment_year, - patient_id, + person_id, model_version, patient_risk_sk ) @@ -35,7 +35,7 @@ SELECT ELSE null END AS risk_score_bucket, payment_year, - patient_id, + person_id, model_version, patient_risk_sk, risk_score diff --git a/models/data_quality/dqi/mart_review/final/mart_review__patient_risk_factors.sql b/models/data_quality/dqi/mart_review/final/mart_review__patient_risk_factors.sql index 4730d31fc..8a54e967f 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__patient_risk_factors.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__patient_risk_factors.sql @@ -5,5 +5,5 @@ }} select * -,dense_rank() over (order by patient_id, model_version, payment_year ) as patient_risk_sk +,dense_rank() over (order by person_id, model_version, payment_year ) as patient_risk_sk from {{ ref('cms_hcc__patient_risk_factors') }} p \ No newline at end of file diff --git a/models/data_quality/dqi/mart_review/final/mart_review__pharmacy.sql b/models/data_quality/dqi/mart_review/final/mart_review__pharmacy.sql index b748324b7..4ee9682a5 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__pharmacy.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__pharmacy.sql @@ -6,9 +6,9 @@ select p.claim_id , p.claim_line_number - , p.patient_id + , p.person_id , p.data_source - , {{ dbt.concat(['p.patient_id', "'|'", 'p.data_source']) }} as patient_source_key + , {{ dbt.concat(['p.person_id', "'|'", 'p.data_source']) }} as patient_source_key , p.ndc_code , coalesce(n.fda_description, n.rxnorm_description) as ndc_description , p.paid_amount diff --git a/models/data_quality/dqi/mart_review/final/mart_review__service_categories_long.sql b/models/data_quality/dqi/mart_review/final/mart_review__service_categories_long.sql index d9d170bb5..a9b7918d2 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__service_categories_long.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__service_categories_long.sql @@ -5,7 +5,7 @@ with encounters as ( select cast(c.year_month_int as {{ dbt.type_string() }}) as year_month - , mc.patient_id + , mc.person_id , service_category_1 , service_category_2 , count(distinct mc.encounter_id) as visits @@ -15,7 +15,7 @@ with encounters as ( on mc.encounter_id = e.encounter_id group by cast(c.year_month_int as {{ dbt.type_string() }}) - , mc.patient_id + , mc.person_id , service_category_1 , service_category_2 ) @@ -31,7 +31,7 @@ with encounters as ( from {{ref('financial_pmpm__patient_spend_with_service_categories')}} as pmpm left join encounters on pmpm.year_month = encounters.year_month - and pmpm.patient_id = encounters.patient_id + and pmpm.person_id = encounters.person_id and pmpm.service_category_1 = encounters.service_category_1 and pmpm.service_category_2 = encounters.service_category_2 group by diff --git a/models/data_quality/dqi/mart_review/final/mart_review__tuva_chronic_conditions.sql b/models/data_quality/dqi/mart_review/final/mart_review__tuva_chronic_conditions.sql index 35f9ec45c..a6b5a3daf 100644 --- a/models/data_quality/dqi/mart_review/final/mart_review__tuva_chronic_conditions.sql +++ b/models/data_quality/dqi/mart_review/final/mart_review__tuva_chronic_conditions.sql @@ -6,41 +6,41 @@ with cte as ( select distinct - patient_id + person_id from {{ ref('chronic_conditions__tuva_chronic_conditions_long')}} ) , patientxwalk as ( select distinct - patient_id + person_id , data_source from {{ ref('core__patient')}} ) , result as ( select - l.patient_id + l.person_id , p.data_source , l.condition from {{ ref('chronic_conditions__tuva_chronic_conditions_long')}} as l inner join patientxwalk as p - on l.patient_id = p.patient_id + on l.person_id = p.person_id union all select - p.patient_id + p.person_id , p.data_source , 'No Chronic Conditions' as condition from {{ ref('core__patient')}} as p left join cte - on p.patient_id = cte.patient_id - where cte.patient_id is null + on p.person_id = cte.person_id + where cte.person_id is null ) select * , {{ dbt.concat([ - 'patient_id', + 'person_id', "'|'", 'data_source']) }} as patient_source_key , '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/data_quality/final/data_quality__data_loss.sql b/models/data_quality/final/data_quality__data_loss.sql index 5139c2c0b..a9b47b4d2 100644 --- a/models/data_quality/final/data_quality__data_loss.sql +++ b/models/data_quality/final/data_quality__data_loss.sql @@ -5,7 +5,7 @@ with input_medical as ( select cast('medical_claim' as {{ dbt.type_string() }}) as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(distinct claim_id) as claim_count , count(*) as record_count , sum(paid_amount) as paid_amount @@ -16,7 +16,7 @@ with input_medical as ( , input_pharmacy as ( select cast('pharmacy_claim' as {{ dbt.type_string() }}) as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(distinct claim_id) as claim_count , count(*) as record_count , sum(paid_amount) as paid_amount @@ -27,7 +27,7 @@ with input_medical as ( ,input_eligibility as ( select cast('eligibility' as {{ dbt.type_string() }}) as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(distinct {{ dbt.concat([ 'member_id' , "'-'" @@ -53,7 +53,7 @@ from {{ ref('eligibility') }} , core_medical as ( select cast( 'medical_claim' as {{ dbt.type_string() }}) as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(distinct claim_id) as claim_count , count(*) as record_count , sum(paid_amount) as paid_amount @@ -64,7 +64,7 @@ from {{ ref('eligibility') }} , core_pharmacy as ( select cast( 'pharmacy_claim' as {{ dbt.type_string() }}) as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(distinct claim_id) as claim_count , count(*) as record_count , sum(paid_amount) as paid_amount @@ -75,7 +75,7 @@ from {{ ref('eligibility') }} , core_eligibility as ( select cast('eligibility' as {{ dbt.type_string() }})as table_name - , count(distinct patient_id) as patient_count + , count(distinct person_id) as patient_count , count(*) as span_count from {{ ref('core__eligibility') }} ) diff --git a/models/data_quality/final/data_quality__data_quality_test_summary.sql b/models/data_quality/final/data_quality__data_quality_test_summary.sql index 9d71a93a9..ff03be3f4 100644 --- a/models/data_quality/final/data_quality__data_quality_test_summary.sql +++ b/models/data_quality/final/data_quality__data_quality_test_summary.sql @@ -10,17 +10,17 @@ with unioned_data as ( ref('data_quality__medical_claim_claim_line_fields') , ref('data_quality__medical_claim_date_checks') , ref('data_quality__medical_claim_inst_header_fields') - , ref('data_quality__medical_claim_patient_id') + , ref('data_quality__medical_claim_person_id') , ref('data_quality__medical_claim_provider_npi') , ref('data_quality__pharmacy_claim_date_checks') , ref('data_quality__pharmacy_claim_ndc') , ref('data_quality__pharmacy_claim_npi') , ref('data_quality__pharmacy_claim_prescription_details') - , ref('data_quality__pharmacy_claim_patient_id') + , ref('data_quality__pharmacy_claim_person_id') , ref('data_quality__primary_key_check') , ref('data_quality__eligibility_date_checks') , ref('data_quality__eligibility_demographics') - , ref('data_quality__eligibility_missing_patient_id') + , ref('data_quality__eligibility_missing_person_id') , ref('data_quality__eligibility_missing_payer') ], exclude=["_loaded_at"] diff --git a/models/data_quality/intermediate/data_quality__chronic_conditions_none.sql b/models/data_quality/intermediate/data_quality__chronic_conditions_none.sql index fe1b6f1a8..33b2f2f37 100644 --- a/models/data_quality/intermediate/data_quality__chronic_conditions_none.sql +++ b/models/data_quality/intermediate/data_quality__chronic_conditions_none.sql @@ -4,17 +4,17 @@ with chronic_conditions as ( - select distinct patient_id + select distinct person_id from {{ ref('chronic_conditions__cms_chronic_conditions_long') }} ) ,results as ( select cast('Percent of patients without chronic conditions' as {{dbt.type_string()}}) as data_quality_check - , sum(case when cccw.patient_id is null then 1 else 0 end) / count(distinct e.patient_id) * 100 as result_count + , sum(case when cccw.person_id is null then 1 else 0 end) / count(distinct e.person_id) * 100 as result_count from {{ ref('core__patient') }} e left join chronic_conditions cccw - on e.patient_id = cccw.patient_id + on e.person_id = cccw.person_id ) select diff --git a/models/data_quality/intermediate/data_quality__chronic_conditions_prevalence.sql b/models/data_quality/intermediate/data_quality__chronic_conditions_prevalence.sql index 88a24942e..f1fbb9ebc 100644 --- a/models/data_quality/intermediate/data_quality__chronic_conditions_prevalence.sql +++ b/models/data_quality/intermediate/data_quality__chronic_conditions_prevalence.sql @@ -5,13 +5,13 @@ with condition_counts as ( select condition - , count(distinct patient_id) as patients + , count(distinct person_id) as patients from {{ ref('chronic_conditions__tuva_chronic_conditions_long') }} group by condition ) , total_patients as ( select - count(distinct patient_id) as total_distinct_patients + count(distinct person_id) as total_distinct_patients from {{ ref('core__eligibility') }} ) diff --git a/models/data_quality/intermediate/data_quality__dx_and_px.sql b/models/data_quality/intermediate/data_quality__dx_and_px.sql index e5379ec76..b0bc6ad77 100644 --- a/models/data_quality/intermediate/data_quality__dx_and_px.sql +++ b/models/data_quality/intermediate/data_quality__dx_and_px.sql @@ -12,7 +12,7 @@ with unpivot_diagnosis as( value_name='diagnosis_code', remove=[ 'claim_line_number' , 'claim_type' - , 'patient_id' + , 'person_id' , 'member_id' , 'payer' , 'plan' @@ -141,7 +141,7 @@ with unpivot_diagnosis as( value_name='procedure_code', remove=[ 'claim_line_number' , 'claim_type' - , 'patient_id' + , 'person_id' , 'member_id' , 'payer' , 'plan' diff --git a/models/data_quality/intermediate/data_quality__eligibility_demographics.sql b/models/data_quality/intermediate/data_quality__eligibility_demographics.sql index e8e1f4c0e..5347374dc 100644 --- a/models/data_quality/intermediate/data_quality__eligibility_demographics.sql +++ b/models/data_quality/intermediate/data_quality__eligibility_demographics.sql @@ -18,7 +18,7 @@ with eligibility_spans as( "'-'", quote_column('plan'), ]) }} as eligibility_span_id - , patient_id + , person_id , birth_date , gender from {{ ref('eligibility') }} @@ -66,12 +66,12 @@ with eligibility_spans as( , multiple_birth_date as( select 'Patient has multiple birthdays' as data_quality_check - , count(distinct patient_id) as result_count + , count(distinct person_id) as result_count from( select - patient_id + person_id , birth_date - , rank() over (partition by patient_id, birth_date order by birth_date) as rank_birth_date + , rank() over (partition by person_id, birth_date order by birth_date) as rank_birth_date from eligibility_spans e where birth_date is not null )x diff --git a/models/data_quality/intermediate/data_quality__eligibility_missing_patient_id.sql b/models/data_quality/intermediate/data_quality__eligibility_missing_person_id.sql similarity index 84% rename from models/data_quality/intermediate/data_quality__eligibility_missing_patient_id.sql rename to models/data_quality/intermediate/data_quality__eligibility_missing_person_id.sql index 5eb69fc63..5e4114506 100644 --- a/models/data_quality/intermediate/data_quality__eligibility_missing_patient_id.sql +++ b/models/data_quality/intermediate/data_quality__eligibility_missing_person_id.sql @@ -18,14 +18,14 @@ with eligibility_spans as( "'-'", quote_column('plan'), ]) }} as eligibility_span_id - , patient_id + , person_id from {{ ref('eligibility') }} ) select - 'Missing patient_id' as data_quality_check + 'Missing person_id' as data_quality_check ,count(*) as result_count , '{{ var('tuva_last_run')}}' as tuva_last_run from eligibility_spans where - patient_id is null or patient_id = '' \ No newline at end of file + person_id is null or person_id = '' \ No newline at end of file diff --git a/models/data_quality/intermediate/data_quality__medical_claim_patient_id.sql b/models/data_quality/intermediate/data_quality__medical_claim_person_id.sql similarity index 68% rename from models/data_quality/intermediate/data_quality__medical_claim_patient_id.sql rename to models/data_quality/intermediate/data_quality__medical_claim_person_id.sql index 0e9af62e8..e171cbe5d 100644 --- a/models/data_quality/intermediate/data_quality__medical_claim_patient_id.sql +++ b/models/data_quality/intermediate/data_quality__medical_claim_person_id.sql @@ -5,8 +5,8 @@ with medical as ( select claim_id - , count(distinct p.patient_id) as patient_id_count - , max(case when p.patient_id is null then 1 else 0 end) as missing_patient_id + , count(distinct p.person_id) as person_id_count + , max(case when p.person_id is null then 1 else 0 end) as missing_person_id , max( case when startdts.month_start_date is null then 1 @@ -16,10 +16,10 @@ with medical as ( ) as missing_eligibility from {{ ref('medical_claim') }} p left join {{ ref('data_quality__eligibility_dq_stage') }} startdts - on p.patient_id = startdts.patient_id + on p.person_id = startdts.person_id and p.claim_start_date between startdts.month_start_date and startdts.month_end_date left join {{ ref('data_quality__eligibility_dq_stage') }} enddts - on p.patient_id = enddts.patient_id + on p.person_id = enddts.person_id and p.claim_end_date between enddts.month_start_date and enddts.month_end_date group by claim_id @@ -27,15 +27,15 @@ with medical as ( , final as ( select - 'multiple medical_claim patient_ids' as data_quality_check - , sum(case when patient_id_count > 1 then 1 else 0 end) as result_count + 'multiple medical_claim person_ids' as data_quality_check + , sum(case when person_id_count > 1 then 1 else 0 end) as result_count from medical union all select - 'missing medical_claim patient_id' as data_quality_check - , sum(missing_patient_id) as result_count + 'missing medical_claim person_id' as data_quality_check + , sum(missing_person_id) as result_count from medical union all diff --git a/models/data_quality/intermediate/data_quality__pharmacy_claim_patient_id.sql b/models/data_quality/intermediate/data_quality__pharmacy_claim_person_id.sql similarity index 64% rename from models/data_quality/intermediate/data_quality__pharmacy_claim_patient_id.sql rename to models/data_quality/intermediate/data_quality__pharmacy_claim_person_id.sql index 55400ed2f..efc28b8f9 100644 --- a/models/data_quality/intermediate/data_quality__pharmacy_claim_patient_id.sql +++ b/models/data_quality/intermediate/data_quality__pharmacy_claim_person_id.sql @@ -5,12 +5,12 @@ with pharmacy as ( select claim_id - , count(distinct p.patient_id) as patient_id_count - , max(case when p.patient_id is null then 1 else 0 end) as missing_patient_id + , count(distinct p.person_id) as person_id_count + , max(case when p.person_id is null then 1 else 0 end) as missing_person_id , max(case when e.month_start_date is null then 1 else 0 end) as missing_eligibility from {{ ref('pharmacy_claim') }} p left join {{ ref('data_quality__eligibility_dq_stage') }} e - on p.patient_id = e.patient_id + on p.person_id = e.person_id and coalesce(p.paid_date, p.dispensing_date) between e.month_start_date and e.month_end_date group by claim_id @@ -18,15 +18,15 @@ with pharmacy as ( , final as ( select - 'multiple pharmacy_claim patient_ids' as data_quality_check - , sum(case when patient_id_count > 1 then 1 else 0 end) as result_count + 'multiple pharmacy_claim person_ids' as data_quality_check + , sum(case when person_id_count > 1 then 1 else 0 end) as result_count from pharmacy union all select - 'missing pharmacy_claim patient_id' as data_quality_check - , sum(missing_patient_id) as result_count + 'missing pharmacy_claim person_id' as data_quality_check + , sum(missing_person_id) as result_count from pharmacy union all diff --git a/models/data_quality/intermediate/data_quality__primary_key_check.sql b/models/data_quality/intermediate/data_quality__primary_key_check.sql index 16760e737..a7e527d51 100644 --- a/models/data_quality/intermediate/data_quality__primary_key_check.sql +++ b/models/data_quality/intermediate/data_quality__primary_key_check.sql @@ -32,7 +32,7 @@ with pharmacy as ( , eligibility as ( select - patient_id + person_id , enrollment_start_date , enrollment_end_date , {{ quote_column('plan') }} @@ -40,7 +40,7 @@ with pharmacy as ( , count(*) as result_count from {{ ref('eligibility') }} p group by - patient_id + person_id , enrollment_start_date , enrollment_end_date , {{ quote_column('plan') }} diff --git a/models/data_quality/intermediate/data_quality__readmissions.sql b/models/data_quality/intermediate/data_quality__readmissions.sql index 7261996cd..71fac01c7 100644 --- a/models/data_quality/intermediate/data_quality__readmissions.sql +++ b/models/data_quality/intermediate/data_quality__readmissions.sql @@ -12,7 +12,7 @@ with disqualified_unpivot as ( value_name='flagvalue', remove=[ 'encounter_id', - 'patient_id', + 'person_id', 'admit_date', 'discharge_date', 'discharge_disposition_code', diff --git a/models/data_quality/stage/data_quality__eligibility_dq_stage.sql b/models/data_quality/stage/data_quality__eligibility_dq_stage.sql index 9e5c97f3a..7dc653f4c 100644 --- a/models/data_quality/stage/data_quality__eligibility_dq_stage.sql +++ b/models/data_quality/stage/data_quality__eligibility_dq_stage.sql @@ -13,7 +13,7 @@ with month_start_and_end_dates as ( ) select distinct - a.patient_id + a.person_id , b.year_month , b.month_start_date , b.month_end_date diff --git a/models/ed_classification/ed_classification_models.yml b/models/ed_classification/ed_classification_models.yml index cf3d2804f..4ce1836c0 100644 --- a/models/ed_classification/ed_classification_models.yml +++ b/models/ed_classification/ed_classification_models.yml @@ -25,7 +25,7 @@ models: description: The order of the classification. meta: terminology: https://github.com/tuva-health/tuva/blob/main/seeds/value_sets/ed_classification/ed_classification__categories.csv - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: encounter_end_date description: Date when the patient was discharged. diff --git a/models/ed_classification/final/ed_classification__summary.sql b/models/ed_classification/final/ed_classification__summary.sql index 49437ed6a..35d278087 100644 --- a/models/ed_classification/final/ed_classification__summary.sql +++ b/models/ed_classification/final/ed_classification__summary.sql @@ -8,7 +8,7 @@ select class.encounter_id , cat.classification_name as ed_classification_description , cat.classification_order as ed_classification_order - , class.patient_id + , class.person_id , class.encounter_end_date , {{ dbt.concat([date_part('year', 'class.encounter_end_date'), dbt.right( @@ -36,4 +36,4 @@ inner join {{ ref('ed_classification__categories') }} cat left join {{ ref('terminology__provider') }} fac_prov on class.facility_id = fac_prov.npi left join {{ ref('ed_classification__stg_patient') }} pat - on class.patient_id = pat.patient_id + on class.person_id = pat.person_id diff --git a/models/ed_classification/staging/ed_classification__stg_encounter.sql b/models/ed_classification/staging/ed_classification__stg_encounter.sql index 9fb106d37..918945054 100644 --- a/models/ed_classification/staging/ed_classification__stg_encounter.sql +++ b/models/ed_classification/staging/ed_classification__stg_encounter.sql @@ -7,7 +7,7 @@ select encounter_id , encounter_type - , patient_id + , person_id , encounter_end_date , facility_id , primary_diagnosis_code_type diff --git a/models/ed_classification/staging/ed_classification__stg_patient.sql b/models/ed_classification/staging/ed_classification__stg_patient.sql index 37aa7b0d7..460c68c42 100644 --- a/models/ed_classification/staging/ed_classification__stg_patient.sql +++ b/models/ed_classification/staging/ed_classification__stg_patient.sql @@ -1,15 +1,16 @@ -{{ config( - enabled = var('ed_classification_enabled',var('claims_enabled',var('tuva_marts_enabled',False))) | as_bool - ) -}} - -select - patient_id - , sex - , birth_date - , race - , state - , zip_code - , latitude - , longitude +{{ config( + enabled = var('ed_classification_enabled',var('claims_enabled',var('tuva_marts_enabled',False))) + | as_bool + ) +}} + +select + person_id + , sex + , birth_date + , race + , state + , zip_code + , latitude + , longitude from {{ ref('core__patient') }} \ No newline at end of file diff --git a/models/financial_pmpm/final/financial_pmpm__pmpm_prep.sql b/models/financial_pmpm/final/financial_pmpm__pmpm_prep.sql index e051b9c2e..290a3fd88 100644 --- a/models/financial_pmpm/final/financial_pmpm__pmpm_prep.sql +++ b/models/financial_pmpm/final/financial_pmpm__pmpm_prep.sql @@ -5,7 +5,7 @@ with combine as ( select - a.patient_id + a.person_id , a.year_month , a.payer , a.{{ quote_column('plan') }} @@ -99,22 +99,22 @@ with combine as ( from {{ ref('core__member_months') }} as a left join {{ ref('financial_pmpm__service_category_1_paid_pivot') }} as b - on a.patient_id = b.patient_id + on a.person_id = b.person_id and a.year_month = b.year_month and a.payer = b.payer and a.{{ quote_column('plan') }} = b.{{ quote_column('plan') }} left join {{ ref('financial_pmpm__service_category_2_paid_pivot') }} as c - on a.patient_id = c.patient_id + on a.person_id = c.person_id and a.year_month = c.year_month and a.payer = c.payer and a.{{ quote_column('plan') }} = c.{{ quote_column('plan') }} left join {{ ref('financial_pmpm__service_category_1_allowed_pivot') }} as d - on a.patient_id = d.patient_id + on a.person_id = d.person_id and a.year_month = d.year_month and a.payer = d.payer and a.{{ quote_column('plan') }} = d.{{ quote_column('plan') }} left join {{ ref('financial_pmpm__service_category_2_allowed_pivot') }} as e - on a.patient_id = e.patient_id + on a.person_id = e.person_id and a.year_month = e.year_month and a.payer = e.payer and a.{{ quote_column('plan') }} = e.{{ quote_column('plan') }} diff --git a/models/financial_pmpm/financial_pmpm_models.yml b/models/financial_pmpm/financial_pmpm_models.yml index ba8e2c8b4..d1148d23c 100644 --- a/models/financial_pmpm/financial_pmpm_models.yml +++ b/models/financial_pmpm/financial_pmpm_models.yml @@ -15,13 +15,13 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - patient_id + - person_id - year_month - "{{ quote_column('plan') }}" description: > - Computes all the paid and allowed statistics for every patient_id and year_month combination. + Computes all the paid and allowed statistics for every person_id and year_month combination. columns: - - name: patient_id + - name: person_id description: Unique identifier for each patient in the dataset. - name: year_month description: Unique year-month of in the dataset computed from eligibility. diff --git a/models/financial_pmpm/intermediate/financial_pmpm__patient_spend_with_service_categories.sql b/models/financial_pmpm/intermediate/financial_pmpm__patient_spend_with_service_categories.sql index b30414def..f9ddb6937 100644 --- a/models/financial_pmpm/intermediate/financial_pmpm__patient_spend_with_service_categories.sql +++ b/models/financial_pmpm/intermediate/financial_pmpm__patient_spend_with_service_categories.sql @@ -5,7 +5,7 @@ with claims_with_service_categories as ( select - patient_id + person_id , payer , {{ quote_column('plan') }} , service_category_1 @@ -19,7 +19,7 @@ with claims_with_service_categories as ( , medical_claims_year_month as ( select - patient_id + person_id , payer , {{ quote_column('plan') }} , service_category_1 @@ -36,7 +36,7 @@ with claims_with_service_categories as ( , rx_claims as ( select - patient_id + person_id , payer , {{ quote_column('plan') }} , 'pharmacy' as service_category_1 @@ -50,7 +50,7 @@ with claims_with_service_categories as ( , rx_claims_year_month as ( select - patient_id + person_id , payer , {{ quote_column('plan') }} , service_category_1 @@ -76,7 +76,7 @@ from rx_claims_year_month ) select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -88,7 +88,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from combine_medical_and_rx group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_allowed_pivot.sql b/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_allowed_pivot.sql index c0863103d..d367a007b 100644 --- a/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_allowed_pivot.sql +++ b/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_allowed_pivot.sql @@ -5,7 +5,7 @@ with service_cat_1 as ( select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -14,7 +14,7 @@ with service_cat_1 as ( , sum(total_allowed) as total_allowed from {{ ref('financial_pmpm__patient_spend_with_service_categories') }} group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -23,7 +23,7 @@ with service_cat_1 as ( ) select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -40,7 +40,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from service_cat_1 group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_paid_pivot.sql b/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_paid_pivot.sql index b0d2ec7de..cf89832e7 100644 --- a/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_paid_pivot.sql +++ b/models/financial_pmpm/intermediate/financial_pmpm__service_category_1_paid_pivot.sql @@ -5,7 +5,7 @@ with service_cat_1 as ( select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -14,7 +14,7 @@ with service_cat_1 as ( , sum(total_paid) as total_paid from {{ ref('financial_pmpm__patient_spend_with_service_categories') }} group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -23,7 +23,7 @@ with service_cat_1 as ( ) select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -40,7 +40,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from service_cat_1 group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_allowed_pivot.sql b/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_allowed_pivot.sql index 0cd87141d..d18e8ab72 100644 --- a/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_allowed_pivot.sql +++ b/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_allowed_pivot.sql @@ -5,7 +5,7 @@ with service_cat_2 as ( select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -14,7 +14,7 @@ with service_cat_2 as ( , sum(total_allowed) as total_allowed from {{ ref('financial_pmpm__patient_spend_with_service_categories') }} group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -23,7 +23,7 @@ with service_cat_2 as ( ) select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -70,7 +70,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from service_cat_2 group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_paid_pivot.sql b/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_paid_pivot.sql index f176ef89c..31a35c56a 100644 --- a/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_paid_pivot.sql +++ b/models/financial_pmpm/intermediate/financial_pmpm__service_category_2_paid_pivot.sql @@ -5,7 +5,7 @@ with service_cat_2 as ( select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -14,7 +14,7 @@ with service_cat_2 as ( , sum(total_paid) as total_paid from {{ ref('financial_pmpm__patient_spend_with_service_categories') }} group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -23,7 +23,7 @@ with service_cat_2 as ( ) select - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} @@ -70,7 +70,7 @@ select , '{{ var('tuva_last_run')}}' as tuva_last_run from service_cat_2 group by - patient_id + person_id , year_month , payer , {{ quote_column('plan') }} diff --git a/models/financial_pmpm/staging/financial_pmpm__stg_eligibility.sql b/models/financial_pmpm/staging/financial_pmpm__stg_eligibility.sql index 9f1b3c023..e0b70b5e3 100644 --- a/models/financial_pmpm/staging/financial_pmpm__stg_eligibility.sql +++ b/models/financial_pmpm/staging/financial_pmpm__stg_eligibility.sql @@ -4,7 +4,7 @@ }} select - patient_id + person_id , enrollment_start_date , enrollment_end_date , payer diff --git a/models/financial_pmpm/staging/financial_pmpm__stg_medical_claim.sql b/models/financial_pmpm/staging/financial_pmpm__stg_medical_claim.sql index d561f893d..5fa6f968b 100644 --- a/models/financial_pmpm/staging/financial_pmpm__stg_medical_claim.sql +++ b/models/financial_pmpm/staging/financial_pmpm__stg_medical_claim.sql @@ -5,7 +5,7 @@ SELECT - patient_id + person_id , claim_id , claim_line_number , claim_start_date diff --git a/models/financial_pmpm/staging/financial_pmpm__stg_pharmacy_claim.sql b/models/financial_pmpm/staging/financial_pmpm__stg_pharmacy_claim.sql index 1a3d26dfc..198f3f943 100644 --- a/models/financial_pmpm/staging/financial_pmpm__stg_pharmacy_claim.sql +++ b/models/financial_pmpm/staging/financial_pmpm__stg_pharmacy_claim.sql @@ -5,7 +5,7 @@ SELECT - patient_id + person_id , dispensing_date , paid_date , paid_amount diff --git a/models/financial_pmpm/staging/financial_pmpm__stg_provider_attribution.sql b/models/financial_pmpm/staging/financial_pmpm__stg_provider_attribution.sql index 83b12d30a..25b45ab4b 100644 --- a/models/financial_pmpm/staging/financial_pmpm__stg_provider_attribution.sql +++ b/models/financial_pmpm/staging/financial_pmpm__stg_provider_attribution.sql @@ -6,7 +6,7 @@ {% if var('provider_attribution_enabled',False) == true -%} select - cast(patient_id as {{ dbt.type_string() }} ) as patient_id + cast(person_id as {{ dbt.type_string() }} ) as person_id , cast(year_month as {{ dbt.type_string() }} ) as year_month , cast(payer as {{ dbt.type_string() }} ) as payer , {{ quote_column('plan') }} @@ -26,7 +26,7 @@ from {{ ref('provider_attribution') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) patient_id + cast(null as {{ dbt.type_string() }} ) person_id , cast(null as {{ dbt.type_string() }} ) as year_month , cast(null as {{ dbt.type_string() }} ) as payer , cast(null as {{ dbt.type_string() }} ) as {{ quote_column('plan') }} @@ -42,7 +42,7 @@ select top 0 , cast(null as {{ dbt.type_string() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) patient_id + cast(null as {{ dbt.type_string() }} ) person_id , cast(null as {{ dbt.type_string() }} ) as year_month , cast(null as {{ dbt.type_string() }} ) as payer , cast(null as {{ dbt.type_string() }} ) as {{ quote_column('plan') }} diff --git a/models/hcc_suspecting/final/hcc_suspecting__list.sql b/models/hcc_suspecting/final/hcc_suspecting__list.sql index f903c0562..66e677a38 100644 --- a/models/hcc_suspecting/final/hcc_suspecting__list.sql +++ b/models/hcc_suspecting/final/hcc_suspecting__list.sql @@ -6,7 +6,7 @@ with hcc_history_suspects as ( select distinct - patient_id + person_id , data_source , hcc_code , hcc_description @@ -27,7 +27,7 @@ with hcc_history_suspects as ( , comorbidity_suspects as ( select distinct - patient_id + person_id , data_source , hcc_code , hcc_description @@ -48,7 +48,7 @@ with hcc_history_suspects as ( , observation_suspects as ( select distinct - patient_id + person_id , data_source , hcc_code , hcc_description @@ -69,7 +69,7 @@ with hcc_history_suspects as ( , lab_suspects as ( select distinct - patient_id + person_id , data_source , hcc_code , hcc_description @@ -90,7 +90,7 @@ with hcc_history_suspects as ( , medication_suspects as ( select distinct - patient_id + person_id , data_source , hcc_code , hcc_description @@ -125,7 +125,7 @@ with hcc_history_suspects as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_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 @@ -137,7 +137,7 @@ with hcc_history_suspects as ( ) select - patient_id + person_id , data_source , hcc_code , hcc_description diff --git a/models/hcc_suspecting/final/hcc_suspecting__list_rollup.sql b/models/hcc_suspecting/final/hcc_suspecting__list_rollup.sql index be6ab4c9e..fc5d5a44f 100644 --- a/models/hcc_suspecting/final/hcc_suspecting__list_rollup.sql +++ b/models/hcc_suspecting/final/hcc_suspecting__list_rollup.sql @@ -6,7 +6,7 @@ with list as ( select - patient_id + person_id , data_source , hcc_code , hcc_description @@ -15,7 +15,7 @@ with list as ( , suspect_date , row_number() over ( partition by - patient_id + person_id , hcc_code order by suspect_date desc ) as row_num @@ -26,7 +26,7 @@ with list as ( , list_dedupe as ( select - patient_id + person_id , hcc_code , hcc_description , reason @@ -40,7 +40,7 @@ with list as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_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 @@ -51,7 +51,7 @@ with list as ( ) select - patient_id + person_id , hcc_code , hcc_description , reason diff --git a/models/hcc_suspecting/final/hcc_suspecting__summary.sql b/models/hcc_suspecting/final/hcc_suspecting__summary.sql index c6841c60e..ca6806134 100644 --- a/models/hcc_suspecting/final/hcc_suspecting__summary.sql +++ b/models/hcc_suspecting/final/hcc_suspecting__summary.sql @@ -6,7 +6,7 @@ with patients as ( select - patient_id + person_id , sex , birth_date {% if target.type == 'fabric' %} @@ -22,31 +22,31 @@ with patients as ( , suspecting_list as ( select - patient_id + person_id , count(*) as gaps from {{ ref('hcc_suspecting__list') }} - group by patient_id + group by person_id ) , joined as ( select - patients.patient_id + patients.person_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 + on patients.person_id = suspecting_list.person_id ) , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_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 @@ -56,7 +56,7 @@ with patients as ( ) select - patient_id + person_id , patient_sex , patient_birth_date , patient_age diff --git a/models/hcc_suspecting/hcc_suspecting_models.yml b/models/hcc_suspecting/hcc_suspecting_models.yml index 363ae4808..d5bc74f9d 100644 --- a/models/hcc_suspecting/hcc_suspecting_models.yml +++ b/models/hcc_suspecting/hcc_suspecting_models.yml @@ -14,7 +14,7 @@ models: data_source, hcc, and diagnosis code with the reason and contributing factors. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -51,7 +51,7 @@ models: This final model displays the list of suspecting conditions per patient and hcc with the latest contributing factor rolled up. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: hcc_code description: > @@ -83,7 +83,7 @@ models: description: > This final model displays a rollup of suspecting conditions per patient. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: patient_sex description: The gender of the patient. @@ -108,7 +108,7 @@ models: materialized: table description: All historical conditions mapped to HCCs. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: recorded_date description: Date in which the condition was recorded. @@ -138,7 +138,7 @@ models: materialized: table description: Union of medications and pharmacy claims. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: dispensing_date description: Date the medication was dispensed or paid date. @@ -162,7 +162,7 @@ models: materialized: table description: Suspecting comorbidities. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -211,7 +211,7 @@ models: materialized: table description: Suspecting conditions based on labs. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -255,7 +255,7 @@ models: materialized: table description: Suspecting conditions based on medications. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -297,7 +297,7 @@ models: materialized: table description: Suspecting observation conditions. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -347,7 +347,7 @@ models: 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 + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -401,7 +401,7 @@ models: materialized: table description: Preparing conditions; mapping snomed-ct conditions to icd-10-cm. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: recorded_date description: Date in which the condition was recorded. @@ -430,7 +430,7 @@ models: materialized: table description: Preparing eGFR labs with clean numeric results. columns: - - name: patient_id + - name: person_id description: Unique ID for the patient. - name: data_source description: > @@ -458,7 +458,7 @@ models: description: Staging conditions from core. columns: - name: claim_id - - name: patient_id + - name: person_id - name: recorded_date - name: condition_type - name: code_type @@ -475,7 +475,7 @@ models: description: Staging conditions from core. columns: - name: lab_result_id - - name: patient_id + - name: person_id - name: code_type - name: code - name: status @@ -492,7 +492,7 @@ models: materialized: ephemeral description: Staging medications from core. columns: - - name: patient_id + - name: person_id - name: dispensing_date - name: source_code - name: source_code_type @@ -509,7 +509,7 @@ models: materialized: ephemeral description: Staging observations from core. columns: - - name: patient_id + - name: person_id - name: observation_date - name: result - name: code_type @@ -525,7 +525,7 @@ models: materialized: ephemeral description: Staging patients from core. columns: - - name: patient_id + - name: person_id - name: sex - name: birth_date - name: death_date @@ -539,7 +539,7 @@ models: materialized: ephemeral description: Staging pharmacy claims from core. columns: - - name: patient_id + - name: person_id - name: dispensing_date - name: ndc_code - name: paid_date diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_conditions.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_conditions.sql index f9d2228d0..c753a6c37 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_conditions.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_conditions.sql @@ -6,7 +6,7 @@ with conditions as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -38,7 +38,7 @@ with conditions as ( , joined as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code @@ -57,7 +57,7 @@ with conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(recorded_date as date) as recorded_date , cast(condition_type as {{ dbt.type_string() }}) as condition_type , cast(code as {{ dbt.type_string() }}) as icd_10_cm_code @@ -69,7 +69,7 @@ with conditions as ( ) select - patient_id + person_id , recorded_date , condition_type , icd_10_cm_code diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_medications.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_medications.sql index 8600fff05..169e9f718 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_medications.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_all_medications.sql @@ -6,7 +6,7 @@ with medications as ( select - patient_id + person_id , dispensing_date , source_code , source_code_type @@ -20,7 +20,7 @@ with medications as ( , pharmacy_claims as ( select - patient_id + person_id , coalesce(dispensing_date, paid_date) as dispensing_date , ndc_code as drug_code , 'ndc' as code_system @@ -32,7 +32,7 @@ with medications as ( , ndc_medications as ( select - patient_id + person_id , dispensing_date , ndc_code as drug_code , 'ndc' as code_system @@ -43,7 +43,7 @@ with medications as ( union all select - patient_id + person_id , dispensing_date , source_code as drug_code , 'ndc' as code_system @@ -56,7 +56,7 @@ with medications as ( , rxnorm_medications as ( select - patient_id + person_id , dispensing_date , rxnorm_code as drug_code , 'rxnorm' as code_system @@ -67,7 +67,7 @@ with medications as ( union all select - patient_id + person_id , dispensing_date , source_code as drug_code , 'rxnorm' as code_system @@ -90,7 +90,7 @@ with medications as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(dispensing_date as date) as dispensing_date , cast(drug_code as {{ dbt.type_string() }}) as drug_code , cast(code_system as {{ dbt.type_string() }}) as code_system @@ -100,7 +100,7 @@ with medications as ( ) select - patient_id + person_id , dispensing_date , drug_code , code_system diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_comorbidity_suspects.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_comorbidity_suspects.sql index 29b14888a..440c3374a 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_comorbidity_suspects.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_comorbidity_suspects.sql @@ -6,7 +6,7 @@ with conditions as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -38,7 +38,7 @@ with conditions as ( , billed_hccs as ( select distinct - patient_id + person_id , data_source , hcc_code , current_year_billed @@ -50,7 +50,7 @@ with conditions as ( , ckd_stage_1_or_2 as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code_type @@ -59,7 +59,7 @@ with conditions as ( , seed_clinical_concepts.concept_name , row_number() over ( partition by - conditions.patient_id + conditions.person_id , conditions.data_source order by conditions.recorded_date desc @@ -79,7 +79,7 @@ with conditions as ( , ckd_stage_1_or_2_dedupe as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -94,7 +94,7 @@ with conditions as ( , diabetes as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code_type @@ -103,7 +103,7 @@ with conditions as ( , seed_clinical_concepts.concept_name , row_number() over ( partition by - conditions.patient_id + conditions.person_id , conditions.data_source order by conditions.recorded_date desc @@ -119,7 +119,7 @@ with conditions as ( , diabetes_dedupe as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -134,7 +134,7 @@ with conditions as ( , hcc_37_suspect as ( select - diabetes_dedupe.patient_id + diabetes_dedupe.person_id , diabetes_dedupe.data_source , seed_hcc_descriptions.hcc_code , seed_hcc_descriptions.hcc_description @@ -146,7 +146,7 @@ with conditions as ( , ckd_stage_1_or_2_dedupe.recorded_date as condition_2_recorded_date from diabetes_dedupe inner join ckd_stage_1_or_2_dedupe - on diabetes_dedupe.patient_id = ckd_stage_1_or_2_dedupe.patient_id + on diabetes_dedupe.person_id = ckd_stage_1_or_2_dedupe.person_id and diabetes_dedupe.data_source = ckd_stage_1_or_2_dedupe.data_source /* ensure conditions overlap in the same year */ and {{ date_part('year', 'diabetes_dedupe.recorded_date') }} = {{ date_part('year', 'ckd_stage_1_or_2_dedupe.recorded_date') }} @@ -165,7 +165,7 @@ with conditions as ( , add_billed_flag as ( select - unioned.patient_id + unioned.person_id , unioned.data_source , unioned.hcc_code , unioned.hcc_description @@ -178,7 +178,7 @@ with conditions as ( , billed_hccs.current_year_billed from unioned left join billed_hccs - on unioned.patient_id = billed_hccs.patient_id + on unioned.person_id = billed_hccs.person_id and unioned.data_source = billed_hccs.data_source and unioned.hcc_code = billed_hccs.hcc_code @@ -187,7 +187,7 @@ with conditions as ( , add_standard_fields as ( select - patient_id + person_id , data_source , hcc_code , hcc_description @@ -221,7 +221,7 @@ with conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_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 @@ -244,7 +244,7 @@ with conditions as ( ) select - patient_id + person_id , data_source , hcc_code , hcc_description diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_lab_suspects.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_lab_suspects.sql index f524c90fa..68db5721d 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_lab_suspects.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_lab_suspects.sql @@ -6,7 +6,7 @@ with egfr_labs as ( select - patient_id + person_id , data_source , code_type , code @@ -28,7 +28,7 @@ with egfr_labs as ( , billed_hccs as ( select distinct - patient_id + person_id , data_source , hcc_code , current_year_billed @@ -45,12 +45,12 @@ with egfr_labs as ( , max_lab_date as ( select - patient_id + person_id , data_source , max(result_date) as max_result_date from egfr_labs group by - patient_id + person_id , data_source ) @@ -58,17 +58,17 @@ with egfr_labs as ( , lab_lookback as ( select - egfr_labs.patient_id + egfr_labs.person_id , egfr_labs.data_source , max_lab_date.max_result_date , max(egfr_labs.result_date) as lookback_result_date from egfr_labs left join max_lab_date - on egfr_labs.patient_id = max_lab_date.patient_id + on egfr_labs.person_id = max_lab_date.person_id and egfr_labs.data_source = max_lab_date.data_source where egfr_labs.result_date <= {{ dateadd('day', -90, 'max_result_date') }} group by - egfr_labs.patient_id + egfr_labs.person_id , egfr_labs.data_source , max_lab_date.max_result_date @@ -80,7 +80,7 @@ with egfr_labs as ( , eligible_labs as ( select - egfr_labs.patient_id + egfr_labs.person_id , egfr_labs.data_source , egfr_labs.code_type , egfr_labs.code @@ -88,13 +88,13 @@ with egfr_labs as ( , egfr_labs.result , row_number() over ( partition by - egfr_labs.patient_id + egfr_labs.person_id , egfr_labs.data_source order by egfr_labs.result desc ) as row_num from egfr_labs inner join lab_lookback - on egfr_labs.patient_id = lab_lookback.patient_id + on egfr_labs.person_id = lab_lookback.person_id and egfr_labs.data_source = lab_lookback.data_source where egfr_labs.result_date >= lab_lookback.lookback_result_date @@ -112,7 +112,7 @@ with egfr_labs as ( , ckd_suspects as ( select - patient_id + person_id , data_source , code_type , code as lab_code @@ -147,7 +147,7 @@ with egfr_labs as ( , add_billed_flag as ( select - unioned.patient_id + unioned.person_id , unioned.data_source , unioned.result_date , unioned.result @@ -160,7 +160,7 @@ with egfr_labs as ( inner join seed_hcc_descriptions on unioned.hcc_code = seed_hcc_descriptions.hcc_code left join billed_hccs - on unioned.patient_id = billed_hccs.patient_id + on unioned.person_id = billed_hccs.person_id and unioned.data_source = billed_hccs.data_source and unioned.hcc_code = billed_hccs.hcc_code @@ -169,7 +169,7 @@ with egfr_labs as ( , add_standard_fields as ( select - patient_id + person_id , data_source , result_date , result @@ -187,7 +187,7 @@ with egfr_labs as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(data_source as {{ dbt.type_string() }}) as data_source , cast(result_date as date) as result_date , cast(result as {{ dbt.type_numeric() }}) as result @@ -207,7 +207,7 @@ with egfr_labs as ( ) select - patient_id + person_id , data_source , result_date , result diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_medication_suspects.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_medication_suspects.sql index 9bb0abd10..679877a9b 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_medication_suspects.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_medication_suspects.sql @@ -6,7 +6,7 @@ with all_medications as ( select - patient_id + person_id , dispensing_date , drug_code , code_system @@ -37,7 +37,7 @@ with all_medications as ( , billed_hccs as ( select distinct - patient_id + person_id , data_source , hcc_code , current_year_billed @@ -52,7 +52,7 @@ with all_medications as ( , hcc_155_suspect as ( select - all_medications.patient_id + all_medications.person_id , all_medications.dispensing_date , all_medications.drug_code , all_medications.code_system @@ -85,7 +85,7 @@ with all_medications as ( , add_billed_flag as ( select - unioned.patient_id + unioned.person_id , unioned.data_source , unioned.hcc_code , unioned.hcc_description @@ -95,7 +95,7 @@ with all_medications as ( , billed_hccs.current_year_billed from unioned left join billed_hccs - on unioned.patient_id = billed_hccs.patient_id + on unioned.person_id = billed_hccs.person_id and unioned.data_source = billed_hccs.data_source and unioned.hcc_code = billed_hccs.hcc_code ) @@ -103,7 +103,7 @@ with all_medications as ( , add_standard_fields as ( select - patient_id + person_id , data_source , hcc_code , hcc_description @@ -124,7 +124,7 @@ with all_medications as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_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 @@ -143,7 +143,7 @@ with all_medications as ( ) select - patient_id + person_id , data_source , hcc_code , hcc_description diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_observation_suspects.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_observation_suspects.sql index 9f1ae9fa8..1e7a92a21 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_observation_suspects.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_observation_suspects.sql @@ -6,7 +6,7 @@ with conditions as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -19,7 +19,7 @@ with conditions as ( , observations as ( select - patient_id + person_id , observation_date , result , code_type @@ -32,7 +32,7 @@ with conditions as ( , numeric_observations as ( select - patient_id + person_id , observation_date {% if target.type == 'fabric' or target.type == 'duckdb' %} , TRY_CAST(result AS {{ dbt.type_numeric() }}) AS result @@ -74,7 +74,7 @@ with conditions as ( , billed_hccs as ( select distinct - patient_id + person_id , data_source , hcc_code , current_year_billed @@ -85,7 +85,7 @@ with conditions as ( , depression_assessment as ( select - numeric_observations.patient_id + numeric_observations.person_id , numeric_observations.observation_date , numeric_observations.result , numeric_observations.code_type @@ -103,7 +103,7 @@ with conditions as ( , diabetes as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code_type @@ -121,7 +121,7 @@ with conditions as ( , hypertension as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code_type @@ -139,7 +139,7 @@ with conditions as ( , obstructive_sleep_apnea as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , conditions.condition_type , conditions.code_type @@ -158,7 +158,7 @@ with conditions as ( , bmi_over_30_with_osa as ( select - numeric_observations.patient_id + numeric_observations.person_id , numeric_observations.data_source , numeric_observations.observation_date , numeric_observations.result as observation_result @@ -172,7 +172,7 @@ with conditions as ( on numeric_observations.code_type = seed_clinical_concepts.code_system and numeric_observations.code = seed_clinical_concepts.code inner join obstructive_sleep_apnea - on numeric_observations.patient_id = obstructive_sleep_apnea.patient_id + on numeric_observations.person_id = obstructive_sleep_apnea.person_id /* ensure bmi and condition overlaps in the same year */ and {{ date_part('year', 'numeric_observations.observation_date') }} = {{ date_part('year', 'obstructive_sleep_apnea.recorded_date') }} inner join seed_hcc_descriptions @@ -185,7 +185,7 @@ with conditions as ( , bmi_over_35_with_diabetes as ( select - numeric_observations.patient_id + numeric_observations.person_id , numeric_observations.data_source , numeric_observations.observation_date , numeric_observations.result as observation_result @@ -199,7 +199,7 @@ with conditions as ( on numeric_observations.code_type = seed_clinical_concepts.code_system and numeric_observations.code = seed_clinical_concepts.code inner join diabetes - on numeric_observations.patient_id = diabetes.patient_id + on numeric_observations.person_id = diabetes.person_id /* ensure bmi and condition overlaps in the same year */ and {{ date_part('year', 'numeric_observations.observation_date') }} = {{ date_part('year', 'diabetes.recorded_date') }} inner join seed_hcc_descriptions @@ -212,7 +212,7 @@ with conditions as ( , bmi_over_35_with_hypertension as ( select - numeric_observations.patient_id + numeric_observations.person_id , numeric_observations.data_source , numeric_observations.observation_date , numeric_observations.result as observation_result @@ -226,7 +226,7 @@ with conditions as ( on numeric_observations.code_type = seed_clinical_concepts.code_system and numeric_observations.code = seed_clinical_concepts.code inner join hypertension - on numeric_observations.patient_id = hypertension.patient_id + on numeric_observations.person_id = hypertension.person_id /* ensure bmi and condition overlaps in the same year */ and {{ date_part('year', 'numeric_observations.observation_date') }} = {{ date_part('year', 'hypertension.recorded_date') }} inner join seed_hcc_descriptions @@ -239,7 +239,7 @@ with conditions as ( , bmi_over_40 as ( select - numeric_observations.patient_id + numeric_observations.person_id , numeric_observations.data_source , numeric_observations.observation_date , numeric_observations.result as observation_result @@ -274,7 +274,7 @@ with conditions as ( , hcc_48_suspect as ( select - patient_id + person_id , data_source , observation_date , observation_result @@ -311,7 +311,7 @@ with conditions as ( , eligible_depression_assessments as ( select - depression_assessment.patient_id + depression_assessment.person_id , depression_assessment.observation_date , depression_assessment.result , depression_assessment.code_type @@ -320,7 +320,7 @@ with conditions as ( , depression_assessment.concept_name , row_number() over ( partition by - depression_assessment.patient_id + depression_assessment.person_id , depression_assessment.data_source order by case when depression_assessment.observation_date is null then 1 else 0 end, @@ -333,7 +333,7 @@ with conditions as ( , depression_assessments_ordered as ( select - patient_id + person_id , observation_date , code_type , code @@ -342,7 +342,7 @@ with conditions as ( , result , row_number() over ( partition by - patient_id + person_id , data_source --order by result desc nulls last order by @@ -357,7 +357,7 @@ with conditions as ( , hcc_155_suspect as ( select - depression_assessments_ordered.patient_id + depression_assessments_ordered.person_id , depression_assessments_ordered.data_source , depression_assessments_ordered.observation_date , depression_assessments_ordered.result as observation_result @@ -392,7 +392,7 @@ with conditions as ( , add_billed_flag as ( select - unioned.patient_id + unioned.person_id , unioned.data_source , unioned.observation_date , unioned.observation_result @@ -405,7 +405,7 @@ with conditions as ( , billed_hccs.current_year_billed from unioned left join billed_hccs - on unioned.patient_id = billed_hccs.patient_id + on unioned.person_id = billed_hccs.person_id and unioned.data_source = billed_hccs.data_source and unioned.hcc_code = billed_hccs.hcc_code @@ -414,7 +414,7 @@ with conditions as ( , add_standard_fields as ( select - patient_id + person_id , data_source , observation_date , observation_result @@ -434,7 +434,7 @@ with conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(data_source as {{ dbt.type_string() }}) as data_source , cast(observation_date as date) as observation_date , cast(observation_result as {{ dbt.type_string() }}) as observation_result @@ -456,7 +456,7 @@ with conditions as ( ) select - patient_id + person_id , data_source , observation_date , observation_result diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_patient_hcc_history.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_patient_hcc_history.sql index b7789030f..35bcca539 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_patient_hcc_history.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_patient_hcc_history.sql @@ -6,7 +6,7 @@ with all_conditions as ( select - patient_id + person_id , data_source , recorded_date , condition_type @@ -21,7 +21,7 @@ with all_conditions as ( , hcc_grouped as ( select - patient_id + person_id , data_source , hcc_code , hcc_description @@ -30,7 +30,7 @@ with all_conditions as ( from all_conditions where hcc_code is not null group by - patient_id + person_id , hcc_code , hcc_description , data_source @@ -40,7 +40,7 @@ with all_conditions as ( , hcc_billed as ( select - patient_id + person_id , data_source , hcc_code , hcc_description @@ -49,7 +49,7 @@ with all_conditions as ( where hcc_code is not null and lower(condition_type) <> 'problem' group by - patient_id + person_id , hcc_code , hcc_description , data_source @@ -59,7 +59,7 @@ with all_conditions as ( , add_flag as ( select - hcc_grouped.patient_id + hcc_grouped.person_id , hcc_grouped.data_source , hcc_grouped.hcc_code , hcc_grouped.hcc_description @@ -74,7 +74,7 @@ with all_conditions as ( from hcc_grouped left join hcc_billed - on hcc_grouped.patient_id = hcc_billed.patient_id + on hcc_grouped.person_id = hcc_billed.person_id and hcc_grouped.hcc_code = hcc_billed.hcc_code and hcc_grouped.data_source = hcc_billed.data_source @@ -83,7 +83,7 @@ with all_conditions as ( , all_conditions_with_flag as ( select distinct - all_conditions.patient_id + all_conditions.person_id , all_conditions.data_source , all_conditions.recorded_date , all_conditions.condition_type @@ -108,7 +108,7 @@ with all_conditions as ( , coalesce(last_billed, last_recorded) as condition_date from all_conditions left join add_flag - on all_conditions.patient_id = add_flag.patient_id + on all_conditions.person_id = add_flag.person_id and all_conditions.hcc_code = add_flag.hcc_code and all_conditions.data_source = add_flag.data_source @@ -117,7 +117,7 @@ with all_conditions as ( , add_standard_fields as ( select distinct - patient_id + person_id , data_source , recorded_date , condition_type @@ -147,7 +147,7 @@ with all_conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(data_source as {{ dbt.type_string() }}) as data_source , cast(recorded_date as date) as recorded_date , cast(condition_type as {{ dbt.type_string() }}) as condition_type @@ -170,7 +170,7 @@ with all_conditions as ( ) select - patient_id + person_id , data_source , recorded_date , condition_type diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_conditions.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_conditions.sql index eb9fc9e14..2f2ffe088 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_conditions.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_conditions.sql @@ -6,7 +6,7 @@ with conditions as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -36,7 +36,7 @@ with conditions as ( , snomed_conditions as ( select - patient_id + person_id , recorded_date , condition_type , 'icd-10-cm' as code_type @@ -52,7 +52,7 @@ with conditions as ( , other_conditions as ( select - patient_id + person_id , recorded_date , condition_type , code_type @@ -74,7 +74,7 @@ with conditions as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(recorded_date as date) as recorded_date , cast(condition_type as {{ dbt.type_string() }}) as condition_type , cast(code_type as {{ dbt.type_string() }}) as code_type @@ -85,7 +85,7 @@ with conditions as ( ) select - patient_id + person_id , recorded_date , condition_type , code_type diff --git a/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_egfr_labs.sql b/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_egfr_labs.sql index 4fb155d53..803b85f7a 100644 --- a/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_egfr_labs.sql +++ b/models/hcc_suspecting/intermediate/hcc_suspecting__int_prep_egfr_labs.sql @@ -6,7 +6,7 @@ with lab_result as ( select - patient_id + person_id , data_source , code_type , code @@ -31,7 +31,7 @@ with lab_result as ( , egfr_labs as ( select distinct - lab_result.patient_id + lab_result.person_id , lab_result.data_source , lab_result.code_type , lab_result.code @@ -49,7 +49,7 @@ with lab_result as ( , numeric_egfr_labs as ( select - patient_id + person_id , data_source , code_type , code @@ -68,7 +68,7 @@ with lab_result as ( , clean_non_numeric_egfr_labs as ( select - patient_id + person_id , data_source , code_type , code @@ -95,7 +95,7 @@ with lab_result as ( , unioned_labs as ( select - patient_id + person_id , data_source , code_type , code @@ -106,7 +106,7 @@ with lab_result as ( union all select - patient_id + person_id , data_source , code_type , code @@ -120,7 +120,7 @@ with lab_result as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(data_source as {{ dbt.type_string() }}) as data_source , cast(code_type as {{ dbt.type_string() }}) as code_type , cast(code as {{ dbt.type_string() }}) as code @@ -131,7 +131,7 @@ with lab_result as ( ) select - patient_id + person_id , data_source , code_type , code diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__condition.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__condition.sql index f573749ab..ba90fa2ee 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__condition.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__condition.sql @@ -4,7 +4,7 @@ }} select claim_id - , patient_id + , person_id , recorded_date , condition_type , lower(normalized_code_type) as code_type diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__lab_result.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__lab_result.sql index 9a39f64f5..2b564cd21 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__lab_result.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__lab_result.sql @@ -7,7 +7,7 @@ select lab_result_id - , patient_id + , person_id , lower(coalesce(normalized_code_type,source_code_type)) as code_type , coalesce(normalized_code,source_code) as code , status @@ -20,7 +20,7 @@ from {{ ref('core__lab_result') }} select lab_result_id - , patient_id + , person_id , lower(coalesce(normalized_code_type,source_code_type)) as code_type , coalesce(normalized_code,source_code) as code , status @@ -34,7 +34,7 @@ from {{ ref('core__lab_result') }} {% if target.type == 'fabric' %} select top 0 cast(null as {{ dbt.type_string() }} ) as lab_result_id - , cast(null as {{ dbt.type_string() }} ) as patient_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as code_type , cast(null as {{ dbt.type_string() }} ) as code , cast(null as {{ dbt.type_string() }} ) as status @@ -44,7 +44,7 @@ from {{ ref('core__lab_result') }} {% else %} select cast(null as {{ dbt.type_string() }} ) as lab_result_id - , cast(null as {{ dbt.type_string() }} ) as patient_id + , cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as code_type , cast(null as {{ dbt.type_string() }} ) as code , cast(null as {{ dbt.type_string() }} ) as status diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__medication.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__medication.sql index 43347c0f3..777d0f439 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__medication.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__medication.sql @@ -5,7 +5,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , source_code , source_code_type @@ -17,7 +17,7 @@ from {{ ref('core__medication') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , source_code , source_code_type @@ -30,7 +30,7 @@ from {{ ref('core__medication') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as source_code , cast(null as {{ dbt.type_string() }} ) as source_code_type @@ -39,7 +39,7 @@ from {{ ref('core__medication') }} , cast(null as {{ dbt.type_string() }} ) as data_source {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as source_code , cast(null as {{ dbt.type_string() }} ) as source_code_type diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__observation.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__observation.sql index f6e8c0153..bb0d050ad 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__observation.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__observation.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , observation_date , result , lower(coalesce(normalized_code_type,source_code_type)) as code_type @@ -17,7 +17,7 @@ from {{ ref('core__observation') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , observation_date , result , lower(coalesce(normalized_code_type,source_code_type)) as code_type @@ -29,7 +29,7 @@ from {{ ref('core__observation') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as observation_date , cast(null as {{ dbt.type_string() }} ) as result , cast(null as {{ dbt.type_string() }} ) as code_type @@ -37,7 +37,7 @@ from {{ ref('core__observation') }} , cast(null as {{ dbt.type_string() }} ) as data_source {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as observation_date , cast(null as {{ dbt.type_string() }} ) as result , cast(null as {{ dbt.type_string() }} ) as code_type diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__patient.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__patient.sql index 69de510ad..d7c5090f9 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__patient.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__patient.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , sex , birth_date , death_date diff --git a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__pharmacy_claim.sql b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__pharmacy_claim.sql index 2bcd567f5..ecf9481a7 100644 --- a/models/hcc_suspecting/staging/hcc_suspecting__stg_core__pharmacy_claim.sql +++ b/models/hcc_suspecting/staging/hcc_suspecting__stg_core__pharmacy_claim.sql @@ -5,7 +5,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , ndc_code , paid_date @@ -15,7 +15,7 @@ from {{ ref('core__pharmacy_claim') }} {% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , ndc_code , paid_date @@ -26,14 +26,14 @@ from {{ ref('core__pharmacy_claim') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as ndc_code , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as paid_date , cast(null as {{ dbt.type_string() }} ) as data_source {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as ndc_code , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as paid_date diff --git a/models/pharmacy/final/pharmacy__pharmacy_claim_expanded.sql b/models/pharmacy/final/pharmacy__pharmacy_claim_expanded.sql index 836262a94..d21e9b93d 100644 --- a/models/pharmacy/final/pharmacy__pharmacy_claim_expanded.sql +++ b/models/pharmacy/final/pharmacy__pharmacy_claim_expanded.sql @@ -7,7 +7,7 @@ with all_drugs as ( p.data_source , p.claim_id , p.claim_line_number - , p.patient_id + , p.person_id , p.member_id , p.prescribing_provider_id , p.dispensing_provider_id @@ -63,8 +63,7 @@ select a.data_source , a.claim_id , a.claim_line_number - , a.patient_id - , a.member_id + , a.person_id , a.prescribing_provider_id , a.dispensing_provider_id , a.dispensing_date diff --git a/models/pharmacy/pharmacy_models.yml b/models/pharmacy/pharmacy_models.yml index 8d85f7f94..cec82f3cd 100644 --- a/models/pharmacy/pharmacy_models.yml +++ b/models/pharmacy/pharmacy_models.yml @@ -137,7 +137,7 @@ models: description: Unique identifier for each pharmacy claim. - name: claim_line_number description: Line number of the claim. - - name: patient_id + - name: person_id description: Unique identifier for each patient. - name: member_id description: Unique identifier for each member. diff --git a/models/pharmacy/staging/pharmacy__stg_pharmacy_claim.sql b/models/pharmacy/staging/pharmacy__stg_pharmacy_claim.sql index 9275cccb2..d0a98dd84 100644 --- a/models/pharmacy/staging/pharmacy__stg_pharmacy_claim.sql +++ b/models/pharmacy/staging/pharmacy__stg_pharmacy_claim.sql @@ -11,7 +11,7 @@ select , p.allowed_amount , p.claim_id , p.claim_line_number - , p.patient_id + , p.person_id , p.member_id , p.prescribing_provider_id , p.dispensing_provider_id diff --git a/models/quality_measures/final/quality_measures__summary_long.sql b/models/quality_measures/final/quality_measures__summary_long.sql index a8243d206..a2382f862 100644 --- a/models/quality_measures/final/quality_measures__summary_long.sql +++ b/models/quality_measures/final/quality_measures__summary_long.sql @@ -24,7 +24,7 @@ with union_measures as ( , patient as ( - select distinct patient_id + select distinct person_id from {{ ref('quality_measures__stg_core__patient') }} ) @@ -33,7 +33,7 @@ with union_measures as ( , joined as ( select distinct - patient.patient_id + patient.person_id , union_measures.denominator_flag , union_measures.numerator_flag , union_measures.exclusion_flag @@ -54,13 +54,13 @@ with union_measures as ( , union_measures.measure_version from patient left join union_measures - on patient.patient_id = union_measures.patient_id + on patient.person_id = union_measures.person_id ) , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -79,7 +79,7 @@ with union_measures as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/final/quality_measures__summary_wide.sql b/models/quality_measures/final/quality_measures__summary_wide.sql index 8080f1a3d..42fa5e493 100644 --- a/models/quality_measures/final/quality_measures__summary_wide.sql +++ b/models/quality_measures/final/quality_measures__summary_wide.sql @@ -10,7 +10,7 @@ with measures_long as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -23,7 +23,7 @@ with measures_long as ( , cqm_438 as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'CQM438' @@ -33,7 +33,7 @@ with measures_long as ( , cqm_130 as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'CQM130' @@ -43,7 +43,7 @@ with measures_long as ( , nqf_0420 as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'NQF0420' @@ -53,7 +53,7 @@ with measures_long as ( , adh_diabetes as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'ADH-Diabetes' @@ -63,7 +63,7 @@ with measures_long as ( , adh_ras as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'ADH-RAS' @@ -73,7 +73,7 @@ with measures_long as ( , supd as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'SUPD' @@ -83,7 +83,7 @@ with measures_long as ( , adh_statins as ( select - patient_id + person_id , performance_flag from measures_long where measure_id = 'ADH-Statins' @@ -93,7 +93,7 @@ with measures_long as ( , joined as ( select - measures_long.patient_id + measures_long.person_id , max(cqm_438.performance_flag) as cqm_438 , max(cqm_130.performance_flag) as cqm_130 , max(nqf_0420.performance_flag) as nqf_0420 @@ -103,27 +103,27 @@ with measures_long as ( , max(adh_statins.performance_flag) as adh_statins from measures_long left join cqm_438 - on measures_long.patient_id = cqm_438.patient_id + on measures_long.person_id = cqm_438.person_id left join cqm_130 - on measures_long.patient_id = cqm_130.patient_id + on measures_long.person_id = cqm_130.person_id left join nqf_0420 - on measures_long.patient_id = nqf_0420.patient_id + on measures_long.person_id = nqf_0420.person_id left join adh_diabetes - on measures_long.patient_id = adh_diabetes.patient_id + on measures_long.person_id = adh_diabetes.person_id left join adh_ras - on measures_long.patient_id = adh_ras.patient_id + on measures_long.person_id = adh_ras.person_id left join supd - on measures_long.patient_id = supd.patient_id + on measures_long.person_id = supd.person_id left join adh_statins - on measures_long.patient_id = adh_statins.patient_id - group by measures_long.patient_id + on measures_long.person_id = adh_statins.person_id + group by measures_long.person_id ) , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(cqm_438 as integer) as cqm_438 , cast(cqm_130 as integer) as cqm_130 , cast(nqf_0420 as integer) as nqf_0420 @@ -136,7 +136,7 @@ with measures_long as ( ) select - patient_id + person_id , adh_diabetes , adh_ras , adh_statins diff --git a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_denominator.sql b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_denominator.sql index 57a9ed6ac..f52dffa36 100644 --- a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_denominator.sql +++ b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_denominator.sql @@ -29,7 +29,7 @@ with performance_period as ( , pharmacy_claim as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -40,7 +40,7 @@ with performance_period as ( , patient_with_claim as ( select - pharmacy_claim.patient_id + pharmacy_claim.person_id , dispensing_date , days_supply , ndc_code @@ -53,7 +53,7 @@ with performance_period as ( , patient_within_performance_period as ( select - patient_id + person_id , dispensing_date , days_supply , ndc_code @@ -74,11 +74,11 @@ with performance_period as ( , patient_with_rank as ( select - patient_id + person_id , dispensing_date , days_supply , ndc_code - , dense_rank() over (partition by patient_id order by dispensing_date) as dense_rank + , dense_rank() over (partition by person_id order by dispensing_date) as dense_rank from patient_within_performance_period ) @@ -86,7 +86,7 @@ with performance_period as ( , patient_with_first_dispensing_date as ( select - patient_id + person_id , dispensing_date as first_dispensing_date from patient_with_rank where dense_rank = 1 @@ -100,21 +100,21 @@ treatment period days is abbreviated as tpd , patient_with_tpd as ( select - patients1.patient_id + patients1.person_id , patients1.dispensing_date , patients2.first_dispensing_date , patients1.days_supply , {{ datediff('first_dispensing_date', 'performance_period_end', 'day') }} as tpd from patient_within_performance_period as patients1 inner join patient_with_first_dispensing_date as patients2 - on patients1.patient_id = patients2.patient_id + on patients1.person_id = patients2.person_id ) , first_check_patient as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -126,7 +126,7 @@ treatment period days is abbreviated as tpd , second_check_patient as ( select - patient_id + person_id , ndc_code from patient_with_rank where dense_rank = 2 @@ -136,21 +136,21 @@ treatment period days is abbreviated as tpd , both_check_patient as ( select - valid_patients1.patient_id + valid_patients1.person_id , valid_patients1.dispensing_date , valid_patients1.first_dispensing_date , valid_patients1.days_supply , valid_patients2.ndc_code from first_check_patient as valid_patients1 inner join second_check_patient as valid_patients2 - on valid_patients1.patient_id = valid_patients2.patient_id + on valid_patients1.person_id = valid_patients2.person_id ) , patient_with_age as ( select - valid_patients1.patient_id + valid_patients1.person_id , floor({{ datediff('birth_date', 'pp.performance_period_begin', 'hour') }} / 8760.0) as age , dispensing_date , first_dispensing_date @@ -163,7 +163,7 @@ treatment period days is abbreviated as tpd , pp.measure_version from {{ ref('quality_measures__stg_core__patient') }} as patient inner join both_check_patient as valid_patients1 - on patient.patient_id = valid_patients1.patient_id + on patient.person_id = valid_patients1.person_id cross join performance_period as pp where patient.death_date is null @@ -172,7 +172,7 @@ treatment period days is abbreviated as tpd , qualifying_patients as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -191,7 +191,7 @@ treatment period days is abbreviated as tpd , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(dispensing_date as date) as dispensing_date , cast(first_dispensing_date as date) as first_dispensing_date , cast(days_supply as integer) as days_supply @@ -207,7 +207,7 @@ treatment period days is abbreviated as tpd ) select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply diff --git a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_exclusions.sql b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_exclusions.sql index e5c03d6c1..8d086e112 100644 --- a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_exclusions.sql +++ b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_exclusions.sql @@ -24,7 +24,7 @@ with denominator as ( select - patient_id + person_id from {{ ref('quality_measures__int_adhras_denominator')}} ) @@ -32,7 +32,7 @@ with denominator as ( , valid_hospice_palliative as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} @@ -57,7 +57,7 @@ with denominator as ( , valid_esrd as ( select - condition.patient_id + condition.person_id , condition.recorded_date as exclusion_date , codes.concept_name as exclusion_reason from {{ ref('quality_measures__stg_core__condition') }} as condition @@ -71,7 +71,7 @@ with denominator as ( , sacubitril_pharmacy_claim as ( select - pharmacy_claim.patient_id + pharmacy_claim.person_id , pharmacy_claim.dispensing_date as exclusion_date , codes.concept_name as exclusion_reason from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claim @@ -84,7 +84,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from valid_hospice_palliative @@ -92,7 +92,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from valid_esrd @@ -100,7 +100,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from sacubitril_pharmacy_claim @@ -110,12 +110,12 @@ with denominator as ( , measure_exclusions as ( select - exclusions.patient_id + exclusions.person_id , exclusion_date , exclusion_reason from exclusions inner join denominator - on exclusions.patient_id = denominator.patient_id + on exclusions.person_id = denominator.person_id ) @@ -123,7 +123,7 @@ with denominator as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , 1 as exclusion_flag @@ -132,7 +132,7 @@ with denominator as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_long.sql b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_long.sql index ced8647d4..e3134863d 100644 --- a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_long.sql +++ b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_adhras_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_adhras_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,16 +84,16 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -114,7 +114,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -132,7 +132,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_numerator.sql b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_numerator.sql index ec7f73a7d..9fdf05048 100644 --- a/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_numerator.sql +++ b/models/quality_measures/intermediate/adh-ras_medication_adherence_for_hypertension/quality_measures__int_adhras_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -38,12 +38,12 @@ The below 3 cte identifies periods of continuous medication use for each patient , ranked_patient as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply - , dense_rank() over (partition by patient_id order by dispensing_date) as dense_rank - , lag(ndc_code) over (partition by patient_id order by dispensing_date) as previous_ndc + , dense_rank() over (partition by person_id order by dispensing_date) as dense_rank + , lag(ndc_code) over (partition by person_id order by dispensing_date) as previous_ndc from denominator ) @@ -51,7 +51,7 @@ The below 3 cte identifies periods of continuous medication use for each patient , grouped_meds as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -67,12 +67,12 @@ The below 3 cte identifies periods of continuous medication use for each patient , final_groups as ( select - patient_id + person_id , ndc_code , dispensing_date , days_supply , sum(med_change_flag) over ( - partition by patient_id + partition by person_id order by dense_rank rows between unbounded preceding and current row ) as group_id @@ -89,7 +89,7 @@ on previous fills and the performance period. , theoretical_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -115,14 +115,14 @@ or use the current rx_fill_date , previous_fill_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , theoretical_end_date , lag(theoretical_end_date) over (partition by - patient_id + person_id , group_id order by dispensing_date @@ -134,7 +134,7 @@ or use the current rx_fill_date , adjusted_fill_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -158,7 +158,7 @@ or use the current rx_fill_date , actual_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -185,14 +185,14 @@ or use the current rx_fill_date , grouped_fill_ranges as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , adjusted_fill_date , actual_end_date - , min(adjusted_fill_date) over(partition by patient_id, group_id) as group_first - , max(adjusted_fill_date) over(partition by patient_id, group_id) as group_last + , min(adjusted_fill_date) over(partition by person_id, group_id) as group_first + , max(adjusted_fill_date) over(partition by person_id, group_id) as group_last from actual_end_dates ) @@ -200,7 +200,7 @@ or use the current rx_fill_date , final_fills as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -213,7 +213,7 @@ or use the current rx_fill_date when adjusted_fill_date = group_last then days_supply else 0 - end) over (partition by patient_id, group_id) as group_last_days_supply + end) over (partition by person_id, group_id) as group_last_days_supply from grouped_fill_ranges ) @@ -227,7 +227,7 @@ or use the current rx_fill_date , covered_days_per_groups as ( select - patient_id + person_id , group_id , group_first , group_last @@ -240,7 +240,7 @@ or use the current rx_fill_date }} ) as covered_days_per_group from final_fills group by - patient_id + person_id , group_id , group_first , group_last @@ -251,13 +251,13 @@ or use the current rx_fill_date , with_lag as ( select - patient_id + person_id , group_id , group_first , group_last , covered_days_per_group - , lag(group_last) over(partition by patient_id order by group_first) as lag_date - , lag(group_last_days_supply) over(partition by patient_id order by group_first) as lag_days_supply + , lag(group_last) over(partition by person_id order by group_first) as lag_date + , lag(group_last_days_supply) over(partition by person_id order by group_first) as lag_days_supply from covered_days_per_groups ) @@ -265,7 +265,7 @@ or use the current rx_fill_date , overlap_days as ( select - patient_id + person_id , group_id , group_first , group_last @@ -299,16 +299,16 @@ or use the current rx_fill_date , final_covered_days as ( select - patient_id + person_id , sum(covered_days_per_group) - sum(overlap) as actual_covered_days from overlap_days - group by patient_id + group by person_id ) , patient_with_treatment_period_days as ( select - patient_id + person_id , {{ datediff('first_dispensing_date', 'performance_period_end', 'day') }} as treatment_period_days from denominator @@ -317,11 +317,11 @@ or use the current rx_fill_date , patient_with_pdc as ( select - final_covered_days.patient_id + final_covered_days.person_id , round(cast(actual_covered_days * 100 / treatment_period_days as {{ dbt.type_numeric() }}), 4) as adherence from final_covered_days inner join patient_with_treatment_period_days - on final_covered_days.patient_id = patient_with_treatment_period_days.patient_id + on final_covered_days.person_id = patient_with_treatment_period_days.person_id ) @@ -332,14 +332,14 @@ Selects only the patient whose pdc is greater than 80%. , valid_patients as ( select - patient_with_pdc.patient_id + patient_with_pdc.person_id , adherence , denominator.dispensing_date as evidence_date , denominator.days_supply as evidence_value , 1 as numerator_flag from patient_with_pdc inner join denominator - on patient_with_pdc.patient_id = denominator.patient_id + on patient_with_pdc.person_id = denominator.person_id where patient_with_pdc.adherence >= 80.00 ) @@ -347,7 +347,7 @@ Selects only the patient whose pdc is greater than 80%. , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(evidence_date as date) as evidence_date , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value , cast(adherence as {{ dbt.type_numeric() }}) as adherence @@ -357,7 +357,7 @@ Selects only the patient whose pdc is greater than 80%. ) select - patient_id + person_id , evidence_date , evidence_value , adherence diff --git a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_denominator.sql b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_denominator.sql index b6c050eca..d421889c7 100644 --- a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_denominator.sql +++ b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_denominator.sql @@ -29,7 +29,7 @@ with performance_period as ( , pharmacy_claim as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -40,7 +40,7 @@ with performance_period as ( , patient_with_claim as ( select - pharmacy_claim.patient_id + pharmacy_claim.person_id , dispensing_date , days_supply , ndc_code @@ -53,7 +53,7 @@ with performance_period as ( , patient_within_performance_period as ( select - patient_id + person_id , dispensing_date , days_supply , ndc_code @@ -74,11 +74,11 @@ with performance_period as ( , patient_with_rank as ( select - patient_id + person_id , dispensing_date , days_supply , ndc_code - , dense_rank() over (partition by patient_id order by dispensing_date) as dense_rank + , dense_rank() over (partition by person_id order by dispensing_date) as dense_rank from patient_within_performance_period ) @@ -86,7 +86,7 @@ with performance_period as ( , patient_with_first_dispensing_date as ( select - patient_id + person_id , dispensing_date as first_dispensing_date from patient_with_rank where dense_rank = 1 @@ -101,21 +101,21 @@ treatment period days is abbreviated as tpd , patient_with_tpd as ( select - patients1.patient_id + patients1.person_id , patients1.dispensing_date , patients2.first_dispensing_date , patients1.days_supply , {{ datediff('first_dispensing_date', 'performance_period_end', 'day') }} as tpd from patient_within_performance_period as patients1 inner join patient_with_first_dispensing_date as patients2 - on patients1.patient_id = patients2.patient_id + on patients1.person_id = patients2.person_id ) , first_check_patient as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -127,7 +127,7 @@ treatment period days is abbreviated as tpd , second_check_patient as ( select - patient_id + person_id , ndc_code from patient_with_rank where dense_rank = 2 @@ -137,21 +137,21 @@ treatment period days is abbreviated as tpd , both_check_patient as ( select - valid_patients1.patient_id + valid_patients1.person_id , valid_patients1.dispensing_date , valid_patients1.first_dispensing_date , valid_patients1.days_supply , valid_patients2.ndc_code from first_check_patient as valid_patients1 inner join second_check_patient as valid_patients2 - on valid_patients1.patient_id = valid_patients2.patient_id + on valid_patients1.person_id = valid_patients2.person_id ) , patient_with_age as ( select - valid_patients1.patient_id + valid_patients1.person_id , floor({{ datediff('birth_date', 'pp.performance_period_begin', 'hour') }} / 8760.0) as age , dispensing_date , first_dispensing_date @@ -164,7 +164,7 @@ treatment period days is abbreviated as tpd , pp.measure_version from {{ ref('quality_measures__stg_core__patient') }} as patient inner join both_check_patient as valid_patients1 - on patient.patient_id = valid_patients1.patient_id + on patient.person_id = valid_patients1.person_id cross join performance_period as pp where patient.death_date is null @@ -173,7 +173,7 @@ treatment period days is abbreviated as tpd , qualifying_patients as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -192,7 +192,7 @@ treatment period days is abbreviated as tpd , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(dispensing_date as date) as dispensing_date , cast(first_dispensing_date as date) as first_dispensing_date , cast(days_supply as integer) as days_supply @@ -208,7 +208,7 @@ treatment period days is abbreviated as tpd ) select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply diff --git a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_exclusions.sql b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_exclusions.sql index 162b0fe05..5bb055667 100644 --- a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_exclusions.sql +++ b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_exclusions.sql @@ -24,7 +24,7 @@ with denominator as ( select - patient_id + person_id from {{ ref('quality_measures__int_adh_statins_denominator')}} ) @@ -32,7 +32,7 @@ with denominator as ( , hospice_palliative as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} @@ -43,7 +43,7 @@ with denominator as ( , valid_hospice as ( select - patient_id + person_id , exclusion_date , exclusion_reason from hospice_palliative @@ -71,7 +71,7 @@ with denominator as ( , valid_esrd as ( select - condition.patient_id + condition.person_id , condition.recorded_date as exclusion_date , esrd_codes.concept_name as exclusion_reason from {{ ref('quality_measures__stg_core__condition') }} as condition @@ -85,7 +85,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from valid_hospice @@ -93,7 +93,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from valid_esrd @@ -103,12 +103,12 @@ with denominator as ( , measure_exclusions as ( select - exclusions.patient_id + exclusions.person_id , exclusion_date , exclusion_reason from exclusions inner join denominator - on exclusions.patient_id = denominator.patient_id + on exclusions.person_id = denominator.person_id ) @@ -116,7 +116,7 @@ with denominator as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , 1 as exclusion_flag @@ -125,7 +125,7 @@ with denominator as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_long.sql b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_long.sql index 0b0a85807..e83f4b889 100644 --- a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_long.sql +++ b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_adh_statins_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_adh_statins_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,16 +84,16 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -114,7 +114,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -132,7 +132,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_numerator.sql b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_numerator.sql index 770813b97..ebcf8ae0c 100644 --- a/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_numerator.sql +++ b/models/quality_measures/intermediate/adh-statins_medication_adherence_for_cholestrol/quality_measures__int_adh_statins_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , dispensing_date , first_dispensing_date , days_supply @@ -38,12 +38,12 @@ The below 3 cte identifies periods of continuous medication use for each patient , ranked_patient as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply - , dense_rank() over (partition by patient_id order by dispensing_date) as dense_rank - , lag(ndc_code) over (partition by patient_id order by dispensing_date) as previous_ndc + , dense_rank() over (partition by person_id order by dispensing_date) as dense_rank + , lag(ndc_code) over (partition by person_id order by dispensing_date) as previous_ndc from denominator ) @@ -51,7 +51,7 @@ The below 3 cte identifies periods of continuous medication use for each patient , grouped_meds as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -67,12 +67,12 @@ The below 3 cte identifies periods of continuous medication use for each patient , final_groups as ( select - patient_id + person_id , ndc_code , dispensing_date , days_supply , sum(med_change_flag) over ( - partition by patient_id + partition by person_id order by dense_rank rows between unbounded preceding and current row ) as group_id @@ -89,7 +89,7 @@ on previous fills and the performance period. , theoretical_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -115,14 +115,14 @@ or use the current rx_fill_date , previous_fill_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , theoretical_end_date , lag(theoretical_end_date) over (partition by - patient_id + person_id , group_id order by dispensing_date @@ -134,7 +134,7 @@ or use the current rx_fill_date , adjusted_fill_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -158,7 +158,7 @@ or use the current rx_fill_date , actual_end_dates as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -185,14 +185,14 @@ or use the current rx_fill_date , grouped_fill_ranges as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , adjusted_fill_date , actual_end_date - , min(adjusted_fill_date) over(partition by patient_id, group_id) as group_first - , max(adjusted_fill_date) over(partition by patient_id, group_id) as group_last + , min(adjusted_fill_date) over(partition by person_id, group_id) as group_first + , max(adjusted_fill_date) over(partition by person_id, group_id) as group_last from actual_end_dates ) @@ -200,7 +200,7 @@ or use the current rx_fill_date , final_fills as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -213,7 +213,7 @@ or use the current rx_fill_date when adjusted_fill_date = group_last then days_supply else 0 - end) over (partition by patient_id, group_id) as group_last_days_supply + end) over (partition by person_id, group_id) as group_last_days_supply from grouped_fill_ranges ) @@ -227,7 +227,7 @@ or use the current rx_fill_date , covered_days_per_groups as ( select - patient_id + person_id , group_id , group_first , group_last @@ -240,7 +240,7 @@ or use the current rx_fill_date }} ) as covered_days_per_group from final_fills group by - patient_id + person_id , group_id , group_first , group_last @@ -251,13 +251,13 @@ or use the current rx_fill_date , with_lag as ( select - patient_id + person_id , group_id , group_first , group_last , covered_days_per_group - , lag(group_last) over(partition by patient_id order by group_first) as lag_date - , lag(group_last_days_supply) over(partition by patient_id order by group_first) as lag_days_supply + , lag(group_last) over(partition by person_id order by group_first) as lag_date + , lag(group_last_days_supply) over(partition by person_id order by group_first) as lag_days_supply from covered_days_per_groups ) @@ -265,7 +265,7 @@ or use the current rx_fill_date , overlap_days as ( select - patient_id + person_id , group_id , group_first , group_last @@ -299,16 +299,16 @@ or use the current rx_fill_date , final_covered_days as ( select - patient_id + person_id , sum(covered_days_per_group) - sum(overlap) as actual_covered_days from overlap_days - group by patient_id + group by person_id ) , patient_with_treatment_period_days as ( select - patient_id + person_id , {{ datediff('first_dispensing_date', 'performance_period_end', 'day') }} as treatment_period_days from denominator @@ -317,11 +317,11 @@ or use the current rx_fill_date , patient_with_pdc as ( select - final_covered_days.patient_id + final_covered_days.person_id , round(cast(actual_covered_days * 100 / treatment_period_days as {{ dbt.type_numeric() }}), 4) as adherence from final_covered_days inner join patient_with_treatment_period_days - on final_covered_days.patient_id = patient_with_treatment_period_days.patient_id + on final_covered_days.person_id = patient_with_treatment_period_days.person_id ) @@ -332,14 +332,14 @@ Selects only the patient whose pdc is greater than 80%. , valid_patients as ( select - patient_with_pdc.patient_id + patient_with_pdc.person_id , adherence , denominator.dispensing_date as evidence_date , denominator.days_supply as evidence_value , 1 as numerator_flag from patient_with_pdc inner join denominator - on patient_with_pdc.patient_id = denominator.patient_id + on patient_with_pdc.person_id = denominator.person_id where patient_with_pdc.adherence >= 80.00 ) @@ -347,7 +347,7 @@ Selects only the patient whose pdc is greater than 80%. , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(evidence_date as date) as evidence_date , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value , cast(adherence as {{ dbt.type_numeric() }}) as adherence @@ -357,7 +357,7 @@ Selects only the patient whose pdc is greater than 80%. ) select - patient_id + person_id , evidence_date , evidence_value , adherence diff --git a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_denominator.sql b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_denominator.sql index cad0f52ea..f4e3a47c1 100644 --- a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_denominator.sql +++ b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_denominator.sql @@ -18,7 +18,7 @@ with diabetics_codes as ( , rx_diabetes as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -32,7 +32,7 @@ with diabetics_codes as ( , rx_diabetes_in_measurement_period as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -52,12 +52,12 @@ with diabetics_codes as ( , rx_fill_order as ( select - patient_id + person_id , dispensing_date , performance_period_end , dense_rank() over ( partition by - patient_id + person_id , performance_period_end order by dispensing_date ) as dr @@ -68,7 +68,7 @@ with diabetics_codes as ( , rx_first_fill as ( select - patient_id + person_id , dispensing_date , performance_period_end from rx_fill_order @@ -79,7 +79,7 @@ with diabetics_codes as ( , timely_fill_check as ( select - patient_id + person_id , ( 1 + {{ dbt.datediff ( datepart = 'day' , first_date = 'dispensing_date' @@ -99,7 +99,7 @@ with diabetics_codes as ( , first_check_passed_patients as ( select - patient_id + person_id , days_in_treatment_period from timely_fill_check where days_in_treatment_period > 90 @@ -109,7 +109,7 @@ with diabetics_codes as ( , second_check_passed_patients as ( select - patient_id + person_id from rx_fill_order where dr = 2 @@ -118,18 +118,18 @@ with diabetics_codes as ( , qualifying_patients as ( select - first_check_passed_patients.patient_id + first_check_passed_patients.person_id , first_check_passed_patients.days_in_treatment_period from first_check_passed_patients inner join second_check_passed_patients - on first_check_passed_patients.patient_id = second_check_passed_patients.patient_id + on first_check_passed_patients.person_id = second_check_passed_patients.person_id ) , qualifying_patients_with_age as ( select - patients.patient_id + patients.person_id , floor({{ datediff('birth_date', 'pp.performance_period_begin', 'hour') }} / 8760.0) as age , days_in_treatment_period , performance_period_begin @@ -139,7 +139,7 @@ with diabetics_codes as ( , measure_version from {{ ref('quality_measures__stg_core__patient') }} patients inner join qualifying_patients - on patients.patient_id = qualifying_patients.patient_id + on patients.person_id = qualifying_patients.person_id cross join {{ ref('quality_measures__int_adh_diabetes__performance_period') }} pp where patients.death_date is null @@ -152,7 +152,7 @@ with diabetics_codes as ( , qualifying_patients_all_claim_info as ( select - qualifying_patients_with_age.patient_id + qualifying_patients_with_age.person_id , qualifying_patients_with_age.age , rx_diabetes_in_measurement_period.dispensing_date , rx_diabetes_in_measurement_period.ndc_code @@ -165,14 +165,14 @@ with diabetics_codes as ( , qualifying_patients_with_age.measure_version from qualifying_patients_with_age inner join rx_diabetes_in_measurement_period - on qualifying_patients_with_age.patient_id = rx_diabetes_in_measurement_period.patient_id + on qualifying_patients_with_age.person_id = rx_diabetes_in_measurement_period.person_id ) , denominator as ( select - patient_id + person_id , age , dispensing_date , ndc_code @@ -192,7 +192,7 @@ with diabetics_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(age as integer) as age , cast(dispensing_date as date) as dispensing_date , cast(ndc_code as {{ dbt.type_string() }}) as ndc_code @@ -209,7 +209,7 @@ with diabetics_codes as ( ) select - patient_id + person_id , age , dispensing_date , ndc_code diff --git a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_exclusions.sql b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_exclusions.sql index 387004271..0b158e8e2 100644 --- a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_exclusions.sql +++ b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_exclusions.sql @@ -26,7 +26,7 @@ with denominator as ( select - patient_id + person_id from {{ ref('quality_measures__int_adh_diabetes_denominator') }} ) @@ -48,7 +48,7 @@ with denominator as ( , hospice_palliative as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} @@ -59,7 +59,7 @@ with denominator as ( , valid_hospice as ( select - patient_id + person_id , exclusion_date , exclusion_reason from hospice_palliative @@ -74,7 +74,7 @@ with denominator as ( , conditions as ( select - patient_id + person_id , recorded_date , claim_id , coalesce ( @@ -96,7 +96,7 @@ with denominator as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date as exclusion_date , exclusion_codes.concept_name as exclusion_reason from conditions @@ -109,7 +109,7 @@ with denominator as ( , pharmacy_exclusions as ( select - patient_id + person_id , dispensing_date as exclusion_date , concept_name as exclusion_reason from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claims @@ -122,7 +122,7 @@ with denominator as ( , exclusion_patients as ( select - patient_id + person_id , exclusion_date , exclusion_reason from valid_hospice @@ -130,7 +130,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from condition_exclusions @@ -138,7 +138,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from pharmacy_exclusions @@ -148,12 +148,12 @@ with denominator as ( , combined_exclusions as ( select - exclusion_patients.patient_id + exclusion_patients.person_id , exclusion_patients.exclusion_date , exclusion_patients.exclusion_reason from exclusion_patients inner join denominator - on exclusion_patients.patient_id = denominator.patient_id + on exclusion_patients.person_id = denominator.person_id ) @@ -161,7 +161,7 @@ with denominator as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , cast(1 as integer) as exclusion_flag @@ -170,7 +170,7 @@ with denominator as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_long.sql b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_long.sql index 2bded6bb8..eb25e38d1 100644 --- a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_long.sql +++ b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_adh_diabetes_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_adh_diabetes_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,9 +84,9 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) @@ -96,7 +96,7 @@ with denominator as ( , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -117,7 +117,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -135,7 +135,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_numerator.sql b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_numerator.sql index 9d88e87a4..c64050369 100644 --- a/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_numerator.sql +++ b/models/quality_measures/intermediate/adh_diabetes/quality_measures__int_adh_diabetes_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -38,12 +38,12 @@ with denominator as ( , ranked_patient as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply - , dense_rank() over (partition by patient_id order by dispensing_date) as dr - , lag(ndc_code) over (partition by patient_id order by dispensing_date) as previous_ndc + , dense_rank() over (partition by person_id order by dispensing_date) as dr + , lag(ndc_code) over (partition by person_id order by dispensing_date) as previous_ndc from denominator ) @@ -51,7 +51,7 @@ with denominator as ( , grouped_meds as ( select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -67,12 +67,12 @@ with denominator as ( , final_groups as ( select - patient_id + person_id , ndc_code , dispensing_date , days_supply , sum(med_change_flag) over ( - partition by patient_id + partition by person_id order by dr rows between unbounded preceding and current row ) as group_id @@ -89,7 +89,7 @@ with denominator as ( , fills as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -110,14 +110,14 @@ with denominator as ( , previous_fill_end_date as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , theoretical_end_date , lag(theoretical_end_date) over (partition by - patient_id + person_id , group_id order by dispensing_date @@ -131,7 +131,7 @@ with denominator as ( /* Adjust start dates based on the previous fill's end date + 1, or use the current rx_fill_date */ select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -154,7 +154,7 @@ with denominator as ( , final_fills as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -181,14 +181,14 @@ with denominator as ( , grouped_fill_ranges as ( select - patient_id + person_id , group_id , dispensing_date , days_supply , adjusted_start_date , final_end_date - , min(adjusted_start_date) over(partition by patient_id, group_id) as first_disp_date - , max(adjusted_start_date) over(partition by patient_id, group_id) as last_disp_date + , min(adjusted_start_date) over(partition by person_id, group_id) as first_disp_date + , max(adjusted_start_date) over(partition by person_id, group_id) as last_disp_date from final_fills ) @@ -196,7 +196,7 @@ with denominator as ( , last_med_end_groupwise as ( select - patient_id + person_id , group_id , dispensing_date , days_supply @@ -209,7 +209,7 @@ with denominator as ( when adjusted_start_date = last_disp_date then days_supply else null - end) over (partition by patient_id, group_id) as last_days_supply + end) over (partition by person_id, group_id) as last_days_supply from grouped_fill_ranges ) @@ -223,7 +223,7 @@ with denominator as ( , covered_days_per_group as ( select - patient_id + person_id , group_id , first_disp_date , last_disp_date @@ -236,7 +236,7 @@ with denominator as ( }} ) as covered_days from last_med_end_groupwise group by - patient_id + person_id , group_id , first_disp_date , last_disp_date @@ -247,13 +247,13 @@ with denominator as ( , final_with_lag as ( select - patient_id + person_id , group_id , first_disp_date , last_disp_date , covered_days - , lag(last_disp_date) over(partition by patient_id order by first_disp_date) as lag_date - , lag(last_days_supply) over(partition by patient_id order by first_disp_date) as lag_days_supply + , lag(last_disp_date) over(partition by person_id order by first_disp_date) as lag_date + , lag(last_days_supply) over(partition by person_id order by first_disp_date) as lag_days_supply from covered_days_per_group ) @@ -261,7 +261,7 @@ with denominator as ( , overlap_days as ( select - patient_id + person_id , group_id , first_disp_date , last_disp_date @@ -294,30 +294,30 @@ with denominator as ( , final_covered_days as ( select - patient_id + person_id , sum(covered_days) - sum(overlap) as actual_covered_days from overlap_days - group by patient_id + group by person_id ) , relevant_patients_from_deno as ( select - final_covered_days.patient_id + final_covered_days.person_id , round(cast(actual_covered_days / days_in_treatment_period as {{ dbt.type_numeric() }}), 4) as adherence , dispensing_date as evidence_date , days_supply as evidence_value from final_covered_days inner join denominator - on final_covered_days.patient_id = denominator.patient_id + on final_covered_days.person_id = denominator.person_id ) , numerator as ( select - patient_id + person_id , adherence * 100 as adherence --percent conversion , evidence_date , evidence_value @@ -330,7 +330,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(evidence_date as date) as evidence_date , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value , cast(adherence as {{ dbt.type_numeric() }}) as adherence @@ -340,7 +340,7 @@ with denominator as ( ) select - patient_id + person_id , evidence_date , evidence_value , adherence diff --git a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_denominator.sql b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_denominator.sql index 380550291..b86ebb162 100644 --- a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_denominator.sql +++ b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_denominator.sql @@ -19,7 +19,7 @@ with visit_codes as ( , visits_encounters as ( select - patient_id + person_id , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as procedure_encounter_date -- alias only to enable union later , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as claims_encounter_date -- alias only to enable union later from {{ ref('quality_measures__stg_core__encounter') }} encounter @@ -39,7 +39,7 @@ with visit_codes as ( , procedure_encounters as ( select - patient_id + person_id , procedure_date as procedure_encounter_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as claims_encounter_date from {{ ref('quality_measures__stg_core__procedure') }} procs @@ -53,7 +53,7 @@ with visit_codes as ( , claims_encounters as ( select - patient_id + person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as procedure_encounter_date , coalesce(claim_end_date,claim_start_date) as claims_encounter_date from {{ ref('quality_measures__stg_medical_claim') }} medical_claim @@ -85,7 +85,7 @@ with visit_codes as ( , multiple_encounters_by_patient as ( select - patient_id + person_id , procedure_encounter_date , claims_encounter_date , case when procedure_encounter_date >= claims_encounter_date @@ -98,43 +98,43 @@ with visit_codes as ( , "coalesce(min(claim_enc), '')" ]) }} as qualifying_types from all_encounters - group by patient_id, procedure_encounter_date, claims_encounter_date + group by person_id, procedure_encounter_date, claims_encounter_date ) , max_encounter_dates_by_patient as ( select - patient_id + person_id , max(max_encounter_date) as max_encounter_date from multiple_encounters_by_patient - group by patient_id + group by person_id ) , latest_patient_encounters as ( select - max_encounter_dates_by_patient.patient_id + max_encounter_dates_by_patient.person_id , max_encounter_dates_by_patient.max_encounter_date , procedure_encounter_date , claims_encounter_date from max_encounter_dates_by_patient inner join multiple_encounters_by_patient - on max_encounter_dates_by_patient.patient_id = multiple_encounters_by_patient.patient_id + on max_encounter_dates_by_patient.person_id = multiple_encounters_by_patient.person_id ) , patients_with_age as ( select - p.patient_id + p.person_id , procedure_encounter_date , claims_encounter_date , floor({{ datediff('birth_date', 'e.max_encounter_date', 'hour') }} / 8760.0) as max_age from {{ ref('quality_measures__stg_core__patient') }} p inner join latest_patient_encounters e - on p.patient_id = e.patient_id + on p.person_id = e.person_id where p.death_date is null ) @@ -143,7 +143,7 @@ with visit_codes as ( select distinct - patients_with_age.patient_id + patients_with_age.person_id , patients_with_age.max_age as age , patients_with_age.procedure_encounter_date , patients_with_age.claims_encounter_date @@ -162,7 +162,7 @@ with visit_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(age as integer) as age , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end @@ -177,7 +177,7 @@ with visit_codes as ( ) select - patient_id + person_id , age , procedure_encounter_date , claims_encounter_date diff --git a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_exclusions.sql b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_exclusions.sql index d8993c4bf..832f9550e 100644 --- a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_exclusions.sql +++ b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_exclusions.sql @@ -35,7 +35,7 @@ with exclusion_codes as ( , conditions as ( select - patient_id + person_id , recorded_date , claim_id , coalesce ( @@ -57,7 +57,7 @@ with exclusion_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -79,7 +79,7 @@ with exclusion_codes as ( , medical_claim as ( select - patient_id + person_id , claim_start_date , claim_end_date , hcpcs_code @@ -91,7 +91,7 @@ with exclusion_codes as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.claim_id , conditions.recorded_date , exclusion_codes.concept_name as concept_name @@ -105,7 +105,7 @@ with exclusion_codes as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name as concept_name from procedures @@ -118,7 +118,7 @@ with exclusion_codes as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , coalesce(medical_claim.claim_end_date, medical_claim.claim_start_date) as exclusion_date , medical_claim.hcpcs_code , exclusion_codes.concept_name as concept_name @@ -132,7 +132,7 @@ with exclusion_codes as ( , patients_with_exclusions as ( select - patient_id + person_id , recorded_date as exclusion_date , concept_name as exclusion_reason from condition_exclusions @@ -140,7 +140,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , procedure_date as exclusion_date , concept_name as exclusion_reason from procedure_exclusions @@ -148,7 +148,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , exclusion_date , concept_name as exclusion_reason from med_claim_exclusions @@ -158,12 +158,12 @@ with exclusion_codes as ( , valid_exclusions as ( select - patients_with_exclusions.patient_id + patients_with_exclusions.person_id , patients_with_exclusions.exclusion_date , patients_with_exclusions.exclusion_reason from patients_with_exclusions inner join {{ ref('quality_measures__int_cqm130_denominator') }} as denominator - on patients_with_exclusions.patient_id = denominator.patient_id + on patients_with_exclusions.person_id = denominator.person_id ) @@ -171,7 +171,7 @@ with exclusion_codes as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , cast(1 as integer) as exclusion_flag @@ -180,7 +180,7 @@ with exclusion_codes as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_long.sql b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_long.sql index 7c1b160ca..4b5b95d89 100644 --- a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_long.sql +++ b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_cqm130_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_cqm130_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,9 +84,9 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) @@ -96,7 +96,7 @@ with denominator as ( , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -117,7 +117,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -135,7 +135,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_numerator.sql b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_numerator.sql index 346805ad9..134174481 100644 --- a/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_numerator.sql +++ b/models/quality_measures/intermediate/cqm130_documentation_of_current_medications_in_the_medical_record/quality_measures__int_cqm130_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , procedure_encounter_date , claims_encounter_date , performance_period_begin @@ -34,7 +34,7 @@ with denominator as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -55,7 +55,7 @@ with denominator as ( , documenting_meds_procedures as ( select - patient_id + person_id , procedure_date from procedures inner join medication_code @@ -67,7 +67,7 @@ with denominator as ( , documenting_meds_claims as ( select - patient_id + person_id , coalesce(claim_end_date,claim_start_date) as encounter_date from {{ ref('quality_measures__stg_medical_claim') }} medical_claim inner join medication_code @@ -79,7 +79,7 @@ with denominator as ( , qualifying_procedure as ( select - documenting_meds_procedures.patient_id + documenting_meds_procedures.person_id , documenting_meds_procedures.procedure_date as encounter_date , denominator.performance_period_begin , denominator.performance_period_end @@ -88,7 +88,7 @@ with denominator as ( , denominator.measure_version from documenting_meds_procedures inner join denominator - on documenting_meds_procedures.patient_id = denominator.patient_id + on documenting_meds_procedures.person_id = denominator.person_id and documenting_meds_procedures.procedure_date = denominator.procedure_encounter_date ) @@ -96,7 +96,7 @@ with denominator as ( , qualifying_claims as ( select - documenting_meds_claims.patient_id + documenting_meds_claims.person_id , documenting_meds_claims.encounter_date , denominator.performance_period_begin , denominator.performance_period_end @@ -105,7 +105,7 @@ with denominator as ( , denominator.measure_version from documenting_meds_claims inner join denominator - on documenting_meds_claims.patient_id = denominator.patient_id + on documenting_meds_claims.person_id = denominator.person_id and documenting_meds_claims.encounter_date = denominator.claims_encounter_date ) @@ -113,7 +113,7 @@ with denominator as ( , qualifying_cares as ( select - patient_id + person_id , encounter_date , performance_period_begin , performance_period_end @@ -126,7 +126,7 @@ with denominator as ( union all select - patient_id + person_id , encounter_date , performance_period_begin , performance_period_end @@ -141,7 +141,7 @@ with denominator as ( , add_data_types as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -155,7 +155,7 @@ with denominator as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator.sql index 2a3310b1b..9b4cdb9a1 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator.sql @@ -6,7 +6,7 @@ with patients_with_ascvd as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with patients_with_ascvd as ( , patients_with_cholesterol as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -34,7 +34,7 @@ with patients_with_ascvd as ( , patients_with_diabetes as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -65,7 +65,7 @@ with patients_with_ascvd as ( , visits_encounters as ( - select patient_id + select person_id , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date from {{ ref('quality_measures__stg_core__encounter') }} encounter @@ -85,7 +85,7 @@ with patients_with_ascvd as ( , procedure_encounters as ( select - patient_id + person_id , procedure_date as min_date , procedure_date as max_date from {{ ref('quality_measures__stg_core__procedure') }} procedures @@ -98,7 +98,7 @@ with patients_with_ascvd as ( , claims_encounters as ( - select patient_id + select person_id , coalesce(claim_start_date,claim_end_date) as min_date , coalesce(claim_end_date,claim_start_date) as max_date from {{ ref('quality_measures__stg_medical_claim') }} medical_claim @@ -129,25 +129,25 @@ with patients_with_ascvd as ( , encounters_by_patient as ( - select patient_id,min(min_date) min_date, max(max_date) max_date, + select person_id,min(min_date) min_date, max(max_date) max_date, concat(concat( coalesce(min(visit_enc),'') ,coalesce(min(proc_enc),'')) ,coalesce(min(claim_enc),'') ) as qualifying_types from all_encounters - group by patient_id + group by person_id ) , patients_with_age as ( select - p.patient_id + p.person_id , floor({{ datediff('birth_date', 'performance_period_begin', 'hour') }} / 8760.0) as age from {{ ref('quality_measures__stg_core__patient') }} p inner join encounters_by_patient e - on p.patient_id = e.patient_id + on p.person_id = e.person_id and p.death_date is null cross join {{ ref('quality_measures__int_cqm438__performance_period') }} @@ -157,7 +157,7 @@ with patients_with_ascvd as ( select distinct - patients_with_ascvd.patient_id + patients_with_ascvd.person_id , patients_with_age.age as age , patients_with_ascvd.performance_period_begin , patients_with_ascvd.performance_period_end @@ -167,7 +167,7 @@ with patients_with_ascvd as ( , 1 as denominator_flag from patients_with_ascvd left join patients_with_age - on patients_with_ascvd.patient_id = patients_with_age.patient_id + on patients_with_ascvd.person_id = patients_with_age.person_id where age is not null ) @@ -176,7 +176,7 @@ with patients_with_ascvd as ( select distinct - patients_with_cholesterol.patient_id + patients_with_cholesterol.person_id , patients_with_age.age as age , patients_with_cholesterol.performance_period_begin , patients_with_cholesterol.performance_period_end @@ -186,7 +186,7 @@ with patients_with_ascvd as ( , 1 as denominator_flag from patients_with_cholesterol left join patients_with_age - on patients_with_cholesterol.patient_id = patients_with_age.patient_id + on patients_with_cholesterol.person_id = patients_with_age.person_id where age between 20 and 75 ) @@ -195,7 +195,7 @@ with patients_with_ascvd as ( select distinct - patients_with_diabetes.patient_id + patients_with_diabetes.person_id , patients_with_age.age as age , patients_with_diabetes.performance_period_begin , patients_with_diabetes.performance_period_end @@ -205,7 +205,7 @@ with patients_with_ascvd as ( , 1 as denominator_flag from patients_with_diabetes left join patients_with_age - on patients_with_diabetes.patient_id = patients_with_age.patient_id + on patients_with_diabetes.person_id = patients_with_age.person_id where age between 40 and 75 ) @@ -213,7 +213,7 @@ with patients_with_ascvd as ( , final_denominator as ( select - patient_id + person_id , age , performance_period_begin , performance_period_end @@ -226,7 +226,7 @@ with patients_with_ascvd as ( union all select - patient_id + person_id , age , performance_period_begin , performance_period_end @@ -239,7 +239,7 @@ with patients_with_ascvd as ( union all select - patient_id + person_id , age , performance_period_begin , performance_period_end @@ -254,7 +254,7 @@ with patients_with_ascvd as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(age as integer) as age , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end @@ -267,7 +267,7 @@ with patients_with_ascvd as ( ) select - patient_id + person_id , age , performance_period_begin , performance_period_end diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria1.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria1.sql index 043406ee1..6ae926c24 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria1.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria1.sql @@ -26,7 +26,7 @@ with ascvd_codes as ( , conditions as ( select - patient_id + person_id , claim_id , encounter_id , recorded_date @@ -41,7 +41,7 @@ with ascvd_codes as ( , ascvd_conditions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date as evidence_date from conditions inner join ascvd_codes @@ -53,7 +53,7 @@ with ascvd_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -74,7 +74,7 @@ with ascvd_codes as ( , ascvd_procedures as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date as evidence_date from procedures inner join ascvd_codes @@ -86,14 +86,14 @@ with ascvd_codes as ( , historical_ascvd as ( select - ascvd_conditions.patient_id + ascvd_conditions.person_id , ascvd_conditions.evidence_date from ascvd_conditions union all select - ascvd_procedures.patient_id + ascvd_procedures.person_id , ascvd_procedures.evidence_date from ascvd_procedures @@ -103,7 +103,7 @@ with ascvd_codes as ( select distinct - historical_ascvd.patient_id + historical_ascvd.person_id , pp.performance_period_begin , pp.performance_period_end , pp.measure_id @@ -118,7 +118,7 @@ with ascvd_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -129,7 +129,7 @@ with ascvd_codes as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria2.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria2.sql index 370569b2e..ffa58bbc8 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria2.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria2.sql @@ -20,7 +20,7 @@ with cholesterol_codes as ( , conditions as ( select - patient_id + person_id , claim_id , encounter_id , recorded_date @@ -35,7 +35,7 @@ with cholesterol_codes as ( , cholesterol_conditions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date as evidence_date from conditions inner join cholesterol_codes @@ -47,7 +47,7 @@ with cholesterol_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -68,7 +68,7 @@ with cholesterol_codes as ( , cholesterol_procedures as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date as evidence_date from procedures inner join cholesterol_codes @@ -80,7 +80,7 @@ with cholesterol_codes as ( , labs as ( select - patient_id + person_id , result , result_date , collection_date @@ -95,11 +95,11 @@ with cholesterol_codes as ( , cholesterol_tests_with_result as ( select - labs.patient_id + labs.person_id , labs.result as evidence_value , coalesce(collection_date, result_date) as evidence_date , cholesterol_codes.concept_name - , row_number() over(partition by labs.patient_id order by + , row_number() over(partition by labs.person_id order by labs.result desc , result_date desc) as rn from labs @@ -118,7 +118,7 @@ with cholesterol_codes as ( , cholesterol_labs as ( select - patient_id + person_id , evidence_date from cholesterol_tests_with_result where rn= 1 @@ -129,21 +129,21 @@ with cholesterol_codes as ( , all_patients_with_cholesterol as ( select - cholesterol_conditions.patient_id + cholesterol_conditions.person_id , cholesterol_conditions.evidence_date from cholesterol_conditions union all select - cholesterol_procedures.patient_id + cholesterol_procedures.person_id , cholesterol_procedures.evidence_date from cholesterol_procedures union all select - cholesterol_labs.patient_id + cholesterol_labs.person_id , cholesterol_labs.evidence_date from cholesterol_labs @@ -153,7 +153,7 @@ with cholesterol_codes as ( select distinct - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -168,7 +168,7 @@ with cholesterol_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -179,7 +179,7 @@ with cholesterol_codes as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria3.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria3.sql index 709a81115..1fb841f7d 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria3.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_denominator_criteria3.sql @@ -19,7 +19,7 @@ with diabetes_codes as ( , conditions as ( select - patient_id + person_id , claim_id , encounter_id , recorded_date @@ -34,7 +34,7 @@ with diabetes_codes as ( , diabetes_conditions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date as evidence_date from conditions inner join diabetes_codes @@ -47,7 +47,7 @@ with diabetes_codes as ( select distinct - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -62,7 +62,7 @@ with diabetes_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -73,7 +73,7 @@ with diabetes_codes as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_exclusions.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_exclusions.sql index 69522f5e4..785804006 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_exclusions.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_exclusions.sql @@ -52,7 +52,7 @@ with exclusion_codes as ( , valid_hospice_palliative as ( select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_type @@ -64,7 +64,7 @@ with exclusion_codes as ( , conditions as ( select - patient_id + person_id , claim_id , recorded_date , coalesce ( @@ -86,7 +86,7 @@ with exclusion_codes as ( , medical_claim as ( select - patient_id + person_id , claim_id , claim_start_date , claim_end_date @@ -100,7 +100,7 @@ with exclusion_codes as ( , observations as ( select - patient_id + person_id , observation_date , coalesce ( normalized_code_type @@ -122,7 +122,7 @@ with exclusion_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -144,7 +144,7 @@ with exclusion_codes as ( , medications as ( select - patient_id + person_id , coalesce(prescribing_date, dispensing_date) as exclusion_date , source_code , source_code_type @@ -155,7 +155,7 @@ with exclusion_codes as ( , pharmacy_claims as ( select - patient_id + person_id , dispensing_date , ndc_code from {{ ref('quality_measures__stg_pharmacy_claim') }} @@ -165,7 +165,7 @@ with exclusion_codes as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.claim_id , conditions.recorded_date , exclusion_codes.concept_name as concept_name @@ -179,7 +179,7 @@ with exclusion_codes as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , medical_claim.claim_id , medical_claim.claim_start_date , medical_claim.claim_end_date @@ -195,7 +195,7 @@ with exclusion_codes as ( , observation_exclusions as ( select - observations.patient_id + observations.person_id , observations.observation_date , exclusion_codes.concept_name as concept_name from observations @@ -208,7 +208,7 @@ with exclusion_codes as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name as concept_name from procedures @@ -221,7 +221,7 @@ with exclusion_codes as ( , medication_exclusions as ( select - medications.patient_id + medications.person_id , medications.exclusion_date , exclusion_codes.concept_name as concept_name from medications @@ -234,7 +234,7 @@ with exclusion_codes as ( , pharmacy_claims_exclusions as ( select - pharmacy_claims.patient_id + pharmacy_claims.person_id , pharmacy_claims.dispensing_date , exclusion_codes.concept_name as concept_name from pharmacy_claims @@ -247,7 +247,7 @@ with exclusion_codes as ( , patients_with_exclusions as( select - patient_id + person_id , recorded_date as exclusion_date , concept_name as exclusion_reason from condition_exclusions @@ -255,7 +255,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , coalesce(claim_end_date, claim_start_date) as exclusion_date , concept_name as exclusion_reason from med_claim_exclusions @@ -263,7 +263,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , observation_date as exclusion_date , concept_name as exclusion_reason from observation_exclusions @@ -271,7 +271,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , procedure_date as exclusion_date , concept_name as exclusion_reason from procedure_exclusions @@ -279,7 +279,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , exclusion_date , concept_name as exclusion_reason from medication_exclusions @@ -287,7 +287,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , dispensing_date as exclusion_date , concept_name as exclusion_reason from pharmacy_claims_exclusions @@ -295,7 +295,7 @@ with exclusion_codes as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from valid_hospice_palliative @@ -305,12 +305,12 @@ with exclusion_codes as ( , valid_exclusions as ( select - patients_with_exclusions.patient_id + patients_with_exclusions.person_id , patients_with_exclusions.exclusion_date , patients_with_exclusions.exclusion_reason from patients_with_exclusions inner join {{ ref('quality_measures__int_cqm438_denominator') }} as denominator - on patients_with_exclusions.patient_id = denominator.patient_id + on patients_with_exclusions.person_id = denominator.person_id ) @@ -318,7 +318,7 @@ with exclusion_codes as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , cast(1 as integer) as exclusion_flag @@ -327,7 +327,7 @@ with exclusion_codes as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_long.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_long.sql index debd65fdc..ffeca80ba 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_long.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_cqm438_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_cqm438_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,9 +84,9 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) @@ -96,7 +96,7 @@ with denominator as ( , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -117,7 +117,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -135,7 +135,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_numerator.sql b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_numerator.sql index 6ff544390..3fb95d656 100644 --- a/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_numerator.sql +++ b/models/quality_measures/intermediate/cqm438_statin_therapy_for_patients_with_cardiovascular_disease/quality_measures__int_cqm438_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -35,7 +35,7 @@ with denominator as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -56,7 +56,7 @@ with denominator as ( , procedure_statin_related as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date as evidence_date from procedures inner join statin_codes @@ -68,7 +68,7 @@ with denominator as ( , pharmacy_claims_statin_related as ( select - patient_id + person_id , dispensing_date as evidence_date , ndc_code from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claims @@ -81,7 +81,7 @@ with denominator as ( , medication_statin_related as ( select - patient_id + person_id , coalesce(dispensing_date, prescribing_date) as evidence_date , source_code , source_code_type @@ -95,21 +95,21 @@ with denominator as ( , qualifying_patients as ( select - procedure_statin_related.patient_id + procedure_statin_related.person_id , procedure_statin_related.evidence_date from procedure_statin_related union all select - pharmacy_claims_statin_related.patient_id + pharmacy_claims_statin_related.person_id , pharmacy_claims_statin_related.evidence_date from pharmacy_claims_statin_related union all select - medication_statin_related.patient_id + medication_statin_related.person_id , medication_statin_related.evidence_date from medication_statin_related @@ -118,7 +118,7 @@ with denominator as ( , qualifying_patients_with_denominator as ( select - qualifying_patients.patient_id + qualifying_patients.person_id , qualifying_patients.evidence_date , denominator.performance_period_begin , denominator.performance_period_end @@ -128,7 +128,7 @@ with denominator as ( , cast(1 as integer) as numerator_flag from qualifying_patients inner join denominator - on qualifying_patients.patient_id = denominator.patient_id + on qualifying_patients.person_id = denominator.person_id and evidence_date between denominator.performance_period_begin and denominator.performance_period_end @@ -138,7 +138,7 @@ with denominator as ( , add_data_types as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -152,7 +152,7 @@ with denominator as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_denominator.sql b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_denominator.sql index 794978547..5546e4b08 100644 --- a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_denominator.sql +++ b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_denominator.sql @@ -21,7 +21,7 @@ with visit_codes as ( , visits_encounters as ( select - patient_id + person_id , coalesce(encounter.encounter_start_date, encounter.encounter_end_date) as min_date , coalesce(encounter.encounter_end_date, encounter.encounter_start_date) as max_date from {{ ref('quality_measures__stg_core__encounter') }} encounter @@ -40,7 +40,7 @@ with visit_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -66,7 +66,7 @@ with visit_codes as ( , claims as ( select - patient_id + person_id , coalesce(claim_start_date,claim_end_date) as min_date , coalesce(claim_end_date,claim_start_date) as max_date , hcpcs_code @@ -83,7 +83,7 @@ with visit_codes as ( , procedure_encounters as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date as min_date , procedures.procedure_date as max_date from procedures @@ -98,7 +98,7 @@ with visit_codes as ( , claims_encounters as ( select - claims.patient_id + claims.person_id , claims.min_date , claims.max_date from claims @@ -131,7 +131,7 @@ with visit_codes as ( , encounters_by_patient as ( select - patient_id + person_id , max(max_date) max_date , {{ dbt.concat([ "coalesce(min(visit_enc), '')" @@ -139,19 +139,19 @@ with visit_codes as ( , "coalesce(min(claim_enc), '')" ]) }} as qualifying_types from all_encounters - group by patient_id + group by person_id ) , patients_with_age as ( select - p.patient_id + p.person_id , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age , qualifying_types from {{ ref('quality_measures__stg_core__patient') }} p inner join encounters_by_patient e - on p.patient_id = e.patient_id + on p.person_id = e.person_id where p.death_date is null ) @@ -160,7 +160,7 @@ with visit_codes as ( select distinct - patient_id + person_id , max_age as age , pp.performance_period_begin , pp.performance_period_end @@ -177,7 +177,7 @@ with visit_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(age as integer) as age , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end @@ -190,7 +190,7 @@ with visit_codes as ( ) select - patient_id + person_id , age , performance_period_begin , performance_period_end diff --git a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_exclusions.sql b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_exclusions.sql index 712a6622a..7fd946ed2 100644 --- a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_exclusions.sql +++ b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_exclusions.sql @@ -24,7 +24,7 @@ with denominator as ( select - patient_id + person_id from {{ ref('quality_measures__int_nqf0420_denominator') }} ) @@ -45,7 +45,7 @@ with denominator as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -67,7 +67,7 @@ with denominator as ( , medical_claim as ( select - patient_id + person_id , claim_start_date , claim_end_date , hcpcs_code @@ -79,7 +79,7 @@ with denominator as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name as concept_name from procedures @@ -92,7 +92,7 @@ with denominator as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , coalesce(medical_claim.claim_end_date, medical_claim.claim_start_date) as exclusion_date , medical_claim.hcpcs_code , exclusion_codes.concept_name as concept_name @@ -106,7 +106,7 @@ with denominator as ( , patients_with_exclusions as( select - patient_id + person_id , exclusion_date , concept_name as exclusion_reason from med_claim_exclusions @@ -114,7 +114,7 @@ with denominator as ( union all select - patient_id + person_id , procedure_date as exclusion_date , concept_name as exclusion_reason from procedure_exclusions @@ -124,12 +124,12 @@ with denominator as ( , valid_exclusions as ( select - patients_with_exclusions.patient_id + patients_with_exclusions.person_id , patients_with_exclusions.exclusion_date , patients_with_exclusions.exclusion_reason from patients_with_exclusions inner join denominator - on patients_with_exclusions.patient_id = denominator.patient_id + on patients_with_exclusions.person_id = denominator.person_id ) @@ -137,7 +137,7 @@ with denominator as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , cast(1 as integer) as exclusion_flag @@ -146,7 +146,7 @@ with denominator as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_long.sql b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_long.sql index 5e8a875df..933ed759a 100644 --- a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_long.sql +++ b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -20,7 +20,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_nqf0420_numerator') }} @@ -30,7 +30,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_nqf0420_exclusions') }} @@ -40,23 +40,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -71,7 +71,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -84,9 +84,9 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) @@ -96,7 +96,7 @@ with denominator as ( , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -117,7 +117,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -135,7 +135,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_numerator.sql b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_numerator.sql index e8be3d1f3..784e20315 100644 --- a/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_numerator.sql +++ b/models/quality_measures/intermediate/nqf0420_pain_assessment_and_follow_up/quality_measures__int_nqf0420_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -32,7 +32,7 @@ with denominator as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -53,7 +53,7 @@ with denominator as ( , pain_assessment_procedures as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date as evidence_date from procedures inner join pain_assessment_code @@ -65,7 +65,7 @@ with denominator as ( , pain_assessment_claims as ( select - patient_id + person_id , coalesce(claim_end_date, claim_start_date) as evidence_date from {{ ref('quality_measures__stg_medical_claim') }} medical_claim inner join pain_assessment_code @@ -77,14 +77,14 @@ with denominator as ( , time_unbounded_qualifying_patients as ( select - patient_id + person_id , evidence_date from pain_assessment_procedures union all select - patient_id + person_id , evidence_date from pain_assessment_claims @@ -93,7 +93,7 @@ with denominator as ( , qualifying_patients_with_denominator as ( select - time_unbounded_qualifying_patients.patient_id + time_unbounded_qualifying_patients.person_id , time_unbounded_qualifying_patients.evidence_date , denominator.performance_period_begin , denominator.performance_period_end @@ -103,7 +103,7 @@ with denominator as ( , 1 as numerator_flag from time_unbounded_qualifying_patients inner join denominator - on time_unbounded_qualifying_patients.patient_id = denominator.patient_id + on time_unbounded_qualifying_patients.person_id = denominator.person_id and time_unbounded_qualifying_patients.evidence_date between denominator.performance_period_begin and denominator.performance_period_end @@ -112,7 +112,7 @@ with denominator as ( , add_data_types as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end , cast(measure_id as {{ dbt.type_string() }}) as measure_id @@ -126,7 +126,7 @@ with denominator as ( ) select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id diff --git a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_advanced_illness.sql b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_advanced_illness.sql index 4de330d68..3c2324cca 100644 --- a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_advanced_illness.sql +++ b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_advanced_illness.sql @@ -6,7 +6,7 @@ with patients_with_frailty as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_frailty') }} @@ -35,7 +35,7 @@ with patients_with_frailty as ( , conditions as ( select - patient_id + person_id , claim_id , recorded_date , coalesce ( @@ -56,7 +56,7 @@ with patients_with_frailty as ( , medical_claim as ( select - patient_id + person_id , claim_id , claim_start_date , claim_end_date @@ -69,7 +69,7 @@ with patients_with_frailty as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -90,7 +90,7 @@ with patients_with_frailty as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.claim_id , conditions.recorded_date , exclusion_codes.concept_name @@ -105,7 +105,7 @@ with patients_with_frailty as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , medical_claim.claim_id , medical_claim.claim_start_date , medical_claim.claim_end_date @@ -121,7 +121,7 @@ with patients_with_frailty as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name from procedures @@ -134,7 +134,7 @@ with patients_with_frailty as ( , acute_inpatient as ( select distinct - patients_with_frailty.patient_id + patients_with_frailty.person_id , coalesce( med_claim_exclusions.claim_start_date , med_claim_exclusions.claim_end_date @@ -151,7 +151,7 @@ with patients_with_frailty as ( , cast(null as date) as procedure_date from patients_with_frailty inner join med_claim_exclusions - on patients_with_frailty.patient_id = med_claim_exclusions.patient_id + on patients_with_frailty.person_id = med_claim_exclusions.person_id inner join condition_exclusions on med_claim_exclusions.claim_id = condition_exclusions.claim_id where lower(med_claim_exclusions.concept_name) = 'acute inpatient' @@ -159,7 +159,7 @@ with patients_with_frailty as ( union all select distinct - patients_with_frailty.patient_id + patients_with_frailty.person_id , procedure_exclusions.procedure_date as exclusion_date , {{ dbt.concat([ "patients_with_frailty.exclusion_reason", @@ -173,9 +173,9 @@ with patients_with_frailty as ( , procedure_exclusions.procedure_date from patients_with_frailty inner join procedure_exclusions - on patients_with_frailty.patient_id = procedure_exclusions.patient_id + on patients_with_frailty.person_id = procedure_exclusions.person_id inner join condition_exclusions - on procedure_exclusions.patient_id = condition_exclusions.patient_id + on procedure_exclusions.person_id = condition_exclusions.person_id and procedure_exclusions.procedure_date = condition_exclusions.recorded_date where lower(procedure_exclusions.concept_name) = 'acute inpatient' @@ -184,7 +184,7 @@ with patients_with_frailty as ( , nonacute_outpatient as ( select distinct - patients_with_frailty.patient_id + patients_with_frailty.person_id , coalesce( med_claim_exclusions.claim_start_date , med_claim_exclusions.claim_end_date @@ -201,7 +201,7 @@ with patients_with_frailty as ( , cast(null as date) as procedure_date from patients_with_frailty inner join med_claim_exclusions - on patients_with_frailty.patient_id = med_claim_exclusions.patient_id + on patients_with_frailty.person_id = med_claim_exclusions.person_id inner join condition_exclusions on med_claim_exclusions.claim_id = condition_exclusions.claim_id where lower(med_claim_exclusions.concept_name) in ( @@ -215,7 +215,7 @@ with patients_with_frailty as ( union all select distinct - patients_with_frailty.patient_id + patients_with_frailty.person_id , procedure_exclusions.procedure_date as exclusion_date , {{ dbt.concat([ "patients_with_frailty.exclusion_reason", @@ -229,9 +229,9 @@ with patients_with_frailty as ( , procedure_exclusions.procedure_date from patients_with_frailty inner join procedure_exclusions - on patients_with_frailty.patient_id = procedure_exclusions.patient_id + on patients_with_frailty.person_id = procedure_exclusions.person_id inner join condition_exclusions - on procedure_exclusions.patient_id = condition_exclusions.patient_id + on procedure_exclusions.person_id = condition_exclusions.person_id and procedure_exclusions.procedure_date = condition_exclusions.recorded_date where lower(procedure_exclusions.concept_name) in ( 'encounter inpatient' @@ -246,7 +246,7 @@ with patients_with_frailty as ( , exclusions_unioned as ( select - acute_inpatient.patient_id + acute_inpatient.person_id , acute_inpatient.exclusion_date , acute_inpatient.exclusion_reason , acute_inpatient.claim_start_date @@ -258,7 +258,7 @@ with patients_with_frailty as ( union all select - nonacute_outpatient.patient_id + nonacute_outpatient.person_id , nonacute_outpatient.exclusion_date , nonacute_outpatient.exclusion_reason , nonacute_outpatient.claim_start_date @@ -270,7 +270,7 @@ with patients_with_frailty as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , 'advanced_illness' as exclusion_type diff --git a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_dementia.sql b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_dementia.sql index a204cbe8e..076443ce0 100644 --- a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_dementia.sql +++ b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_dementia.sql @@ -7,7 +7,7 @@ with patients_with_frailty as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_frailty') }} @@ -30,7 +30,7 @@ with patients_with_frailty as ( , medications as ( select - patient_id + person_id , dispensing_date , source_code_type , source_code @@ -43,7 +43,7 @@ with patients_with_frailty as ( , pharmacy_claim as ( select - patient_id + person_id , dispensing_date , ndc_code , paid_date @@ -54,7 +54,7 @@ with patients_with_frailty as ( , medication_exclusions as ( select - medications.patient_id + medications.person_id , medications.dispensing_date , exclusion_codes.concept_name from medications @@ -65,7 +65,7 @@ with patients_with_frailty as ( union all select - medications.patient_id + medications.person_id , medications.dispensing_date , exclusion_codes.concept_name from medications @@ -76,7 +76,7 @@ with patients_with_frailty as ( union all select - medications.patient_id + medications.person_id , medications.dispensing_date , exclusion_codes.concept_name from medications @@ -89,7 +89,7 @@ with patients_with_frailty as ( , pharmacy_claim_exclusions as ( select - pharmacy_claim.patient_id + pharmacy_claim.person_id , pharmacy_claim.dispensing_date , pharmacy_claim.ndc_code , pharmacy_claim.paid_date @@ -104,7 +104,7 @@ with patients_with_frailty as ( , frailty_with_dementia as ( select - patients_with_frailty.patient_id + patients_with_frailty.person_id , patients_with_frailty.exclusion_date , {{ dbt.concat([ "patients_with_frailty.exclusion_reason", @@ -115,12 +115,12 @@ with patients_with_frailty as ( , pharmacy_claim_exclusions.paid_date from patients_with_frailty inner join pharmacy_claim_exclusions - on patients_with_frailty.patient_id = pharmacy_claim_exclusions.patient_id + on patients_with_frailty.person_id = pharmacy_claim_exclusions.person_id union all select - patients_with_frailty.patient_id + patients_with_frailty.person_id , medication_exclusions.dispensing_date as exclusion_date , {{ dbt.concat([ "patients_with_frailty.exclusion_reason", @@ -131,12 +131,12 @@ with patients_with_frailty as ( , null as paid_date from patients_with_frailty inner join medication_exclusions - on patients_with_frailty.patient_id = medication_exclusions.patient_id + on patients_with_frailty.person_id = medication_exclusions.person_id ) select - patient_id + person_id , exclusion_date , exclusion_reason , 'dementia' as exclusion_type diff --git a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_frailty.sql b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_frailty.sql index 1a6b41f01..659850e33 100644 --- a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_frailty.sql +++ b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_frailty.sql @@ -7,7 +7,7 @@ with patients as ( select - patient_id + person_id from {{ ref('quality_measures__stg_core__patient') }} ) @@ -31,7 +31,7 @@ with patients as ( , conditions as ( select - patient_id + person_id , recorded_date , coalesce ( normalized_code_type @@ -51,7 +51,7 @@ with patients as ( , medical_claim as ( select - patient_id + person_id , claim_start_date , claim_end_date , hcpcs_code @@ -63,7 +63,7 @@ with patients as ( , observations as ( select - patient_id + person_id , observation_date , coalesce ( normalized_code_type @@ -84,7 +84,7 @@ with patients as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -105,7 +105,7 @@ with patients as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date , exclusion_codes.concept_name from conditions @@ -118,7 +118,7 @@ with patients as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , medical_claim.claim_start_date , medical_claim.claim_end_date , medical_claim.hcpcs_code @@ -133,7 +133,7 @@ with patients as ( , observation_exclusions as ( select - observations.patient_id + observations.person_id , observations.observation_date , exclusion_codes.concept_name from observations @@ -146,7 +146,7 @@ with patients as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name from procedures @@ -159,17 +159,17 @@ with patients as ( , patients_with_frailty as ( select - patients.patient_id + patients.person_id , condition_exclusions.recorded_date as exclusion_date , condition_exclusions.concept_name as exclusion_reason from patients inner join condition_exclusions - on patients.patient_id = condition_exclusions.patient_id + on patients.person_id = condition_exclusions.person_id union all select - patients.patient_id + patients.person_id , coalesce( med_claim_exclusions.claim_start_date , med_claim_exclusions.claim_end_date @@ -177,32 +177,32 @@ with patients as ( , med_claim_exclusions.concept_name as exclusion_reason from patients inner join med_claim_exclusions - on patients.patient_id = med_claim_exclusions.patient_id + on patients.person_id = med_claim_exclusions.person_id union all select - patients.patient_id + patients.person_id , observation_exclusions.observation_date as exclusion_date , observation_exclusions.concept_name as exclusion_reason from patients inner join observation_exclusions - on patients.patient_id = observation_exclusions.patient_id + on patients.person_id = observation_exclusions.person_id union all select - patients.patient_id + patients.person_id , procedure_exclusions.procedure_date as exclusion_date , procedure_exclusions.concept_name as exclusion_reason from patients inner join procedure_exclusions - on patients.patient_id = procedure_exclusions.patient_id + on patients.person_id = procedure_exclusions.person_id ) select - patient_id + person_id , exclusion_date , exclusion_reason , '{{ var('tuva_last_run')}}' as tuva_last_run diff --git a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_hospice_palliative.sql b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_hospice_palliative.sql index 7570ac5c9..851556a71 100644 --- a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_hospice_palliative.sql +++ b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_hospice_palliative.sql @@ -35,7 +35,7 @@ with exclusion_codes as ( , conditions as ( select - patient_id + person_id , claim_id , recorded_date , coalesce ( @@ -56,7 +56,7 @@ with exclusion_codes as ( , medical_claim as ( select - patient_id + person_id , claim_id , claim_start_date , claim_end_date @@ -69,7 +69,7 @@ with exclusion_codes as ( , observations as ( select - patient_id + person_id , observation_date , coalesce ( normalized_code_type @@ -90,7 +90,7 @@ with exclusion_codes as ( , procedures as ( select - patient_id + person_id , procedure_date , coalesce ( normalized_code_type @@ -111,7 +111,7 @@ with exclusion_codes as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.claim_id , conditions.recorded_date , exclusion_codes.concept_name as concept_name @@ -125,7 +125,7 @@ with exclusion_codes as ( , med_claim_exclusions as ( select - medical_claim.patient_id + medical_claim.person_id , medical_claim.claim_id , medical_claim.claim_start_date , medical_claim.claim_end_date @@ -141,7 +141,7 @@ with exclusion_codes as ( , observation_exclusions as ( select - observations.patient_id + observations.person_id , observations.observation_date , exclusion_codes.concept_name as concept_name from observations @@ -154,7 +154,7 @@ with exclusion_codes as ( , procedure_exclusions as ( select - procedures.patient_id + procedures.person_id , procedures.procedure_date , exclusion_codes.concept_name as concept_name from procedures @@ -166,28 +166,28 @@ with exclusion_codes as ( , patients_with_exclusions as( - select patient_id + select person_id , recorded_date as exclusion_date , concept_name as exclusion_reason from condition_exclusions union all - select patient_id + select person_id , coalesce(claim_end_date, claim_start_date) as exclusion_date , concept_name as exclusion_reason from med_claim_exclusions union all - select patient_id + select person_id , observation_date as exclusion_date , concept_name as exclusion_reason from observation_exclusions union all - select patient_id + select person_id , procedure_date as exclusion_date , concept_name as exclusion_reason from procedure_exclusions @@ -195,7 +195,7 @@ with exclusion_codes as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , 'hospice_palliative' as exclusion_type diff --git a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_institutional_snp.sql b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_institutional_snp.sql index 0c184b34b..dabfee6e1 100644 --- a/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_institutional_snp.sql +++ b/models/quality_measures/intermediate/shared_exclusions/quality_measures__int_shared_exclusions_institutional_snp.sql @@ -17,7 +17,7 @@ with patients as ( select - patient_id + person_id from {{ ref('quality_measures__stg_core__patient') }} ) @@ -25,7 +25,7 @@ with patients as ( , medical_claim as ( select - patient_id + person_id , claim_start_date , claim_end_date , hcpcs_code @@ -37,7 +37,7 @@ with patients as ( , exclusions as ( select - patients.patient_id + patients.person_id , coalesce( medical_claim.claim_start_date , medical_claim.claim_end_date @@ -45,14 +45,14 @@ with patients as ( , 'institutional or long term care' as exclusion_reason from patients inner join medical_claim - on patients.patient_id = medical_claim.patient_id + on patients.person_id = medical_claim.person_id where place_of_service_code in ('32', '33', '34', '54', '56') and {{ datediff('medical_claim.claim_start_date', 'medical_claim.claim_end_date', 'day') }} >= 90 ) select - patient_id + person_id , exclusion_date , exclusion_reason , 'institutional_snp' as exclusion_type diff --git a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_denominator.sql b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_denominator.sql index 43849c738..4edd0b4cd 100644 --- a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_denominator.sql +++ b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_denominator.sql @@ -18,7 +18,7 @@ with diabetics_codes as ( , rx_diabetes as ( select - patient_id + person_id , dispensing_date , ndc_code from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claims @@ -31,7 +31,7 @@ with diabetics_codes as ( , rx_diabetes_in_measurement_period as ( select - patient_id + person_id , dispensing_date from rx_diabetes inner join {{ ref('quality_measures__int_supd__performance_period') }} pp @@ -47,11 +47,11 @@ with diabetics_codes as ( , rx_fill_order as ( select - patient_id + person_id , dispensing_date , dense_rank() over ( partition by - patient_id + person_id order by dispensing_date ) as dr from rx_diabetes_in_measurement_period @@ -61,7 +61,7 @@ with diabetics_codes as ( , check_passed_patients as ( select - patient_id + person_id from rx_fill_order where dr = 2 @@ -70,7 +70,7 @@ with diabetics_codes as ( , qualifying_patients_with_age as ( select - patients.patient_id + patients.person_id , floor({{ datediff('birth_date', 'pp.performance_period_begin', 'hour') }} / 8760.0) as age , performance_period_begin , performance_period_end @@ -79,7 +79,7 @@ with diabetics_codes as ( , measure_version from {{ ref('quality_measures__stg_core__patient') }} patients inner join check_passed_patients - on patients.patient_id = check_passed_patients.patient_id + on patients.person_id = check_passed_patients.person_id cross join {{ ref('quality_measures__int_supd__performance_period') }} pp where patients.death_date is null @@ -88,7 +88,7 @@ with diabetics_codes as ( , denominator as ( select - patient_id + person_id , age , performance_period_begin , performance_period_end @@ -104,7 +104,7 @@ with diabetics_codes as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(age as integer) as age , cast(performance_period_begin as date) as performance_period_begin , cast(performance_period_end as date) as performance_period_end @@ -117,7 +117,7 @@ with diabetics_codes as ( ) select - patient_id + person_id , age , performance_period_begin , performance_period_end diff --git a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_exclusions.sql b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_exclusions.sql index 8f3f4426d..c91a80167 100644 --- a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_exclusions.sql +++ b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_exclusions.sql @@ -26,7 +26,7 @@ with denominator as ( select - patient_id + person_id from {{ ref('quality_measures__int_supd_denominator') }} ) @@ -54,7 +54,7 @@ with denominator as ( , hospice_palliative as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} @@ -65,7 +65,7 @@ with denominator as ( , valid_hospice as ( select - patient_id + person_id , exclusion_date , exclusion_reason from hospice_palliative @@ -80,7 +80,7 @@ with denominator as ( , conditions as ( select - patient_id + person_id , recorded_date , claim_id , coalesce ( @@ -102,7 +102,7 @@ with denominator as ( , condition_exclusions as ( select - conditions.patient_id + conditions.person_id , conditions.recorded_date as exclusion_date , exclusion_codes.concept_name as exclusion_reason from conditions @@ -115,7 +115,7 @@ with denominator as ( , pharmacy_exclusions as ( select - patient_id + person_id , dispensing_date as exclusion_date , concept_name as exclusion_reason from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claims @@ -128,7 +128,7 @@ with denominator as ( , exclusion_patients as ( select - patient_id + person_id , exclusion_date , exclusion_reason from valid_hospice @@ -136,7 +136,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from condition_exclusions @@ -144,7 +144,7 @@ with denominator as ( union all select - patient_id + person_id , exclusion_date , exclusion_reason from pharmacy_exclusions @@ -154,12 +154,12 @@ with denominator as ( , combined_exclusions as ( select - exclusion_patients.patient_id + exclusion_patients.person_id , exclusion_patients.exclusion_date , exclusion_patients.exclusion_reason from exclusion_patients inner join denominator - on exclusion_patients.patient_id = denominator.patient_id + on exclusion_patients.person_id = denominator.person_id ) @@ -167,7 +167,7 @@ with denominator as ( select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(exclusion_date as date) as exclusion_date , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason , cast(1 as integer) as exclusion_flag @@ -176,7 +176,7 @@ with denominator as ( ) select - patient_id + person_id , exclusion_date , exclusion_reason , exclusion_flag diff --git a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_long.sql b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_long.sql index 2630ff25d..ac54473a4 100644 --- a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_long.sql +++ b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_long.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -19,7 +19,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , evidence_value from {{ ref('quality_measures__int_supd_numerator') }} @@ -29,7 +29,7 @@ with denominator as ( , exclusions as ( select - patient_id + person_id , exclusion_date , exclusion_reason from {{ ref('quality_measures__int_supd_exclusions') }} @@ -39,23 +39,23 @@ with denominator as ( , measure_flags as ( select - denominator.patient_id + denominator.person_id , case - when denominator.patient_id is not null + when denominator.person_id is not null then 1 else null end as denominator_flag , case - when numerator.patient_id is not null and denominator.patient_id is not null + when numerator.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as numerator_flag , case - when exclusions.patient_id is not null and denominator.patient_id is not null + when exclusions.person_id is not null and denominator.person_id is not null then 1 - when denominator.patient_id is not null + when denominator.person_id is not null then 0 else null end as exclusion_flag @@ -70,7 +70,7 @@ with denominator as ( , denominator.measure_version , (row_number() over( partition by - denominator.patient_id + denominator.person_id , denominator.performance_period_begin , denominator.performance_period_end , denominator.measure_id @@ -83,9 +83,9 @@ with denominator as ( )) as rn from denominator left join numerator - on denominator.patient_id = numerator.patient_id + on denominator.person_id = numerator.person_id left join exclusions - on denominator.patient_id = exclusions.patient_id + on denominator.person_id = exclusions.person_id ) @@ -95,7 +95,7 @@ with denominator as ( , deduped as ( select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag @@ -116,7 +116,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(denominator_flag as integer) as denominator_flag , cast(numerator_flag as integer) as numerator_flag , cast(exclusion_flag as integer) as exclusion_flag @@ -134,7 +134,7 @@ with denominator as ( ) select - patient_id + person_id , denominator_flag , numerator_flag , exclusion_flag diff --git a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_numerator.sql b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_numerator.sql index 0ef844c36..251c68d69 100644 --- a/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_numerator.sql +++ b/models/quality_measures/intermediate/supd_statin_use_in_persons_with_diabetes/quality_measures__int_supd_numerator.sql @@ -6,7 +6,7 @@ with denominator as ( select - patient_id + person_id , performance_period_begin , performance_period_end , measure_id @@ -31,7 +31,7 @@ with denominator as ( , patients_taking_statin_meds as ( select - patient_id + person_id , dispensing_date from {{ ref('quality_measures__stg_pharmacy_claim') }} as pharmacy_claims inner join statin_codes @@ -43,11 +43,11 @@ with denominator as ( , qualifying_patients_in_deno as ( select - patients_taking_statin_meds.patient_id + patients_taking_statin_meds.person_id , patients_taking_statin_meds.dispensing_date as evidence_date from patients_taking_statin_meds inner join denominator - on patients_taking_statin_meds.patient_id = denominator.patient_id + on patients_taking_statin_meds.person_id = denominator.person_id and dispensing_date between denominator.performance_period_begin and denominator.performance_period_end @@ -56,7 +56,7 @@ with denominator as ( , numerator as ( select - patient_id + person_id , evidence_date , 1 as numerator_flag from qualifying_patients_in_deno @@ -66,7 +66,7 @@ with denominator as ( , add_data_types as ( select - cast(patient_id as {{ dbt.type_string() }}) as patient_id + cast(person_id as {{ dbt.type_string() }}) as person_id , cast(evidence_date as date) as evidence_date , cast(null as {{ dbt.type_string() }}) as evidence_value , cast(numerator_flag as integer) as numerator_flag @@ -75,7 +75,7 @@ with denominator as ( ) select - patient_id + person_id , evidence_date , evidence_value , numerator_flag diff --git a/models/quality_measures/quality_measures_models.yml b/models/quality_measures/quality_measures_models.yml index 08cd1b488..15775d87d 100644 --- a/models/quality_measures/quality_measures_models.yml +++ b/models/quality_measures/quality_measures_models.yml @@ -60,8 +60,8 @@ models: Each row represents the results a measure per patient. A null for the denominator indicates that the patient was not eligible for that measure. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -125,8 +125,8 @@ models: with flags for each measure. The false flags can be treated as care gaps as exclusions have been included in the pivot logic. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: cqm_438 description: > Performance flag for CQM438, Statin Therapy for the Prevention and @@ -233,8 +233,8 @@ models: description: > Subset of denominator logic for submission of criteria 1 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -258,8 +258,8 @@ models: description: > Subset of denominator logic for submission of criteria 2 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -283,8 +283,8 @@ models: description: > Subset of denominator logic for submission of criteria 3 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -308,8 +308,8 @@ models: description: > Denominator logic for submission of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: age description: Patient's age as of performance_period_begin date. - name: performance_period_begin @@ -339,8 +339,8 @@ models: description: > Combined exclusion logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -366,8 +366,8 @@ models: description: > Final preparation of the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -418,8 +418,8 @@ models: description: > Numerator logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -465,8 +465,8 @@ models: description: > Denominator logic for the reporting version of Documentation of Current Medications in the Medical Record. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: age description: Patient's age during latest encounter in the performance period. - name: procedure_encounter_date @@ -500,8 +500,8 @@ models: description: > Combined exclusion logic for the reporting version of CQM 130, Documentation of Current Medications in the Medical Record. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -527,8 +527,8 @@ models: description: > Final preparation of the reporting version of CQM 130, Documentation of Current Medications in the Medical Record before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -579,8 +579,8 @@ models: description: > Numerator logic for the reporting version of CQM 130, Documentation of Current Medications in the Medical Record. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -626,8 +626,8 @@ models: description: > Denominator logic for the reporting version of NQF 0420, Pain Assessment and Follow-Up. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: age description: Patient's age during latest encounter in the performance period. - name: performance_period_begin @@ -657,8 +657,8 @@ models: description: > Combined exclusion logic for the reporting version of NQF 0420, Pain Assessment and Follow-Up. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -684,8 +684,8 @@ models: description: > Final preparation of the reporting version of NQF 0420, Pain Assessment and Follow-Up before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -736,8 +736,8 @@ models: description: > Numerator logic for the reporting version of NQF 0420, Pain Assessment and Follow-Up. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -783,8 +783,8 @@ models: description: > Denominator logic for the reporting version of ADH-Diabetes, Medication Adherence for Diabetes Medications. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: age description: Patient's age during latest encounter in the performance period. - name: dispensing_date @@ -822,8 +822,8 @@ models: description: > Combined exclusion logic for the reporting version of ADH-Diabetes, Medication Adherence for Diabetes Medications. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -849,8 +849,8 @@ models: description: > Final preparation of the reporting version of ADH-Diabetes, Medication Adherence for Diabetes Medications before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -901,8 +901,8 @@ models: description: > Numerator logic for the reporting version of ADH-Diabetes, Medication Adherence for Diabetes Medications. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: evidence_date description: > Date of event or service that places patient in the numerator. @@ -941,8 +941,8 @@ models: description: > Denominator logic for the reporting version of ADH-RAS, Medication Adherence for Hypertension columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: dispensing_date description: Date the prescription was filled. - name: first_dispensing_date @@ -978,8 +978,8 @@ models: description: > Combined exclusion logic for the reporting version of ADH-RAS, Medication Adherence for Hypertension columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -1005,8 +1005,8 @@ models: description: > Final preparation of the reporting version of ADH-RAS, Medication Adherence for Hypertension before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -1057,8 +1057,8 @@ models: description: > Numerator logic for the reporting version of ADH-RAS, Medication Adherence for Hypertension columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: evidence_date description: > Date of event or service that places patient in the numerator. @@ -1097,8 +1097,8 @@ models: description: > Denominator logic for the reporting version of SUPD, Statin Use in Persons with Diabetes columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: age description: Patient's age as of the performance_period_begin date. - name: performance_period_begin @@ -1128,8 +1128,8 @@ models: description: > Combined exclusion logic for the reporting version of SUPD, Statin Use in Persons with Diabetes columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -1155,8 +1155,8 @@ models: description: > Final preparation of the reporting version of SUPD, Statin Use in Persons with Diabetes before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -1207,8 +1207,8 @@ models: description: > Numerator logic for the reporting version of SUPD, Statin Use in Persons with Diabetes columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: evidence_date description: > Date of event or service that places patient in the numerator. @@ -1244,8 +1244,8 @@ models: description: > Denominator logic for the reporting version of ADH-Statins, Medication Adherence for Cholesterol columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: dispensing_date description: Date the prescription was filled. - name: first_dispensing_date @@ -1281,8 +1281,8 @@ models: description: > Combined exclusion logic for the reporting version of ADH-Statins, Medication Adherence for Cholesterol columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: exclusion_date description: > Date of event or service that excludes patient from the measure. @@ -1308,8 +1308,8 @@ models: description: > Final preparation of the reporting version of ADH-Statins, Medication Adherence for Cholesterol before combining with other measures. columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: denominator_flag description: > The denominator is associated with a given patient population that @@ -1360,8 +1360,8 @@ models: description: > Numerator logic for the reporting version of ADH-Statins, Medication Adherence for Cholesterol columns: - - name: patient_id - description: Unique patient_id for each person. + - name: person_id + description: Unique person_id for each person. - name: evidence_date description: > Date of event or service that places patient in the numerator. @@ -1389,7 +1389,7 @@ models: materialized: ephemeral description: Staging conditions from core. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1410,7 +1410,7 @@ models: description: > Staging encounters from core. Creates an empty table if using claims only. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1429,7 +1429,7 @@ models: description: > Staging medications from core. Creates an empty table if using claims only. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1450,7 +1450,7 @@ models: description: > Staging medications from core. Creates an empty table if using claims only. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1470,7 +1470,7 @@ models: materialized: ephemeral description: Staging eligibility from the input layer. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1497,7 +1497,7 @@ models: materialized: ephemeral description: Staging procedures from core. columns: - - name: patient_id + - name: person_id tests: - not_null: severity: warn @@ -1524,7 +1524,7 @@ models: Staging medical claims from the input layer. Creates an empty table if using clinical only. columns: - - name: patient_id + - name: person_id - name: claim_start_date - name: claim_end_date - name: place_of_service @@ -1547,7 +1547,7 @@ models: Staging pharmacy claims from the input layer. Creates an empty table if using clinical only. columns: - - name: patient_id + - name: person_id - name: dispensing_date - name: ndc_code - name: days_supply @@ -1566,7 +1566,7 @@ models: Staging lab results from the input layer. Creates an empty table if using claims only. columns: - - name: patient_id + - name: person_id - name: result_date - name: collection_date - name: source_code_type diff --git a/models/quality_measures/staging/quality_measures__stg_core__condition.sql b/models/quality_measures/staging/quality_measures__stg_core__condition.sql index ebf4d2900..db0f212f3 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__condition.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__condition.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , claim_id , encounter_id , recorded_date diff --git a/models/quality_measures/staging/quality_measures__stg_core__encounter.sql b/models/quality_measures/staging/quality_measures__stg_core__encounter.sql index a644d8d26..5fefe8e26 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__encounter.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__encounter.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , encounter_type , length_of_stay @@ -18,7 +18,7 @@ from {{ ref('core__encounter') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , encounter_type , length_of_stay @@ -31,7 +31,7 @@ from {{ ref('core__encounter') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as encounter_type , cast(null as {{dbt.type_numeric()}} ) as length_of_stay @@ -40,7 +40,7 @@ from {{ ref('core__encounter') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , cast(null as {{ dbt.type_string() }} ) as encounter_type , cast(null as {{dbt.type_numeric()}} ) as length_of_stay diff --git a/models/quality_measures/staging/quality_measures__stg_core__lab_result.sql b/models/quality_measures/staging/quality_measures__stg_core__lab_result.sql index 6f0b079aa..deb75be38 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__lab_result.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__lab_result.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , result , result_date , collection_date @@ -20,7 +20,7 @@ from {{ ref('core__lab_result') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , result , result_date , collection_date @@ -35,7 +35,7 @@ from {{ ref('core__lab_result') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as result , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as result_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as collection_date @@ -46,7 +46,7 @@ from {{ ref('core__lab_result') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as result , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as result_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as collection_date diff --git a/models/quality_measures/staging/quality_measures__stg_core__medication.sql b/models/quality_measures/staging/quality_measures__stg_core__medication.sql index 0fdbab9fa..7f47b672f 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__medication.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__medication.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , prescribing_date , dispensing_date @@ -20,7 +20,7 @@ from {{ ref('core__medication') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , prescribing_date , dispensing_date @@ -35,7 +35,7 @@ from {{ ref('core__medication') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as prescribing_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date @@ -46,7 +46,7 @@ from {{ ref('core__medication') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as prescribing_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date diff --git a/models/quality_measures/staging/quality_measures__stg_core__observation.sql b/models/quality_measures/staging/quality_measures__stg_core__observation.sql index 91c07b4d5..464766313 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__observation.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__observation.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , observation_date , result @@ -21,7 +21,7 @@ from {{ ref('core__observation') }} {% elif var('clinical_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , encounter_id , observation_date , result @@ -37,7 +37,7 @@ from {{ ref('core__observation') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as observation_date , cast(null as {{ dbt.type_string() }} ) as result @@ -49,7 +49,7 @@ from {{ ref('core__observation') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as encounter_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as observation_date , cast(null as {{ dbt.type_string() }} ) as result diff --git a/models/quality_measures/staging/quality_measures__stg_core__patient.sql b/models/quality_measures/staging/quality_measures__stg_core__patient.sql index 81e779d52..7bfc9c7b1 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__patient.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__patient.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , sex , birth_date , death_date diff --git a/models/quality_measures/staging/quality_measures__stg_core__procedure.sql b/models/quality_measures/staging/quality_measures__stg_core__procedure.sql index 528f53f38..fa4f59038 100644 --- a/models/quality_measures/staging/quality_measures__stg_core__procedure.sql +++ b/models/quality_measures/staging/quality_measures__stg_core__procedure.sql @@ -3,7 +3,7 @@ ) }} select - patient_id + person_id , encounter_id , procedure_date , source_code_type diff --git a/models/quality_measures/staging/quality_measures__stg_medical_claim.sql b/models/quality_measures/staging/quality_measures__stg_medical_claim.sql index 5c7f0c07e..f0720a7c1 100644 --- a/models/quality_measures/staging/quality_measures__stg_medical_claim.sql +++ b/models/quality_measures/staging/quality_measures__stg_medical_claim.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , claim_id , claim_start_date , claim_end_date @@ -23,7 +23,7 @@ from {{ ref('core__medical_claim') }} {% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , claim_id , claim_start_date , claim_end_date @@ -41,7 +41,7 @@ from {{ ref('core__medical_claim') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as claim_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as claim_start_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as claim_end_date @@ -55,7 +55,7 @@ from {{ ref('core__medical_claim') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , cast(null as {{ dbt.type_string() }} ) as claim_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as claim_start_date , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as claim_end_date diff --git a/models/quality_measures/staging/quality_measures__stg_pharmacy_claim.sql b/models/quality_measures/staging/quality_measures__stg_pharmacy_claim.sql index 095fc56d5..ab6d35a00 100644 --- a/models/quality_measures/staging/quality_measures__stg_pharmacy_claim.sql +++ b/models/quality_measures/staging/quality_measures__stg_pharmacy_claim.sql @@ -6,7 +6,7 @@ {% if var('clinical_enabled', var('tuva_marts_enabled',False)) == true and var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -17,7 +17,7 @@ from {{ ref('core__pharmacy_claim') }} {% elif var('claims_enabled', var('tuva_marts_enabled',False)) == true -%} select - patient_id + person_id , dispensing_date , ndc_code , days_supply @@ -29,7 +29,7 @@ from {{ ref('core__pharmacy_claim') }} {% if target.type == 'fabric' %} select top 0 - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as ndc_code , cast(null as {{ dbt.type_int() }} ) as days_supply @@ -37,7 +37,7 @@ from {{ ref('core__pharmacy_claim') }} , cast(null as {{ dbt.type_timestamp() }} ) as tuva_last_run {% else %} select - cast(null as {{ dbt.type_string() }} ) as patient_id + cast(null as {{ dbt.type_string() }} ) as person_id , {{ try_to_cast_date('null', 'YYYY-MM-DD') }} as dispensing_date , cast(null as {{ dbt.type_string() }} ) as ndc_code , cast(null as {{ dbt.type_int() }} ) as days_supply diff --git a/models/readmissions/final/readmissions__encounter_augmented.sql b/models/readmissions/final/readmissions__encounter_augmented.sql index 2c078f70f..33ad6e860 100644 --- a/models/readmissions/final/readmissions__encounter_augmented.sql +++ b/models/readmissions/final/readmissions__encounter_augmented.sql @@ -8,7 +8,7 @@ -- that are relevant for readmission measures select aa.encounter_id, - aa.patient_id, + aa.person_id, aa.admit_date, aa.discharge_date, aa.discharge_disposition_code, diff --git a/models/readmissions/final/readmissions__readmission_summary.sql b/models/readmissions/final/readmissions__readmission_summary.sql index 3f7148cac..e07fbda54 100644 --- a/models/readmissions/final/readmissions__readmission_summary.sql +++ b/models/readmissions/final/readmissions__readmission_summary.sql @@ -14,7 +14,7 @@ with encounter_sequence as ( select *, row_number() over( - partition by patient_id order by admit_date, discharge_date + partition by person_id order by admit_date, discharge_date ) as encounter_seq from {{ ref('readmissions__encounter_augmented') }} where disqualified_encounter_flag = 0 @@ -24,7 +24,7 @@ where disqualified_encounter_flag = 0 readmission_calc as ( select aa.encounter_id, - aa.patient_id, + aa.person_id, aa.admit_date, aa.discharge_date, aa.discharge_disposition_code, @@ -67,7 +67,7 @@ select from encounter_sequence aa left join encounter_sequence bb - on aa.patient_id = bb.patient_id + on aa.person_id = bb.person_id and aa.encounter_seq + 1 = bb.encounter_seq ) diff --git a/models/readmissions/intermediate/readmissions__encounter.sql b/models/readmissions/intermediate/readmissions__encounter.sql index 706412637..16fef75d5 100644 --- a/models/readmissions/intermediate/readmissions__encounter.sql +++ b/models/readmissions/intermediate/readmissions__encounter.sql @@ -9,7 +9,7 @@ select cast(encounter_id as {{ dbt.type_string() }}) as encounter_id, - cast(patient_id as {{ dbt.type_string() }}) as patient_id, + cast(person_id as {{ dbt.type_string() }}) as person_id, cast(encounter_start_date as date) as admit_date, cast(encounter_end_date as date) as discharge_date, cast(discharge_disposition_code as {{ dbt.type_string() }}) as discharge_disposition_code, diff --git a/models/readmissions/intermediate/readmissions__encounter_overlap.sql b/models/readmissions/intermediate/readmissions__encounter_overlap.sql index e64b44c49..12271d179 100644 --- a/models/readmissions/intermediate/readmissions__encounter_overlap.sql +++ b/models/readmissions/intermediate/readmissions__encounter_overlap.sql @@ -10,11 +10,11 @@ with encounters_with_row_num as ( select encounter_id, - patient_id, + person_id, admit_date, discharge_date, row_number() over ( - partition by patient_id order by encounter_id + partition by person_id order by encounter_id ) as row_num from {{ ref('readmissions__encounter') }} ), @@ -24,7 +24,7 @@ cartesian as ( select aa.encounter_id as encounter_id_A, bb.encounter_id as encounter_id_B, - aa.patient_id, + aa.person_id, aa.admit_date as Ai, aa.discharge_date as Af, bb.admit_date as Bi, @@ -37,7 +37,7 @@ select end as overlap from encounters_with_row_num aa left join encounters_with_row_num bb - on aa.patient_id = bb.patient_id and aa.row_num < bb.row_num + on aa.person_id = bb.person_id and aa.row_num < bb.row_num ), @@ -45,7 +45,7 @@ overlapping_pairs as ( select - patient_id, + person_id, encounter_id_A, encounter_id_B from cartesian diff --git a/models/readmissions/intermediate/readmissions__encounter_with_ccs.sql b/models/readmissions/intermediate/readmissions__encounter_with_ccs.sql index d87cd0382..7fb129804 100644 --- a/models/readmissions/intermediate/readmissions__encounter_with_ccs.sql +++ b/models/readmissions/intermediate/readmissions__encounter_with_ccs.sql @@ -11,7 +11,7 @@ select aa.encounter_id, - aa.patient_id, + aa.person_id, aa.admit_date, aa.discharge_date, aa.discharge_disposition_code, diff --git a/models/readmissions/intermediate/readmissions__readmission_crude.sql b/models/readmissions/intermediate/readmissions__readmission_crude.sql index 6e2be97ba..ca93a4821 100644 --- a/models/readmissions/intermediate/readmissions__readmission_crude.sql +++ b/models/readmissions/intermediate/readmissions__readmission_crude.sql @@ -12,7 +12,7 @@ with encounter_info as ( select enc.encounter_id, - enc.patient_id, + enc.person_id, enc.admit_date, enc.discharge_date from {{ ref('readmissions__encounter') }} enc @@ -33,11 +33,11 @@ and over_a.encounter_id_A is null and over_b.encounter_id_B is null encounter_sequence as ( select encounter_id, - patient_id, + person_id, admit_date, discharge_date, row_number() over( - partition by patient_id order by admit_date, discharge_date + partition by person_id order by admit_date, discharge_date ) as encounter_seq from encounter_info ), @@ -46,7 +46,7 @@ from encounter_info readmission_calc as ( select aa.encounter_id, - aa.patient_id, + aa.person_id, aa.admit_date, aa.discharge_date, case @@ -59,7 +59,7 @@ select else 0 end as readmit_30_flag from encounter_sequence aa left join encounter_sequence bb - on aa.patient_id = bb.patient_id + on aa.person_id = bb.person_id and aa.encounter_seq + 1 = bb.encounter_seq ) diff --git a/models/readmissions/readmissions_models.yml b/models/readmissions/readmissions_models.yml index 20656e823..5ceffa808 100644 --- a/models/readmissions/readmissions_models.yml +++ b/models/readmissions/readmissions_models.yml @@ -14,7 +14,7 @@ models: columns: - name: encounter_id description: "The unique identifier for the encounter" - - name: patient_id + - name: person_id description: "The unique identifier for the patient" - name: admit_date description: "The date of admission for the inpatient visit" @@ -109,7 +109,7 @@ models: columns: - name: encounter_id description: "The unique identifier for the encounter" - - name: patient_id + - name: person_id description: "The unique identifier for the patient" - name: admit_date description: "The date of admission for the inpatient visit" @@ -252,7 +252,7 @@ models: materialized: view description: "This model lists all pairs of encounters that have some date overlap." columns: - - name: patient_id + - name: person_id description: "The unique identifier for the patient" - name: encounter_id_A description: "Unique identifier for one of the overlapping encounters" @@ -379,7 +379,7 @@ models: columns: - name: encounter_id description: "The unique identifier for the encounter" - - name: patient_id + - name: person_id description: "The unique identifier for the patient" - name: admit_date description: "The date of admission for the inpatient visit" @@ -403,7 +403,7 @@ models: columns: - name: encounter_id description: "The unique identifier for the encounter" - - name: patient_id + - name: person_id description: "The unique identifier for the patient" - name: admit_date description: "The date of admission for the inpatient visit" diff --git a/models/readmissions/staging/readmissions__stg_core__encounter.sql b/models/readmissions/staging/readmissions__stg_core__encounter.sql index 3f41a4682..3f5601b2c 100644 --- a/models/readmissions/staging/readmissions__stg_core__encounter.sql +++ b/models/readmissions/staging/readmissions__stg_core__encounter.sql @@ -5,7 +5,7 @@ select encounter_id, - patient_id, + person_id, encounter_start_date, encounter_end_date, discharge_disposition_code,