diff --git a/dbt/sagerx/models/marts/products/brand_products_with_related_ndcs.sql b/dbt/sagerx/models/marts/products/brand_products_with_related_ndcs.sql new file mode 100644 index 00000000..ec5a02a0 --- /dev/null +++ b/dbt/sagerx/models/marts/products/brand_products_with_related_ndcs.sql @@ -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 diff --git a/dbt/sagerx/models/marts/products/products.sql b/dbt/sagerx/models/marts/products/products.sql new file mode 100644 index 00000000..31cb1cea --- /dev/null +++ b/dbt/sagerx/models/marts/products/products.sql @@ -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