forked from Erinaceida/mimic3cancerpromin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_select_records_of_selected_patients
187 lines (177 loc) · 5.2 KB
/
02_select_records_of_selected_patients
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--- create subset of admissions table of selected cancer patients
CREATE TABLE cancer.admissions AS
SELECT
admissions.subject_id,
admissions.hadm_id,
admissions.admittime,
admissions.dischtime,
admissions.deathtime,
admissions.edregtime,
admissions.edouttime
FROM
mimiciii.admissions,
mimiciii.diagnoses_icd
WHERE
admissions.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of chartevents table
CREATE TABLE cancer.chartevents AS
SELECT
chartevents.subject_id,
chartevents.hadm_id,
d_items.label activity,
d_items.category category,
chartevents.charttime
FROM
mimiciii.chartevents,
mimiciii.d_items
WHERE
d_items.itemid = chartevents.itemid AND
chartevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of cptevents table
CREATE TABLE cancer.cptevents AS
SELECT
cptevents.subject_id,
cptevents.hadm_id,
d_items.label activity,
d_items.category,
cptevents.chartdate
FROM
mimiciii.diagnoses_icd,
mimiciii.d_items,
mimiciii.cptevents
WHERE
cptevents.cpt_cd = d_items.label AND
cptevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of datetimeevents table
CREATE TABLE cancer.datetimeevents AS
SELECT
datetimeevents.subject_id,
datetimeevents.hadm_id,
d_items.label,
d_items.category,
datetimeevents.charttime
FROM
mimiciii.datetimeevents,
mimiciii.d_items
WHERE
datetimeevents.itemid = d_items.itemid AND
datetimeevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of inputevents_cv table
CREATE TABLE cancer.inputevents_cv AS
SELECT
inputevents_cv.subject_id,
inputevents_cv.hadm_id,
d_items.label,
d_items.category,
inputevents_cv.charttime
FROM
mimiciii.inputevents_cv,
mimiciii.d_items
WHERE
inputevents_cv.itemid = d_items.itemid AND
inputevents_cv.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of inputevents_mv table
CREATE TABLE cancer.inputevents_mv AS
SELECT
inputevents_mv.subject_id,
inputevents_mv.hadm_id,
d_items.label activity,
d_items.category,
inputevents_mv.starttime charttime
FROM
mimiciii.d_items,
mimiciii.inputevents_mv,
mimiciii.d_items
WHERE
d_items.itemid = inputevents_mv.itemid AND
inputevents_mv.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of labevents table
CREATE TABLE cancer.labevents AS
SELECT
labevents.subject_id,
labevents.hadm_id,
d_labitems.label,
d_labitems.category,
labevents.charttime
FROM
mimiciii.d_labitems,
mimiciii.labevents
WHERE
labevents.itemid = d_labitems.itemid AND
labevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of microbiologyevents table
CREATE TABLE cancer.microbiologyevents AS
SELECT
microbiologyevents.subject_id,
microbiologyevents.hadm_id,
d_items.label activity,
d_items.category,
microbiologyevents.charttime
FROM
mimiciii.d_items,
mimiciii.microbiologyevents
WHERE
microbiologyevents.spec_itemid = d_items.itemid AND
microbiologyevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of noteevents table
CREATE TABLE cancer.noteevents AS
SELECT
noteevents.subject_id,
noteevents.hadm_id,
noteevents.description,
noteevents.category,
noteevents.charttime
FROM
mimiciii.noteevents
WHERE
noteevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of outputevents table
CREATE TABLE cancer.outputevents AS
SELECT
outputevents.subject_id,
outputevents.hadm_id,
d_items.label activity,
d_items.category,
outputevents.charttime
FROM
mimiciii.outputevents,
mimiciii.d_items
WHERE
outputevents.itemid = d_items.itemid AND
outputevents.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');
--- create subset of procedureevents_mv table
CREATE TABLE cancer.procedureevents_mv AS
SELECT
procedureevents_mv.subject_id,
procedureevents_mv.hadm_id,
d_items.label activity,
d_items.category,
procedureevents_mv.starttime charttime
FROM
mimiciii.d_items,
mimiciii.procedureevents_mv
WHERE
procedureevents_mv.itemid = d_items.itemid AND
procedureevents_mv.subject_id IN
(SELECT DISTINCT subject_id FROM mimiciii.diagnoses_icd
WHERE icd9_code SIMILAR TO '14%|15%|16%|17%|18%|19%|20%|21%|22%|23%');