diff --git a/models/final/eligibility.sql b/models/final/eligibility.sql index a37d4310..cd56e575 100644 --- a/models/final/eligibility.sql +++ b/models/final/eligibility.sql @@ -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 @@ -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 diff --git a/models/final/medical_claim.sql b/models/final/medical_claim.sql index ec9185f0..a9632e26 100644 --- a/models/final/medical_claim.sql +++ b/models/final/medical_claim.sql @@ -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 diff --git a/models/final/pharmacy_claim.sql b/models/final/pharmacy_claim.sql index 0a84a16b..7380cd9a 100644 --- a/models/final/pharmacy_claim.sql +++ b/models/final/pharmacy_claim.sql @@ -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 @@ -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 ) @@ -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 diff --git a/models/intermediate/int_dme_claim_deduped.sql b/models/intermediate/int_dme_claim_deduped.sql index b409e5f2..9d14ee2d 100644 --- a/models/intermediate/int_dme_claim_deduped.sql +++ b/models/intermediate/int_dme_claim_deduped.sql @@ -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 @@ -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 @@ -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 ) @@ -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 diff --git a/models/intermediate/int_institutional_claim_deduped.sql b/models/intermediate/int_institutional_claim_deduped.sql index cce56e6e..fa47b89a 100644 --- a/models/intermediate/int_institutional_claim_deduped.sql +++ b/models/intermediate/int_institutional_claim_deduped.sql @@ -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 @@ -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( [ @@ -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 @@ -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 ) @@ -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 diff --git a/models/intermediate/int_pharmacy_claim_deduped.sql b/models/intermediate/int_pharmacy_claim_deduped.sql index 15b76f3f..0f2eec8b 100644 --- a/models/intermediate/int_pharmacy_claim_deduped.sql +++ b/models/intermediate/int_pharmacy_claim_deduped.sql @@ -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 @@ -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 diff --git a/models/intermediate/int_physician_claim_deduped.sql b/models/intermediate/int_physician_claim_deduped.sql index 46d3d4d0..2195d058 100644 --- a/models/intermediate/int_physician_claim_deduped.sql +++ b/models/intermediate/int_physician_claim_deduped.sql @@ -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 @@ -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 @@ -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 ) @@ -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