From 5b26814d4873af1eff70e90495a4ad68ef0af8aa Mon Sep 17 00:00:00 2001 From: J'aime Tue Date: Fri, 20 Dec 2024 01:12:24 -0700 Subject: [PATCH] creation of data viz tables --- .../medical_economics__dim_apr_drg.sql | 11 + .../medical_economics__dim_calendar.sql | 22 ++ ...medical_economics__dim_condition_group.sql | 28 ++ .../medical_economics__dim_hcpcs.sql | 11 + .../medical_economics__dim_ms_drg.sql | 11 + .../medical_economics__dim_patient.sql | 27 ++ .../medical_economics__dim_provider.sql | 24 ++ ...edical_economics__dim_service_category.sql | 28 ++ ...ical_economics__dim_specialty_provider.sql | 21 ++ .../medical_economics__fact_medical_claim.sql | 27 ++ .../medical_economics__fact_member_months.sql | 8 + .../medical_economics/medical_economics.yml | 332 ++++++++++++++++++ 12 files changed, 550 insertions(+) create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_apr_drg.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_calendar.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_condition_group.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_hcpcs.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_ms_drg.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_patient.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_provider.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_service_category.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__dim_specialty_provider.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__fact_medical_claim.sql create mode 100644 models/medical_economics/data_visualization/medical_economics__fact_member_months.sql diff --git a/models/medical_economics/data_visualization/medical_economics__dim_apr_drg.sql b/models/medical_economics/data_visualization/medical_economics__dim_apr_drg.sql new file mode 100644 index 00000000..ce949ce0 --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_apr_drg.sql @@ -0,0 +1,11 @@ +with apr_drg as ( + + select + apr_drg_code + , apr_drg_description + from {{ ref('terminology__apr_drg') }} + +) + +select * +from apr_drg \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_calendar.sql b/models/medical_economics/data_visualization/medical_economics__dim_calendar.sql new file mode 100644 index 00000000..c737fa2f --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_calendar.sql @@ -0,0 +1,22 @@ +with calendar as ( + + select + full_date + , year + , month + , day + , month_name + , day_of_week_number + , day_of_week_name + , week_of_year + , day_of_year + , year_month + , first_day_of_month + , last_day_of_month + , year_month_int + from {{ ref('reference_data__calendar') }} + +) + +select * +from calendar \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_condition_group.sql b/models/medical_economics/data_visualization/medical_economics__dim_condition_group.sql new file mode 100644 index 00000000..08649e94 --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_condition_group.sql @@ -0,0 +1,28 @@ +with condition_group_distinct as ( + + select distinct + condition_group_1 + , condition_group_2 + , condition_group_3 + from {{ ref('medical_economics__specialty_condition_grouper_medical_claim') }} + +), + +condition_group_final as ( + + select + condition_group_1 + , condition_group_2 + , condition_group_3 + , row_number() over ( + order by + condition_group_1 + , condition_group_2 + , condition_group_3 + ) as condition_group_id + from condition_group_distinct + +) + +select * +from condition_group_final \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_hcpcs.sql b/models/medical_economics/data_visualization/medical_economics__dim_hcpcs.sql new file mode 100644 index 00000000..9e5b4369 --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_hcpcs.sql @@ -0,0 +1,11 @@ +with hcpcs as ( + + select + hcpcs_cd as hcpcs_code + , rbcs_family_desc as hcpcs_description + from {{ ref('terminology__hcpcs_to_rbcs') }} + +) + +select * +from hcpcs \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_ms_drg.sql b/models/medical_economics/data_visualization/medical_economics__dim_ms_drg.sql new file mode 100644 index 00000000..e8fae2df --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_ms_drg.sql @@ -0,0 +1,11 @@ +with ms_drg as ( + + select + ms_drg_code + , ms_drg_description + from {{ ref('terminology__ms_drg') }} + +) + +select * +from ms_drg \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_patient.sql b/models/medical_economics/data_visualization/medical_economics__dim_patient.sql new file mode 100644 index 00000000..8a4152b7 --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_patient.sql @@ -0,0 +1,27 @@ +with patient as ( + + select + person_id + , first_name + , last_name + , sex + , race + , birth_date + , death_date + , address + , city + , state + , zip_code + , county + , latitude + , longitude + , phone + , age + , age_group + , data_source + from {{ ref('core__patient') }} + +) + +select * +from patient \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_provider.sql b/models/medical_economics/data_visualization/medical_economics__dim_provider.sql new file mode 100644 index 00000000..da50517c --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_provider.sql @@ -0,0 +1,24 @@ +with provider as ( + + select + npi + , entity_type_description + , primary_specialty_description + , provider_first_name + , provider_last_name + , provider_organization_name + , parent_organization_name + , practice_address_line_1 + , practice_address_line_2 + , practice_city + , practice_zip_code + , mailing_telephone_number + , location_telephone_number + , official_telephone_number + , last_updated + from {{ ref('terminology__provider') }} + +) + +select * +from provider \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_service_category.sql b/models/medical_economics/data_visualization/medical_economics__dim_service_category.sql new file mode 100644 index 00000000..426eaafe --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_service_category.sql @@ -0,0 +1,28 @@ +with service_category_distinct as ( + + select distinct + service_category_1 + , service_category_2 + , service_category_3 + from {{ ref('medical_economics__specialty_condition_grouper_medical_claim') }} + +), + +service_category_final as ( + + select + service_category_1 + , service_category_2 + , service_category_3 + , row_number() over ( + order by + service_category_1 + , service_category_2 + , service_category_3 + ) as service_category_id + from service_category_distinct + +) + +select * +from service_category_final \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__dim_specialty_provider.sql b/models/medical_economics/data_visualization/medical_economics__dim_specialty_provider.sql new file mode 100644 index 00000000..56c09d4d --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__dim_specialty_provider.sql @@ -0,0 +1,21 @@ +with provider_distinct as ( + + select distinct + primary_specialty_description as specialty_provider + from {{ ref('terminology__provider') }} + +), + +provider as ( + + select + specialty_provider + , row_number() over ( + order by specialty_provider + ) as specialty_provider_id + from provider_distinct + +) + +select * +from provider \ No newline at end of file diff --git a/models/medical_economics/data_visualization/medical_economics__fact_medical_claim.sql b/models/medical_economics/data_visualization/medical_economics__fact_medical_claim.sql new file mode 100644 index 00000000..d0b702c8 --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__fact_medical_claim.sql @@ -0,0 +1,27 @@ +select + aa.person_id + , aa.claim_id + , aa.payer + , aa.claim_start_date + , aa.claim_end_date + , aa.claim_line_number + , cc.service_category_id + , aa.ms_drg_code + , aa.apr_drg_code + , aa.hcpcs_code + , aa.rendering_id + , aa.paid_amount + , aa.allowed_amount + , bb.condition_group_id + , dd.specialty_provider_id +from {{ ref('medical_economics__specialty_condition_grouper_medical_claim') }} aa +left join {{ ref('medical_economics__dim_condition_group') }} bb + on aa.condition_group_1 = bb.condition_group_1 + on aa.condition_group_2 = bb.condition_group_2 + on aa.condition_group_3 = bb.condition_group_3 +left join {{ ref('medical_economics__dim_service_category') }} cc + on aa.service_category_1 = cc.service_category_1 + on aa.service_category_2 = cc.service_category_2 + on aa.service_category_3 = cc.service_category_3 +left join {{ ref('medical_economics__dim_service_category') }} dd + on aa.specialty_provider = dd.specialty_provider diff --git a/models/medical_economics/data_visualization/medical_economics__fact_member_months.sql b/models/medical_economics/data_visualization/medical_economics__fact_member_months.sql new file mode 100644 index 00000000..de46379b --- /dev/null +++ b/models/medical_economics/data_visualization/medical_economics__fact_member_months.sql @@ -0,0 +1,8 @@ +select + person_id + , payer + , year_month + , member_month + , payment_risk_score + , risk_adjusted_member_months +from {{ ref('medical_economics__risk_adjusted_member_months') }} diff --git a/models/medical_economics/medical_economics.yml b/models/medical_economics/medical_economics.yml index 40decc85..846d9a87 100644 --- a/models/medical_economics/medical_economics.yml +++ b/models/medical_economics/medical_economics.yml @@ -2,6 +2,338 @@ version: 2 models: +## data_visualization + - name: medical_economics__dim_apr_drg + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_apr_drg + tags: + - apr_drg + materialized: table + description: > + dim apr drg + columns: + - name: apr_drg_code + description: apr drg code + - name: apr_drg_description + description: apr drg description + + - name: medical_economics__dim_calendar + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_calendar + tags: + - calendar + materialized: table + description: > + dim calendar + columns: + - name: full_date + description: full date + - name: year + description: year + - name: month + description: month + - name: day + description: day + - name: month_name + description: month_name + - name: day_of_week_number + description: day_of_week_number + - name: day_of_week_name + description: day_of_week_name + - name: week_of_year + description: week_of_year + - name: day_of_year + description: day_of_year + - name: year_month + description: year_month + - name: first_day_of_month + description: first_day_of_month + - name: last_day_of_month + description: last_day_of_month + - name: year_month_int + description: year_month_int + + - name: medical_economics__dim_condition_group + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_condition_group + tags: + - condition_group + materialized: table + description: > + condition grouper reference table + columns: + - name: condition_group_1 + description: primary condition group + - name: condition_group_2 + description: secondary condition group + - name: condition_group_3 + description: tertiary condition group + - name: condition_group_id + description: condition group id + + - name: medical_economics__dim_hcpcs + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_hcpcs + tags: + - hcpcs + materialized: table + description: > + hcpcs reference table + columns: + - name: hcpcs_code + description: hcpcs code + - name: hcpcs_description + description: hcpcs description + + - name: medical_economics__dim_ms_drg + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_ms_drg + tags: + - ms_drg + materialized: table + description: > + ms drg reference table + columns: + - name: ms_drg_code + description: ms drg code + - name: ms_drg_description + description: ms drg description + + - name: medical_economics__dim_patient + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_patient + tags: + - patient + materialized: table + description: > + patient reference table + columns: + - name: person_id + description: person id + - name: first_name + description: first name + - name: last_name + description: last name + - name: sex + description: sex + - name: race + description: race + - name: birth_date + description: birth date + - name: death_date + description: death date + - name: address + description: patient address + - name: city + description: patient city + - name: state + description: patient state + - name: zip_code + description: patient zip code + - name: county + description: patient county + - name: latitude + description: patient latitude + - name: longitude + description: patient longitude + - name: phone + description: patient phone + - name: age + description: age + - name: age_group + description: age group + + - name: medical_economics__dim_provider + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_provider + tags: + - provider + materialized: table + description: > + provider reference table + columns: + - name: npi + description: npi + - name: entity_type_description + description: individual or orgnaization + - name: primary_specialty_description + description: specialty description + - name: provider_first_name + description: first name + - name: provider_last_name + description: last name + - name: provider_organization_name + description: provider_organization_name + - name: parent_organization_name + description: parent_organization_name + - name: practice_address_line_1 + description: practice_address_line_1 + - name: practice_address_line_2 + description: practice_address_line_2 + - name: practice_city + description: practice_city + - name: practice_zip_code + description: practice_zip_code + - name: mailing_telephone_number + description: mailing_telephone_number + - name: location_telephone_number + description: location_telephone_number + - name: official_telephone_number + description: official_telephone_number + - name: last_updated + description: last updated in NPPES + + - name: medical_economics__dim_service_category + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: dim_service_category + tags: + - service_category + materialized: table + description: > + service category reference table + columns: + - name: service_category_1 + description: service_category_1 + - name: service_category_2 + description: service_category_2 + - name: service_category_3 + description: service_category_3 + - name: service_category_id + description: service_category_id + + - name: medical_economics__fact_medical_claim + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: fact_medical_claim + tags: + - medical_economics + materialized: table + description: > + fact medical claim table + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - claim_id + - claim_line_number + columns: + - name: person_id + description: Unique identifier for the patient. + - name: claim_id + description: Unique identifier for the claim. + - name: payer + description: Unique identifier for the payer. + - name: claim_start_date + description: claim start date + - name: claim_end_date + description: claim end date + - name: claim_line_number + description: Line number of the claim. + - name: service_category_id + description: service category id + - name: ms_drg_code + description: MS DRG code + - name: apr_drg_code + description: APR DRG code + - name: hcpcs_code + description: All hcpcs codes + - name: rendering_id + description: Rendering npi on claim + - name: paid_amount + description: Amount paid for the drug. + - name: allowed_amount + description: allowed amount for the drug + - name: condition_grouper_id + description: condition grouper id + - name: specialty_provider_id + description: specialty provider id + + - name: medical_economics__fact_member_months + config: + schema: | + {%- if var('tuva_schema_prefix', None) != None -%} + {{var('tuva_schema_prefix')}}_medical_economics + {%- else -%} + medical_economics + {%- endif -%} + alias: fact_member_months + tags: + - member_months + materialized: table + description: > + Member months table with risk adjustment added + columns: + - name: person_id + description: Unique identifier for each patient + - name: claim_id + description: Unique identifier for each pharmacy claim. + - name: payer + description: Unique identifier for the payer. + - name: year_month + description: year month of YYYYMM format + - name: member_months + description: Number of unqiue person_id and payer + - name: payment_risk_score + description: > + The normalized risk score multiplied by the MA coding pattern + adjustment factor for the corresponding HCC model version + and payment year's rate announcement from CMS. + - name: risk_adjusted_member_months + description: > + Payment risk score multiplied by member_months. + ## Final - name: medical_economics__specialty_condition_grouper_pharmacy_claim config: