Skip to content

Commit d9d10c8

Browse files
authored
Merge pull request #104 from mcwdsi/resolve-duplicate-ndcs
fixed duplicate NDCs, updated script to hopefully prevent them in the…
2 parents fa22f4a + afda7de commit d9d10c8

File tree

5 files changed

+113
-95
lines changed

5 files changed

+113
-95
lines changed

src/scripts/update-dron-from-rxnorm.sql

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ WHERE r.RELA = 'has_inactive_ingredient'
256256
AND c2.RXAUI = r.RXAUI2
257257
AND c2.RXCUI = bd.rxcui;
258258

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

274-
-- Add NDCs for clinical drugs not already in that table.
277+
-- Add NDCs for clinical drugs not already in ndc_clinical_drug or ndc_branded_drug.
275278
INSERT OR IGNORE INTO ndc_clinical_drug
276279
SELECT DISTINCT
277280
NULL AS curie,
@@ -285,4 +288,29 @@ WHERE s.RXCUI = cd.rxcui
285288
AND s.SAB = 'RXNORM'
286289
AND s.ATN = 'NDC'
287290
AND n.curie IS NULL
288-
AND s.ATV not in (select ndc from ndc_branded_drug);
291+
AND s.ATV not in (select ndc from ndc_branded_drug);
292+
293+
-- In the event that there is an NDC in ndc_clinical_drug, and that is now--
294+
-- in the current version of RxNorm that we are processing--
295+
-- associated with a branded drug, then we will isnert a row in
296+
-- ndc_branded_drug for this new association. Later, we will deal
297+
-- with the redundancy.
298+
INSERT INTO ndc_branded_drug
299+
SELECT DISTINCT
300+
n.curie as curie,
301+
n.ndc as ndc,
302+
bd.curie as drug
303+
FROM rxnorm.RXNSAT as s,
304+
branded_drug as bd,
305+
ndc_clinical_drug AS n
306+
WHERE s.ATV = n.ndc
307+
AND s.RXCUI = bd.RXCUI
308+
AND s.SAB = 'RXNORM'
309+
AND s.ATN = 'NDC';
310+
311+
-- Here, we delete anything that got duplicated in the previous step.
312+
-- If we updated the NDC to a new branded_drug association, then
313+
-- we created a new row in ndc_branded_drug, and to avoid duplicawtion
314+
-- now here will remove all such dups from ndc_clinical_drug
315+
DELETE from ndc_clinical_drug
316+
WHERE ndc in (select ndc from ndc_branded_drug);

src/templates/ingredient.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ CHEBI:7465 naltrexone 7243
25142514
CHEBI:7466 nandrolone 7244
25152515
CHEBI:74669 1,2-dioleoyl-sn-glycero-3-phosphocholine 1424656
25162516
CHEBI:746859 travoprost 283809
2517-
CHEBI:746867 remibrutinib 2724365
2517+
CHEBI:746867 Remibrutinib 2724365
25182518
CHEBI:746908 lurbinectedin 2374729
25192519
CHEBI:7470 Naphazoline 7247
25202520
CHEBI:7476 naproxen 7258

0 commit comments

Comments
 (0)