From aa56dbd99f5062129175019c26cb0b28ac3505be Mon Sep 17 00:00:00 2001 From: Sarah Morgan Date: Mon, 26 Aug 2024 08:56:40 -0600 Subject: [PATCH] Upgrade to Tuva package v0.10 (#35) * Update gitignore * Update package version * Add staging models * Add columns to staging models * Add new fields to claims * Add new fields to eligibility * Remove unnecessary intermediate model * Reorder columns in medical claim * Fix data type in pharmacy claim * Rename github workflows * Rename github workflows --- ...bt_v1.6.3_bigquery_build_full_refresh.yml} | 2 +- ...bt_v1.6.3_redshift_build_full_refresh.yml} | 2 +- ...t_v1.6.3_snowflake_build_full_refresh.yml} | 2 +- ...tor_dbt_v1.6.3_all_build_full_refresh.yml} | 20 +- .gitignore | 6 + models/_models.yml | 119 +++++++-- models/final/eligibility.sql | 93 +++++-- models/final/medical_claim.sql | 219 +++++++++++++--- models/final/pharmacy_claim.sql | 48 ++-- models/intermediate/_int_medical_claim.sql | 5 - models/intermediate/carrier_claim.sql | 30 ++- models/intermediate/dme_claim.sql | 28 ++- models/intermediate/eligibility_unpivot.sql | 124 +++++----- models/intermediate/home_health_claim.sql | 47 ++-- models/intermediate/hospice_claim.sql | 50 ++-- models/intermediate/inpatient_claim.sql | 66 ++--- models/intermediate/outpatient_claim.sql | 54 ++-- models/intermediate/snf_claim.sql | 43 ++-- models/staging/stg_carrier_base_claim.sql | 61 +++++ models/staging/stg_carrier_claim_line.sql | 73 ++++++ models/staging/stg_dme_base_claim.sql | 57 +++++ models/staging/stg_dme_claim_line.sql | 61 +++++ models/staging/stg_hha_base_claim.sql | 96 ++++++++ models/staging/stg_hha_revenue_center.sql | 34 +++ models/staging/stg_hospice_base_claim.sql | 94 +++++++ models/staging/stg_hospice_revenue_center.sql | 31 +++ models/staging/stg_inpatient_base_claim.sql | 233 ++++++++++++++++++ .../staging/stg_inpatient_revenue_center.sql | 27 ++ .../stg_master_beneficiary_summary.sql | 83 +++++++ models/staging/stg_outpatient_base_claim.sql | 154 ++++++++++++ .../staging/stg_outpatient_revenue_center.sql | 45 ++++ models/staging/stg_snf_base_claim.sql | 166 +++++++++++++ models/staging/stg_snf_revenue_center.sql | 26 ++ packages.yml | 2 +- 34 files changed, 1890 insertions(+), 311 deletions(-) rename .github/workflows/{dbt_v1.4.6_bigquery_build_full_refresh.yml => dbt_v1.6.3_bigquery_build_full_refresh.yml} (96%) rename .github/workflows/{dbt_v1.4.6_redshift_build_full_refresh.yml => dbt_v1.6.3_redshift_build_full_refresh.yml} (96%) rename .github/workflows/{dbt_v1.4.6_snowflake_build_full_refresh.yml => dbt_v1.6.3_snowflake_build_full_refresh.yml} (96%) rename .github/workflows/{outside_contributor_dbt_v1.4.6_all_build_full_refresh.yml => outside_contributor_dbt_v1.6.3_all_build_full_refresh.yml} (90%) delete mode 100644 models/intermediate/_int_medical_claim.sql create mode 100644 models/staging/stg_carrier_base_claim.sql create mode 100644 models/staging/stg_carrier_claim_line.sql create mode 100644 models/staging/stg_dme_base_claim.sql create mode 100644 models/staging/stg_dme_claim_line.sql create mode 100644 models/staging/stg_hha_base_claim.sql create mode 100644 models/staging/stg_hha_revenue_center.sql create mode 100644 models/staging/stg_hospice_base_claim.sql create mode 100644 models/staging/stg_hospice_revenue_center.sql create mode 100644 models/staging/stg_inpatient_base_claim.sql create mode 100644 models/staging/stg_inpatient_revenue_center.sql create mode 100644 models/staging/stg_master_beneficiary_summary.sql create mode 100644 models/staging/stg_outpatient_base_claim.sql create mode 100644 models/staging/stg_outpatient_revenue_center.sql create mode 100644 models/staging/stg_snf_base_claim.sql create mode 100644 models/staging/stg_snf_revenue_center.sql diff --git a/.github/workflows/dbt_v1.4.6_bigquery_build_full_refresh.yml b/.github/workflows/dbt_v1.6.3_bigquery_build_full_refresh.yml similarity index 96% rename from .github/workflows/dbt_v1.4.6_bigquery_build_full_refresh.yml rename to .github/workflows/dbt_v1.6.3_bigquery_build_full_refresh.yml index 3589b36..ada5dcc 100644 --- a/.github/workflows/dbt_v1.4.6_bigquery_build_full_refresh.yml +++ b/.github/workflows/dbt_v1.6.3_bigquery_build_full_refresh.yml @@ -1,4 +1,4 @@ -name: dbt_v1.4.6_bigquery_build_full_refresh +name: dbt_v1.6.3_bigquery_build_full_refresh on: workflow_dispatch: diff --git a/.github/workflows/dbt_v1.4.6_redshift_build_full_refresh.yml b/.github/workflows/dbt_v1.6.3_redshift_build_full_refresh.yml similarity index 96% rename from .github/workflows/dbt_v1.4.6_redshift_build_full_refresh.yml rename to .github/workflows/dbt_v1.6.3_redshift_build_full_refresh.yml index 4764227..49856e6 100644 --- a/.github/workflows/dbt_v1.4.6_redshift_build_full_refresh.yml +++ b/.github/workflows/dbt_v1.6.3_redshift_build_full_refresh.yml @@ -1,4 +1,4 @@ -name: dbt_v1.4.6_redshift_build_full_refresh +name: dbt_v1.6.3_redshift_build_full_refresh on: workflow_dispatch: diff --git a/.github/workflows/dbt_v1.4.6_snowflake_build_full_refresh.yml b/.github/workflows/dbt_v1.6.3_snowflake_build_full_refresh.yml similarity index 96% rename from .github/workflows/dbt_v1.4.6_snowflake_build_full_refresh.yml rename to .github/workflows/dbt_v1.6.3_snowflake_build_full_refresh.yml index 3ebeeb4..9ba7ebe 100644 --- a/.github/workflows/dbt_v1.4.6_snowflake_build_full_refresh.yml +++ b/.github/workflows/dbt_v1.6.3_snowflake_build_full_refresh.yml @@ -1,4 +1,4 @@ -name: dbt_v1.4.6_snowflake_build_full_refresh +name: dbt_v1.6.3_snowflake_build_full_refresh on: workflow_dispatch: diff --git a/.github/workflows/outside_contributor_dbt_v1.4.6_all_build_full_refresh.yml b/.github/workflows/outside_contributor_dbt_v1.6.3_all_build_full_refresh.yml similarity index 90% rename from .github/workflows/outside_contributor_dbt_v1.4.6_all_build_full_refresh.yml rename to .github/workflows/outside_contributor_dbt_v1.6.3_all_build_full_refresh.yml index 5131457..8cd4560 100644 --- a/.github/workflows/outside_contributor_dbt_v1.4.6_all_build_full_refresh.yml +++ b/.github/workflows/outside_contributor_dbt_v1.6.3_all_build_full_refresh.yml @@ -1,4 +1,4 @@ -name: outside_contributor_dbt_v1.4.6_all_build_full_refresh +name: outside_contributor_dbt_v1.6.3_all_build_full_refresh on: workflow_dispatch: @@ -35,17 +35,17 @@ jobs: ref: refs/pull/${{ github.event.inputs.prNumber }}/merge - name: dbt-deps - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt deps --profiles-dir ./integration_tests/profiles/snowflake" - name: dbt-debug - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt debug --profiles-dir ./integration_tests/profiles/snowflake" - name: dbt-build - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: 'dbt build --full-refresh --profiles-dir ./integration_tests/profiles/snowflake --vars {"tuva_database":"dev_ci_testing","input_database":"dev_ci_testing","input_schema":"saf","tuva_schema_prefix":"saf"}' @@ -64,17 +64,17 @@ jobs: ref: refs/pull/${{ github.event.inputs.prNumber }}/merge - name: dbt-deps - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt deps --profiles-dir ./integration_tests/profiles/redshift" - name: dbt-debug - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt debug --profiles-dir ./integration_tests/profiles/redshift" - name: dbt-build - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: 'dbt build --full-refresh --profiles-dir ./integration_tests/profiles/redshift --vars {"tuva_database":"dev_ci_testing","input_database":"dev_ci_testing","input_schema":"saf","tuva_schema_prefix":"saf"}' @@ -94,17 +94,17 @@ jobs: ref: refs/pull/${{ github.event.inputs.prNumber }}/merge - name: dbt-deps - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt deps --profiles-dir ./integration_tests/profiles/bigquery" - name: dbt-debug - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: "dbt debug --profiles-dir ./integration_tests/profiles/bigquery" - name: dbt-build - uses: mwhitaker/dbt-action@v1.4.6 + uses: mwhitaker/dbt-action@v1.6.3 with: dbt_command: 'dbt build --full-refresh --profiles-dir ./integration_tests/profiles/bigquery --vars {"tuva_database":"dev-ci-testing","input_database":"dev-ci-testing","input_schema":"lds","tuva_schema_prefix":"lds"}' diff --git a/.gitignore b/.gitignore index d4c91fb..9c8694e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ target/ dbt_packages/ logs/ package-lock.yml +.idea/ +.DS_Store +.mise.toml +.venv/ +package-lock.yml +.vscode diff --git a/models/_models.yml b/models/_models.yml index a12da0e..e6b9a5c 100644 --- a/models/_models.yml +++ b/models/_models.yml @@ -7,21 +7,21 @@ models: description: Member eligibility at the month grain config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} materialized: table - name: medical_claim description: Claim line details of all claim types config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} materialized: table - name: pharmacy_claim description: Claim line details of all claim types config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} materialized: table ### intermediate @@ -29,13 +29,13 @@ models: description: Claim line details of carrier claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: dme_claim description: Claim line details of durable medical equipment claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: eligibility_unpivot description: > @@ -44,40 +44,125 @@ models: of eligibility. config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: home_health_claim description: Claim line details of home health claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: hospice_claim description: Claim line details of hospice claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: inpatient_claim description: Claim line details of inpatient claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} - - - name: _int_medical_claim - description: union of all medical claim tables - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: outpatient_claim description: Claim line details of outpatient claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} - name: snf_claim description: Claim line details of skilled nursing facility claims config: schema: | - {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%} + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_int_input_layer{% else %}_int_input_layer{%- endif -%} + +### staging + - name: stg_carrier_base_claim + description: Staging carrier base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_carrier_claim_line + description: Staging carrier claim line + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_dme_base_claim + description: Staging dme base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_dme_claim_line + description: Staging dme claim line + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_hha_base_claim + description: Staging hha base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_hha_revenue_center + description: Staging hha revenue center + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_hospice_base_claim + description: Staging hospice base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_hospice_revenue_center + description: Staging hospice revenue center + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_inpatient_base_claim + description: Staging inpatient base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_inpatient_revenue_center + description: Staging inpatient revenue center + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_master_beneficiary_summary + description: Staging master beneficiary summary + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_outpatient_base_claim + description: Staging outpatient base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_outpatient_revenue_center + description: Staging outpatient revenue center + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_snf_base_claim + description: Staging snf base claim + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} + + - name: stg_snf_revenue_center + description: Staging snf revenue center + config: + schema: | + {%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_stg_input_layer{% else %}_stg_input_layer{%- endif -%} diff --git a/models/final/eligibility.sql b/models/final/eligibility.sql index 7908b5c..faad5e2 100644 --- a/models/final/eligibility.sql +++ b/models/final/eligibility.sql @@ -6,20 +6,34 @@ with eligibility_unpivot as ( - select * + select + desy_sort_key + , age + , sex_code + , race_code + , state_code + , date_of_death + , orig_reason_for_entitlement + , dual_status + , medicare_status + , year_month + , hmo_status + , entitlement + , file_name + , ingest_datetime , {{ to_date('year_month', 'YYYYMM') }} as enrollment_date , cast(year as integer) - cast(age as integer) as birth_year from {{ ref('eligibility_unpivot') }} -), +) -medicare_state_fips as ( +, medicare_state_fips as ( select * from {{ ref('reference_data__ssa_fips_state') }} -), +) -add_row_num as ( +, add_row_num as ( select desy_sort_key @@ -36,13 +50,13 @@ add_row_num as ( end as disenrolled_flag from eligibility_unpivot -), +) /* remove member months where the patient was not enrolled medicare and did not have dual medicaid status */ -remove_disenrolled_months as ( +, remove_disenrolled_months as ( select desy_sort_key @@ -52,9 +66,9 @@ remove_disenrolled_months as ( from add_row_num where disenrolled_flag = 0 -), +) -add_lag_enrollment as ( +, add_lag_enrollment as ( select desy_sort_key @@ -66,9 +80,9 @@ add_lag_enrollment as ( ) as lag_enrollment from remove_disenrolled_months -), +) -calculate_lag_diff as ( +, calculate_lag_diff as ( select desy_sort_key @@ -78,9 +92,9 @@ calculate_lag_diff as ( , {{ datediff('lag_enrollment', 'enrollment_date', 'month') }} as lag_diff from add_lag_enrollment -), +) -calculate_gaps as ( +, calculate_gaps as ( select desy_sort_key @@ -94,9 +108,9 @@ calculate_gaps as ( end as gap_flag from calculate_lag_diff -), +) -calculate_groups as ( +, calculate_groups as ( select desy_sort_key @@ -110,9 +124,9 @@ calculate_groups as ( ) as row_group from calculate_gaps -), +) -enrollment_span as ( +, enrollment_span as ( select desy_sort_key @@ -123,9 +137,9 @@ enrollment_span as ( from calculate_groups group by desy_sort_key, row_group -), +) -joined as ( +, joined as ( select cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as patient_id @@ -169,17 +183,44 @@ joined as ( , cast(NULL as {{ dbt.type_string() }} ) as zip_code , cast(NULL as {{ dbt.type_string() }} ) as phone , 'medicare_lds' as data_source - , 'master_beneficiary_summary' as file_name - , cast(NULL as date ) as ingest_datetime - - + , cast(eligibility_unpivot.file_name as {{ dbt.type_string() }} ) as file_name + , cast(eligibility_unpivot.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from enrollment_span - left join eligibility_unpivot + left join eligibility_unpivot on enrollment_span.desy_sort_key = eligibility_unpivot.desy_sort_key and enrollment_span.enrollment_end_date_max = eligibility_unpivot.enrollment_date - left join medicare_state_fips + left join medicare_state_fips on eligibility_unpivot.state_code = medicare_state_fips.ssa_fips_state_code ) -select * from joined \ No newline at end of file +select + 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 +from joined \ No newline at end of file diff --git a/models/final/medical_claim.sql b/models/final/medical_claim.sql index 16e5bbe..0a3cf07 100644 --- a/models/final/medical_claim.sql +++ b/models/final/medical_claim.sql @@ -1,34 +1,197 @@ +with unioned as ( + + {{ dbt_utils.union_relations(relations=[ + ref('carrier_claim') + , ref('dme_claim') + , ref('home_health_claim') + , ref('hospice_claim') + , ref('inpatient_claim') + , ref('outpatient_claim') + , ref('snf_claim') + ], + exclude=["_DBT_SOURCE_RELATION"] +) }} -with month_start_and_end_dates as ( - select distinct - year as year_nbr - ,month as month_nbr - ,first_day_of_month - ,last_day_of_month - from {{ ref('reference_data__calendar')}} ) -,member_months as ( -select distinct - a.patient_id - , year_nbr - , month_nbr - , a.payer - , a.plan - , data_source -from {{ ref('eligibility') }} a -inner join month_start_and_end_dates b - on a.enrollment_start_date <= b.last_day_of_month - and a.enrollment_end_date >= b.first_day_of_month +, month_start_and_end_dates as ( + + select distinct + year as year_nbr + , month as month_nbr + , first_day_of_month + , last_day_of_month + from {{ ref('reference_data__calendar') }} + +) + +, member_months as ( + + select distinct + a.patient_id + , year_nbr + , month_nbr + , a.payer + , a.plan + , data_source + from {{ ref('eligibility') }} as a + inner join month_start_and_end_dates as b + on a.enrollment_start_date <= b.last_day_of_month + and a.enrollment_end_date >= b.first_day_of_month + ) -- limit claims to only enrolled members, removing claims for members that we only have partial claims data for. -select c.* -,cast(null as {{ dbt.type_string() }} ) as rendering_tin -,cast(null as {{ dbt.type_string() }} ) as billing_tin -from {{ ref('_int_medical_claim') }} c -inner join member_months mm on c.patient_id = mm.patient_id -and -extract(year from c.claim_start_date) = mm.year_nbr -and -extract(month from c.claim_start_date) = mm.month_nbr \ No newline at end of file +select + c.claim_id + , c.claim_line_number + , c.claim_type + , c.patient_id + , c.member_id + , c.payer + , c.plan + , c.claim_start_date + , c.claim_end_date + , c.claim_line_start_date + , c.claim_line_end_date + , c.admission_date + , c.discharge_date + , c.admit_source_code + , c.admit_type_code + , c.discharge_disposition_code + , c.place_of_service_code + , c.bill_type_code + , c.ms_drg_code + , c.apr_drg_code + , c.revenue_center_code + , c.service_unit_quantity + , c.hcpcs_code + , c.hcpcs_modifier_1 + , c.hcpcs_modifier_2 + , c.hcpcs_modifier_3 + , c.hcpcs_modifier_4 + , c.hcpcs_modifier_5 + , c.rendering_npi + , c.rendering_tin + , c.billing_npi + , c.billing_tin + , c.facility_npi + , c.paid_date + , c.paid_amount + , c.allowed_amount + , c.charge_amount + , c.coinsurance_amount + , c.copayment_amount + , c.deductible_amount + , c.total_cost_amount + , c.diagnosis_code_type + , c.diagnosis_code_1 + , c.diagnosis_code_2 + , c.diagnosis_code_3 + , c.diagnosis_code_4 + , c.diagnosis_code_5 + , c.diagnosis_code_6 + , c.diagnosis_code_7 + , c.diagnosis_code_8 + , c.diagnosis_code_9 + , c.diagnosis_code_10 + , c.diagnosis_code_11 + , c.diagnosis_code_12 + , c.diagnosis_code_13 + , c.diagnosis_code_14 + , c.diagnosis_code_15 + , c.diagnosis_code_16 + , c.diagnosis_code_17 + , c.diagnosis_code_18 + , c.diagnosis_code_19 + , c.diagnosis_code_20 + , c.diagnosis_code_21 + , c.diagnosis_code_22 + , c.diagnosis_code_23 + , c.diagnosis_code_24 + , c.diagnosis_code_25 + , c.diagnosis_poa_1 + , c.diagnosis_poa_2 + , c.diagnosis_poa_3 + , c.diagnosis_poa_4 + , c.diagnosis_poa_5 + , c.diagnosis_poa_6 + , c.diagnosis_poa_7 + , c.diagnosis_poa_8 + , c.diagnosis_poa_9 + , c.diagnosis_poa_10 + , c.diagnosis_poa_11 + , c.diagnosis_poa_12 + , c.diagnosis_poa_13 + , c.diagnosis_poa_14 + , c.diagnosis_poa_15 + , c.diagnosis_poa_16 + , c.diagnosis_poa_17 + , c.diagnosis_poa_18 + , c.diagnosis_poa_19 + , c.diagnosis_poa_20 + , c.diagnosis_poa_21 + , c.diagnosis_poa_22 + , c.diagnosis_poa_23 + , c.diagnosis_poa_24 + , c.diagnosis_poa_25 + , c.procedure_code_type + , c.procedure_code_1 + , c.procedure_code_2 + , c.procedure_code_3 + , c.procedure_code_4 + , c.procedure_code_5 + , c.procedure_code_6 + , c.procedure_code_7 + , c.procedure_code_8 + , c.procedure_code_9 + , c.procedure_code_10 + , c.procedure_code_11 + , c.procedure_code_12 + , c.procedure_code_13 + , c.procedure_code_14 + , c.procedure_code_15 + , c.procedure_code_16 + , c.procedure_code_17 + , c.procedure_code_18 + , c.procedure_code_19 + , c.procedure_code_20 + , c.procedure_code_21 + , c.procedure_code_22 + , c.procedure_code_23 + , c.procedure_code_24 + , c.procedure_code_25 + , c.procedure_date_1 + , c.procedure_date_2 + , c.procedure_date_3 + , c.procedure_date_4 + , c.procedure_date_5 + , c.procedure_date_6 + , c.procedure_date_7 + , c.procedure_date_8 + , c.procedure_date_9 + , c.procedure_date_10 + , c.procedure_date_11 + , c.procedure_date_12 + , c.procedure_date_13 + , c.procedure_date_14 + , c.procedure_date_15 + , c.procedure_date_16 + , c.procedure_date_17 + , c.procedure_date_18 + , c.procedure_date_19 + , c.procedure_date_20 + , c.procedure_date_21 + , c.procedure_date_22 + , c.procedure_date_23 + , c.procedure_date_24 + , c.procedure_date_25 + , c.in_network_flag + , c.data_source + , c.file_name + , c.ingest_datetime +from unioned as c + inner join member_months as mm + on c.patient_id = mm.patient_id + and extract(year from c.claim_start_date) = mm.year_nbr + and extract(month from c.claim_start_date) = mm.month_nbr \ No newline at end of file diff --git a/models/final/pharmacy_claim.sql b/models/final/pharmacy_claim.sql index 8522051..f281615 100644 --- a/models/final/pharmacy_claim.sql +++ b/models/final/pharmacy_claim.sql @@ -1,26 +1,26 @@ select - cast(null as {{ dbt.type_string() }}) as CLAIM_ID - ,cast(null as {{ dbt.type_string() }}) as CLAIM_LINE_NUMBER - ,cast(null 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 PLAN - ,cast(null as {{ dbt.type_string() }}) as PRESCRIBING_PROVIDER_NPI - ,cast(null as {{ dbt.type_string() }}) as DISPENSING_PROVIDER_NPI - ,cast(null as date ) as DISPENSING_DATE - ,cast(null as {{ dbt.type_string() }}) as NDC_CODE - ,cast(null as int) as QUANTITY - ,cast(null as int) as DAYS_SUPPLY - ,cast(null as int) as REFILLS - ,cast(null as date) as PAID_DATE - ,cast(null as numeric) as CHARGE_AMOUNT - ,cast(null as numeric) as PAID_AMOUNT - ,cast(null as numeric) as ALLOWED_AMOUNT - ,cast(null as numeric) as COPAYMENT_AMOUNT - ,cast(null as numeric) as COINSURANCE_AMOUNT - ,cast(null as numeric) as DEDUCTIBLE_AMOUNT - ,cast(null as {{ dbt.type_string() }}) as DATA_SOURCE - ,cast(null as numeric) as in_network_flag - ,cast(null as {{ dbt.type_string() }}) as file_name - ,cast(NULL as date ) as ingest_datetime + cast(null as {{ dbt.type_string() }}) as claim_id + , cast(null as {{ dbt.type_string() }}) as claim_line_number + , cast(null 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 plan + , cast(null as {{ dbt.type_string() }}) as prescribing_provider_npi + , cast(null as {{ dbt.type_string() }}) as dispensing_provider_npi + , cast(null as date ) as dispensing_date + , cast(null as {{ dbt.type_string() }}) as ndc_code + , cast(null as int) as quantity + , cast(null as int) as days_supply + , cast(null as int) as refills + , cast(null as date) as paid_date + , cast(null as numeric) as paid_amount + , cast(null as numeric) as allowed_amount + , cast(null as numeric) as charge_amount + , cast(null as numeric) as copayment_amount + , cast(null as numeric) as coinsurance_amount + , cast(null as numeric) as deductible_amount + , cast(null as int) as in_network_flag + , cast(null as {{ dbt.type_string() }}) as data_source + , cast(null as {{ dbt.type_timestamp() }}) as file_name + , cast(null as date ) as ingest_datetime limit 0 \ No newline at end of file diff --git a/models/intermediate/_int_medical_claim.sql b/models/intermediate/_int_medical_claim.sql deleted file mode 100644 index 0d701d1..0000000 --- a/models/intermediate/_int_medical_claim.sql +++ /dev/null @@ -1,5 +0,0 @@ -{{ dbt_utils.union_relations( - relations=[ref('carrier_claim'), ref('dme_claim'), ref('home_health_claim'), ref('hospice_claim') - , ref('inpatient_claim'), ref('outpatient_claim'), ref('snf_claim')], - exclude=["_DBT_SOURCE_RELATION"] -) }} \ No newline at end of file diff --git a/models/intermediate/carrier_claim.sql b/models/intermediate/carrier_claim.sql index 3c360a4..73bcc2e 100644 --- a/models/intermediate/carrier_claim.sql +++ b/models/intermediate/carrier_claim.sql @@ -2,7 +2,7 @@ with carrier_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','carrier_base_claim') }} + from {{ ref('stg_carrier_base_claim') }} where carr_clm_pmt_dnl_cd <> '0' /** filter out denied claims **/ @@ -10,10 +10,12 @@ with carrier_base_claim as ( , claim_start_date as ( - select l.claim_no - ,min(l.line_last_expns_dt) as claim_start_date - from {{ source('medicare_lds','carrier_claim_line') }} l - group by l.claim_no + select + claim_no + , min(line_last_expns_dt) as claim_start_date + from {{ ref('stg_carrier_claim_line') }} + group by claim_no + ) select @@ -50,7 +52,9 @@ select , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(l.prf_physn_npi as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(b.carr_clm_blg_npi_num as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(null as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , cast(l.line_nch_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount @@ -171,12 +175,12 @@ select , date(NULL) as procedure_date_23 , date(NULL) as procedure_date_24 , date(NULL) as procedure_date_25 - , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'carrier_claim' as file_name - , cast(NULL as date ) as ingest_datetime - + , cast(1 as int) as in_network_flag + , cast('medicare_lds' as {{ dbt.type_string() }} ) as data_source + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from carrier_base_claim as b -inner join {{ source('medicare_lds','carrier_claim_line') }} as l - on b.claim_no = l.claim_no -inner join claim_start_date c on b.claim_no = c.claim_no \ No newline at end of file + inner join {{ ref('stg_carrier_claim_line') }} as l + on b.claim_no = l.claim_no + inner join claim_start_date as c + on b.claim_no = c.claim_no \ No newline at end of file diff --git a/models/intermediate/dme_claim.sql b/models/intermediate/dme_claim.sql index 05675bc..8d96b5d 100644 --- a/models/intermediate/dme_claim.sql +++ b/models/intermediate/dme_claim.sql @@ -2,17 +2,20 @@ with dme_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','dme_base_claim') }} + from {{ ref('stg_dme_base_claim') }} where carr_clm_pmt_dnl_cd <> '0' /** filter out denied claims **/ + ) , claim_start_date as ( - select l.claim_no - ,min(l.line_last_expns_dt) as claim_start_date - from {{ source('medicare_lds','dme_claim_line') }} l - group by l.claim_no + select + claim_no + , min(line_last_expns_dt) as claim_start_date + from {{ ref('stg_dme_claim_line') }} + group by claim_no + ) select @@ -49,7 +52,9 @@ select , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(null as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(l.prvdr_npi as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(NULL as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , cast(l.line_nch_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount @@ -170,11 +175,12 @@ select , date(NULL) as procedure_date_23 , date(NULL) as procedure_date_24 , date(NULL) as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'dme_claim' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from dme_base_claim as b -inner join {{ source('medicare_lds','dme_claim_line') }} as l - on b.claim_no = l.claim_no -inner join claim_start_date c on b.claim_no = c.claim_no \ No newline at end of file + inner join {{ ref('stg_dme_claim_line') }} as l + on b.claim_no = l.claim_no + inner join claim_start_date as c + on b.claim_no = c.claim_no \ No newline at end of file diff --git a/models/intermediate/eligibility_unpivot.sql b/models/intermediate/eligibility_unpivot.sql index 8217ce6..6ce6407 100644 --- a/models/intermediate/eligibility_unpivot.sql +++ b/models/intermediate/eligibility_unpivot.sql @@ -1,10 +1,10 @@ with demographics as ( - select * from {{ source('medicare_lds','master_beneficiary_summary') }} + select * from {{ ref('stg_master_beneficiary_summary') }} -), +) -unpivot_dual_status as ( +, unpivot_dual_status as ( select desy_sort_key @@ -13,23 +13,23 @@ unpivot_dual_status as ( , dual_status as dual_status from demographics unpivot( - dual_status for month in (DUAL_STUS_CD_01 - ,DUAL_STUS_CD_02 - ,DUAL_STUS_CD_03 - ,DUAL_STUS_CD_04 - ,DUAL_STUS_CD_05 - ,DUAL_STUS_CD_06 - ,DUAL_STUS_CD_07 - ,DUAL_STUS_CD_08 - ,DUAL_STUS_CD_09 - ,DUAL_STUS_CD_10 - ,DUAL_STUS_CD_11 - ,DUAL_STUS_CD_12) + dual_status for month in (dual_stus_cd_01 + ,dual_stus_cd_02 + ,dual_stus_cd_03 + ,dual_stus_cd_04 + ,dual_stus_cd_05 + ,dual_stus_cd_06 + ,dual_stus_cd_07 + ,dual_stus_cd_08 + ,dual_stus_cd_09 + ,dual_stus_cd_10 + ,dual_stus_cd_11 + ,dual_stus_cd_12) )p1 -), +) -unpivot_medicare_status as ( +, unpivot_medicare_status as ( select desy_sort_key @@ -38,78 +38,72 @@ unpivot_medicare_status as ( , medicare_status from demographics unpivot( - medicare_status for month in (MDCR_STATUS_CODE_01 - ,MDCR_STATUS_CODE_02 - ,MDCR_STATUS_CODE_03 - ,MDCR_STATUS_CODE_04 - ,MDCR_STATUS_CODE_05 - ,MDCR_STATUS_CODE_06 - ,MDCR_STATUS_CODE_07 - ,MDCR_STATUS_CODE_08 - ,MDCR_STATUS_CODE_09 - ,MDCR_STATUS_CODE_10 - ,MDCR_STATUS_CODE_11 - ,MDCR_STATUS_CODE_12) + medicare_status for month in (mdcr_status_code_01 + ,mdcr_status_code_02 + ,mdcr_status_code_03 + ,mdcr_status_code_04 + ,mdcr_status_code_05 + ,mdcr_status_code_06 + ,mdcr_status_code_07 + ,mdcr_status_code_08 + ,mdcr_status_code_09 + ,mdcr_status_code_10 + ,mdcr_status_code_11 + ,mdcr_status_code_12) )p1 ) -, +, unpivot_hmo_status as ( -unpivot_hmo_status as ( select desy_sort_key - , case when LENGTH(month) = 14 then substring(month, 14, 1) -- 'entitlement_buy_in_ind1' -> '1' - when LENGTH(month) = 15 then substring(month, 14, 2) -- 'entitlement_buy_in_ind10' -> '10' + , case when length(month) = 14 then substring(month, 14, 1) -- 'entitlement_buy_in_ind1' -> '1' + when length(month) = 15 then substring(month, 14, 2) -- 'entitlement_buy_in_ind10' -> '10' else null end as month , reference_year as year , hmo_status from demographics unpivot( - hmo_status for month in (HMO_INDICATOR1 - ,HMO_INDICATOR2 - ,HMO_INDICATOR3 - ,HMO_INDICATOR4 - ,HMO_INDICATOR5 - ,HMO_INDICATOR6 - ,HMO_INDICATOR7 - ,HMO_INDICATOR8 - ,HMO_INDICATOR9 - ,HMO_INDICATOR10 - ,HMO_INDICATOR11 - ,HMO_INDICATOR12 - ) + hmo_status for month in (hmo_indicator1 + ,hmo_indicator2 + ,hmo_indicator3 + ,hmo_indicator4 + ,hmo_indicator5 + ,hmo_indicator6 + ,hmo_indicator7 + ,hmo_indicator8 + ,hmo_indicator9 + ,hmo_indicator10 + ,hmo_indicator11 + ,hmo_indicator12) )p1 - ) -, - -unpivot_entitlement as ( +, unpivot_entitlement as ( select desy_sort_key - , case when LENGTH(month) = 23 then substring(month, 23, 1) -- 'entitlement_buy_in_ind1' -> '1' - when LENGTH(month) = 24 then substring(month, 23, 2) -- 'entitlement_buy_in_ind10' -> '10' + , case when length(month) = 23 then substring(month, 23, 1) -- 'entitlement_buy_in_ind1' -> '1' + when length(month) = 24 then substring(month, 23, 2) -- 'entitlement_buy_in_ind10' -> '10' else null end as month , reference_year as year , entitlement from demographics unpivot( entitlement for month in (entitlement_buy_in_ind1 - ,entitlement_buy_in_ind2 - ,entitlement_buy_in_ind3 - ,entitlement_buy_in_ind4 - ,entitlement_buy_in_ind5 - ,entitlement_buy_in_ind6 - ,entitlement_buy_in_ind7 - ,entitlement_buy_in_ind8 - ,entitlement_buy_in_ind9 - ,entitlement_buy_in_ind10 - ,entitlement_buy_in_ind11 - ,entitlement_buy_in_ind12 - ) + ,entitlement_buy_in_ind2 + ,entitlement_buy_in_ind3 + ,entitlement_buy_in_ind4 + ,entitlement_buy_in_ind5 + ,entitlement_buy_in_ind6 + ,entitlement_buy_in_ind7 + ,entitlement_buy_in_ind8 + ,entitlement_buy_in_ind9 + ,entitlement_buy_in_ind10 + ,entitlement_buy_in_ind11 + ,entitlement_buy_in_ind12) )p1 ) @@ -136,6 +130,8 @@ select ) as year_month , unpivot_hmo_status.hmo_status , unpivot_entitlement.entitlement + , demographics.file_name + , demographics.ingest_datetime from demographics inner join unpivot_dual_status on demographics.desy_sort_key = unpivot_dual_status.desy_sort_key diff --git a/models/intermediate/home_health_claim.sql b/models/intermediate/home_health_claim.sql index 4f7d6b5..b320bbb 100644 --- a/models/intermediate/home_health_claim.sql +++ b/models/intermediate/home_health_claim.sql @@ -2,29 +2,35 @@ with hha_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','hha_base_claim') }} + from {{ ref('stg_hha_base_claim') }} where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ + ) + , header_payment as ( + select - claim_no as claim_id + claim_no as claim_id , cast(clm_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount , /** medicare payment **/ cast(clm_pmt_amt as {{ dbt.type_numeric() }}) - /** primary payer payment **/ - + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) - as total_cost_amount + /** primary payer payment **/ + + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) + as total_cost_amount , cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }}) as charge_amount from hha_base_claim + ) , claim_start_date as ( - select l.claim_no - ,min(coalesce(l.rev_cntr_dt,l.clm_thru_dt)) as claim_start_date - from {{ source('medicare_lds','hha_revenue_center') }} l - group by l.claim_no + select + claim_no + , min(coalesce(rev_cntr_dt,clm_thru_dt)) as claim_start_date + from {{ ref('stg_hha_revenue_center') }} + group by claim_no + ) select @@ -64,7 +70,9 @@ select , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(l.rev_cntr_rndrng_physn_npi as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(b.org_npi_num as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(coalesce(b.org_npi_num,b.srvc_loc_npi_num) as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , p.paid_amount as paid_amount @@ -176,15 +184,16 @@ select , date(NULL) as procedure_date_23 , date(NULL) as procedure_date_24 , date(NULL) as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'home_health_claim' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from hha_base_claim as b -inner join {{ source('medicare_lds','hha_revenue_center') }} as l - on b.claim_no = l.claim_no -/* Payment is provided at the header level only. Populating on revenu center 001 to avoid duplication. */ -left join header_payment p - on b.claim_no = p.claim_id - and l.rev_cntr = '0001' -left join claim_start_date s on b.claim_no = s.claim_no \ No newline at end of file + inner join {{ ref('stg_hha_revenue_center') }} as l + on b.claim_no = l.claim_no + /* Payment is provided at the header level only. Populating on revenue center 001 to avoid duplication. */ + left join header_payment as p + on b.claim_no = p.claim_id + and l.rev_cntr = '0001' + left join claim_start_date as s + on b.claim_no = s.claim_no \ No newline at end of file diff --git a/models/intermediate/hospice_claim.sql b/models/intermediate/hospice_claim.sql index 4c30387..1f51d58 100644 --- a/models/intermediate/hospice_claim.sql +++ b/models/intermediate/hospice_claim.sql @@ -2,28 +2,35 @@ with hospice_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','hospice_base_claim') }} + from {{ ref('stg_hospice_base_claim') }} where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ + ) + , header_payment as ( + select - claim_no as claim_id + claim_no as claim_id , cast(clm_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount , /** medicare payment **/ - cast(clm_pmt_amt as {{ dbt.type_numeric() }}) - /** primary payer payment **/ - + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) - as total_cost_amount + cast(clm_pmt_amt as {{ dbt.type_numeric() }}) + /** primary payer payment **/ + + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) + as total_cost_amount , cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }}) as charge_amount from hospice_base_claim + ) , claim_start_date as ( - select l.claim_no - ,min(l.rev_cntr_dt) as claim_start_date - from {{ source('medicare_lds','hospice_revenue_center') }} l - group by l.claim_no + + select + claim_no + , min(rev_cntr_dt) as claim_start_date + from {{ ref('stg_hospice_revenue_center') }} + group by claim_no + ) select @@ -63,7 +70,9 @@ select , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(l.rev_cntr_rndrng_physn_npi as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(b.org_npi_num as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(coalesce(b.org_npi_num,b.srvc_loc_npi_num) as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , p.paid_amount as paid_amount @@ -175,15 +184,16 @@ select , date(NULL) as procedure_date_23 , date(NULL) as procedure_date_24 , date(NULL) as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'hospice' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from hospice_base_claim as b -inner join {{ source('medicare_lds','hospice_revenue_center') }} as l - on b.claim_no = l.claim_no -/* Payment is provided at the header level only. Populating on revenu center 001 to avoid duplication. */ -left join header_payment p - on b.claim_no = p.claim_id - and l.rev_cntr = '0001' -left join claim_start_date c on b.claim_no = c.claim_no \ No newline at end of file + inner join {{ ref('stg_hospice_revenue_center') }} as l + on b.claim_no = l.claim_no + /* Payment is provided at the header level only. Populating on revenue center 001 to avoid duplication. */ + left join header_payment as p + on b.claim_no = p.claim_id + and l.rev_cntr = '0001' + left join claim_start_date as c + on b.claim_no = c.claim_no \ No newline at end of file diff --git a/models/intermediate/inpatient_claim.sql b/models/intermediate/inpatient_claim.sql index 7de3dbd..a2ea89f 100644 --- a/models/intermediate/inpatient_claim.sql +++ b/models/intermediate/inpatient_claim.sql @@ -1,28 +1,34 @@ with inpatient_base_claim as ( -select - * -, left(clm_thru_dt,4) as clm_thru_dt_year -from {{ source('medicare_lds','inpatient_base_claim') }} -where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ -), + + select * + , left(clm_thru_dt,4) as clm_thru_dt_year + from {{ ref('stg_inpatient_base_claim') }} + where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ + +) /* Claim ID is not unique across claim types. Concatenating original claim ID, claim year, and claim type. */ -add_claim_id as ( -select - * -, cast(claim_no as {{ dbt.type_string() }} ) || cast(clm_thru_dt_year as {{ dbt.type_string() }} ) || cast(nch_clm_type_cd as {{ dbt.type_string() }} ) as claim_id -from inpatient_base_claim +, add_claim_id as ( -), + select * + , cast(claim_no as {{ dbt.type_string() }} ) + || cast(clm_thru_dt_year as {{ dbt.type_string() }} ) + || cast(nch_clm_type_cd as {{ dbt.type_string() }} + ) as claim_id + from inpatient_base_claim -header_payment as ( -select - claim_id -, sum(cast(clm_pmt_amt as {{ dbt.type_numeric() }})) as paid_amount -, sum(cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }})) as charge_amount -from add_claim_id -group by 1 -) +) + +, header_payment as ( + + select + claim_id + , sum(cast(clm_pmt_amt as {{ dbt.type_numeric() }})) as paid_amount + , sum(cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }})) as charge_amount + from add_claim_id + group by claim_id + +) select b.claim_id @@ -57,7 +63,9 @@ select , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(b.rndrng_physn_npi as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(b.org_npi_num as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(b.org_npi_num as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , coalesce(p.paid_amount,cast(0 as {{ dbt.type_numeric() }})) as paid_amount @@ -169,14 +177,14 @@ select , {{ try_to_cast_date('b.prcdr_dt23', 'YYYYMMDD') }} as procedure_date_23 , {{ try_to_cast_date('b.prcdr_dt24', 'YYYYMMDD') }} as procedure_date_24 , {{ try_to_cast_date('b.prcdr_dt25', 'YYYYMMDD') }} as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'inpatient_claim' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from add_claim_id as b -inner join {{ source('medicare_lds','inpatient_revenue_center') }} as l - on b.claim_no = l.claim_no -/* Payment is provided at the header level only. Populating on revenue center 0001 to avoid duplication. */ -left join header_payment p - on b.claim_id = p.claim_id - and l.rev_cntr = '0001' \ No newline at end of file + inner join {{ ref('stg_inpatient_revenue_center') }} as l + on b.claim_no = l.claim_no + /* Payment is provided at the header level only. Populating on revenue center 0001 to avoid duplication. */ + left join header_payment as p + on b.claim_id = p.claim_id + and l.rev_cntr = '0001' \ No newline at end of file diff --git a/models/intermediate/outpatient_claim.sql b/models/intermediate/outpatient_claim.sql index b0670f1..615aba6 100644 --- a/models/intermediate/outpatient_claim.sql +++ b/models/intermediate/outpatient_claim.sql @@ -2,31 +2,38 @@ with outpatient_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','outpatient_base_claim') }} + from {{ ref('stg_outpatient_base_claim') }} where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ + ) -, header_payment as( + +, header_payment as ( + select - claim_no as claim_id + claim_no as claim_id , cast(clm_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount , /** medicare payment **/ cast(clm_pmt_amt as {{ dbt.type_numeric() }}) - /** beneficiary payment **/ - + cast(nch_bene_ptb_coinsrnc_amt as {{ dbt.type_numeric() }}) + cast(nch_bene_ptb_ddctbl_amt as {{ dbt.type_numeric() }}) + cast(nch_bene_blood_ddctbl_lblty_am as {{ dbt.type_numeric() }}) - /** primary payer payment **/ - + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) - as total_cost_amount + /** beneficiary payment **/ + + cast(nch_bene_ptb_coinsrnc_amt as {{ dbt.type_numeric() }}) + + cast(nch_bene_ptb_ddctbl_amt as {{ dbt.type_numeric() }}) + + cast(nch_bene_blood_ddctbl_lblty_am as {{ dbt.type_numeric() }}) + /** primary payer payment **/ + + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) + as total_cost_amount , cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }}) as charge_amount from outpatient_base_claim ) , claim_start_date as ( - select l.claim_no - ,min(coalesce(l.rev_cntr_dt,l.clm_thru_dt)) as claim_start_date - from {{ source('medicare_lds','outpatient_revenue_center') }} l - group by l.claim_no + select + claim_no + , min(coalesce(rev_cntr_dt,clm_thru_dt)) as claim_start_date + from {{ ref('stg_outpatient_revenue_center') }} + group by claim_no + ) select @@ -66,7 +73,9 @@ select , cast(l.hcpcs_4th_mdfr_cd as {{ dbt.type_string() }} ) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }} ) as hcpcs_modifier_5 , cast(b.rndrng_physn_npi as {{ dbt.type_string() }} ) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(b.org_npi_num as {{ dbt.type_string() }} ) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(coalesce(b.org_npi_num,b.srvc_loc_npi_num) as {{ dbt.type_string() }} ) as facility_npi , date(NULL) as paid_date , coalesce( @@ -181,15 +190,16 @@ select , {{ try_to_cast_date('b.prcdr_dt23', 'YYYYMMDD') }} as procedure_date_23 , {{ try_to_cast_date('b.prcdr_dt24', 'YYYYMMDD') }} as procedure_date_24 , {{ try_to_cast_date('b.prcdr_dt25', 'YYYYMMDD') }} as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'outpatient_claim' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from outpatient_base_claim as b -inner join {{ source('medicare_lds','outpatient_revenue_center') }} as l - on b.claim_no = l.claim_no -/* Payment is provided at the header level only. Populating on revenu center 001 to avoid duplication. */ -left join header_payment p - on b.claim_no = p.claim_id - and l.rev_cntr = '0001' -left join claim_start_date c on b.claim_no = c.claim_no \ No newline at end of file + inner join {{ ref('stg_outpatient_revenue_center') }} as l + on b.claim_no = l.claim_no + /* Payment is provided at the header level only. Populating on revenue center 001 to avoid duplication. */ + left join header_payment as p + on b.claim_no = p.claim_id + and l.rev_cntr = '0001' + left join claim_start_date as c + on b.claim_no = c.claim_no \ No newline at end of file diff --git a/models/intermediate/snf_claim.sql b/models/intermediate/snf_claim.sql index 13e11b3..7f00f41 100644 --- a/models/intermediate/snf_claim.sql +++ b/models/intermediate/snf_claim.sql @@ -2,13 +2,14 @@ with snf_base_claim as ( select * , left(clm_thru_dt,4) as clm_thru_dt_year - from {{ source('medicare_lds','snf_base_claim') }} + from {{ ref('stg_snf_base_claim') }} where clm_mdcr_non_pmt_rsn_cd is null /** filter out denied claims **/ -), + +) /* Claim ID is not unique across claim types. Concatenating original claim ID, claim year, and claim type. */ -add_claim_id as ( +, add_claim_id as ( select cast(claim_no as {{ dbt.type_string() }} ) @@ -18,20 +19,22 @@ add_claim_id as ( , * from snf_base_claim -), +) -header_payment as ( +, header_payment as ( select claim_id , cast(clm_pmt_amt as {{ dbt.type_numeric() }}) as paid_amount , /** Medicare payment **/ cast(clm_pmt_amt as {{ dbt.type_numeric() }}) - /** benficiary payment **/ - + cast(nch_bene_ip_ddctbl_amt as {{ dbt.type_numeric() }}) + cast(nch_bene_pta_coinsrnc_lblty_am as {{ dbt.type_numeric() }}) + cast(nch_bene_blood_ddctbl_lblty_am as {{ dbt.type_numeric() }}) - /** primary payer payment **/ - + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) - as total_cost_amount + /** benficiary payment **/ + + cast(nch_bene_ip_ddctbl_amt as {{ dbt.type_numeric() }}) + + cast(nch_bene_pta_coinsrnc_lblty_am as {{ dbt.type_numeric() }}) + + cast(nch_bene_blood_ddctbl_lblty_am as {{ dbt.type_numeric() }}) + /** primary payer payment **/ + + cast(nch_prmry_pyr_clm_pd_amt as {{ dbt.type_numeric() }}) + as total_cost_amount , cast(clm_tot_chrg_amt as {{ dbt.type_numeric() }}) as charge_amount from add_claim_id @@ -70,7 +73,9 @@ select , cast(NULL as {{ dbt.type_string() }}) as hcpcs_modifier_4 , cast(NULL as {{ dbt.type_string() }}) as hcpcs_modifier_5 , cast(b.rndrng_physn_npi as {{ dbt.type_string() }}) as rendering_npi + , cast(NULL as {{ dbt.type_string() }} ) as rendering_tin , cast(NULL as {{ dbt.type_string() }}) as billing_npi + , cast(NULL as {{ dbt.type_string() }} ) as billing_tin , cast(b.org_npi_num as {{ dbt.type_string() }}) as facility_npi , date(NULL) as paid_date , coalesce( @@ -185,14 +190,14 @@ select , {{ try_to_cast_date('b.prcdr_dt23', 'YYYYMMDD') }} as procedure_date_23 , {{ try_to_cast_date('b.prcdr_dt24', 'YYYYMMDD') }} as procedure_date_24 , {{ try_to_cast_date('b.prcdr_dt25', 'YYYYMMDD') }} as procedure_date_25 + , cast(1 as int) as in_network_flag , 'medicare_lds' as data_source - , 1 as in_network_flag - , 'snf_claim' as file_name - , cast(NULL as date ) as ingest_datetime + , cast(b.file_name as {{ dbt.type_string() }} ) as file_name + , cast(b.ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime from add_claim_id as b -inner join {{ source('medicare_lds','snf_revenue_center') }} as l - on b.claim_no = l.claim_no -/* Payment is provided at the header level only. Populating on revenu center 001 to avoid duplication. */ -left join header_payment p - on b.claim_id = p.claim_id - and l.rev_cntr = '0001' \ No newline at end of file + inner join {{ ref('stg_snf_revenue_center') }} as l + on b.claim_no = l.claim_no + /* Payment is provided at the header level only. Populating on revenue center 001 to avoid duplication. */ + left join header_payment as p + on b.claim_id = p.claim_id + and l.rev_cntr = '0001' \ No newline at end of file diff --git a/models/staging/stg_carrier_base_claim.sql b/models/staging/stg_carrier_base_claim.sql new file mode 100644 index 0000000..e63dc04 --- /dev/null +++ b/models/staging/stg_carrier_base_claim.sql @@ -0,0 +1,61 @@ +select + desy_sort_key + , claim_no + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , clm_disp_cd + , carr_num + , carr_clm_pmt_dnl_cd + , clm_pmt_amt + , carr_clm_prmry_pyr_pd_amt + , rfr_physn_upin + , rfr_physn_npi + , carr_clm_prvdr_asgnmt_ind_sw + , nch_clm_prvdr_pmt_amt + , nch_clm_bene_pmt_amt + , nch_carr_clm_sbmtd_chrg_amt + , nch_carr_clm_alowd_amt + , carr_clm_cash_ddctbl_apld_amt + , carr_clm_hcpcs_yr_cd + , carr_clm_rfrng_pin_num + , prncpal_dgns_cd + , prncpal_dgns_vrsn_cd + , icd_dgns_cd1 + , icd_dgns_vrsn_cd1 + , icd_dgns_cd2 + , icd_dgns_vrsn_cd2 + , icd_dgns_cd3 + , icd_dgns_vrsn_cd3 + , icd_dgns_cd4 + , icd_dgns_vrsn_cd4 + , icd_dgns_cd5 + , icd_dgns_vrsn_cd5 + , icd_dgns_cd6 + , icd_dgns_vrsn_cd6 + , icd_dgns_cd7 + , icd_dgns_vrsn_cd7 + , icd_dgns_cd8 + , icd_dgns_vrsn_cd8 + , icd_dgns_cd9 + , icd_dgns_vrsn_cd9 + , icd_dgns_cd10 + , icd_dgns_vrsn_cd10 + , icd_dgns_cd11 + , icd_dgns_vrsn_cd11 + , icd_dgns_cd12 + , icd_dgns_vrsn_cd12 + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_bene_pd_amt + , cpo_prvdr_num + , cpo_org_npi_num + , carr_clm_blg_npi_num + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','carrier_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_carrier_claim_line.sql b/models/staging/stg_carrier_claim_line.sql new file mode 100644 index 0000000..aeb374c --- /dev/null +++ b/models/staging/stg_carrier_claim_line.sql @@ -0,0 +1,73 @@ +select + desy_sort_key + , claim_no + , line_num + , clm_thru_dt + , nch_clm_type_cd + , carr_prfrng_pin_num + , prf_physn_upin + , prf_physn_npi + , org_npi_num + , carr_line_prvdr_type_cd + , prvdr_state_cd + , prvdr_spclty + , prtcptng_ind_cd + , carr_line_rdcd_pmt_phys_astn_c + , line_srvc_cnt + , line_cms_type_srvc_cd + , line_place_of_srvc_cd + , carr_line_prcng_lclty_cd + , line_last_expns_dt + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , betos_cd + , line_nch_pmt_amt + , line_bene_pmt_amt + , line_prvdr_pmt_amt + , line_bene_ptb_ddctbl_amt + , line_bene_prmry_pyr_cd + , line_bene_prmry_pyr_pd_amt + , line_coinsrnc_amt + , line_sbmtd_chrg_amt + , line_alowd_chrg_amt + , line_prcsg_ind_cd + , line_pmt_80_100_cd + , line_service_deductible + , carr_line_mtus_cnt + , carr_line_mtus_cd + , line_icd_dgns_cd + , line_icd_dgns_vrsn_cd + , line_hct_hgb_rslt_num + , line_hct_hgb_type_cd + , line_ndc_cd + , carr_line_clia_lab_num + , carr_line_ansthsa_unit_cnt + , carr_line_cl_chrg_amt + , line_othr_apld_ind_cd1 + , line_othr_apld_ind_cd2 + , line_othr_apld_ind_cd3 + , line_othr_apld_ind_cd4 + , line_othr_apld_ind_cd5 + , line_othr_apld_ind_cd6 + , line_othr_apld_ind_cd7 + , line_othr_apld_amt1 + , line_othr_apld_amt2 + , line_othr_apld_amt3 + , line_othr_apld_amt4 + , line_othr_apld_amt5 + , line_othr_apld_amt6 + , line_othr_apld_amt7 + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , thrpy_cap_ind_cd3 + , thrpy_cap_ind_cd4 + , thrpy_cap_ind_cd5 + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , file_name + , ingest_datetime +from {{ source('medicare_lds','carrier_claim_line') }} \ No newline at end of file diff --git a/models/staging/stg_dme_base_claim.sql b/models/staging/stg_dme_base_claim.sql new file mode 100644 index 0000000..cbd40c1 --- /dev/null +++ b/models/staging/stg_dme_base_claim.sql @@ -0,0 +1,57 @@ +select + desy_sort_key + , claim_no + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , clm_disp_cd + , carr_num + , carr_clm_pmt_dnl_cd + , clm_pmt_amt + , carr_clm_prmry_pyr_pd_amt + , carr_clm_prvdr_asgnmt_ind_sw + , nch_clm_prvdr_pmt_amt + , nch_clm_bene_pmt_amt + , nch_carr_clm_sbmtd_chrg_amt + , nch_carr_clm_alowd_amt + , carr_clm_cash_ddctbl_apld_amt + , carr_clm_hcpcs_yr_cd + , prncpal_dgns_cd + , prncpal_dgns_vrsn_cd + , icd_dgns_cd1 + , icd_dgns_vrsn_cd1 + , icd_dgns_cd2 + , icd_dgns_vrsn_cd2 + , icd_dgns_cd3 + , icd_dgns_vrsn_cd3 + , icd_dgns_cd4 + , icd_dgns_vrsn_cd4 + , icd_dgns_cd5 + , icd_dgns_vrsn_cd5 + , icd_dgns_cd6 + , icd_dgns_vrsn_cd6 + , icd_dgns_cd7 + , icd_dgns_vrsn_cd7 + , icd_dgns_cd8 + , icd_dgns_vrsn_cd8 + , icd_dgns_cd9 + , icd_dgns_vrsn_cd9 + , icd_dgns_cd10 + , icd_dgns_vrsn_cd10 + , icd_dgns_cd11 + , icd_dgns_vrsn_cd11 + , icd_dgns_cd12 + , icd_dgns_vrsn_cd12 + , rfr_physn_upin + , rfr_physn_npi + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_bene_pd_amt + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','dme_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_dme_claim_line.sql b/models/staging/stg_dme_claim_line.sql new file mode 100644 index 0000000..e5af3af --- /dev/null +++ b/models/staging/stg_dme_claim_line.sql @@ -0,0 +1,61 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , prvdr_spclty + , prtcptng_ind_cd + , line_srvc_cnt + , line_cms_type_srvc_cd + , line_place_of_srvc_cd + , line_last_expns_dt + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , betos_cd + , line_nch_pmt_amt + , line_bene_pmt_amt + , line_prvdr_pmt_amt + , line_bene_ptb_ddctbl_amt + , line_bene_prmry_pyr_cd + , line_bene_prmry_pyr_pd_amt + , line_coinsrnc_amt + , line_prmry_alowd_chrg_amt + , line_sbmtd_chrg_amt + , line_alowd_chrg_amt + , line_prcsg_ind_cd + , line_pmt_80_100_cd + , line_service_deductible + , line_icd_dgns_cd + , line_icd_dgns_vrsn_cd + , line_dme_prchs_price_amt + , prvdr_num + , prvdr_npi + , dmerc_line_prcng_state_cd + , prvdr_state_cd + , hcpcs_3rd_mdfr_cd + , hcpcs_4th_mdfr_cd + , dmerc_line_scrn_svgs_amt + , dmerc_line_mtus_cnt + , dmerc_line_mtus_cd + , line_hct_hgb_rslt_num + , line_hct_hgb_type_cd + , line_ndc_cd + , line_othr_apld_ind_cd1 + , line_othr_apld_ind_cd2 + , line_othr_apld_ind_cd3 + , line_othr_apld_ind_cd4 + , line_othr_apld_ind_cd5 + , line_othr_apld_ind_cd6 + , line_othr_apld_ind_cd7 + , line_othr_apld_amt1 + , line_othr_apld_amt2 + , line_othr_apld_amt3 + , line_othr_apld_amt4 + , line_othr_apld_amt5 + , line_othr_apld_amt6 + , line_othr_apld_amt7 + , file_name + , ingest_datetime +from {{ source('medicare_lds','dme_claim_line') }} \ No newline at end of file diff --git a/models/staging/stg_hha_base_claim.sql b/models/staging/stg_hha_base_claim.sql new file mode 100644 index 0000000..0604886 --- /dev/null +++ b/models/staging/stg_hha_base_claim.sql @@ -0,0 +1,96 @@ +select + desy_sort_key + , claim_no + , prvdr_num + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , clm_fac_type_cd + , clm_srvc_clsfctn_type_cd + , clm_freq_cd + , fi_num + , clm_mdcr_non_pmt_rsn_cd + , clm_pmt_amt + , nch_prmry_pyr_clm_pd_amt + , nch_prmry_pyr_cd + , prvdr_state_cd + , org_npi_num + , srvc_loc_npi_num + , at_physn_upin + , at_physn_npi + , at_physn_spclty_cd + , op_physn_npi + , op_physn_spclty_cd + , ot_physn_npi + , ot_physn_spclty_cd + , rndrng_physn_npi + , rndrng_physn_spclty_cd + , rfr_physn_npi + , rfr_physn_spclty_cd + , ptnt_dschrg_stus_cd + , clm_pps_ind_cd + , clm_tot_chrg_amt + , prncpal_dgns_cd + , icd_dgns_cd1 + , icd_dgns_cd2 + , icd_dgns_cd3 + , icd_dgns_cd4 + , icd_dgns_cd5 + , icd_dgns_cd6 + , icd_dgns_cd7 + , icd_dgns_cd8 + , icd_dgns_cd9 + , icd_dgns_cd10 + , icd_dgns_cd11 + , icd_dgns_cd12 + , icd_dgns_cd13 + , icd_dgns_cd14 + , icd_dgns_cd15 + , icd_dgns_cd16 + , icd_dgns_cd17 + , icd_dgns_cd18 + , icd_dgns_cd19 + , icd_dgns_cd20 + , icd_dgns_cd21 + , icd_dgns_cd22 + , icd_dgns_cd23 + , icd_dgns_cd24 + , icd_dgns_cd25 + , fst_dgns_e_cd + , icd_dgns_e_cd1 + , icd_dgns_e_cd2 + , icd_dgns_e_cd3 + , icd_dgns_e_cd4 + , icd_dgns_e_cd5 + , icd_dgns_e_cd6 + , icd_dgns_e_cd7 + , icd_dgns_e_cd8 + , icd_dgns_e_cd9 + , icd_dgns_e_cd10 + , icd_dgns_e_cd11 + , icd_dgns_e_cd12 + , clm_hha_lupa_ind_cd + , clm_hha_rfrl_cd + , clm_hha_tot_visit_cnt + , clm_admsn_dt + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_query_cd + , fi_clm_actn_cd + , clm_mco_pd_sw + , nch_bene_dschrg_dt + , clm_trtmt_authrztn_num + , clm_prcr_rtrn_cd + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','hha_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_hha_revenue_center.sql b/models/staging/stg_hha_revenue_center.sql new file mode 100644 index 0000000..776923e --- /dev/null +++ b/models/staging/stg_hha_revenue_center.sql @@ -0,0 +1,34 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , rev_cntr + , rev_cntr_dt + , rev_cntr_apc_hipps_cd + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , hcpcs_3rd_mdfr_cd + , rev_cntr_pmt_mthd_ind_cd + , rev_cntr_unit_cnt + , rev_cntr_rate_amt + , rev_cntr_pmt_amt_amt + , rev_cntr_tot_chrg_amt + , rev_cntr_ncvrd_chrg_amt + , rev_cntr_ddctbl_coinsrnc_cd + , rev_cntr_stus_ind_cd + , rev_cntr_rndrng_physn_upin + , rev_cntr_rndrng_physn_npi + , rev_cntr_rndrng_physn_spclty_cd + , rev_cntr_dscnt_ind_cd + , rev_cntr_ide_ndc_upc_num + , rev_cntr_prvdr_pmt_amt + , rev_cntr_ptnt_rspnsblty_pmt + , rev_cntr_prcng_ind_cd + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , file_name + , ingest_datetime +from {{ source('medicare_lds','hha_revenue_center') }} \ No newline at end of file diff --git a/models/staging/stg_hospice_base_claim.sql b/models/staging/stg_hospice_base_claim.sql new file mode 100644 index 0000000..adda266 --- /dev/null +++ b/models/staging/stg_hospice_base_claim.sql @@ -0,0 +1,94 @@ +select + desy_sort_key + , claim_no + , prvdr_num + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , clm_fac_type_cd + , clm_srvc_clsfctn_type_cd + , clm_freq_cd + , fi_num + , clm_mdcr_non_pmt_rsn_cd + , clm_pmt_amt + , nch_prmry_pyr_clm_pd_amt + , nch_prmry_pyr_cd + , prvdr_state_cd + , org_npi_num + , srvc_loc_npi_num + , at_physn_upin + , at_physn_npi + , at_physn_spclty_cd + , op_physn_npi + , op_physn_spclty_cd + , ot_physn_npi + , ot_physn_spclty_cd + , rndrng_physn_npi + , rndrng_physn_spclty_cd + , rfr_physn_npi + , rfr_physn_spclty_cd + , ptnt_dschrg_stus_cd + , clm_tot_chrg_amt + , nch_ptnt_status_ind_cd + , clm_utlztn_day_cnt + , nch_bene_dschrg_dt + , prncpal_dgns_cd + , icd_dgns_cd1 + , icd_dgns_cd2 + , icd_dgns_cd3 + , icd_dgns_cd4 + , icd_dgns_cd5 + , icd_dgns_cd6 + , icd_dgns_cd7 + , icd_dgns_cd8 + , icd_dgns_cd9 + , icd_dgns_cd10 + , icd_dgns_cd11 + , icd_dgns_cd12 + , icd_dgns_cd13 + , icd_dgns_cd14 + , icd_dgns_cd15 + , icd_dgns_cd16 + , icd_dgns_cd17 + , icd_dgns_cd18 + , icd_dgns_cd19 + , icd_dgns_cd20 + , icd_dgns_cd21 + , icd_dgns_cd22 + , icd_dgns_cd23 + , icd_dgns_cd24 + , icd_dgns_cd25 + , fst_dgns_e_cd + , icd_dgns_e_cd1 + , icd_dgns_e_cd2 + , icd_dgns_e_cd3 + , icd_dgns_e_cd4 + , icd_dgns_e_cd5 + , icd_dgns_e_cd6 + , icd_dgns_e_cd7 + , icd_dgns_e_cd8 + , icd_dgns_e_cd9 + , icd_dgns_e_cd10 + , icd_dgns_e_cd11 + , icd_dgns_e_cd12 + , clm_hospc_start_dt_id + , bene_hospc_prd_cnt + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_query_cd + , fi_clm_actn_cd + , clm_trtmt_authrztn_num + , clm_prcr_rtrn_cd + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','hospice_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_hospice_revenue_center.sql b/models/staging/stg_hospice_revenue_center.sql new file mode 100644 index 0000000..07742e6 --- /dev/null +++ b/models/staging/stg_hospice_revenue_center.sql @@ -0,0 +1,31 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , rev_cntr + , rev_cntr_dt + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , hcpcs_3rd_mdfr_cd + , rev_cntr_unit_cnt + , rev_cntr_rate_amt + , rev_cntr_prvdr_pmt_amt + , rev_cntr_bene_pmt_amt + , rev_cntr_pmt_amt_amt + , rev_cntr_tot_chrg_amt + , rev_cntr_ncvrd_chrg_amt + , rev_cntr_ddctbl_coinsrnc_cd + , rev_cntr_rndrng_physn_upin + , rev_cntr_rndrng_physn_npi + , rev_cntr_rndrng_physn_spclty_cd + , rev_cntr_ide_ndc_upc_num + , rev_cntr_stus_ind_cd + , rev_cntr_prcng_ind_cd + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , file_name + , ingest_datetime +from {{ source('medicare_lds','hospice_revenue_center') }} \ No newline at end of file diff --git a/models/staging/stg_inpatient_base_claim.sql b/models/staging/stg_inpatient_base_claim.sql new file mode 100644 index 0000000..2a1bd2e --- /dev/null +++ b/models/staging/stg_inpatient_base_claim.sql @@ -0,0 +1,233 @@ +select + desy_sort_key + , claim_no + , prvdr_num + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , claim_query_code + , clm_fac_type_cd + , clm_srvc_clsfctn_type_cd + , clm_freq_cd + , fi_num + , clm_mdcr_non_pmt_rsn_cd + , clm_pmt_amt + , nch_prmry_pyr_clm_pd_amt + , nch_prmry_pyr_cd + , fi_clm_actn_cd + , prvdr_state_cd + , org_npi_num + , at_physn_upin + , at_physn_npi + , at_physn_spclty_cd + , op_physn_upin + , op_physn_npi + , op_physn_spclty_cd + , ot_physn_upin + , ot_physn_npi + , ot_physn_spclty_cd + , rndrng_physn_npi + , rndrng_physn_spclty_cd + , clm_mco_pd_sw + , ptnt_dschrg_stus_cd + , clm_pps_ind_cd + , clm_tot_chrg_amt + , clm_admsn_dt + , clm_ip_admsn_type_cd + , clm_src_ip_admsn_cd + , nch_ptnt_status_ind_cd + , clm_pass_thru_per_diem_amt + , nch_bene_ip_ddctbl_amt + , nch_bene_pta_coinsrnc_lblty_am + , nch_bene_blood_ddctbl_lblty_am + , nch_profnl_cmpnt_chrg_amt + , nch_ip_ncvrd_chrg_amt + , clm_tot_pps_cptl_amt + , clm_pps_cptl_fsp_amt + , clm_pps_cptl_outlier_amt + , clm_pps_cptl_dsprprtnt_shr_amt + , clm_pps_cptl_ime_amt + , clm_pps_cptl_excptn_amt + , clm_pps_old_cptl_hld_hrmls_amt + , clm_pps_cptl_drg_wt_num + , clm_utlztn_day_cnt + , bene_tot_coinsrnc_days_cnt + , bene_lrd_used_cnt + , clm_non_utlztn_days_cnt + , nch_blood_pnts_frnshd_qty + , nch_vrfd_ncvrd_stay_from_dt + , nch_vrfd_ncvrd_stay_thru_dt + , nch_bene_mdcr_bnfts_exhtd_dt_i + , nch_bene_dschrg_dt + , clm_drg_cd + , clm_drg_outlier_stay_cd + , nch_drg_outlier_aprvd_pmt_amt + , admtg_dgns_cd + , prncpal_dgns_cd + , icd_dgns_cd1 + , clm_poa_ind_sw1 + , icd_dgns_cd2 + , clm_poa_ind_sw2 + , icd_dgns_cd3 + , clm_poa_ind_sw3 + , icd_dgns_cd4 + , clm_poa_ind_sw4 + , icd_dgns_cd5 + , clm_poa_ind_sw5 + , icd_dgns_cd6 + , clm_poa_ind_sw6 + , icd_dgns_cd7 + , clm_poa_ind_sw7 + , icd_dgns_cd8 + , clm_poa_ind_sw8 + , icd_dgns_cd9 + , clm_poa_ind_sw9 + , icd_dgns_cd10 + , clm_poa_ind_sw10 + , icd_dgns_cd11 + , clm_poa_ind_sw11 + , icd_dgns_cd12 + , clm_poa_ind_sw12 + , icd_dgns_cd13 + , clm_poa_ind_sw13 + , icd_dgns_cd14 + , clm_poa_ind_sw14 + , icd_dgns_cd15 + , clm_poa_ind_sw15 + , icd_dgns_cd16 + , clm_poa_ind_sw16 + , icd_dgns_cd17 + , clm_poa_ind_sw17 + , icd_dgns_cd18 + , clm_poa_ind_sw18 + , icd_dgns_cd19 + , clm_poa_ind_sw19 + , icd_dgns_cd20 + , clm_poa_ind_sw20 + , icd_dgns_cd21 + , clm_poa_ind_sw21 + , icd_dgns_cd22 + , clm_poa_ind_sw22 + , icd_dgns_cd23 + , clm_poa_ind_sw23 + , icd_dgns_cd24 + , clm_poa_ind_sw24 + , icd_dgns_cd25 + , clm_poa_ind_sw25 + , fst_dgns_e_cd + , icd_dgns_e_cd1 + , clm_e_poa_ind_sw1 + , icd_dgns_e_cd2 + , clm_e_poa_ind_sw2 + , icd_dgns_e_cd3 + , clm_e_poa_ind_sw3 + , icd_dgns_e_cd4 + , clm_e_poa_ind_sw4 + , icd_dgns_e_cd5 + , clm_e_poa_ind_sw5 + , icd_dgns_e_cd6 + , clm_e_poa_ind_sw6 + , icd_dgns_e_cd7 + , clm_e_poa_ind_sw7 + , icd_dgns_e_cd8 + , clm_e_poa_ind_sw8 + , icd_dgns_e_cd9 + , clm_e_poa_ind_sw9 + , icd_dgns_e_cd10 + , clm_e_poa_ind_sw10 + , icd_dgns_e_cd11 + , clm_e_poa_ind_sw11 + , icd_dgns_e_cd12 + , clm_e_poa_ind_sw12 + , icd_prcdr_cd1 + , prcdr_dt1 + , icd_prcdr_cd2 + , prcdr_dt2 + , icd_prcdr_cd3 + , prcdr_dt3 + , icd_prcdr_cd4 + , prcdr_dt4 + , icd_prcdr_cd5 + , prcdr_dt5 + , icd_prcdr_cd6 + , prcdr_dt6 + , icd_prcdr_cd7 + , prcdr_dt7 + , icd_prcdr_cd8 + , prcdr_dt8 + , icd_prcdr_cd9 + , prcdr_dt9 + , icd_prcdr_cd10 + , prcdr_dt10 + , icd_prcdr_cd11 + , prcdr_dt11 + , icd_prcdr_cd12 + , prcdr_dt12 + , icd_prcdr_cd13 + , prcdr_dt13 + , icd_prcdr_cd14 + , prcdr_dt14 + , icd_prcdr_cd15 + , prcdr_dt15 + , icd_prcdr_cd16 + , prcdr_dt16 + , icd_prcdr_cd17 + , prcdr_dt17 + , icd_prcdr_cd18 + , prcdr_dt18 + , icd_prcdr_cd19 + , prcdr_dt19 + , icd_prcdr_cd20 + , prcdr_dt20 + , icd_prcdr_cd21 + , prcdr_dt21 + , icd_prcdr_cd22 + , prcdr_dt22 + , icd_prcdr_cd23 + , prcdr_dt23 + , icd_prcdr_cd24 + , prcdr_dt24 + , icd_prcdr_cd25 + , prcdr_dt25 + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_trtmt_authrztn_num + , clm_prcr_rtrn_cd + , clm_ip_low_vol_pmt_amt + , clm_care_imprvmt_model_cd1 + , clm_care_imprvmt_model_cd2 + , clm_care_imprvmt_model_cd3 + , clm_care_imprvmt_model_cd4 + , clm_bndld_model_1_dscnt_pct + , clm_base_oprtg_drg_amt + , clm_vbp_prtcpnt_ind_cd + , clm_vbp_adjstmt_pct + , clm_hrr_prtcpnt_ind_cd + , clm_hrr_adjstmt_pct + , clm_model_4_readmsn_ind_cd + , clm_uncompd_care_pmt_amt + , clm_bndld_adjstmt_pmt_amt + , clm_vbp_adjstmt_pmt_amt + , clm_hrr_adjstmt_pmt_amt + , ehr_pymt_adjstmt_amt + , pps_std_val_pymt_amt + , finl_std_amt + , hac_pgm_rdctn_ind_sw + , ehr_pgm_rdctn_ind_sw + , clm_site_ntrl_pymt_cst_amt + , clm_site_ntrl_pymt_ipps_amt + , clm_full_std_pymt_amt + , clm_ss_outlier_std_pymt_amt + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','inpatient_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_inpatient_revenue_center.sql b/models/staging/stg_inpatient_revenue_center.sql new file mode 100644 index 0000000..ec2493d --- /dev/null +++ b/models/staging/stg_inpatient_revenue_center.sql @@ -0,0 +1,27 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , rev_cntr + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , hcpcs_3rd_mdfr_cd + , rev_cntr_unit_cnt + , rev_cntr_rate_amt + , rev_cntr_tot_chrg_amt + , rev_cntr_ncvrd_chrg_amt + , rev_cntr_ddctbl_coinsrnc_cd + , rev_cntr_apc_hipps_cd + , rev_cntr_rndrng_physn_upin + , rev_cntr_rndrng_physn_npi + , rev_cntr_rndrng_physn_spclty_cd + , rev_cntr_ide_ndc_upc_num + , rev_cntr_prcng_ind_cd + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , file_name + , ingest_datetime +from {{ source('medicare_lds','inpatient_revenue_center') }} \ No newline at end of file diff --git a/models/staging/stg_master_beneficiary_summary.sql b/models/staging/stg_master_beneficiary_summary.sql new file mode 100644 index 0000000..a2c443c --- /dev/null +++ b/models/staging/stg_master_beneficiary_summary.sql @@ -0,0 +1,83 @@ +select + desy_sort_key + , reference_year + , sample_group + , state_code + , county_code + , state_cnty_fips_cd_01 + , state_cnty_fips_cd_02 + , state_cnty_fips_cd_03 + , state_cnty_fips_cd_04 + , state_cnty_fips_cd_05 + , state_cnty_fips_cd_06 + , state_cnty_fips_cd_07 + , state_cnty_fips_cd_08 + , state_cnty_fips_cd_09 + , state_cnty_fips_cd_10 + , state_cnty_fips_cd_11 + , state_cnty_fips_cd_12 + , sex_code + , race_code + , age + , orig_reason_for_entitlement + , curr_reason_for_entitlement + , esrd_indicator + , mdcr_status_code_01 + , mdcr_status_code_02 + , mdcr_status_code_03 + , mdcr_status_code_04 + , mdcr_status_code_05 + , mdcr_status_code_06 + , mdcr_status_code_07 + , mdcr_status_code_08 + , mdcr_status_code_09 + , mdcr_status_code_10 + , mdcr_status_code_11 + , mdcr_status_code_12 + , part_a_termination_code + , part_b_termination_code + , entitlement_buy_in_ind1 + , entitlement_buy_in_ind2 + , entitlement_buy_in_ind3 + , entitlement_buy_in_ind4 + , entitlement_buy_in_ind5 + , entitlement_buy_in_ind6 + , entitlement_buy_in_ind7 + , entitlement_buy_in_ind8 + , entitlement_buy_in_ind9 + , entitlement_buy_in_ind10 + , entitlement_buy_in_ind11 + , entitlement_buy_in_ind12 + , hmo_indicator1 + , hmo_indicator2 + , hmo_indicator3 + , hmo_indicator4 + , hmo_indicator5 + , hmo_indicator6 + , hmo_indicator7 + , hmo_indicator8 + , hmo_indicator9 + , hmo_indicator10 + , hmo_indicator11 + , hmo_indicator12 + , hi_coverage + , smi_coverage + , hmo_coverage + , state_buy_in_coverage + , valid_date_of_death_switch + , date_of_death + , dual_stus_cd_01 + , dual_stus_cd_02 + , dual_stus_cd_03 + , dual_stus_cd_04 + , dual_stus_cd_05 + , dual_stus_cd_06 + , dual_stus_cd_07 + , dual_stus_cd_08 + , dual_stus_cd_09 + , dual_stus_cd_10 + , dual_stus_cd_11 + , dual_stus_cd_12 + , file_name + , ingest_datetime +from {{ source('medicare_lds','master_beneficiary_summary') }} \ No newline at end of file diff --git a/models/staging/stg_outpatient_base_claim.sql b/models/staging/stg_outpatient_base_claim.sql new file mode 100644 index 0000000..f29dbe1 --- /dev/null +++ b/models/staging/stg_outpatient_base_claim.sql @@ -0,0 +1,154 @@ +select + desy_sort_key + , claim_no + , prvdr_num + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , claim_query_code + , clm_fac_type_cd + , clm_srvc_clsfctn_type_cd + , clm_freq_cd + , fi_num + , clm_mdcr_non_pmt_rsn_cd + , clm_pmt_amt + , nch_prmry_pyr_clm_pd_amt + , nch_prmry_pyr_cd + , prvdr_state_cd + , org_npi_num + , srvc_loc_npi_num + , at_physn_upin + , at_physn_npi + , at_physn_spclty_cd + , op_physn_upin + , op_physn_npi + , op_physn_spclty_cd + , ot_physn_upin + , ot_physn_npi + , ot_physn_spclty_cd + , rndrng_physn_npi + , rndrng_physn_spclty_cd + , rfr_physn_npi + , rfr_physn_spclty_cd + , clm_mco_pd_sw + , ptnt_dschrg_stus_cd + , clm_tot_chrg_amt + , nch_bene_blood_ddctbl_lblty_am + , nch_profnl_cmpnt_chrg_amt + , prncpal_dgns_cd + , icd_dgns_cd1 + , icd_dgns_cd2 + , icd_dgns_cd3 + , icd_dgns_cd4 + , icd_dgns_cd5 + , icd_dgns_cd6 + , icd_dgns_cd7 + , icd_dgns_cd8 + , icd_dgns_cd9 + , icd_dgns_cd10 + , icd_dgns_cd11 + , icd_dgns_cd12 + , icd_dgns_cd13 + , icd_dgns_cd14 + , icd_dgns_cd15 + , icd_dgns_cd16 + , icd_dgns_cd17 + , icd_dgns_cd18 + , icd_dgns_cd19 + , icd_dgns_cd20 + , icd_dgns_cd21 + , icd_dgns_cd22 + , icd_dgns_cd23 + , icd_dgns_cd24 + , icd_dgns_cd25 + , fst_dgns_e_cd + , icd_dgns_e_cd1 + , icd_dgns_e_cd2 + , icd_dgns_e_cd3 + , icd_dgns_e_cd4 + , icd_dgns_e_cd5 + , icd_dgns_e_cd6 + , icd_dgns_e_cd7 + , icd_dgns_e_cd8 + , icd_dgns_e_cd9 + , icd_dgns_e_cd10 + , icd_dgns_e_cd11 + , icd_dgns_e_cd12 + , icd_prcdr_cd1 + , prcdr_dt1 + , icd_prcdr_cd2 + , prcdr_dt2 + , icd_prcdr_cd3 + , prcdr_dt3 + , icd_prcdr_cd4 + , prcdr_dt4 + , icd_prcdr_cd5 + , prcdr_dt5 + , icd_prcdr_cd6 + , prcdr_dt6 + , icd_prcdr_cd7 + , prcdr_dt7 + , icd_prcdr_cd8 + , prcdr_dt8 + , icd_prcdr_cd9 + , prcdr_dt9 + , icd_prcdr_cd10 + , prcdr_dt10 + , icd_prcdr_cd11 + , prcdr_dt11 + , icd_prcdr_cd12 + , prcdr_dt12 + , icd_prcdr_cd13 + , prcdr_dt13 + , icd_prcdr_cd14 + , prcdr_dt14 + , icd_prcdr_cd15 + , prcdr_dt15 + , icd_prcdr_cd16 + , prcdr_dt16 + , icd_prcdr_cd17 + , prcdr_dt17 + , icd_prcdr_cd18 + , prcdr_dt18 + , icd_prcdr_cd19 + , prcdr_dt19 + , icd_prcdr_cd20 + , prcdr_dt20 + , icd_prcdr_cd21 + , prcdr_dt21 + , icd_prcdr_cd22 + , prcdr_dt22 + , icd_prcdr_cd23 + , prcdr_dt23 + , icd_prcdr_cd24 + , prcdr_dt24 + , icd_prcdr_cd25 + , prcdr_dt25 + , rsn_visit_cd1 + , rsn_visit_cd2 + , rsn_visit_cd3 + , nch_bene_ptb_ddctbl_amt + , nch_bene_ptb_coinsrnc_amt + , clm_op_prvdr_pmt_amt + , clm_op_bene_pmt_amt + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , fi_clm_actn_cd + , nch_blood_pnts_frnshd_qty + , clm_trtmt_authrztn_num + , clm_prcr_rtrn_cd + , clm_op_trans_type_cd + , clm_op_esrd_mthd_cd + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','outpatient_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_outpatient_revenue_center.sql b/models/staging/stg_outpatient_revenue_center.sql new file mode 100644 index 0000000..88171da --- /dev/null +++ b/models/staging/stg_outpatient_revenue_center.sql @@ -0,0 +1,45 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , rev_cntr + , rev_cntr_dt + , rev_cntr_apc_hipps_cd + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , hcpcs_3rd_mdfr_cd + , hcpcs_4th_mdfr_cd + , rev_cntr_pmt_mthd_ind_cd + , rev_cntr_dscnt_ind_cd + , rev_cntr_packg_ind_cd + , rev_cntr_otaf_pmt_cd + , rev_cntr_ide_ndc_upc_num + , rev_cntr_unit_cnt + , rev_cntr_rate_amt + , rev_cntr_blood_ddctbl_amt + , rev_cntr_cash_ddctbl_amt + , rev_cntr_coinsrnc_wge_adjstd_c + , rev_cntr_rdcd_coinsrnc_amt + , rev_cntr_1st_msp_pd_amt + , rev_cntr_2nd_msp_pd_amt + , rev_cntr_prvdr_pmt_amt + , rev_cntr_bene_pmt_amt + , rev_cntr_ptnt_rspnsblty_pmt + , rev_cntr_pmt_amt_amt + , rev_cntr_tot_chrg_amt + , rev_cntr_ncvrd_chrg_amt + , rev_cntr_stus_ind_cd + , rev_cntr_pricng_ind_cd + , rev_cntr_rndrng_physn_upin + , rev_cntr_rndrng_physn_npi + , rev_cntr_rndrng_physn_spclty_cd + , rev_cntr_ddctbl_coinsrnc_cd + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , rc_ptnt_add_on_pymt_amt + , file_name + , ingest_datetime +from {{ source('medicare_lds','outpatient_revenue_center') }} \ No newline at end of file diff --git a/models/staging/stg_snf_base_claim.sql b/models/staging/stg_snf_base_claim.sql new file mode 100644 index 0000000..1b1bfdc --- /dev/null +++ b/models/staging/stg_snf_base_claim.sql @@ -0,0 +1,166 @@ +select + desy_sort_key + , claim_no + , prvdr_num + , clm_thru_dt + , nch_near_line_rec_ident_cd + , nch_clm_type_cd + , claim_query_code + , clm_fac_type_cd + , clm_srvc_clsfctn_type_cd + , clm_freq_cd + , fi_num + , clm_mdcr_non_pmt_rsn_cd + , clm_pmt_amt + , nch_prmry_pyr_clm_pd_amt + , nch_prmry_pyr_cd + , fi_clm_actn_cd + , prvdr_state_cd + , org_npi_num + , at_physn_upin + , at_physn_npi + , at_physn_spclty_cd + , op_physn_upin + , op_physn_npi + , op_physn_spclty_cd + , ot_physn_upin + , ot_physn_npi + , ot_physn_spclty_cd + , rndrng_physn_npi + , rndrng_physn_spclty_cd + , clm_mco_pd_sw + , ptnt_dschrg_stus_cd + , clm_pps_ind_cd + , clm_tot_chrg_amt + , clm_admsn_dt + , clm_ip_admsn_type_cd + , clm_src_ip_admsn_cd + , nch_ptnt_status_ind_cd + , nch_bene_ip_ddctbl_amt + , nch_bene_pta_coinsrnc_lblty_am + , nch_bene_blood_ddctbl_lblty_am + , nch_ip_ncvrd_chrg_amt + , clm_pps_cptl_fsp_amt + , clm_pps_cptl_outlier_amt + , clm_pps_cptl_dsprprtnt_shr_amt + , clm_pps_cptl_ime_amt + , clm_pps_cptl_excptn_amt + , clm_pps_old_cptl_hld_hrmls_amt + , clm_utlztn_day_cnt + , bene_tot_coinsrnc_days_cnt + , clm_non_utlztn_days_cnt + , nch_blood_pnts_frnshd_qty + , nch_qlfyd_stay_thru_dt + , nch_vrfd_ncvrd_stay_from_dt + , nch_vrfd_ncvrd_stay_thru_dt + , nch_bene_mdcr_bnfts_exhtd_dt_i + , nch_bene_dschrg_dt + , clm_drg_cd + , admtg_dgns_cd + , prncpal_dgns_cd + , icd_dgns_cd1 + , icd_dgns_cd2 + , icd_dgns_cd3 + , icd_dgns_cd4 + , icd_dgns_cd5 + , icd_dgns_cd6 + , icd_dgns_cd7 + , icd_dgns_cd8 + , icd_dgns_cd9 + , icd_dgns_cd10 + , icd_dgns_cd11 + , icd_dgns_cd12 + , icd_dgns_cd13 + , icd_dgns_cd14 + , icd_dgns_cd15 + , icd_dgns_cd16 + , icd_dgns_cd17 + , icd_dgns_cd18 + , icd_dgns_cd19 + , icd_dgns_cd20 + , icd_dgns_cd21 + , icd_dgns_cd22 + , icd_dgns_cd23 + , icd_dgns_cd24 + , icd_dgns_cd25 + , fst_dgns_e_cd + , icd_dgns_e_cd1 + , icd_dgns_e_cd2 + , icd_dgns_e_cd3 + , icd_dgns_e_cd4 + , icd_dgns_e_cd5 + , icd_dgns_e_cd6 + , icd_dgns_e_cd7 + , icd_dgns_e_cd8 + , icd_dgns_e_cd9 + , icd_dgns_e_cd10 + , icd_dgns_e_cd11 + , icd_dgns_e_cd12 + , icd_prcdr_cd1 + , prcdr_dt1 + , icd_prcdr_cd2 + , prcdr_dt2 + , icd_prcdr_cd3 + , prcdr_dt3 + , icd_prcdr_cd4 + , prcdr_dt4 + , icd_prcdr_cd5 + , prcdr_dt5 + , icd_prcdr_cd6 + , prcdr_dt6 + , icd_prcdr_cd7 + , prcdr_dt7 + , icd_prcdr_cd8 + , prcdr_dt8 + , icd_prcdr_cd9 + , prcdr_dt9 + , icd_prcdr_cd10 + , prcdr_dt10 + , icd_prcdr_cd11 + , prcdr_dt11 + , icd_prcdr_cd12 + , prcdr_dt12 + , icd_prcdr_cd13 + , prcdr_dt13 + , icd_prcdr_cd14 + , prcdr_dt14 + , icd_prcdr_cd15 + , prcdr_dt15 + , icd_prcdr_cd16 + , prcdr_dt16 + , icd_prcdr_cd17 + , prcdr_dt17 + , icd_prcdr_cd18 + , prcdr_dt18 + , icd_prcdr_cd19 + , prcdr_dt19 + , icd_prcdr_cd20 + , prcdr_dt20 + , icd_prcdr_cd21 + , prcdr_dt21 + , icd_prcdr_cd22 + , prcdr_dt22 + , icd_prcdr_cd23 + , prcdr_dt23 + , icd_prcdr_cd24 + , prcdr_dt24 + , icd_prcdr_cd25 + , prcdr_dt25 + , dob_dt + , gndr_cd + , bene_race_cd + , bene_cnty_cd + , bene_state_cd + , cwf_bene_mdcr_stus_cd + , clm_trtmt_authrztn_num + , clm_prcr_rtrn_cd + , nch_profnl_cmpnt_chrg_amt + , clm_next_gnrtn_aco_ind_cd1 + , clm_next_gnrtn_aco_ind_cd2 + , clm_next_gnrtn_aco_ind_cd3 + , clm_next_gnrtn_aco_ind_cd4 + , clm_next_gnrtn_aco_ind_cd5 + , aco_id_num + , file_name + , ingest_datetime +from {{ source('medicare_lds','snf_base_claim') }} \ No newline at end of file diff --git a/models/staging/stg_snf_revenue_center.sql b/models/staging/stg_snf_revenue_center.sql new file mode 100644 index 0000000..c5863e6 --- /dev/null +++ b/models/staging/stg_snf_revenue_center.sql @@ -0,0 +1,26 @@ +select + desy_sort_key + , claim_no + , clm_line_num + , clm_thru_dt + , nch_clm_type_cd + , rev_cntr + , hcpcs_cd + , hcpcs_1st_mdfr_cd + , hcpcs_2nd_mdfr_cd + , hcpcs_3rd_mdfr_cd + , rev_cntr_unit_cnt + , rev_cntr_rate_amt + , rev_cntr_tot_chrg_amt + , rev_cntr_ncvrd_chrg_amt + , rev_cntr_ddctbl_coinsrnc_cd + , rev_cntr_rndrng_physn_upin + , rev_cntr_rndrng_physn_npi + , rev_cntr_rndrng_physn_spclty_cd + , rev_cntr_ide_ndc_upc_num + , rev_cntr_prcng_ind_cd + , thrpy_cap_ind_cd1 + , thrpy_cap_ind_cd2 + , file_name + , ingest_datetime +from {{ source('medicare_lds','snf_revenue_center') }} \ No newline at end of file diff --git a/packages.yml b/packages.yml index 16d3734..182c310 100644 --- a/packages.yml +++ b/packages.yml @@ -2,4 +2,4 @@ packages: - package: dbt-labs/dbt_utils version: [">=0.9.2","<1.3.0"] - package: tuva-health/the_tuva_project - version: [">=0.7.0","<9.9.9"] + version: [">=0.10.0","<0.11.0"]