Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/dbt_v1.4.6_bigquery_build_full_refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ jobs:
- uses: actions/checkout@v2

- 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"}'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dbt_v1.4.6_redshift_build_full_refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ jobs:
- uses: actions/checkout@v2

- 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"}'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dbt_v1.4.6_snowflake_build_full_refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ jobs:
- uses: actions/checkout@v2

- 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"}'

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
target/
dbt_packages/
logs/
package-lock.yml
11 changes: 7 additions & 4 deletions macros/generate_schema_name.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
See https://docs.getdbt.com/docs/building-a-dbt-project/building-models/using-custom-schemas for the original macro.
#}

{% macro generate_schema_name(custom_schema_name, node) -%}

{{ custom_schema_name }}

{% macro default__generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if custom_schema_name is not none -%}
{{ custom_schema_name | trim }}
{%- else -%}
{{ default_schema }}
{%- endif -%}
{%- endmacro %}
28 changes: 17 additions & 11 deletions models/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ models:
description: Member eligibility at the month grain
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_tuva_claims{% else %}_tuva_claims{%- 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')}}_tuva_claims{% else %}_tuva_claims{%- 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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%}
materialized: table

### intermediate
- name: carrier_claim
description: Claim line details of carrier claims
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%}

- name: eligibility_unpivot
description: >
Expand All @@ -44,34 +44,40 @@ models:
of eligibility.
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- 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 -%}

- name: outpatient_claim
description: Claim line details of outpatient claims
config:
schema: |
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}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')}}_tuva_claims{% else %}_tuva_claims{%- endif -%}
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%}
16 changes: 12 additions & 4 deletions models/final/eligibility.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with eligibility_unpivot as (

medicare_state_fips as (

select * from {{ ref('terminology__ssa_fips_state') }}
select * from {{ ref('reference_data__ssa_fips_state') }}

),

Expand All @@ -29,8 +29,9 @@ add_row_num as (
order by enrollment_date
) as row_num
, case
when medicare_status in (null, '00')
and dual_status in (null, '00', '99', 'NA') then 1
when medicare_status in (null, '00') and dual_status in (null, '00', '99', 'NA') then 1
when hmo_status <> '0' then 1 -- MA coverage
when entitlement not in ('3','C') then 1 --Doesn't have both Part A and B
else 0
end as disenrolled_flag
from eligibility_unpivot
Expand Down Expand Up @@ -128,7 +129,8 @@ joined as (

select
cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as patient_id
, cast(NULL as {{ dbt.type_string() }} ) as member_id
, cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as member_id
, cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as subscriber_id
, case eligibility_unpivot.sex_code
when '0' then 'unknown'
when '1' then 'male'
Expand Down Expand Up @@ -159,12 +161,18 @@ joined as (
, cast(eligibility_unpivot.medicare_status as {{ dbt.type_string() }} ) as medicare_status_code
, cast(NULL as {{ dbt.type_string() }} ) as first_name
, cast(NULL as {{ dbt.type_string() }} ) as last_name
, cast(NULL as {{ dbt.type_string() }} ) as social_security_number
, 'self' as subscriber_relation
, cast(NULL as {{ dbt.type_string() }} ) as address
, cast(NULL as {{ dbt.type_string() }} ) as city
, cast(medicare_state_fips.ssa_fips_state_name as {{ dbt.type_string() }} ) as state
, 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


from enrollment_span
left join eligibility_unpivot
on enrollment_span.desy_sort_key = eligibility_unpivot.desy_sort_key
Expand Down
47 changes: 34 additions & 13 deletions models/final/medical_claim.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
select * from {{ ref('carrier_claim')}}
union all
select * from {{ ref('dme_claim')}}
union all
select * from {{ ref('home_health_claim')}}
union all
select * from {{ ref('hospice_claim')}}
union all
select * from {{ ref('inpatient_claim')}}
union all
select * from {{ ref('outpatient_claim')}}
union all
select * from {{ ref('snf_claim')}}

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
)

-- 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
4 changes: 4 additions & 0 deletions models/final/pharmacy_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ select
,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
limit 0
5 changes: 5 additions & 0 deletions models/intermediate/_int_medical_claim.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ 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"]
) }}
21 changes: 17 additions & 4 deletions models/intermediate/carrier_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ 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 ID is not unique across claim types. Concatenating original claim ID, claim year, and claim type. */
cast(b.claim_no as {{ dbt.type_string() }} )
Expand All @@ -20,10 +28,10 @@ select
, cast(b.desy_sort_key as {{ dbt.type_string() }} ) as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare' as {{ dbt.type_string() }} ) as plan
, date(NULL) as claim_start_date
, {{try_to_cast_date('b.clm_thru_dt', 'YYYYMMDD')}} as claim_end_date
, date(NULL) as claim_line_start_date
, {{ try_to_cast_date('l.clm_thru_dt', 'YYYYMMDD') }} as claim_line_end_date
, {{ try_to_cast_date('c.claim_start_date', 'YYYYMMDD') }} as claim_start_date
, {{ try_to_cast_date('b.clm_thru_dt', 'YYYYMMDD') }} as claim_end_date
, {{ try_to_cast_date('l.line_last_expns_dt', 'YYYYMMDD') }} as claim_line_start_date
, {{ try_to_cast_date('l.line_last_expns_dt', 'YYYYMMDD') }} as claim_line_end_date
, date(NULL) as admission_date
, date(NULL) as discharge_date
, cast(NULL as {{ dbt.type_string() }} ) as admit_source_code
Expand Down Expand Up @@ -164,6 +172,11 @@ select
, 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

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
18 changes: 15 additions & 3 deletions models/intermediate/dme_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ with dme_base_claim as (
/** 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 ID is not unique across claim types. Concatenating original claim ID, claim year, and claim type. */
cast(b.claim_no as {{ dbt.type_string() }} )
Expand All @@ -19,10 +27,10 @@ select
, cast(b.desy_sort_key as {{ dbt.type_string() }} ) as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare' as {{ dbt.type_string() }} ) as plan
, date(NULL) as claim_start_date
, {{ try_to_cast_date('c.claim_start_date', 'YYYYMMDD') }} as claim_start_date
, {{ try_to_cast_date('b.clm_thru_dt', 'YYYYMMDD') }} as claim_end_date
, date(NULL) as claim_line_start_date
, {{ try_to_cast_date('l.clm_thru_dt', 'YYYYMMDD') }} as claim_line_end_date
, {{ try_to_cast_date('l.line_last_expns_dt', 'YYYYMMDD') }} as claim_line_start_date
, {{ try_to_cast_date('l.line_last_expns_dt', 'YYYYMMDD') }} as claim_line_end_date
, date(NULL) as admission_date
, date(NULL) as discharge_date
, cast(NULL as {{ dbt.type_string() }} ) as admit_source_code
Expand Down Expand Up @@ -163,6 +171,10 @@ select
, date(NULL) as procedure_date_24
, date(NULL) as procedure_date_25
, 'medicare_lds' as data_source
, 1 as in_network_flag
, 'dme_claim' as file_name
, cast(NULL as date ) 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
Loading
Loading