-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
dbt/sagerx/models/marts/products/brand_products_with_related_ndcs.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |