-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrxnorm.sql
More file actions
59 lines (48 loc) · 2.08 KB
/
rxnorm.sql
File metadata and controls
59 lines (48 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Create rxnorm tables
# Yen Low 11-Dec-13
drop table if exists rxnorm.rxnorm_rxid;
create table rxnorm.rxnorm_rxid as
SELECT b.code as ingredient,
c.code as drug
FROM terminology3.rxnorm_cui a,
umls2011ab.MRCONSO b, umls2011ab.MRCONSO c
where b.sab='RXNORM' and a.ingredient=b.cui
and c.sab='RXNORM' and a.drug=c.cui;
alter table rxnorm.rxnorm_rxid modify ingredient mediumint(8), modify drug mediumint(8);
alter table rxnorm.rxnorm_rxid add index (ingredient), add index (drug);
#Create rxnorm.pin2in tables mapping precise ingredient to ingredient
create table rxnorm.pin2in_cui as
SELECT CUI1 as PIN, CUI2 as `IN`
FROM umls2011ab.MRREL
where sab='RXNORM' and rela like 'has_form';
drop table if exists user_yenlow.tmp;
create table user_yenlow.tmp as
select cid, cui from terminology3.str2cid where grp=2;
drop table if exists rxnorm.pin2in;
create table rxnorm.pin2in as
SELECT b.cid as PIN, c.cid as `IN`
FROM rxnorm.pin2in_cui a, user_yenlow.tmp b, user_yenlow.tmp c
where a.pin=b.cui and a.in=c.cui;
ALTER TABLE rxnorm.pin2in MODIFY pin int(8) NOT NULL;
ALTER TABLE rxnorm.pin2in MODIFY `in` int(8) NOT NULL;
ALTER TABLE rxnorm.pin2in ADD index(pin), ADD index(`in`);
drop table if exists user_yenlow.tmp2;
create table user_yenlow.tmp2
select a.ingredient as rxcui, b.cui, b.str
from (select distinct ingredient from rxnorm.rxnorm_rxid) a
left outer join umls2011ab.MRCONSO b
on a.ingredient=b.code
where b.sab='rxnorm' and b.tty='in';
alter table user_yenlow.tmp2 modify rxcui mediumint(8), modify cui char(8);
alter table user_yenlow.tmp2 add index (cui);
drop table if exists rxnorm.cid2rxcui_ingredient;
create table rxnorm.cid2rxcui_ingredient
select distinct a.*, c.cid
from user_yenlow.tmp2 a,
(select cui, cid from terminology3.str2cid where grp=2) c
where a.cui=c.cui;
select * from rxnorm.cid2rxcui_ingredient limit 10;
alter table rxnorm.cid2rxcui_ingredient drop str, drop cui;
alter table rxnorm.cid2rxcui_ingredient add index (rxcui), add index (cid);
drop table user_yenlow.tmp;
drop table user_yenlow.tmp2;