Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mart review plan updates #705

Merged
merged 9 commits into from
Feb 4, 2025
4 changes: 4 additions & 0 deletions dbt_doc_blocks/column_descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1004,4 +1004,8 @@ Unique year-month of in the dataset computed from eligibility.

{% docs zip_code %}
The zip code of the record (e.g., facility location, patient, etc).
{% enddocs %}

{% docs member_month_key %}
The unique combination of person_id, year_month, payer, plan, and data source.
{% enddocs %}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ with claim_dates as(
, member_id
, payer
, {{ quote_column('plan') }}
, data_source
, coalesce(claim_line_start_date, claim_start_date, admission_date) as inferred_claim_start_date
, coalesce(claim_line_end_date, claim_end_date, discharge_date) as inferred_claim_end_date
, case
when claim_line_start_date is not null then 'claim_line_start_date'
when claim_line_start_date is null and claim_start_date is not null then 'claim_start_date'
when claim_line_start_date is null and claim_start_date is null and admission_date is not null then 'admission_date'
end as inferred_claim_start_column_used
, case
when claim_line_end_date is not null then 'claim_line_end_date'
when claim_line_end_date is null and claim_end_date is not null then 'claim_end_date'
when claim_line_end_date is null and claim_end_date is null and discharge_date is not null then 'discharge_date'
end as inferred_claim_end_column_used
from {{ ref('normalized_input__medical_claim') }}
)

Expand All @@ -36,11 +31,9 @@ with claim_dates as(
, member_id
, payer
, {{ quote_column('plan') }}
, data_source
, inferred_claim_start_date
, inferred_claim_end_date
, inferred_claim_start_column_used
, inferred_claim_end_column_used

, {{ dbt.concat([
date_part('year', 'inferred_claim_start_date'),
dbt.right(
Expand All @@ -51,18 +44,6 @@ with claim_dates as(
2
)
]) }} as inferred_claim_start_year_month

, {{ dbt.concat([
date_part('year', 'inferred_claim_end_date'),
dbt.right(
dbt.concat([
"'0'",
date_part('month', 'inferred_claim_end_date'),
]),
2
)
]) }} as inferred_claim_end_year_month

from claim_dates

)
Expand All @@ -74,16 +55,15 @@ select distinct
, claim.member_id
, claim.payer
, claim.{{ quote_column('plan') }}
, claim.data_source
, mm.member_month_key
, claim.inferred_claim_start_year_month
, claim.inferred_claim_end_year_month
, claim.inferred_claim_start_column_used
, claim.inferred_claim_end_column_used
, cast('{{ var('tuva_last_run')}}' as {{ dbt.type_timestamp() }} ) as tuva_last_run
from {{ ref('core__member_months')}} mm
inner join claim_year_month claim
on mm.person_id = claim.person_id
and mm.member_id = claim.member_id
and mm.payer = claim.payer
and mm.{{ quote_column('plan') }} = claim.{{ quote_column('plan') }}
and mm.year_month >= claim.inferred_claim_start_year_month
and mm.year_month <= claim.inferred_claim_end_year_month
and mm.year_month = claim.inferred_claim_start_year_month
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{ config(
enabled = var('claims_preprocessing_enabled',var('claims_enabled',var('tuva_marts_enabled',False)))
| as_bool
)
}}


with claim_dates as(
select
claim_id
, claim_line_number
, person_id
, member_id
, payer
, {{ quote_column('plan') }}
, data_source
, {{ dbt.concat([
date_part('year', 'paid_date'),
dbt.right(
dbt.concat([
"'0'",
date_part('month', 'paid_date'),
]),
2
)
]) }} as paid_year_month
from {{ ref('normalized_input__pharmacy_claim') }}
)

select distinct
claim.claim_id
, claim.claim_line_number
, claim.person_id
, claim.member_id
, claim.payer
, claim.{{ quote_column('plan') }}
, claim.data_source
, mm.member_month_key
, claim.paid_year_month
, cast('{{ var('tuva_last_run')}}' as {{ dbt.type_timestamp() }} ) as tuva_last_run
from {{ ref('core__member_months')}} mm
inner join claim_dates claim
on mm.person_id = claim.person_id
and mm.member_id = claim.member_id
and mm.payer = claim.payer
and mm.{{ quote_column('plan') }} = claim.{{ quote_column('plan') }}
and mm.year_month = claim.paid_year_month
33 changes: 33 additions & 0 deletions models/claims_preprocessing/claims_preprocessing_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ models:
description: Name of the payer.
- name: plan
description: Name of the plan.
- name: data_source
description: '{{ doc("data_source") }}'
- name: member_month_key
description: '{{ doc("member_month_key") }}'
- name: inferred_claim_start_year_month
description: |
The claim start date year and month. If claim line start date is missing then the following column will be used,
Expand All @@ -39,6 +43,35 @@ models:
- name: inferred_claim_end_column_used
description: The name of the column used to populated inferred_claim_start_column_used.

- name: claims_enrollment__flag_rx_claims_with_enrollment
description: This table contains pharmacy claims with matching enrollment
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_claims_preprocessing
{%- else -%}claims_preprocessing{%- endif -%}
alias: flag_rx_claims_with_enrollment
tags:
- claims_preprocessing
materialized: table
columns:
- name: claim_id
description: Unique identifier for each claim.
- name: claim_line_number
description: >
Indicates the line number for the particular line of the claim.
- name: person_id
description: Unique identifier for each patient in the dataset.
- name: payer
description: Name of the payer.
- name: plan
description: Name of the plan.
- name: data_source
description: '{{ doc("data_source") }}'
- name: member_month_key
description: '{{ doc("member_month_key") }}'
- name: paid_year_month
description: the year and month of the date the pharmacy claim was paid.



### Normalized Claim Input Layer
Expand Down
10 changes: 10 additions & 0 deletions models/core/core_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ models:
description: '{{ doc("in_network_flag") }}'
- name: enrollment_flag
description: '{{ doc("enrollment_flag") }}'
- name: member_month_key
description: '{{ doc("member_month_key") }}'
- name: data_source
description: '{{ doc("data_source") }}'
- name: tuva_last_run
Expand Down Expand Up @@ -711,6 +713,10 @@ models:
- core
materialized: table
columns:
- name: member_month_key
description: '{{ doc("member_month_key") }}'
tests:
- not_null
- name: person_id
description: '{{ doc("person_id") }}'
tests:
Expand Down Expand Up @@ -990,6 +996,10 @@ models:
description: '{{ doc("deductible_amount") }}'
- name: in_network_flag
description: '{{ doc("in_network_flag") }}'
- name: enrollment_flag
description: '{{ doc("enrollment_flag") }}'
- name: member_month_key
description: '{{ doc("member_month_key") }}'
- name: data_source
description: '{{ doc("data_source") }}'
- name: tuva_last_run
Expand Down
31 changes: 29 additions & 2 deletions models/core/final/core__member_months.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ inner join month_start_and_end_dates b
and a.enrollment_end_date >= b.month_start_date
),


add_attribution_fields as (
select
a.person_id
Expand All @@ -56,6 +55,34 @@ and a.year_month = b.year_month
and a.payer = b.payer
and a.{{ quote_column('plan') }} = b.{{ quote_column('plan') }}
and a.data_source = b.data_source
),

final_with_sk as (
select
dense_rank() over (
order by
person_id
, year_month
, payer
, {{ quote_column('plan') }}
, data_source
) as member_month_key
, person_id
, member_id
, year_month
, payer
, {{ quote_column('plan') }}
, data_source
, tuva_last_run
, payer_attributed_provider
, payer_attributed_provider_practice
, payer_attributed_provider_organization
, payer_attributed_provider_lob
, custom_attributed_provider
, custom_attributed_provider_practice
, custom_attributed_provider_organization
, custom_attributed_provider_lob
from add_attribution_fields
)

select * from add_attribution_fields
select * from final_with_sk
7 changes: 6 additions & 1 deletion models/core/staging/core__stg_claims_medical_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ select
when enroll.claim_id is not null then 1
else 0
end as int) as enrollment_flag
, enroll.member_month_key
, cast(med.data_source as {{ dbt.type_string() }} ) as data_source
, cast('{{ var('tuva_last_run')}}' as {{ dbt.type_timestamp() }} ) as tuva_last_run
from {{ ref('normalized_input__medical_claim') }} as med
Expand All @@ -116,4 +117,8 @@ inner join all_encounters as x
and med.claim_line_number = x.claim_line_number
left join {{ ref('claims_enrollment__flag_claims_with_enrollment') }} as enroll
on med.claim_id = enroll.claim_id
and med.claim_line_number = enroll.claim_line_number
and med.claim_line_number = enroll.claim_line_number
and med.person_id = enroll.person_id
and med.payer = enroll.payer
and med.{{ quote_column('plan') }} = enroll.{{ quote_column('plan') }}
and med.data_source = enroll.data_source
71 changes: 42 additions & 29 deletions models/core/staging/core__stg_claims_pharmacy_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,49 @@

select
{{ dbt.concat([
"cast(claim_id as " ~ dbt.type_string() ~ ")",
"cast(pharm.claim_id as " ~ dbt.type_string() ~ ")",
"'-'",
"cast(claim_line_number as " ~ dbt.type_string() ~ ")",
"cast(pharm.claim_line_number as " ~ dbt.type_string() ~ ")",
"'-'",
"cast(data_source as " ~ dbt.type_string() ~ ")"
"cast(pharm.data_source as " ~ dbt.type_string() ~ ")"
]) }} as pharmacy_claim_id
, cast(claim_id as {{ dbt.type_string() }} ) as claim_id
, cast(claim_line_number as integer ) as claim_line_number
, cast(person_id as {{ dbt.type_string() }} ) as person_id
, cast(member_id as {{ dbt.type_string() }} ) as member_id
, cast(payer as {{ dbt.type_string() }} ) as payer
, {{ quote_column('plan') }}
, cast(prescribing_provider_id as {{ dbt.type_string() }} ) as prescribing_provider_id
, cast(prescribing_provider_name as {{ dbt.type_string() }} ) as prescribing_provider_name
, cast(dispensing_provider_id as {{ dbt.type_string() }} ) as dispensing_provider_id
, cast(dispensing_provider_name as {{ dbt.type_string() }} ) as dispensing_provider_name
, cast(dispensing_date as date ) as dispensing_date
, cast(ndc_code as {{ dbt.type_string() }} ) as ndc_code
, cast(ndc_description as {{ dbt.type_string() }} ) as ndc_description
, cast(quantity as integer ) as quantity
, cast(days_supply as integer ) as days_supply
, cast(refills as integer ) as refills
, cast(paid_date as date ) as paid_date
, cast(paid_amount as {{ dbt.type_numeric() }}) as paid_amount
, cast(allowed_amount as {{ dbt.type_numeric() }} ) as allowed_amount
, cast(charge_amount as {{ dbt.type_numeric() }} ) as charge_amount
, cast(coinsurance_amount as {{ dbt.type_numeric() }} ) as coinsurance_amount
, cast(copayment_amount as {{ dbt.type_numeric() }} ) as copayment_amount
, cast(deductible_amount as {{ dbt.type_numeric() }} ) as deductible_amount
, cast(in_network_flag as int ) as in_network_flag
, cast(data_source as {{ dbt.type_string() }} ) as data_source
, cast(pharm.claim_id as {{ dbt.type_string() }} ) as claim_id
, cast(pharm.claim_line_number as integer ) as claim_line_number
, cast(pharm.person_id as {{ dbt.type_string() }} ) as person_id
, cast(pharm.member_id as {{ dbt.type_string() }} ) as member_id
, cast(pharm.payer as {{ dbt.type_string() }} ) as payer
, pharm.{{ quote_column('plan') }}
, cast(pharm.prescribing_provider_id as {{ dbt.type_string() }} ) as prescribing_provider_id
, cast(pharm.prescribing_provider_name as {{ dbt.type_string() }} ) as prescribing_provider_name
, cast(pharm.dispensing_provider_id as {{ dbt.type_string() }} ) as dispensing_provider_id
, cast(pharm.dispensing_provider_name as {{ dbt.type_string() }} ) as dispensing_provider_name
, cast(pharm.dispensing_date as date ) as dispensing_date
, cast(pharm.ndc_code as {{ dbt.type_string() }} ) as ndc_code
, cast(pharm.ndc_description as {{ dbt.type_string() }} ) as ndc_description
, cast(pharm.quantity as integer ) as quantity
, cast(pharm.days_supply as integer ) as days_supply
, cast(pharm.refills as integer ) as refills
, cast(pharm.paid_date as date ) as paid_date
, cast(pharm.paid_amount as {{ dbt.type_numeric() }}) as paid_amount
, cast(pharm.allowed_amount as {{ dbt.type_numeric() }} ) as allowed_amount
, cast(pharm.charge_amount as {{ dbt.type_numeric() }} ) as charge_amount
, cast(pharm.coinsurance_amount as {{ dbt.type_numeric() }} ) as coinsurance_amount
, cast(pharm.copayment_amount as {{ dbt.type_numeric() }} ) as copayment_amount
, cast(pharm.deductible_amount as {{ dbt.type_numeric() }} ) as deductible_amount
, cast(pharm.in_network_flag as int ) as in_network_flag
, cast(
case
when enroll.claim_id is not null then 1
else 0
end as int) as enrollment_flag
, enroll.member_month_key
, cast(pharm.data_source as {{ dbt.type_string() }} ) as data_source
, '{{ var('tuva_last_run')}}' as tuva_last_run
from {{ ref('normalized_input__pharmacy_claim') }} pharm
from {{ ref('normalized_input__pharmacy_claim') }} pharm
left join {{ ref('claims_enrollment__flag_rx_claims_with_enrollment') }} as enroll
on pharm.claim_id = enroll.claim_id
and pharm.claim_line_number = enroll.claim_line_number
and pharm.person_id = enroll.person_id
and pharm.payer = enroll.payer
and pharm.{{ quote_column('plan') }} = enroll.{{ quote_column('plan') }}
and pharm.data_source = enroll.data_source
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ with enrollment_stage as(
SELECT
mc.data_source,
mc.year_month,
mc.payer,
mc.{{ quote_column('plan') }},
SUM(CASE WHEN mm.person_id IS NOT NULL THEN 1 ELSE 0 END) AS claims_with_enrollment,
COUNT(*) AS claims
FROM {{ ref('mart_review__stg_medical_claim') }} mc
LEFT JOIN {{ ref('core__member_months')}} mm
ON mc.person_id = mm.person_id
AND mc.data_source = mm.data_source
AND mc.year_month = mm.year_month
ON mc.member_month_key = mm.member_month_key
GROUP BY mc.data_source
, mc.year_month
, mc.payer
, mc.{{ quote_column('plan') }}
)

select
data_source
, year_month
, payer
, {{ quote_column('plan') }}
, claims_with_enrollment
, claims
, cast(claims_with_enrollment / claims as {{ dbt.type_numeric()}} ) AS percentage_claims_with_enrollment
Expand Down
Loading