-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIMIC3-delirium_extraction.txt
239 lines (167 loc) · 12.2 KB
/
MIMIC3-delirium_extraction.txt
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
1) from clinical actions (pqsl commands)
********************************************************** PRESCRIPTIONS ************************************************************
** For patients with delirium ICD-9 codes **
\copy (SELECT admissions.hadm_id,
prescriptions.drug, prescriptions.drug_name_generic, prescriptions.drug_name_poe,
prescriptions.startdate
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN prescriptions ON admissions.hadm_id = prescriptions.hadm_id
WHERE diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097') ) to '/output/prescriptions_with.csv' WITH CSV HEADER;
** For patients without delirium ICD-9 codes: **
\copy (SELECT admissions.hadm_id,
prescriptions.drug, prescriptions.drug_name_generic, prescriptions.drug_name_poe,
prescriptions.startdate
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN prescriptions ON admissions.hadm_id = prescriptions.hadm_id
WHERE diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097') ) to '/output/prescriptions_WO.csv' WITH CSV HEADER;
********************************************************** PROCEDURES ************************************************************
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
noteevents.category, noteevents.description
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE noteevents.category = 'Radiology'
AND diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/radiology_with.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
noteevents.category, noteevents.description
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE noteevents.category = 'Radiology'
AND diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/radiology_WO.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
noteevents.category, noteevents.description
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE noteevents.category = 'ECG'
AND diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/ecg_with.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
noteevents.category, noteevents.description
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE noteevents.category = 'ECG'
AND diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/ecg_WO.csv' WITH CSV HEADER;
********************************************************** LABS ************************************************************
\copy (SELECT admissions.hadm_id,
d_labitems.label, d_labitems.fluid, d_labitems.category,
labevents.charttime, labevents.value, labevents.valuenum
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN labevents
INNER JOIN d_labitems ON labevents.itemid = d_labitems.itemid
ON admissions.hadm_id = labevents.hadm_id
WHERE diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/labs_with.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
d_labitems.label, d_labitems.fluid, d_labitems.category,
labevents.charttime, labevents.value, labevents.valuenum
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN labevents
INNER JOIN d_labitems ON labevents.itemid = d_labitems.itemid
ON admissions.hadm_id = labevents.hadm_id
WHERE diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/labs_WO.csv' WITH CSV HEADER;
********************************************************** MICROBIOLOGY ************************************************************
\copy (SELECT admissions.hadm_id,
microbiologyevents.chartdate, microbiologyevents.charttime,
microbiologyevents.spec_itemid, microbiologyevents.spec_type_desc,
microbiologyevents.org_name
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN microbiologyevents
ON admissions.hadm_id = microbiologyevents.hadm_id
WHERE diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/microbiology_with.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
microbiologyevents.chartdate, microbiologyevents.charttime,
microbiologyevents.spec_itemid, microbiologyevents.spec_type_desc,
microbiologyevents.org_name
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN microbiologyevents
ON admissions.hadm_id = microbiologyevents.hadm_id
WHERE diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/microbiology_WO.csv' WITH CSV HEADER;
********************************************************** WORDS ************************************************************
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
regexp_matches(noteevents.text, 'AMS', 'i'),
regexp_matches(noteevents.text, 'mental status', 'i'),
regexp_matches(noteevents.text, 'deliri', 'i'),
regexp_matches(noteevents.text, 'hallucin', 'i'),
regexp_matches(noteevents.text, 'confus', 'i'),
regexp_matches(noteevents.text, 'reorient', 'i'),
regexp_matches(noteevents.text, 'disorient', 'i'),
regexp_matches(noteevents.text, 'encephalopathy', 'i')
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/words_with.csv' WITH CSV HEADER;
\copy (SELECT admissions.hadm_id,
noteevents.cgid, noteevents.chartdate,
regexp_matches(noteevents.text, 'AMS', 'i'),
regexp_matches(noteevents.text, 'mental status', 'i'),
regexp_matches(noteevents.text, 'deliri', 'i'),
regexp_matches(noteevents.text, 'hallucin', 'i'),
regexp_matches(noteevents.text, 'confus', 'i'),
regexp_matches(noteevents.text, 'reorient', 'i'),
regexp_matches(noteevents.text, 'disorient', 'i'),
regexp_matches(noteevents.text, 'encephalopathy', 'i')
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN noteevents ON admissions.hadm_id = noteevents.hadm_id
WHERE diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903',
'29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384',
'29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002',
'2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831',
'34839', '34982', '78097')) to '/output/words_WO.csv' WITH CSV HEADER;
********************************************************** DEMOGRAPHICS ************************************************************
\copy (SELECT admissions.hadm_id,
admissions.admittime, admissions.dischtime, admissions.deathtime,
admissions.admission_type, admissions.admission_location, admissions.discharge_location,
admissions.insurance, admissions.language, admissions.religion, admissions.marital_status,
admissions.ethnicity, admissions.hospital_expire_flag,
diagnoses_icd.icd9_code,
d_icd_diagnoses.short_title,
patients.subject_id, patients.gender, patients.dob, patients.dod,
icustays.los,
drgcodes.drg_type, drgcodes.drg_code, drgcodes.description,
drgcodes.drg_severity, drgcodes.drg_mortality
FROM admissions
LEFT JOIN diagnoses_icd ON admissions.hadm_id = diagnoses_icd.hadm_id
LEFT JOIN d_icd_diagnoses ON diagnoses_icd.icd9_code = d_icd_diagnoses.icd9_code
LEFT JOIN patients ON admissions.subject_id = patients.subject_id
LEFT JOIN icustays ON admissions.hadm_id = icustays.hadm_id
LEFT JOIN drgcodes ON admissions.hadm_id = drgcodes.hadm_id) to '/output/dems.csv' WITH CSV HEADER;
********************************************************** OUTCOMES ************************************************************
\copy (SELECT diagnoses_icd.hadm_id
FROM diagnoses_icd
WHERE diagnoses_icd.icd9_code IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/positive_del.csv' WITH CSV HEADER;
\copy (SELECT diagnoses_icd.hadm_id
FROM diagnoses_icd
WHERE diagnoses_icd.icd9_code NOT IN ('2930', '2931', '29281', '29011', '2903', '29041', '2910', '2939', '78009', '29381', '29382', '29383', '29384', '29389', '29012', '29013', '29043', '29211', '29212', '2922', '78002', '2902', '29042', '2908', '2909', '2920', '29282', '3483', '34831', '34839', '34982', '78097')) to '/output/negative_del.csv' WITH CSV HEADER;