Skip to content

Commit

Permalink
Add product mart dbt docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrlegrand committed May 7, 2024
1 parent 944d086 commit b9a5a84
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
41 changes: 41 additions & 0 deletions dbt/sagerx/models/marts/products/_products__models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2

models:
- name: products
description: |
Product information including name, RXCUI, brand vs generic, ingredient, and dose form.
Data generally comes from RxNorm.
columns:
- name: brand_vs_generic
description: |
Simple (not comprehensive) brand vs generic flag.
If TTY = SBD or BPCK, this will be brand.
If TTY = SCD or GPCK, this will be generic.
- name: brand_products_with_related_ndcs
description: |
Brand Product RXCUI → Related Clinical Product RXCUI → NDCs related to that Clinical Product RXCUI → FDA Start Marketing Dates
columns:
- name: product_tty
description: Will always be SBD or BPCK since we are starting with brand products only.
- name: product_name
description: The name of the brand product we are starting from.
- name: ndc_product_tty
description: |
Could be SCD, SBD, GPCK, BPCK, or null.
A product related to the original brand product based on a clinical product identifier.
Example: starting with a product TTY / RXCUI of SBD 1000000, you could have a related ndc_product
of SBD 1000000 because that brand product relates to itself, as well as a related ndc_product of
SCD 999996 which is the generic version of the same product.
Can have duplicate RXCUIs if there are multiple NDCs related to that RXCUI.
- name: ndc
description: The NDC that relates to the ndc_product_rxcui.
- name: product_startmarketingdate
description: The start marketing date of the **product**. Can be different from that of the package.
- name: package_startmarketingdate
description: The start marketing date of the **package**. Can be different from that of the product.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ with brand_products as (
where product_tty in ('SBD', 'BPCK') -- brand products only
)

, fda_ndcs as (
select * from {{ ref('stg_fda_ndc__ndcs') }}
)

, rxnorm_ndcs_to_products as (
select * from {{ ref('int_rxnorm_ndcs_to_products') }}
)

, 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
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 rxnorm_ndcs_to_products ndc
on ndc.clinical_product_rxcui = prod.clinical_product_rxcui
left join fda_ndcs fda
on fda.ndc11 = ndc.ndc
order by prod.product_rxcui
)

select
Expand Down

0 comments on commit b9a5a84

Please sign in to comment.