diff --git a/models/intermediate/int__assign_all_visit_ids.sql b/models/intermediate/int__assign_all_visit_ids.sql index 800dc53..b627ca8 100644 --- a/models/intermediate/int__assign_all_visit_ids.sql +++ b/models/intermediate/int__assign_all_visit_ids.sql @@ -3,12 +3,12 @@ SELECT e.encounter_id , e.patient_id AS person_source_value - , e.encounter_start_datetime AS date_service - , e.encounter_stop_datetime AS date_service_end + , e.encounter_start_datetime AS datetime_service + , e.encounter_stop_datetime AS datetime_service_end , e.encounter_class , av.encounter_class AS visit_type - , av.visit_start_date - , av.visit_end_date + , av.visit_start_datetime + , av.visit_end_datetime , av.visit_occurrence_id , CASE WHEN @@ -19,11 +19,11 @@ SELECT CASE WHEN av.encounter_class = 'inpatient' - AND e.encounter_start_datetime > av.visit_start_date + AND e.encounter_start_datetime > av.visit_start_datetime THEN visit_occurrence_id WHEN av.encounter_class IN ('emergency', 'urgent') - AND e.encounter_start_datetime = av.visit_start_date + AND e.encounter_start_datetime = av.visit_start_datetime THEN visit_occurrence_id END ) @@ -32,7 +32,7 @@ SELECT CASE WHEN av.encounter_class = 'inpatient' - AND e.encounter_start_datetime >= av.visit_start_date + AND e.encounter_start_datetime >= av.visit_start_datetime THEN visit_occurrence_id WHEN av.encounter_class IN ( @@ -46,5 +46,5 @@ FROM {{ ref('stg_synthea__encounters') }} AS e INNER JOIN {{ ref('int__all_visits') }} AS av ON e.patient_id = av.patient_id - AND e.encounter_start_datetime >= av.visit_start_date - AND e.encounter_start_datetime <= av.visit_end_date + AND e.encounter_start_datetime >= av.visit_start_datetime + AND e.encounter_start_datetime <= av.visit_end_datetime diff --git a/models/intermediate/int__cost_condition.sql b/models/intermediate/int__cost_condition.sql index dc40ab1..9d18c3e 100644 --- a/models/intermediate/int__cost_condition.sql +++ b/models/intermediate/int__cost_condition.sql @@ -3,12 +3,12 @@ WITH cte AS ( co.condition_occurrence_id , ppp.payer_plan_period_id , coalesce( - sum(CASE WHEN ct.transfer_type = '1' THEN {{ dbt.cast("ct.transaction_amount", api.Column.translate_type("decimal")) }} END) + sum(CASE WHEN ct.transfer_type = '1' THEN ct.transaction_amount END) , 0 ) AS payer_paid , coalesce( - sum(CASE WHEN ct.transfer_type = 'p' THEN {{ dbt.cast("ct.transaction_amount", api.Column.translate_type("decimal")) }} END) + sum(CASE WHEN ct.transfer_type = 'p' THEN ct.transaction_amount END) , 0 ) AS patient_paid @@ -41,7 +41,7 @@ WITH cte AS ( AND e.encounter_id = ca.encounter_id AND e.provider_id = ca.provider_id AND e.payer_id = ca.primary_patient_insurance_id - AND e.encounter_start_datetime = ca.service_date + AND e.encounter_start_datetime = ca.service_datetime INNER JOIN {{ ref ('stg_synthea__claims_transactions') }} AS ct ON ca.claim_id = ct.claim_id @@ -62,14 +62,14 @@ SELECT , {{ dbt.cast("payer_paid ", api.Column.translate_type("decimal")) }} + {{ dbt.cast("patient_paid", api.Column.translate_type("decimal")) }} AS total_paid , payer_paid AS paid_by_payer , patient_paid AS paid_by_patient - , cast(null AS numeric) AS paid_patient_copay - , cast(null AS numeric) AS paid_patient_coinsurance - , cast(null AS numeric) AS paid_patient_deductible + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_copay + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_coinsurance + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_deductible , payer_paid AS paid_by_primary - , cast(null AS numeric) AS paid_ingredient_cost - , cast(null AS numeric) AS paid_dispensing_fee + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_ingredient_cost + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_dispensing_fee , payer_plan_period_id - , cast(null AS numeric) AS amount_allowed + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS amount_allowed , 0 AS revenue_code_concept_id , 'unknown / unknown' AS revenue_code_source_value , 0 AS drg_concept_id diff --git a/models/intermediate/int__cost_drug_exposure_1.sql b/models/intermediate/int__cost_drug_exposure_1.sql index bc67569..35661be 100644 --- a/models/intermediate/int__cost_drug_exposure_1.sql +++ b/models/intermediate/int__cost_drug_exposure_1.sql @@ -3,21 +3,19 @@ SELECT DISTINCT , 'Drug' AS cost_domain_id , 32814 AS cost_type_concept_id , 44818668 AS currency_concept_id - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("i.immunization_base_cost", api.Column.translate_type("decimal")) }} AS total_charge - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("i.immunization_base_cost", api.Column.translate_type("decimal")) }} AS total_cost - , {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} + {{ dbt.cast("i.immunization_base_cost", api.Column.translate_type("decimal")) }} AS total_paid + , e.total_encounter_cost + i.immunization_base_cost AS total_charge + , e.total_encounter_cost + i.immunization_base_cost AS total_cost + , e.encounter_payer_coverage + i.immunization_base_cost AS total_paid , e.encounter_payer_coverage AS paid_by_payer - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} - + {{ dbt.cast("i.immunization_base_cost", api.Column.translate_type("decimal")) }} - - {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} AS paid_by_patient - , cast(null AS numeric) AS paid_patient_copay - , cast(null AS numeric) AS paid_patient_coinsurance - , cast(null AS numeric) AS paid_patient_deductible - , cast(null AS numeric) AS paid_by_primary - , cast(null AS numeric) AS paid_ingredient_cost - , cast(null AS numeric) AS paid_dispensing_fee + , e.total_encounter_cost + i.immunization_base_cost - e.encounter_payer_coverage AS paid_by_patient + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_copay + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_coinsurance + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_deductible + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_by_primary + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_ingredient_cost + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_dispensing_fee , ppp.payer_plan_period_id - , cast(null AS numeric) AS amount_allowed + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS amount_allowed , 0 AS revenue_code_concept_id , 'UNKNOWN / UNKNOWN' AS revenue_code_source_value , 0 AS drg_concept_id diff --git a/models/intermediate/int__cost_drug_exposure_2.sql b/models/intermediate/int__cost_drug_exposure_2.sql index 285d520..ba8d886 100644 --- a/models/intermediate/int__cost_drug_exposure_2.sql +++ b/models/intermediate/int__cost_drug_exposure_2.sql @@ -3,21 +3,19 @@ SELECT DISTINCT , 'Drug' AS cost_domain_id , 32814 AS cost_type_concept_id , 44818668 AS currency_concept_id - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("m.medication_base_cost", api.Column.translate_type("decimal")) }} AS total_charge - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("m.medication_base_cost", api.Column.translate_type("decimal")) }} AS total_cost - , {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} + {{ dbt.cast("m.medication_base_cost", api.Column.translate_type("decimal")) }} AS total_paid + , e.total_encounter_cost + m.medication_base_cost AS total_charge + , e.total_encounter_cost + m.medication_base_cost AS total_cost + , e.encounter_payer_coverage + m.medication_base_cost AS total_paid , e.encounter_payer_coverage AS paid_by_payer - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} - + {{ dbt.cast("m.medication_base_cost", api.Column.translate_type("decimal")) }} - - {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} AS paid_by_patient - , cast(null AS numeric) AS paid_patient_copay - , cast(null AS numeric) AS paid_patient_coinsurance - , cast(null AS numeric) AS paid_patient_deductible - , cast(null AS numeric) AS paid_by_primary - , cast(null AS numeric) AS paid_ingredient_cost - , cast(null AS numeric) AS paid_dispensing_fee + , e.total_encounter_cost + m.medication_base_cost - e.encounter_payer_coverage AS paid_by_patient + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_copay + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_coinsurance + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_deductible + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_by_primary + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_ingredient_cost + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_dispensing_fee , ppp.payer_plan_period_id - , cast(null AS numeric) AS amount_allowed + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS amount_allowed , 0 AS revenue_code_concept_id , 'UNKNOWN / UNKNOWN' AS revenue_code_source_value , 0 AS drg_concept_id diff --git a/models/intermediate/int__cost_procedure.sql b/models/intermediate/int__cost_procedure.sql index bf970b8..6950ed1 100644 --- a/models/intermediate/int__cost_procedure.sql +++ b/models/intermediate/int__cost_procedure.sql @@ -3,21 +3,19 @@ SELECT DISTINCT , 'Procedure' AS cost_domain_id , 32814 AS cost_type_concept_id , 44818668 AS currency_concept_id - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("pr.procedure_base_cost", api.Column.translate_type("decimal")) }} AS total_charge - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} + {{ dbt.cast("pr.procedure_base_cost", api.Column.translate_type("decimal")) }} AS total_cost - , {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} + {{ dbt.cast("pr.procedure_base_cost", api.Column.translate_type("decimal")) }} AS total_paid + , e.total_encounter_cost + pr.procedure_base_cost AS total_charge + , e.total_encounter_cost + pr.procedure_base_cost AS total_cost + , e.total_encounter_cost + pr.procedure_base_cost AS total_paid , e.encounter_payer_coverage AS paid_by_payer - , {{ dbt.cast("e.total_encounter_cost", api.Column.translate_type("decimal")) }} - + {{ dbt.cast("pr.procedure_base_cost", api.Column.translate_type("decimal")) }} - - {{ dbt.cast("e.encounter_payer_coverage", api.Column.translate_type("decimal")) }} AS paid_by_patient - , cast(null AS numeric) AS paid_patient_copay - , cast(null AS numeric) AS paid_patient_coinsurance - , cast(null AS numeric) AS paid_patient_deductible - , cast(null AS numeric) AS paid_by_primary - , cast(null AS numeric) AS paid_ingredient_cost - , cast(null AS numeric) AS paid_dispensing_fee + , e.total_encounter_cost + pr.procedure_base_cost - e.encounter_payer_coverage AS paid_by_patient + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_copay + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_coinsurance + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_patient_deductible + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_by_primary + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_ingredient_cost + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS paid_dispensing_fee , ppp.payer_plan_period_id - , cast(null AS numeric) AS amount_allowed + , {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS amount_allowed , 0 AS revenue_code_concept_id , 'UNKNOWN / UNKNOWN' AS revenue_code_source_value , 0 AS drg_concept_id diff --git a/models/intermediate/int__drug_immunisations.sql b/models/intermediate/int__drug_immunisations.sql index eb75429..142d680 100644 --- a/models/intermediate/int__drug_immunisations.sql +++ b/models/intermediate/int__drug_immunisations.sql @@ -2,23 +2,23 @@ SELECT i.patient_id , i.encounter_id , srctostdvm.target_concept_id AS drug_concept_id - , i.immunization_date AS drug_exposure_start_date + , {{ dbt.cast("i.immunization_date", api.Column.translate_type("date")) }} AS drug_exposure_start_date , i.immunization_date AS drug_exposure_start_datetime - , i.immunization_date AS drug_exposure_end_date + , {{ dbt.cast("i.immunization_date", api.Column.translate_type("date")) }} AS drug_exposure_end_date , i.immunization_date AS drug_exposure_end_datetime - , i.immunization_date AS verbatim_end_date + , {{ dbt.cast("i.immunization_date", api.Column.translate_type("date")) }} AS verbatim_end_date , 32827 AS drug_type_concept_id - , cast(null AS varchar) AS stop_reason - , cast(null AS integer) AS refills - , cast(null AS integer) AS quantity - , cast(null AS integer) AS days_supply - , cast(null AS varchar) AS sig + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS stop_reason + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS refills + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS quantity + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS days_supply + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS sig , 0 AS route_concept_id , '0' AS lot_number , i.immunization_code AS drug_source_value , srctosrcvm.source_concept_id AS drug_source_concept_id - , cast(null AS varchar) AS route_source_value - , cast(null AS varchar) AS dose_unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS route_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS dose_unit_source_value FROM {{ ref ('stg_synthea__immunizations') }} AS i INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm ON diff --git a/models/intermediate/int__drug_medications.sql b/models/intermediate/int__drug_medications.sql index 56f31ba..5c3f519 100644 --- a/models/intermediate/int__drug_medications.sql +++ b/models/intermediate/int__drug_medications.sql @@ -2,31 +2,27 @@ SELECT m.patient_id , m.encounter_id , srctostdvm.target_concept_id AS drug_concept_id - , m.medication_start_datetime AS drug_exposure_start_date + , m.medication_start_date AS drug_exposure_start_date , m.medication_start_datetime AS drug_exposure_start_datetime - , coalesce( - m.medication_stop_datetime, m.medication_start_datetime - ) AS drug_exposure_end_date - , coalesce( - m.medication_stop_datetime, m.medication_start_datetime - ) AS drug_exposure_end_datetime - , m.medication_stop_datetime AS verbatim_end_date + , coalesce(m.medication_stop_date, m.medication_start_date) AS drug_exposure_end_date + , coalesce(m.medication_stop_datetime, m.medication_start_datetime) AS drug_exposure_end_datetime + , m.medication_stop_date AS verbatim_end_date , 32838 AS drug_type_concept_id - , cast(null AS varchar) AS stop_reason - , cast(null AS integer) AS refills - , cast(null AS integer) AS quantity + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS stop_reason + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS refills + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS quantity , {{ dbt.datediff( - dbt.cast("m.medication_start_datetime", api.Column.translate_type("date")), - dbt.cast("m.medication_stop_datetime", api.Column.translate_type("date")), - "day") + "m.medication_start_date", + "m.medication_stop_date", + "day") }} AS days_supply - , cast(null AS varchar) AS sig + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS sig , 0 AS route_concept_id , '0' AS lot_number , m.medication_code AS drug_source_value , srctosrcvm.source_concept_id AS drug_source_concept_id - , cast(null AS varchar) AS route_source_value - , cast(null AS varchar) AS dose_unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS route_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS dose_unit_source_value FROM {{ ref ('stg_synthea__medications') }} AS m INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm ON diff --git a/models/intermediate/int__er_visits.sql b/models/intermediate/int__er_visits.sql index 87bf704..7dcdd4a 100644 --- a/models/intermediate/int__er_visits.sql +++ b/models/intermediate/int__er_visits.sql @@ -5,22 +5,22 @@ SELECT t2.encounter_id , t2.patient_id , t2.encounter_class - , t2.visit_start_date - , t2.visit_end_date + , t2.visit_start_datetime + , t2.visit_end_datetime FROM ( SELECT min(encounter_id) AS encounter_id , patient_id , encounter_class - , visit_start_date - , max(visit_end_date) AS visit_end_date + , visit_start_datetime + , max(visit_end_datetime) AS visit_end_datetime FROM ( SELECT cl1.encounter_id , cl1.patient_id , cl1.encounter_class - , cl1.encounter_start_datetime AS visit_start_date - , cl2.encounter_stop_datetime AS visit_end_date + , cl1.encounter_start_datetime AS visit_start_datetime + , cl2.encounter_stop_datetime AS visit_end_datetime FROM {{ ref( 'stg_synthea__encounters') }} AS cl1 INNER JOIN {{ ref( 'stg_synthea__encounters') }} AS cl2 ON @@ -29,5 +29,5 @@ FROM ( AND cl1.encounter_class = cl2.encounter_class WHERE cl1.encounter_class IN ('emergency', 'urgent') ) AS t1 - GROUP BY patient_id, encounter_class, visit_start_date + GROUP BY patient_id, encounter_class, visit_start_datetime ) AS t2 diff --git a/models/intermediate/int__ip_visits.sql b/models/intermediate/int__ip_visits.sql index 3858333..be8eef8 100644 --- a/models/intermediate/int__ip_visits.sql +++ b/models/intermediate/int__ip_visits.sql @@ -5,30 +5,30 @@ WITH cte_end_dates AS ( SELECT patient_id , encounter_class - , event_date - interval '1 day' AS end_date + , {{ dbt.dateadd(datepart="day", interval=-1, from_date_or_timestamp="event_datetime") }} AS end_datetime FROM ( SELECT patient_id , encounter_class - , event_date + , event_datetime , event_type , max(start_ordinal) OVER ( PARTITION BY patient_id , encounter_class - ORDER BY event_date, event_type ROWS UNBOUNDED PRECEDING + ORDER BY event_datetime, event_type ROWS UNBOUNDED PRECEDING ) AS start_ordinal , row_number() OVER ( PARTITION BY patient_id, encounter_class - ORDER BY event_date, event_type + ORDER BY event_datetime, event_type ) AS overall_ord FROM ( SELECT patient_id , encounter_class - , encounter_start_datetime AS event_date + , encounter_start_datetime AS event_datetime , -1 AS event_type , row_number() OVER ( PARTITION BY patient_id, encounter_class @@ -40,7 +40,7 @@ WITH cte_end_dates AS ( SELECT patient_id , encounter_class - , encounter_stop_datetime + interval '1 day' AS event_date + , {{ dbt.dateadd(datepart="day", interval=1, from_date_or_timestamp="encounter_stop_datetime") }} AS event_datetime , 1 AS event_type , NULL AS start_ordinal FROM {{ ref( 'stg_synthea__encounters') }} @@ -55,14 +55,14 @@ WITH cte_end_dates AS ( min(v.encounter_id) AS encounter_id , v.patient_id , v.encounter_class - , v.encounter_start_datetime AS visit_start_date - , min(e.end_date) AS visit_end_date + , v.encounter_start_datetime AS visit_start_datetime + , min(e.end_datetime) AS visit_end_datetime FROM {{ ref( 'stg_synthea__encounters') }} AS v INNER JOIN cte_end_dates AS e ON v.patient_id = e.patient_id AND v.encounter_class = e.encounter_class - AND v.encounter_start_datetime <= e.end_date + AND v.encounter_start_datetime <= e.end_datetime GROUP BY v.patient_id, v.encounter_class, v.encounter_start_datetime ) @@ -70,15 +70,15 @@ SELECT t2.encounter_id , t2.patient_id , t2.encounter_class - , t2.visit_start_date - , t2.visit_end_date + , t2.visit_start_datetime + , t2.visit_end_datetime FROM ( SELECT encounter_id , patient_id , encounter_class - , min(visit_start_date) AS visit_start_date - , visit_end_date + , min(visit_start_datetime) AS visit_start_datetime + , visit_end_datetime FROM cte_visit_ends - GROUP BY encounter_id, patient_id, encounter_class, visit_end_date + GROUP BY encounter_id, patient_id, encounter_class, visit_end_datetime ) AS t2 diff --git a/models/intermediate/int__observation_observations.sql b/models/intermediate/int__observation_observations.sql index 7a843c2..12bcbec 100644 --- a/models/intermediate/int__observation_observations.sql +++ b/models/intermediate/int__observation_observations.sql @@ -2,7 +2,7 @@ SELECT o.patient_id , o.encounter_id , srctostdvm.target_concept_id AS observation_concept_id - , o.observation_datetime AS observation_date + , o.observation_date , o.observation_datetime , 38000280 AS observation_type_concept_id , o.observation_code AS observation_source_value diff --git a/models/intermediate/int__op_visits.sql b/models/intermediate/int__op_visits.sql index 2a9fb6b..9e25963 100644 --- a/models/intermediate/int__op_visits.sql +++ b/models/intermediate/int__op_visits.sql @@ -5,8 +5,8 @@ WITH cte_visits_distinct AS ( min(encounter_id) AS encounter_id , patient_id , encounter_class - , encounter_start_datetime AS visit_start_date - , encounter_stop_datetime AS visit_end_date + , encounter_start_datetime AS visit_start_datetime + , encounter_stop_datetime AS visit_end_datetime FROM {{ ref( 'stg_synthea__encounters') }} WHERE encounter_class IN ('ambulatory', 'wellness', 'outpatient') GROUP BY @@ -20,7 +20,7 @@ SELECT min(encounter_id) AS encounter_id , patient_id , encounter_class - , visit_start_date - , max(visit_end_date) AS visit_end_date + , visit_start_datetime + , max(visit_end_datetime) AS visit_end_datetime FROM cte_visits_distinct -GROUP BY patient_id, encounter_class, visit_start_date +GROUP BY patient_id, encounter_class, visit_start_datetime diff --git a/models/intermediate/int__person.sql b/models/intermediate/int__person.sql index f3cc436..8d78421 100644 --- a/models/intermediate/int__person.sql +++ b/models/intermediate/int__person.sql @@ -7,7 +7,7 @@ SELECT , extract(YEAR FROM p.birth_date) AS year_of_birth , extract(MONTH FROM p.birth_date) AS month_of_birth , extract(DAY FROM p.birth_date) AS day_of_birth - , cast(NULL AS TIMESTAMP) AS birth_datetime + , {{ dbt.cast("NULL", api.Column.translate_type("timestamp")) }} AS birth_datetime , CASE upper(p.race) WHEN 'WHITE' THEN 8527 WHEN 'BLACK' THEN 8516 diff --git a/models/omop/care_site.sql b/models/omop/care_site.sql index 94771fc..b1cadab 100644 --- a/models/omop/care_site.sql +++ b/models/omop/care_site.sql @@ -2,7 +2,7 @@ SELECT ROW_NUMBER() OVER (ORDER BY organization_id) AS care_site_id , organization_name AS care_site_name , 0 AS place_of_service_concept_id - , CAST(NULL AS INTEGER) AS location_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS location_id , organization_id AS care_site_source_value - , CAST(NULL AS VARCHAR) AS place_of_service_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS place_of_service_source_value FROM {{ ref('stg_synthea__organizations') }} diff --git a/models/omop/condition_occurrence.sql b/models/omop/condition_occurrence.sql index 5f8e52f..0cd0569 100644 --- a/models/omop/condition_occurrence.sql +++ b/models/omop/condition_occurrence.sql @@ -3,17 +3,17 @@ SELECT , p.person_id , srctostdvm.target_concept_id AS condition_concept_id , c.condition_start_date - , NULL AS condition_start_datetime + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS condition_start_datetime , c.condition_stop_date AS condition_end_date - , NULL AS condition_end_datetime + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS condition_end_datetime , 32827 AS condition_type_concept_id - , cast(NULL AS varchar) AS stop_reason + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS stop_reason , pr.provider_id , fv.visit_occurrence_id_new AS visit_occurrence_id , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id , c.condition_code AS condition_source_value , srctosrcvm.source_concept_id AS condition_source_concept_id - , NULL AS condition_status_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS condition_status_source_value , 0 AS condition_status_concept_id FROM {{ ref('stg_synthea__conditions') }} AS c INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm diff --git a/models/omop/death.sql b/models/omop/death.sql index 96d8879..b6c3ef0 100644 --- a/models/omop/death.sql +++ b/models/omop/death.sql @@ -10,7 +10,7 @@ SELECT p.person_id - , {{ dbt.cast("e.encounter_start_datetime", api.Column.translate_type("date")) }} AS death_date + , e.encounter_start_date AS death_date , e.encounter_start_datetime AS death_datetime , 32817 AS death_type_concept_id , srctostdvm.target_concept_id AS cause_concept_id diff --git a/models/omop/device_exposure.sql b/models/omop/device_exposure.sql index acf7d2d..94ee23d 100644 --- a/models/omop/device_exposure.sql +++ b/models/omop/device_exposure.sql @@ -2,22 +2,22 @@ SELECT row_number() OVER (ORDER BY person_id) AS device_exposure_id , p.person_id , srctostdvm.target_concept_id AS device_concept_id - , {{ dbt.cast("d.device_start_datetime", api.Column.translate_type("date")) }} AS device_exposure_start_date + , d.device_start_date AS device_exposure_start_date , d.device_start_datetime AS device_exposure_start_datetime - , {{ dbt.cast("d.device_stop_datetime", api.Column.translate_type("date")) }} AS device_exposure_end_date + , d.device_stop_date AS device_exposure_end_date , d.device_stop_datetime AS device_exposure_end_datetime , 32827 AS device_type_concept_id , d.udi AS unique_device_id - , cast(null AS varchar) AS production_id - , cast(null AS int) AS quantity + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS production_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS quantity , pr.provider_id , fv.visit_occurrence_id_new AS visit_occurrence_id , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id , d.device_code AS device_source_value , srctosrcvm.source_concept_id AS device_source_concept_id - , cast(null AS int) AS unit_concept_id - , cast(null AS varchar) AS unit_source_value - , cast(null AS int) AS unit_source_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_source_concept_id FROM {{ ref('stg_synthea__devices') }} AS d INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm ON diff --git a/models/omop/dose_era.sql b/models/omop/dose_era.sql index 7573c7b..0675c81 100644 --- a/models/omop/dose_era.sql +++ b/models/omop/dose_era.sql @@ -1,9 +1,9 @@ SELECT - CAST(NULL AS INTEGER) AS dose_era_id - , CAST(NULL AS INTEGER) AS person_id - , CAST(NULL AS INTEGER) AS drug_concept_id - , CAST(NULL AS INTEGER) AS unit_concept_id - , CAST(NULL AS FLOAT) AS dose_value - , CAST(NULL AS DATE) AS dose_era_start_date - , CAST(NULL AS DATE) AS dose_era_end_date + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS dose_era_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS person_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS drug_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_concept_id + , {{ dbt.cast('null', api.Column.translate_type("decimal")) }} AS dose_value + , {{ dbt.cast('null', api.Column.translate_type("date")) }} AS dose_era_start_date + , {{ dbt.cast('null', api.Column.translate_type("date")) }} AS dose_era_end_date WHERE 1 = 0 diff --git a/models/omop/drug_exposure.sql b/models/omop/drug_exposure.sql index f11d8f6..3e62152 100644 --- a/models/omop/drug_exposure.sql +++ b/models/omop/drug_exposure.sql @@ -8,11 +8,11 @@ SELECT row_number() OVER (ORDER BY p.person_id) AS drug_exposure_id , p.person_id , drug_concept_id - , {{ dbt.cast("drug_exposure_start_date", api.Column.translate_type("date")) }} AS drug_exposure_start_date + , drug_exposure_start_date , drug_exposure_start_datetime - , {{ dbt.cast("drug_exposure_end_date", api.Column.translate_type("date")) }} AS drug_exposure_end_date + , drug_exposure_end_date , drug_exposure_end_datetime - , {{ dbt.cast("verbatim_end_date", api.Column.translate_type("date")) }} AS verbatim_end_date + , verbatim_end_date , drug_type_concept_id , stop_reason , refills diff --git a/models/omop/episode.sql b/models/omop/episode.sql index 6e7c56c..dfdbdb2 100644 --- a/models/omop/episode.sql +++ b/models/omop/episode.sql @@ -1,15 +1,15 @@ SELECT - CAST(NULL AS INTEGER) AS episode_id - , CAST(NULL AS INTEGER) AS person_id - , CAST(NULL AS INTEGER) AS episode_concept_id - , CAST(NULL AS DATE) AS episode_start_date - , CAST(NULL AS TIMESTAMP) AS episode_start_datetime - , CAST(NULL AS DATE) AS episode_end_date - , CAST(NULL AS TIMESTAMP) AS episode_end_datetime - , CAST(NULL AS INTEGER) AS episode_parent_id - , CAST(NULL AS INTEGER) AS episode_number - , CAST(NULL AS INTEGER) AS episode_object_concept_id - , CAST(NULL AS INTEGER) AS episode_type_concept_id - , CAST(NULL AS VARCHAR) AS episode_source_value - , CAST(NULL AS INTEGER) AS episode_source_concept_id + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS person_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_concept_id + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS episode_start_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS episode_start_datetime + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS episode_end_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS episode_end_datetime + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_parent_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_number + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_object_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_type_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS episode_source_value + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_source_concept_id WHERE 1 = 0 diff --git a/models/omop/episode_event.sql b/models/omop/episode_event.sql index a2cde83..1e0bd90 100644 --- a/models/omop/episode_event.sql +++ b/models/omop/episode_event.sql @@ -1,6 +1,6 @@ SELECT - CAST(NULL AS INTEGER) AS episode_event_id - , CAST(NULL AS INTEGER) AS episode_id - , CAST(NULL AS INTEGER) AS event_id - , CAST(NULL AS INTEGER) AS episode_event_field_concept_id + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS episode_event_field_concept_id WHERE 1 = 0 diff --git a/models/omop/fact_relationship.sql b/models/omop/fact_relationship.sql index 52a89d8..1d0b51d 100644 --- a/models/omop/fact_relationship.sql +++ b/models/omop/fact_relationship.sql @@ -1,8 +1,8 @@ SELECT - CAST(NULL AS INTEGER) AS fact_relationship_id - , CAST(NULL AS INTEGER) AS domain_concept_id_1 - , CAST(NULL AS INTEGER) AS fact_id_1 - , CAST(NULL AS INTEGER) AS domain_concept_id_2 - , CAST(NULL AS INTEGER) AS fact_id_2 - , CAST(NULL AS INTEGER) AS relationship_concept_id + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS fact_relationship_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS domain_concept_id_1 + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS fact_id_1 + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS domain_concept_id_2 + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS fact_id_2 + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS relationship_concept_id WHERE 1 = 0 diff --git a/models/omop/location.sql b/models/omop/location.sql index 10076ce..9a0b959 100644 --- a/models/omop/location.sql +++ b/models/omop/location.sql @@ -1,15 +1,15 @@ SELECT ROW_NUMBER() OVER () AS location_id - , CAST(NULL AS VARCHAR) AS address_1 - , CAST(NULL AS VARCHAR) AS address_2 + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS address_1 + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS address_2 , p.patient_city AS city , s.state_abbreviation AS state - , CAST(NULL AS VARCHAR) AS county + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS county , p.patient_zip AS zip , p.patient_zip AS location_source_value - , CAST(NULL AS INTEGER) AS country_concept_id - , CAST(NULL AS VARCHAR) AS country_source_value - , CAST(NULL AS FLOAT) AS latitude - , CAST(NULL AS FLOAT) AS longitude + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS country_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS country_source_value + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS latitude + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS longitude FROM {{ ref('stg_synthea__patients') }} AS p LEFT JOIN {{ ref('stg_map__states') }} AS s ON p.patient_state = s.state_name diff --git a/models/omop/measurement.sql b/models/omop/measurement.sql index d68a640..ae7eeb0 100644 --- a/models/omop/measurement.sql +++ b/models/omop/measurement.sql @@ -2,26 +2,26 @@ WITH snomed_measurements AS ( SELECT p.person_id , srctostdvm.target_concept_id AS measurement_concept_id - , {{ dbt.cast("pr.procedure_start_datetime", api.Column.translate_type("date")) }} AS measurement_date + , pr.procedure_start_date AS measurement_date , pr.procedure_start_datetime AS measurement_datetime , {{ dbt.cast("pr.procedure_start_datetime", api.Column.translate_type("time")) }} AS measurement_time , 32827 AS measurement_type_concept_id , 0 AS operator_concept_id - , cast(null AS float) AS value_as_number + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS value_as_number , 0 AS value_as_concept_id , 0 AS unit_concept_id - , cast(null AS float) AS range_low - , cast(null AS float) AS range_high + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS range_low + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS range_high , prv.provider_id , fv.visit_occurrence_id_new AS visit_occurrence_id , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id , pr.procedure_code AS measurement_source_value , srctosrcvm.source_concept_id AS measurement_source_concept_id - , cast(null AS varchar) AS unit_source_value - , cast(null AS varchar) AS value_source_value - , cast(null AS int) AS unit_source_concept_id - , cast(null AS bigint) AS measurement_event_id - , cast(null AS int) AS meas_event_field_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS value_source_value + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_source_concept_id + , {{ dbt.cast("null", api.Column.translate_type("bigint")) }} AS measurement_event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS meas_event_field_concept_id FROM {{ ref ('stg_synthea__procedures') }} AS pr INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm ON @@ -51,20 +51,20 @@ WITH snomed_measurements AS ( SELECT p.person_id , srctostdvm.target_concept_id AS measurement_concept_id - , {{ dbt.cast("o.observation_datetime", api.Column.translate_type("date")) }} AS measurement_date + , o.observation_date AS measurement_date , o.observation_datetime AS measurement_datetime , {{ dbt.cast("o.observation_datetime", api.Column.translate_type("time")) }} AS measurement_time , 32827 AS measurement_type_concept_id , 0 AS operator_concept_id , CASE WHEN o.observation_value ~ '^[-+]?[0-9]+\.?[0-9]*$' - THEN cast(o.observation_value AS float) - ELSE cast(null AS float) + THEN {{ dbt.cast("o.observation_value", api.Column.translate_type("decimal")) }} + ELSE {{ dbt.cast("null", api.Column.translate_type("decimal")) }} END AS value_as_number , coalesce(srcmap2.target_concept_id, 0) AS value_as_concept_id , coalesce(srcmap1.target_concept_id, 0) AS unit_concept_id - , cast(null AS float) AS range_low - , cast(null AS float) AS range_high + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS range_low + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS range_high , pr.provider_id , fv.visit_occurrence_id_new AS visit_occurrence_id , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id @@ -74,9 +74,9 @@ WITH snomed_measurements AS ( ) AS measurement_source_concept_id , o.observation_units AS unit_source_value , o.observation_value AS value_source_value - , cast(null AS int) AS unit_source_concept_id - , cast(null AS bigint) AS measurement_event_id - , cast(null AS int) AS meas_event_field_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_source_concept_id + , {{ dbt.cast("null", api.Column.translate_type("bigint")) }} AS measurement_event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS meas_event_field_concept_id FROM {{ ref ('stg_synthea__observations') }} AS o INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm diff --git a/models/omop/metadata.sql b/models/omop/metadata.sql index aae0b5c..8534338 100644 --- a/models/omop/metadata.sql +++ b/models/omop/metadata.sql @@ -1,11 +1,11 @@ SELECT - CAST(NULL AS INTEGER) AS metadata_id - , CAST(NULL AS INTEGER) AS metadata_concept_id - , CAST(NULL AS INTEGER) AS metadata_type_concept_id - , CAST(NULL AS VARCHAR) AS "name" - , CAST(NULL AS VARCHAR) AS value_as_string - , CAST(NULL AS INTEGER) AS value_as_concept_id - , CAST(NULL AS FLOAT) AS value_as_number - , CAST(NULL AS DATE) AS metadata_date - , CAST(NULL AS TIMESTAMP) AS metadata_datetime + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS metadata_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS metadata_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS metadata_type_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS "name" + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS value_as_string + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS value_as_concept_id + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS value_as_number + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS metadata_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS metadata_datetime WHERE 1 = 0 diff --git a/models/omop/note.sql b/models/omop/note.sql index 13175c0..784718d 100644 --- a/models/omop/note.sql +++ b/models/omop/note.sql @@ -1,18 +1,18 @@ SELECT - CAST(NULL AS INTEGER) AS note_id - , CAST(NULL AS INTEGER) AS person_id - , CAST(NULL AS DATE) AS note_date - , CAST(NULL AS TIMESTAMP) AS note_datetime - , CAST(NULL AS INTEGER) AS note_type_concept_id - , CAST(NULL AS INTEGER) AS note_class_concept_id - , CAST(NULL AS VARCHAR) AS note_title - , CAST(NULL AS VARCHAR) AS note_text - , CAST(NULL AS INTEGER) AS encoding_concept_id - , CAST(NULL AS INTEGER) AS language_concept_id - , CAST(NULL AS INTEGER) AS provider_id - , CAST(NULL AS INTEGER) AS visit_occurrence_id - , CAST(NULL AS INTEGER) AS visit_detail_id - , CAST(NULL AS VARCHAR) AS note_source_value - , CAST(NULL AS INTEGER) AS note_event_id - , CAST(NULL AS INTEGER) AS note_event_field_concept_id + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS person_id + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS note_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS note_datetime + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_type_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_class_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS note_title + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS note_text + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS encoding_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS language_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS provider_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS visit_occurrence_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS visit_detail_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS note_source_value + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_event_field_concept_id WHERE 1 = 0 diff --git a/models/omop/note_nlp.sql b/models/omop/note_nlp.sql index f94207d..05c57ea 100644 --- a/models/omop/note_nlp.sql +++ b/models/omop/note_nlp.sql @@ -1,16 +1,16 @@ SELECT - CAST(NULL AS INTEGER) AS note_nlp_id - , CAST(NULL AS INTEGER) AS note_id - , CAST(NULL AS INTEGER) AS section_concept_id - , CAST(NULL AS VARCHAR) AS snippet - , CAST(NULL AS INTEGER) AS "offset" - , CAST(NULL AS VARCHAR) AS lexical_variant - , CAST(NULL AS INTEGER) AS note_nlp_concept_id - , CAST(NULL AS INTEGER) AS note_nlp_source_concept_id - , CAST(NULL AS VARCHAR) AS nlp_system - , CAST(NULL AS DATE) AS nlp_date - , CAST(NULL AS TIMESTAMP) AS nlp_datetime - , CAST(NULL AS BOOLEAN) AS term_exists - , CAST(NULL AS VARCHAR) AS term_temporal - , CAST(NULL AS VARCHAR) AS term_modifiers + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_nlp_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS section_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS snippet + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS "offset" + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS lexical_variant + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_nlp_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS note_nlp_source_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS nlp_system + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS nlp_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS nlp_datetime + , {{ dbt.cast("null", api.Column.translate_type("boolean")) }} AS term_exists + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS term_temporal + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS term_modifiers WHERE 1 = 0 diff --git a/models/omop/observation.sql b/models/omop/observation.sql index 2deda46..b3ea210 100644 --- a/models/omop/observation.sql +++ b/models/omop/observation.sql @@ -10,11 +10,11 @@ SELECT row_number() OVER (ORDER BY person_id) AS observation_id , p.person_id , observation_concept_id - , {{ dbt.cast("observation_date", api.Column.translate_type("date")) }} AS observation_date + , observation_date , observation_datetime , observation_type_concept_id - , cast(null AS float) AS value_as_number - , cast(null AS varchar) AS value_as_string + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS value_as_number + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS value_as_string , 0 AS value_as_concept_id , 0 AS qualifier_concept_id , 0 AS unit_concept_id @@ -23,11 +23,11 @@ SELECT , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id , observation_source_value , observation_source_concept_id - , cast(null AS varchar) AS unit_source_value - , cast(null AS varchar) AS qualifier_source_value - , cast(null AS varchar) AS value_source_value - , cast(null AS bigint) AS observation_event_id - , cast(null AS int) AS obs_event_field_concept_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS qualifier_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS value_source_value + , {{ dbt.cast("null", api.Column.translate_type("bigint")) }} AS observation_event_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS obs_event_field_concept_id FROM all_observations AS ao LEFT JOIN {{ ref ('int__final_visit_ids') }} AS fv ON ao.encounter_id = fv.encounter_id diff --git a/models/omop/observation_period.sql b/models/omop/observation_period.sql index 0cb34ea..dcf5764 100644 --- a/models/omop/observation_period.sql +++ b/models/omop/observation_period.sql @@ -7,12 +7,8 @@ SELECT FROM ( SELECT p.person_id - , min( - {{ dbt.cast("e.encounter_start_datetime", api.Column.translate_type("date")) }} - ) AS start_date - , max( - {{ dbt.cast("e.encounter_stop_datetime", api.Column.translate_type("date")) }} - ) AS end_date + , min(e.encounter_start_date) AS start_date + , max(e.encounter_stop_date) AS end_date FROM {{ ref ('person') }} AS p INNER JOIN {{ ref ('stg_synthea__encounters') }} AS e ON p.person_source_value = e.patient_id diff --git a/models/omop/payer_plan_period.sql b/models/omop/payer_plan_period.sql index eb50114..9252f71 100644 --- a/models/omop/payer_plan_period.sql +++ b/models/omop/payer_plan_period.sql @@ -3,8 +3,8 @@ SELECT OVER (ORDER BY pat.patient_id, pt.coverage_start_datetime) AS payer_plan_period_id , per.person_id - , {{ dbt.cast("pt.coverage_start_datetime", api.Column.translate_type("date")) }} AS payer_plan_period_start_date - , {{ dbt.cast("pt.coverage_end_datetime", api.Column.translate_type("date")) }} AS payer_plan_period_end_date + , pt.coverage_start_date AS payer_plan_period_start_date + , pt.coverage_end_date AS payer_plan_period_end_date , 0 AS payer_concept_id , pt.payer_id AS payer_source_value , 0 AS payer_source_concept_id @@ -12,11 +12,11 @@ SELECT , pay.payer_name AS plan_source_value , 0 AS plan_source_concept_id , 0 AS sponsor_concept_id - , cast(NULL AS varchar) AS sponsor_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS sponsor_source_value , 0 AS sponsor_source_concept_id - , cast(NULL AS varchar) AS family_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS family_source_value , 0 AS stop_reason_concept_id - , cast(NULL AS varchar) AS stop_reason_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS stop_reason_source_value , 0 AS stop_reason_source_concept_id FROM {{ ref ('stg_synthea__payers') }} AS pay INNER JOIN {{ ref ('stg_synthea__payer_transitions') }} AS pt diff --git a/models/omop/procedure_occurrence.sql b/models/omop/procedure_occurrence.sql index aed476a..4f56907 100644 --- a/models/omop/procedure_occurrence.sql +++ b/models/omop/procedure_occurrence.sql @@ -2,13 +2,13 @@ SELECT row_number() OVER (ORDER BY p.person_id) AS procedure_occurrence_id , p.person_id , srctostdvm.target_concept_id AS procedure_concept_id - , {{ dbt.cast("pr.procedure_start_datetime", api.Column.translate_type("date")) }} AS procedure_date + , pr.procedure_start_date AS procedure_date , pr.procedure_start_datetime AS procedure_datetime - , {{ dbt.cast("pr.procedure_stop_datetime", api.Column.translate_type("date")) }} AS procedure_end_date + , pr.procedure_stop_date AS procedure_end_date , pr.procedure_stop_datetime AS procedure_end_datetime , 32827 AS procedure_type_concept_id , 0 AS modifier_concept_id - , cast(null AS integer) AS quantity + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS quantity , prv.provider_id , fv.visit_occurrence_id_new AS visit_occurrence_id , fv.visit_occurrence_id_new + 1000000 AS visit_detail_id diff --git a/models/omop/provider.sql b/models/omop/provider.sql index 69cc58a..984ee7d 100644 --- a/models/omop/provider.sql +++ b/models/omop/provider.sql @@ -1,11 +1,11 @@ SELECT row_number() OVER (ORDER BY (SELECT null)) AS provider_id , provider_name - , cast(null AS varchar(20)) AS npi - , cast(null AS varchar(20)) AS dea + , {{ dbt.cast("null", api.Column.translate_type("varchar(20)")) }} AS npi + , {{ dbt.cast("null", api.Column.translate_type("varchar(20)")) }} AS dea , 38004446 AS specialty_concept_id - , cast(null AS integer) AS care_site_id - , cast(null AS integer) AS year_of_birth + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS care_site_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS year_of_birth , CASE upper(provider_gender) WHEN 'M' THEN 8507 WHEN 'F' THEN 8532 diff --git a/models/omop/specimen.sql b/models/omop/specimen.sql index f63a784..60bb385 100644 --- a/models/omop/specimen.sql +++ b/models/omop/specimen.sql @@ -1,17 +1,17 @@ SELECT - CAST(NULL AS INTEGER) AS specimen_id - , CAST(NULL AS INTEGER) AS person_id - , CAST(NULL AS INTEGER) AS specimen_concept_id - , CAST(NULL AS INTEGER) AS specimen_type_concept_id - , CAST(NULL AS DATE) AS specimen_date - , CAST(NULL AS TIMESTAMP) AS specimen_datetime - , CAST(NULL AS FLOAT) AS quantity - , CAST(NULL AS INTEGER) AS unit_concept_id - , CAST(NULL AS INTEGER) AS anatomic_site_concept_id - , CAST(NULL AS INTEGER) AS disease_status_concept_id - , CAST(NULL AS INTEGER) AS specimen_source_id - , CAST(NULL AS VARCHAR) AS specimen_source_value - , CAST(NULL AS VARCHAR) AS unit_source_value - , CAST(NULL AS VARCHAR) AS anatomic_site_source_value - , CAST(NULL AS VARCHAR) AS disease_status_source_value + {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS specimen_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS person_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS specimen_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS specimen_type_concept_id + , {{ dbt.cast("null", api.Column.translate_type("date")) }} AS specimen_date + , {{ dbt.cast("null", api.Column.translate_type("timestamp")) }} AS specimen_datetime + , {{ dbt.cast("null", api.Column.translate_type("decimal")) }} AS quantity + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS unit_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS anatomic_site_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS disease_status_concept_id + , {{ dbt.cast("null", api.Column.translate_type("integer")) }} AS specimen_source_id + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS specimen_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS unit_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS anatomic_site_source_value + , {{ dbt.cast("null", api.Column.translate_type("varchar")) }} AS disease_status_source_value WHERE 1 = 0 diff --git a/models/omop/visit_detail.sql b/models/omop/visit_detail.sql index 16d7a82..c8746e0 100644 --- a/models/omop/visit_detail.sql +++ b/models/omop/visit_detail.sql @@ -15,10 +15,10 @@ SELECT ELSE 0 END AS visit_detail_concept_id - , {{ dbt.cast("av.visit_start_date", api.Column.translate_type("date")) }} AS visit_detail_start_date - , av.visit_start_date AS visit_detail_start_datetime - , {{ dbt.cast("av.visit_end_date", api.Column.translate_type("date")) }} AS visit_detail_end_date - , av.visit_end_date AS visit_detail_end_datetime + , {{ dbt.cast("av.visit_start_datetime", api.Column.translate_type("date")) }} AS visit_detail_start_date + , av.visit_start_datetime AS visit_detail_start_datetime + , {{ dbt.cast("av.visit_end_datetime", api.Column.translate_type("date")) }} AS visit_detail_end_date + , av.visit_end_datetime AS visit_detail_end_datetime , 32827 AS visit_detail_type_concept_id , pr.provider_id , {{ dbt.cast("NULL", api.Column.translate_type("integer")) }} AS care_site_id @@ -27,7 +27,7 @@ SELECT , lag(av.visit_occurrence_id) OVER ( PARTITION BY p.person_id - ORDER BY av.visit_start_date + ORDER BY av.visit_start_datetime ) + 1000000 AS preceding_visit_detail_id , av.encounter_id AS visit_detail_source_value diff --git a/models/omop/visit_occurrence.sql b/models/omop/visit_occurrence.sql index 3e875d0..200ecb3 100644 --- a/models/omop/visit_occurrence.sql +++ b/models/omop/visit_occurrence.sql @@ -10,10 +10,10 @@ SELECT WHEN 'outpatient' THEN 9202 ELSE 0 END AS visit_concept_id - , {{ dbt.cast("av.visit_start_date", api.Column.translate_type("date")) }} AS visit_start_date - , av.visit_start_date AS visit_start_datetime - , {{ dbt.cast("av.visit_end_date", api.Column.translate_type("date")) }} AS visit_end_date - , av.visit_end_date AS visit_end_datetime + , {{ dbt.cast("av.visit_start_datetime", api.Column.translate_type("date")) }} AS visit_start_date + , av.visit_start_datetime + , {{ dbt.cast("av.visit_end_datetime", api.Column.translate_type("date")) }} AS visit_end_date + , av.visit_end_datetime , 32827 AS visit_type_concept_id , pr.provider_id , {{ dbt.cast("NULL", api.Column.translate_type("integer")) }} AS care_site_id @@ -26,7 +26,7 @@ SELECT , lag(av.visit_occurrence_id) OVER ( PARTITION BY p.person_id - ORDER BY av.visit_start_date + ORDER BY av.visit_start_datetime ) AS preceding_visit_occurrence_id FROM {{ ref( 'int__all_visits') }} AS av diff --git a/models/staging/synthea/stg_synthea__claims.sql b/models/staging/synthea/stg_synthea__claims.sql index a53e79d..43c7ce7 100644 --- a/models/staging/synthea/stg_synthea__claims.sql +++ b/models/staging/synthea/stg_synthea__claims.sql @@ -37,7 +37,7 @@ WITH cte_claims_lower AS ( , referringproviderid AS referring_provider_id , appointmentid AS encounter_id , currentillnessdate AS current_illness_date - , servicedate AS service_date + , servicedate AS service_datetime , supervisingproviderid AS supervising_provider_id , status1 AS claim_status_1 , status2 AS claim_status_2 diff --git a/models/staging/synthea/stg_synthea__claims_transactions.sql b/models/staging/synthea/stg_synthea__claims_transactions.sql index 3730833..9e8b95d 100644 --- a/models/staging/synthea/stg_synthea__claims_transactions.sql +++ b/models/staging/synthea/stg_synthea__claims_transactions.sql @@ -18,7 +18,7 @@ WITH cte_claims_transactions_lower AS ( , chargeid AS charge_id , patientid AS patient_id , "type" AS transaction_type - , amount AS transaction_amount + , {{ dbt.cast("amount", api.Column.translate_type("decimal")) }} AS transaction_amount , method AS transaction_method , fromdate AS transaction_from_date , todate AS transaction_to_date diff --git a/models/staging/synthea/stg_synthea__devices.sql b/models/staging/synthea/stg_synthea__devices.sql index 90eb73b..693809a 100644 --- a/models/staging/synthea/stg_synthea__devices.sql +++ b/models/staging/synthea/stg_synthea__devices.sql @@ -14,7 +14,9 @@ WITH cte_devices_lower AS ( SELECT "start" AS device_start_datetime + , {{ dbt.cast("\"start\"", api.Column.translate_type("date")) }} AS device_start_date , "stop" AS device_stop_datetime + , {{ dbt.cast("\"stop\"", api.Column.translate_type("date")) }} AS device_stop_date , patient AS patient_id , encounter AS encounter_id , code AS device_code diff --git a/models/staging/synthea/stg_synthea__encounters.sql b/models/staging/synthea/stg_synthea__encounters.sql index 150bdce..834e464 100644 --- a/models/staging/synthea/stg_synthea__encounters.sql +++ b/models/staging/synthea/stg_synthea__encounters.sql @@ -14,8 +14,10 @@ WITH cte_encounters_lower AS ( SELECT id AS encounter_id - , start AS encounter_start_datetime - , stop AS encounter_stop_datetime + , "start" AS encounter_start_datetime + , {{ dbt.cast("\"start\"", api.Column.translate_type("date")) }} AS encounter_start_date + , "stop" AS encounter_stop_datetime + , {{ dbt.cast("\"stop\"", api.Column.translate_type("date")) }} AS encounter_stop_date , patient AS patient_id , organization AS organization_id , provider AS provider_id @@ -24,8 +26,8 @@ WITH cte_encounters_lower AS ( , code AS encounter_code , description AS encounter_description , base_encounter_cost - , total_claim_cost AS total_encounter_cost - , payer_coverage AS encounter_payer_coverage + , {{ dbt.cast("total_claim_cost", api.Column.translate_type("decimal")) }} AS total_encounter_cost + , {{ dbt.cast("payer_coverage", api.Column.translate_type("decimal")) }} AS encounter_payer_coverage , reasoncode AS encounter_reason_code , reasondescription AS encounter_reason_description FROM cte_encounters_lower diff --git a/models/staging/synthea/stg_synthea__immunizations.sql b/models/staging/synthea/stg_synthea__immunizations.sql index 5f29c45..7635345 100644 --- a/models/staging/synthea/stg_synthea__immunizations.sql +++ b/models/staging/synthea/stg_synthea__immunizations.sql @@ -18,7 +18,7 @@ WITH cte_immunizations_lower AS ( , encounter AS encounter_id , code AS immunization_code , "description" AS immunization_description - , base_cost AS immunization_base_cost + , {{ dbt.cast("base_cost", api.Column.translate_type("decimal")) }} AS immunization_base_cost FROM cte_immunizations_lower ) diff --git a/models/staging/synthea/stg_synthea__medications.sql b/models/staging/synthea/stg_synthea__medications.sql index 03dc530..efcf66f 100644 --- a/models/staging/synthea/stg_synthea__medications.sql +++ b/models/staging/synthea/stg_synthea__medications.sql @@ -14,13 +14,15 @@ WITH cte_medications_lower AS ( SELECT "start" AS medication_start_datetime + , {{ dbt.cast("\"start\"", api.Column.translate_type("date")) }} AS medication_start_date , "stop" AS medication_stop_datetime + , {{ dbt.cast("\"stop\"", api.Column.translate_type("date")) }} AS medication_stop_date , patient AS patient_id , payer AS payer_id , encounter AS encounter_id , code AS medication_code , "description" AS medication_description - , base_cost AS medication_base_cost + , {{ dbt.cast("base_cost", api.Column.translate_type("decimal")) }} AS medication_base_cost , payer_coverage AS medication_payer_coverage , dispenses , totalcost AS medication_total_cost diff --git a/models/staging/synthea/stg_synthea__observations.sql b/models/staging/synthea/stg_synthea__observations.sql index ccfb8ae..bf94c7f 100644 --- a/models/staging/synthea/stg_synthea__observations.sql +++ b/models/staging/synthea/stg_synthea__observations.sql @@ -14,6 +14,7 @@ WITH cte_observations_lower AS ( SELECT "date" AS observation_datetime + , {{ dbt.cast("\"date\"", api.Column.translate_type("date")) }} AS observation_date , patient AS patient_id , encounter AS encounter_id , category AS observation_category diff --git a/models/staging/synthea/stg_synthea__payer_transitions.sql b/models/staging/synthea/stg_synthea__payer_transitions.sql index f934285..bdb1a4c 100644 --- a/models/staging/synthea/stg_synthea__payer_transitions.sql +++ b/models/staging/synthea/stg_synthea__payer_transitions.sql @@ -16,7 +16,9 @@ WITH cte_payer_transitions_lower AS ( patient AS patient_id , memberid AS member_id , start_year AS coverage_start_datetime + , {{ dbt.cast("start_year", api.Column.translate_type("date")) }} AS coverage_start_date , end_year AS coverage_end_datetime + , {{ dbt.cast("end_year", api.Column.translate_type("date")) }} AS coverage_end_date , payer AS payer_id , secondary_payer AS secondary_payer_id , "ownership" AS plan_owner_relationship diff --git a/models/staging/synthea/stg_synthea__procedures.sql b/models/staging/synthea/stg_synthea__procedures.sql index 32ba41e..40c9383 100644 --- a/models/staging/synthea/stg_synthea__procedures.sql +++ b/models/staging/synthea/stg_synthea__procedures.sql @@ -14,12 +14,14 @@ WITH cte_procedures_lower AS ( SELECT "start" AS procedure_start_datetime + , {{ dbt.cast("start", api.Column.translate_type("date")) }} AS procedure_start_date , "stop" AS procedure_stop_datetime + , {{ dbt.cast("stop", api.Column.translate_type("date")) }} AS procedure_stop_date , patient AS patient_id , encounter AS encounter_id , code AS procedure_code , "description" AS procedure_description - , base_cost AS procedure_base_cost + , {{ dbt.cast("base_cost", api.Column.translate_type("decimal")) }} AS procedure_base_cost , reasoncode AS procedure_reason_code , reasondescription AS procedure_reason_description FROM cte_procedures_lower diff --git a/package-lock.yml b/package-lock.yml index 5e486a0..17c0350 100644 --- a/package-lock.yml +++ b/package-lock.yml @@ -1,4 +1,4 @@ packages: - package: dbt-labs/dbt_utils - version: 1.2.0 -sha1_hash: d4f259856543b0ef301e0b3b0bbc94ccb6b12a54 + version: 1.3.0 +sha1_hash: 226ae69cdfbc9367e2aa2c472b01f99dbce11de0 diff --git a/seeds/vocabulary/_sources.yml b/seeds/vocabulary/_sources.yml index 327bbd8..5162d24 100644 --- a/seeds/vocabulary/_sources.yml +++ b/seeds/vocabulary/_sources.yml @@ -32,3 +32,4 @@ seeds: valid_start_date: date valid_end_date: date invalid_reason: varchar + \ No newline at end of file