Skip to content

Commit bb90edf

Browse files
committed
Updating script to avoid duplicating NDC classes.
1 parent cde8437 commit bb90edf

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,32 +239,33 @@ WHERE r.RELA = 'has_inactive_ingredient'
239239
AND c2.RXAUI = r.RXAUI2
240240
AND c2.RXCUI = bd.rxcui;
241241

242-
-- Add NDCs for clinical drugs not already in that table.
243-
INSERT OR IGNORE INTO ndc_clinical_drug
242+
-- Add NDCs for branded drugs not already in that table.
243+
INSERT OR IGNORE INTO ndc_branded_drug
244244
SELECT DISTINCT
245245
NULL AS curie,
246246
s.ATV AS ndc,
247-
cd.curie AS drug
247+
bd.curie AS drug
248248
FROM rxnorm.RXNSAT AS s
249-
LEFT JOIN clinical_drug AS cd
250-
LEFT JOIN ndc_clinical_drug AS n
249+
LEFT JOIN branded_drug AS bd
250+
LEFT JOIN ndc_branded_drug AS n
251251
ON s.ATV = n.ndc
252-
WHERE s.RXCUI = cd.rxcui
252+
WHERE s.RXCUI = bd.rxcui
253253
AND s.SAB = 'RXNORM'
254254
AND s.ATN = 'NDC'
255255
AND n.curie IS NULL;
256256

257-
-- Add NDCs for branded drugs not already in that table.
258-
INSERT OR IGNORE INTO ndc_branded_drug
257+
-- Add NDCs for clinical drugs not already in that table.
258+
INSERT OR IGNORE INTO ndc_clinical_drug
259259
SELECT DISTINCT
260260
NULL AS curie,
261261
s.ATV AS ndc,
262-
bd.curie AS drug
262+
cd.curie AS drug
263263
FROM rxnorm.RXNSAT AS s
264-
LEFT JOIN branded_drug AS bd
265-
LEFT JOIN ndc_branded_drug AS n
264+
LEFT JOIN clinical_drug AS cd
265+
LEFT JOIN ndc_clinical_drug AS n
266266
ON s.ATV = n.ndc
267-
WHERE s.RXCUI = bd.rxcui
267+
WHERE s.RXCUI = cd.rxcui
268268
AND s.SAB = 'RXNORM'
269269
AND s.ATN = 'NDC'
270-
AND n.curie IS NULL;
270+
AND n.curie IS NULL
271+
AND s.ATV not in (select ndc from ndc_branded_drug);

0 commit comments

Comments
 (0)