Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor visit and cost models, plus other small changes #111

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
templater = dbt
dialect = postgres
sql_file_exts = .sql,.sql.j2,.dml,.ddl
exclude_rules = L031, L014, ST06, LT05, RF02, RF03
exclude_rules = L031, L014, ST06, LT05
large_file_skip_byte_limit = 0

[sqlfluff:indentation]
Expand Down
11 changes: 0 additions & 11 deletions models/intermediate/int__all_visits.sql

This file was deleted.

50 changes: 0 additions & 50 deletions models/intermediate/int__assign_all_visit_ids.sql

This file was deleted.

77 changes: 0 additions & 77 deletions models/intermediate/int__cost_condition.sql

This file was deleted.

43 changes: 0 additions & 43 deletions models/intermediate/int__cost_drug_exposure_1.sql

This file was deleted.

43 changes: 0 additions & 43 deletions models/intermediate/int__cost_drug_exposure_2.sql

This file was deleted.

45 changes: 0 additions & 45 deletions models/intermediate/int__cost_procedure.sql

This file was deleted.

34 changes: 34 additions & 0 deletions models/intermediate/int__drug_exposure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
WITH all_drugs AS (
SELECT * FROM {{ ref('int__drug_medications') }}
UNION ALL
SELECT * FROM {{ ref('int__drug_immunisations') }}
)

SELECT
row_number() OVER (ORDER BY person_id, drug_concept_id, drug_exposure_start_datetime) AS drug_exposure_id
, drug_base_cost
, drug_paid_by_payer
, person_id
, drug_concept_id
, drug_exposure_start_date
, drug_exposure_start_datetime
, drug_exposure_end_date
, drug_exposure_end_datetime
, verbatim_end_date
, drug_type_concept_id
, stop_reason
, refills
, quantity
, days_supply
, sig
, route_concept_id
, lot_number
, provider_id
, visit_occurrence_id
, visit_detail_id
, drug_source_value
, drug_source_concept_id
, route_source_value
, dose_unit_source_value
FROM
all_drugs
12 changes: 7 additions & 5 deletions models/intermediate/int__drug_immunisations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ SELECT
p.person_id
, i.patient_id
, i.encounter_id
, epr.provider_id
, epr.visit_occurrence_id
, epr.visit_occurrence_id + 1000000 AS visit_detail_id
, vd.provider_id
, vd.visit_occurrence_id
, vd.visit_detail_id
, srctostdvm.target_concept_id AS drug_concept_id
, {{ dbt.cast("i.immunization_date", api.Column.translate_type("date")) }} AS drug_exposure_start_date
, i.immunization_date AS drug_exposure_start_datetime
Expand All @@ -23,6 +23,8 @@ SELECT
, srctosrcvm.source_concept_id AS drug_source_concept_id
, {{ 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
, i.immunization_base_cost AS drug_base_cost
, {{ dbt.cast("null", api.Column.translate_type("numeric")) }} AS drug_paid_by_payer
FROM {{ ref ('stg_synthea__immunizations') }} AS i
INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm
ON
Expand All @@ -37,5 +39,5 @@ INNER JOIN {{ ref ('int__source_to_source_vocab_map') }} AS srctosrcvm
AND srctosrcvm.source_vocabulary_id = 'CVX'
INNER JOIN {{ ref ('int__person') }} AS p
ON i.patient_id = p.person_source_value
LEFT JOIN {{ ref ('int__encounter_provider') }} AS epr
ON i.encounter_id = epr.encounter_id
LEFT JOIN {{ ref ('int__visit_detail') }} AS vd
ON i.encounter_id = vd.visit_detail_source_value
12 changes: 7 additions & 5 deletions models/intermediate/int__drug_medications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ SELECT
p.person_id
, m.patient_id
, m.encounter_id
, epr.provider_id
, epr.visit_occurrence_id
, epr.visit_occurrence_id + 1000000 AS visit_detail_id
, vd.provider_id
, vd.visit_occurrence_id
, vd.visit_detail_id
, srctostdvm.target_concept_id AS drug_concept_id
, m.medication_start_date AS drug_exposure_start_date
, m.medication_start_datetime AS drug_exposure_start_datetime
Expand All @@ -27,6 +27,8 @@ SELECT
, srctosrcvm.source_concept_id AS drug_source_concept_id
, {{ 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
, m.medication_base_cost AS drug_base_cost
, m.medication_payer_coverage AS drug_paid_by_payer
FROM {{ ref ('stg_synthea__medications') }} AS m
INNER JOIN {{ ref ('int__source_to_standard_vocab_map') }} AS srctostdvm
ON
Expand All @@ -41,5 +43,5 @@ INNER JOIN {{ ref ('int__source_to_source_vocab_map') }} AS srctosrcvm
AND srctosrcvm.source_vocabulary_id = 'RxNorm'
INNER JOIN {{ ref ('int__person') }} AS p
ON m.patient_id = p.person_source_value
LEFT JOIN {{ ref ('int__encounter_provider') }} AS epr
ON m.encounter_id = epr.encounter_id
LEFT JOIN {{ ref ('int__visit_detail') }} AS vd
ON m.encounter_id = vd.visit_detail_source_value
14 changes: 0 additions & 14 deletions models/intermediate/int__encounter_provider.sql

This file was deleted.

Loading