Skip to content

Commit

Permalink
Add marts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrlegrand committed May 4, 2024
1 parent 10effdc commit 944d086
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
with brand_products as (
select * from {{ ref('stg_rxnorm__products') }}
where product_tty in ('SBD', 'BPCK') -- brand products only
)

, map as (
select
prod.product_tty
, prod.product_rxcui
, prod.product_name
, ndc.product_tty as ndc_product_tty
, ndc.product_rxcui as ndc_product_rxcui
, ndc.product_name as ndc_product_name
, ndc.ndc
, fda.product_startmarketingdate
, fda.package_startmarketingdate
from brand_products prod
left join sagerx_dev.int_rxnorm_ndcs_to_products ndc
on ndc.clinical_product_rxcui = prod.clinical_product_rxcui
left join sagerx_dev.stg_fda_ndc__ndcs fda
on fda.ndc11 = ndc.ndc
order by prod.product_rxcui
)

select
*
from map
23 changes: 23 additions & 0 deletions dbt/sagerx/models/marts/products/products.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
with rxnorm_products as (
select * from {{ ref('stg_rxnorm__products') }}
)

, rxnorm_clinical_products_to_ingredients as (
select * from {{ ref('int_rxnorm_clinical_products_to_ingredients') }}
)

select
product_rxcui
, product_name
, product_tty
, case
when product_tty in ('SBD', 'BPCK') then 'brand'
when product_tty in ('SCD', 'GPCK') then 'generic'
end as brand_vs_generic
, substring(product_name from '\[(.*)\]') as brand_name
, cping.ingredient_name
-- strength - couldn't easily get strength at this grain - can if needed
, cping.dose_form_name
from rxnorm_products prod
left join rxnorm_clinical_products_to_ingredients cping
on cping.clinical_product_rxcui = prod.clinical_product_rxcui

0 comments on commit 944d086

Please sign in to comment.