Skip to content

Commit

Permalink
Add cross-database support for Fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-tuva committed Nov 14, 2024
1 parent 2d90aed commit 66aa255
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions models/final/eligibility.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ with demographics as (
end as integer) as death_flag
, cast(enrollment.enrollment_start_date as date) as enrollment_start_date
, case
when enrollment.enrollment_end_date >= current_date then {{ last_day('current_date', 'month') }}
when enrollment.enrollment_end_date is null then {{ last_day('current_date', 'month') }}
when enrollment.enrollment_end_date >= {{ dbt.current_timestamp() }} then {{ last_day(dbt.current_timestamp(), 'month') }}
when enrollment.enrollment_end_date is null then {{ last_day(dbt.current_timestamp(), 'month') }}
else cast(enrollment.enrollment_end_date as date)
end as enrollment_end_date
, 'medicare' as payer
, 'medicare' as payer_type
, 'medicare' as plan
, 'medicare' as {{ the_tuva_project.quote_column('plan') }}
, cast(demographics.bene_orgnl_entlmt_rsn_cd as {{ dbt.type_string() }} ) as original_reason_entitlement_code
, cast(demographics.bene_dual_stus_cd as {{ dbt.type_string() }} ) as dual_status_code
, cast(demographics.bene_mdcr_stus_cd as {{ dbt.type_string() }} ) as medicare_status_code
Expand Down Expand Up @@ -149,7 +149,7 @@ select
, enrollment_end_date
, payer
, payer_type
, plan
, {{ the_tuva_project.quote_column('plan') }}
, original_reason_entitlement_code
, dual_status_code
, medicare_status_code
Expand Down
2 changes: 1 addition & 1 deletion models/final/medical_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, claim_start_date
, claim_end_date
, claim_line_start_date
Expand Down
6 changes: 3 additions & 3 deletions models/final/pharmacy_claim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ with deduped_claims as (
, cast(patient_id as {{ dbt.type_string() }}) as patient_id
, cast(member_id as {{ dbt.type_string() }}) as member_id
, cast(payer as {{ dbt.type_string() }}) as payer
, cast(plan as {{ dbt.type_string() }}) as plan
, cast({{ the_tuva_project.quote_column('plan') }} as {{ dbt.type_string() }}) as {{ the_tuva_project.quote_column('plan') }}
, cast(prescribing_provider_npi as {{ dbt.type_string() }}) as prescribing_provider_npi
, cast(dispensing_provider_npi as {{ dbt.type_string() }}) as dispensing_provider_npi
, cast(dispensing_date as date) as dispensing_date
Expand All @@ -30,7 +30,7 @@ with deduped_claims as (
, cast(in_network_flag as integer) as in_network_flag
, cast(data_source as {{ dbt.type_string() }}) as data_source
, cast(file_name as {{ dbt.type_string() }}) as file_name
, cast(ingest_datetime as datetime) as ingest_datetime
, cast(ingest_datetime as {{ dbt.type_timestamp() }}) as ingest_datetime
from deduped_claims

)
Expand All @@ -41,7 +41,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, prescribing_provider_npi
, dispensing_provider_npi
, dispensing_date
Expand Down
8 changes: 4 additions & 4 deletions models/intermediate/int_dme_claim_deduped.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ with sort_adjusted_claims as (
, current_bene_mbi_id as patient_id
, current_bene_mbi_id as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare'as {{ dbt.type_string() }} ) as plan
, cast('medicare'as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, case
when clm_from_dt in ('1000-01-01', '9999-12-31') then null
else clm_from_dt
Expand Down Expand Up @@ -282,7 +282,7 @@ with sort_adjusted_claims as (
, cast(patient_id as {{ dbt.type_string() }} ) as patient_id
, cast(member_id as {{ dbt.type_string() }} ) as member_id
, cast(payer as {{ dbt.type_string() }} ) as payer
, cast(plan as {{ dbt.type_string() }} ) as plan
, cast({{ the_tuva_project.quote_column('plan') }} as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, {{ try_to_cast_date('claim_start_date', 'YYYY-MM-DD') }} as claim_start_date
, {{ try_to_cast_date('claim_end_date', 'YYYY-MM-DD') }} as claim_end_date
, {{ try_to_cast_date('claim_line_start_date', 'YYYY-MM-DD') }} as claim_line_start_date
Expand Down Expand Up @@ -422,7 +422,7 @@ with sort_adjusted_claims as (
, cast(in_network_flag as integer) as in_network_flag
, cast(data_source as {{ dbt.type_string() }} ) as data_source
, cast(file_name as {{ dbt.type_string() }} ) as file_name
, cast(ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime
, cast(ingest_datetime as {{ dbt.type_string() }} ) as ingest_datetime
from mapping

)
Expand All @@ -434,7 +434,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, claim_start_date
, claim_end_date
, claim_line_start_date
Expand Down
10 changes: 5 additions & 5 deletions models/intermediate/int_institutional_claim_deduped.sql
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ with sort_adjusted_claims as (
, current_bene_mbi_id as patient_id
, current_bene_mbi_id as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare'as {{ dbt.type_string() }} ) as plan
, cast('medicare'as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, case
when clm_from_dt in ('1000-01-01', '9999-12-31') then null
else clm_from_dt
Expand All @@ -374,7 +374,7 @@ with sort_adjusted_claims as (
end as discharge_date
, clm_admsn_src_cd as admit_source_code
, clm_admsn_type_cd as admit_type_code
, lpad(bene_ptnt_stus_cd, 2, '0') as discharge_disposition_code
, bene_ptnt_stus_cd as discharge_disposition_code
, cast(null as {{ dbt.type_string() }} ) as place_of_service_code
, {{ dbt.concat(
[
Expand Down Expand Up @@ -548,7 +548,7 @@ with sort_adjusted_claims as (
, cast(patient_id as {{ dbt.type_string() }} ) as patient_id
, cast(member_id as {{ dbt.type_string() }} ) as member_id
, cast(payer as {{ dbt.type_string() }} ) as payer
, cast(plan as {{ dbt.type_string() }} ) as plan
, cast({{ the_tuva_project.quote_column('plan') }} as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, {{ try_to_cast_date('claim_start_date', 'YYYY-MM-DD') }} as claim_start_date
, {{ try_to_cast_date('claim_end_date', 'YYYY-MM-DD') }} as claim_end_date
, {{ try_to_cast_date('claim_line_start_date', 'YYYY-MM-DD') }} as claim_line_start_date
Expand Down Expand Up @@ -688,7 +688,7 @@ with sort_adjusted_claims as (
, cast(in_network_flag as integer) as in_network_flag
, cast(data_source as {{ dbt.type_string() }} ) as data_source
, cast(file_name as {{ dbt.type_string() }} ) as file_name
, cast(ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime
, cast(ingest_datetime as {{ dbt.type_string() }} ) as ingest_datetime
from mapping

)
Expand All @@ -700,7 +700,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, claim_start_date
, claim_end_date
, claim_line_start_date
Expand Down
4 changes: 2 additions & 2 deletions models/intermediate/int_pharmacy_claim_deduped.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ with sort_adjusted_claims as (
, current_bene_mbi_id as patient_id
, current_bene_mbi_id as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare'as {{ dbt.type_string() }} ) as plan
, cast('medicare'as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, case
when prvdr_prsbng_id_qlfyr_cd in ('1', '01')
then clm_prsbng_prvdr_gnrc_id_num
Expand Down Expand Up @@ -129,7 +129,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, prescribing_provider_npi
, dispensing_provider_npi
, dispensing_date
Expand Down
8 changes: 4 additions & 4 deletions models/intermediate/int_physician_claim_deduped.sql
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ with sort_adjusted_claims as (
, current_bene_mbi_id as patient_id
, current_bene_mbi_id as member_id
, cast('medicare' as {{ dbt.type_string() }} ) as payer
, cast('medicare' as {{ dbt.type_string() }} ) as plan
, cast('medicare' as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, case
when clm_from_dt in ('1000-01-01', '9999-12-31') then null
else clm_from_dt
Expand Down Expand Up @@ -324,7 +324,7 @@ with sort_adjusted_claims as (
, cast(patient_id as {{ dbt.type_string() }} ) as patient_id
, cast(member_id as {{ dbt.type_string() }} ) as member_id
, cast(payer as {{ dbt.type_string() }} ) as payer
, cast(plan as {{ dbt.type_string() }} ) as plan
, cast({{ the_tuva_project.quote_column('plan') }} as {{ dbt.type_string() }} ) as {{ the_tuva_project.quote_column('plan') }}
, {{ try_to_cast_date('claim_start_date', 'YYYY-MM-DD') }} as claim_start_date
, {{ try_to_cast_date('claim_end_date', 'YYYY-MM-DD') }} as claim_end_date
, {{ try_to_cast_date('claim_line_start_date', 'YYYY-MM-DD') }} as claim_line_start_date
Expand Down Expand Up @@ -464,7 +464,7 @@ with sort_adjusted_claims as (
, cast(in_network_flag as integer) as in_network_flag
, cast(data_source as {{ dbt.type_string() }} ) as data_source
, cast(file_name as {{ dbt.type_string() }} ) as file_name
, cast(ingest_datetime as {{ dbt.type_timestamp() }} ) as ingest_datetime
, cast(ingest_datetime as {{ dbt.type_string() }} ) as ingest_datetime
from mapping

)
Expand All @@ -476,7 +476,7 @@ select
, patient_id
, member_id
, payer
, plan
, {{ the_tuva_project.quote_column('plan') }}
, claim_start_date
, claim_end_date
, claim_line_start_date
Expand Down

0 comments on commit 66aa255

Please sign in to comment.