Skip to content

Commit b23c55f

Browse files
committed
updating script that builds dron tables from rxnorm tables. Fixes #74
1 parent 72d6c72 commit b23c55f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ CREATE TABLE new_ingredient (
5656
-- the RXCUI1 is the ingredient
5757
-- and the RXCUI2 is the clinical drug form.
5858
INSERT OR IGNORE INTO new_ingredient
59+
SELECT DISTINCT
60+
c.RXCUI AS rxcui,
61+
c.STR AS label
62+
FROM new_clinical_drug_form AS cdf
63+
LEFT JOIN rxnorm.RXNREL AS r ON r.RXCUI2 = cdf.rxcui
64+
LEFT JOIN rxnorm.RXNCONSO AS c ON c.RXCUI = r.RXCUI1
65+
WHERE r.RELA = 'has_ingredient'
66+
AND c.SAB = 'RXNORM'
67+
AND c.RXCUI NOT IN (SELECT rxcui FROM dron.ingredient);
68+
69+
-- Find new ingredients for existing clinical drug forms.
70+
-- Shouldn't happen going forward but needed to fix first time.
71+
-- We join the RXNREL table
72+
-- where the relation is 'has_ingredient'
73+
-- the RXCUI1 is the ingredient
74+
-- and the RXCUI2 is the clinical drug form.
75+
INSERT OR IGNORE INTO new_ingredient
5976
SELECT DISTINCT
6077
c.RXCUI AS rxcui,
6178
c.STR AS label

0 commit comments

Comments
 (0)