Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/scripts/update-dron-from-rxnorm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ WHERE r.RELA = 'has_inactive_ingredient'
AND c2.RXAUI = r.RXAUI2
AND c2.RXCUI = bd.rxcui;

-- Add NDCs for branded drugs not already in that table.
-- Add NDCs for branded drugs not already in ndc_branded_drug or ndc_clinical_drug.
-- Note that by starting with branded drugs, we prefer branded drug association
-- in hte event that an NDC is associated with both a branded & a clinical drug.
INSERT OR IGNORE INTO ndc_branded_drug
SELECT DISTINCT
NULL AS curie,
Expand All @@ -269,9 +271,10 @@ LEFT JOIN ndc_branded_drug AS n
WHERE s.RXCUI = bd.rxcui
AND s.SAB = 'RXNORM'
AND s.ATN = 'NDC'
AND n.curie IS NULL;
AND n.curie IS NULL
AND s.ATV not in (select ndc from ndc_clinical_drug);

-- Add NDCs for clinical drugs not already in that table.
-- Add NDCs for clinical drugs not already in ndc_clinical_drug or ndc_branded_drug.
INSERT OR IGNORE INTO ndc_clinical_drug
SELECT DISTINCT
NULL AS curie,
Expand All @@ -285,4 +288,29 @@ WHERE s.RXCUI = cd.rxcui
AND s.SAB = 'RXNORM'
AND s.ATN = 'NDC'
AND n.curie IS NULL
AND s.ATV not in (select ndc from ndc_branded_drug);
AND s.ATV not in (select ndc from ndc_branded_drug);

-- In the event that there is an NDC in ndc_clinical_drug, and that is now--
-- in the current version of RxNorm that we are processing--
-- associated with a branded drug, then we will isnert a row in
-- ndc_branded_drug for this new association. Later, we will deal
-- with the redundancy.
INSERT INTO ndc_branded_drug
SELECT DISTINCT
n.curie as curie,
n.ndc as ndc,
bd.curie as drug
FROM rxnorm.RXNSAT as s,
branded_drug as bd,
ndc_clinical_drug AS n
WHERE s.ATV = n.ndc
AND s.RXCUI = bd.RXCUI
AND s.SAB = 'RXNORM'
AND s.ATN = 'NDC';

-- Here, we delete anything that got duplicated in the previous step.
-- If we updated the NDC to a new branded_drug association, then
-- we created a new row in ndc_branded_drug, and to avoid duplicawtion
-- now here will remove all such dups from ndc_clinical_drug
DELETE from ndc_clinical_drug
WHERE ndc in (select ndc from ndc_branded_drug);
2 changes: 1 addition & 1 deletion src/templates/ingredient.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ CHEBI:7465 naltrexone 7243
CHEBI:7466 nandrolone 7244
CHEBI:74669 1,2-dioleoyl-sn-glycero-3-phosphocholine 1424656
CHEBI:746859 travoprost 283809
CHEBI:746867 remibrutinib 2724365
CHEBI:746867 Remibrutinib 2724365
CHEBI:746908 lurbinectedin 2374729
CHEBI:7470 Naphazoline 7247
CHEBI:7476 naproxen 7258
Expand Down
Loading