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

Get RxNorm data models up to speed with dbt best practices #280

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions dbt/sagerx/macros/active_and_prescribable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro active_and_prescribable() %}
case
when suppress = 'N'
then true
else false
end as active,
case
when cvf = '4096'
then true
else false
end as prescribable
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
-- int_mthspl_products_to_active_ingredients.sql

with

substance as (

select * from {{ ref('stg_rxnorm__mthspl_substances') }}

),

product as (
with substance as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_substances') }}
)

select * from {{ ref('stg_rxnorm__mthspl_products') }}
, product as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_products') }}
)

, rxnrel AS (
SELECT * FROM {{ source('rxnorm', 'rxnorm_rxnrel') }}
)

select distinct
Expand All @@ -26,7 +24,7 @@ select distinct
, substance.tty as active_ingredient_tty
, product.active as active
, product.prescribable as prescribable
from sagerx_lake.rxnorm_rxnrel rxnrel
from rxnrel
inner join substance
on rxnrel.rxaui1 = substance.rxaui
inner join product
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
-- int_mthspl_products_to_active_moieties.sql

with

substance as (

select * from {{ ref('stg_rxnorm__mthspl_substances') }}

),

product as (
with substance as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_substances') }}
)

select * from {{ ref('stg_rxnorm__mthspl_products') }}
, product as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_products') }}
)

, rxnrel AS (
SELECT * FROM {{ source('rxnorm', 'rxnorm_rxnrel') }}
)

select distinct
Expand All @@ -26,7 +24,7 @@ select distinct
, substance.tty as active_moiety_tty
, product.active as active
, product.prescribable as prescribable
from sagerx_lake.rxnorm_rxnrel rxnrel
from rxnrel
inner join substance
on rxnrel.rxaui1 = substance.rxaui
inner join product
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
-- int_mthspl_products_to_inactive_ingredients.sql

with

substance as (

select * from {{ ref('stg_rxnorm__mthspl_substances') }}

),

product as (
with substance as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_substances') }}
)

select * from {{ ref('stg_rxnorm__mthspl_products') }}
, product as (
SELECT * FROM {{ ref('stg_rxnorm__mthspl_products') }}
)

, rxnrel AS (
SELECT * FROM {{ source('rxnorm', 'rxnorm_rxnrel') }}
)

select distinct
Expand All @@ -26,7 +24,7 @@ select distinct
, substance.tty as inactive_ingredient_tty
, product.active as active
, product.prescribable as prescribable
from sagerx_lake.rxnorm_rxnrel rxnrel
from rxnrel
inner join substance
on rxnrel.rxaui1 = substance.rxaui
inner join product
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
with all_ndcs as
(
select * from {{ ref('stg_rxnorm__all_ndcs') }}
),
)

product_rxcuis as
, product_rxcuis as
(
select * from sagerx_lake.rxnorm_rxnconso
select * from {{ source('rxnorm', 'rxnorm_rxnconso') }}
where sab = 'RXNORM'
and tty in ('SCD', 'SBD', 'GPCK', 'BPCK')
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
-- int_rxnorm_clinical_products_to_clinical_product_components.sql

with

ndc as (

with ndc as (
select * from {{ ref('stg_rxnorm__ndcs') }}
)

),

rcp as (

, rcp as (
select * from {{ ref('stg_rxnorm__clinical_products') }}
)

),

rcpcl as (

, rcpcl as (
select * from {{ ref('stg_rxnorm__clinical_product_component_links') }}
)

),

rcpc as (

, rcpc as (
select * from {{ ref('stg_rxnorm__clinical_product_components') }}

)

select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
-- int_rxnorm_clinical_products_to_dose_forms.sql

with

rcp as (

with rcp as (
select * from {{ ref('stg_rxnorm__clinical_products') }}
)

),

rcpcl as (

, rcpcl as (
select * from {{ ref('stg_rxnorm__clinical_product_component_links') }}
)

),

rcpc as (

, rcpc as (
select * from {{ ref('stg_rxnorm__clinical_product_components') }}
)

),

rdf as (

, rdf as (
select * from {{ ref('stg_rxnorm__dose_forms') }}

)

select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
-- int_rxnorm_clinical_products_to_ingredient_components.sql

with

rcp as (

with rcp as (
select * from {{ ref('stg_rxnorm__clinical_products') }}
)

),

rcpcl as (

, rcpcl as (
select * from {{ ref('stg_rxnorm__clinical_product_component_links') }}
)

),

rcpc as (

, rcpc as (
select * from {{ ref('stg_rxnorm__clinical_product_components') }}
)

),

rdf as (

, rdf as (
select * from {{ ref('stg_rxnorm__dose_forms') }}
)

),

ri as (

, ri as (
select * from {{ ref('stg_rxnorm__ingredients') }}
)

),

ricl as (

, ricl as (
select * from {{ ref('stg_rxnorm__ingredient_component_links') }}
)

),

ric as (

, ric as (
select * from {{ ref('stg_rxnorm__ingredient_components') }}

)

select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,47 @@
-- int_rxnorm_clinical_products_to_ingredient_strengths.sql

with

rcp as (

with rcp as (
select * from {{ ref('stg_rxnorm__clinical_products') }}
)

),

rcpcl as (

, rcpcl as (
select * from {{ ref('stg_rxnorm__clinical_product_component_links') }}
)

),

rcpc as (

, rcpc as (
select * from {{ ref('stg_rxnorm__clinical_product_components') }}
)

),

rdf as (

, rdf as (
select * from {{ ref('stg_rxnorm__dose_forms') }}
)

),

ri as (

, ri as (
select * from {{ ref('stg_rxnorm__ingredients') }}
)

),

ricl as (

, ricl as (
select * from {{ ref('stg_rxnorm__ingredient_component_links') }}
)

),

ric as (

, ric as (
select * from {{ ref('stg_rxnorm__ingredient_components') }}
)

),

risl as (

, risl as (
select * from {{ ref('stg_rxnorm__ingredient_strength_links') }}
)

),

ris as (

, ris as (
select * from {{ ref('stg_rxnorm__ingredient_strengths') }}
)

),

pinl as (

, pinl as (
select * from {{ ref('stg_rxnorm__precise_ingredient_links') }}
)

),

pin as (

, pin as (
select * from {{ ref('stg_rxnorm__precise_ingredients') }}

)

select
Expand Down
Loading