-
Notifications
You must be signed in to change notification settings - Fork 1
/
diagnosis_analysis.sql
256 lines (248 loc) · 7.46 KB
/
diagnosis_analysis.sql
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* This file finds shows stats reagrding Ds-connect vs CDM completeness in diagnosis data
*/
-------------------------
---find patient that have
---dementia, alzahimre, cognitive decline
---from CDM and DS connect
-------------------------
-- CDM
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND dx LIKE 'F03%'
OR dx LIKE 'F01%'
OR dx LIKE 'F02%'
OR dx LIKE 'G30'
OR dx IN ('331.0', '331.1', '294.2', '294.1', '331.83', 'R41.81', 'G31.84')
-- DS-connect
SELECT
col4,
col224,
col327,
col328,
col329,
col941
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col224 != 'No';
/** DS connect columns(col224, col327, col328, col329, col941):
* Has the participant ever been diagnosed with Dementia, Alzheimer's disease, or cognitive decline?
* Has the participant ever been diagnosed with Dementia, Alzheimer's disease, or cognitive decline?_Adult
* What was the age of the participant at the earliest onset of dementia symptoms?
* What was the age of the participant at diagnosis of Dementia, Alzheimer's disease, or cognitive decline?
* If the participant has had a brain imaging study, what was the reason for obtaining the study? (Select all that apply.) - Symptoms of dementia
*/
-- find the intersection between CDM and DS-connect patients
SELECT
col4
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col224 != 'No'
AND (length(col224) > 10
OR col327 = 'Yes')
INTERSECT
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND dx LIKE 'F03%'
OR dx LIKE 'F01%'
OR dx LIKE 'F02%'
OR dx LIKE 'G30'
OR dx IN ('331.0', '331.1', '294.2', '294.1', '331.83', 'R41.81', 'G31.84')
-------------------------
---find patient that have
---Sleep Apnea
---from CDM and DS connect
-------------------------
-- CDM
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND dx = 'G47.33'
OR dx = '327.23'
-- DS-connect
SELECT
col4,
col91,
col487
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col91 = '1';
/* DS connect columns (col91, col487):
* Which of the following sleep problems have been diagnosed? (Select all that apply.) - Sleep apnea
* Has a doctor ever diagnosed the participant with sleep apnea based on a sleep study?
*
*/
-- find the intersection between CDM and DS-connect patients
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND dx = 'G47.33'
OR dx = '327.23'
UNION
SELECT
col4
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col91 = '1';
-------------------------
---find patient that have
---Diabetes
---from CDM and DS connect
-------------------------
-- CDM
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND (dx LIKE 'E08%'
OR dx LIKE 'E09%'
OR dx LIKE 'E10%'
OR dx LIKE 'E11%'
OR dx LIKE 'E13%')
-- DS-connect
SELECT
col4,
col132,
col735
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col132 = 'Yes';
/* DS connect columns (col132, col735):
* Has the participant ever been diagnosed with diabetes?
* Did the participant's mother have any of the following conditions or treatments during her pregnancy with the participant? (Select all that apply.) - Gestational diabetes (diabetes during pregnancy)
*/
-- find the intersection between CDM and DS-connect patients
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND (dx LIKE 'E08%'
OR dx LIKE 'E09%'
OR dx LIKE 'E10%'
OR dx LIKE 'E11%'
OR dx LIKE 'E13%')
INTERSECT
SELECT DISTINCT
dc.col4
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND col132 = 'Yes';
-------------------------
---find patient that have
---Depression
---from CDM and DS connect
-------------------------
--CDM
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND (dx LIKE 'F32%'
OR dx LIKE 'F33%'
OR dx LIKE 'F31%'
OR dx LIKE '296.2%'
OR dx LIKE '296.3%'
OR dx LIKE '296%')
-- DS-connect
SELECT
col192,
col198,
col319,
col897,
col909
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND (col192 = '1'
OR col198 = '1'
OR col897 = 'Currently a problem'
OR col909 = 'Currently a problem')
/* DS connect columns (col192, col198, col319, col897, col909):
* Has the participant ever been diagnosed with any of the following behavioral or mental health conditions? (Select all that apply.) - Depression
* Has the participant ever been diagnosed with any of the following behavioral or mental health conditions? (Select all that apply.) - Bipolar/manic depression
* What is the status and age at diagnosis for each of these conditions? (Select all that apply.) - Depression - Status
* For the following behavioral or mental health conditions, select the status and age in years at diagnosis for the participant. (Select all that apply) - Depression - Status
* For the following behavioral or mental health conditions, select the status and age in years at diagnosis for the participant. (Select all that apply) - Bipolar/manic depression - Status
*
*/
-- find the intersection between CDM and DS-connect patients
SELECT DISTINCT
d.patid
FROM
diagnosis_all d
JOIN consented c ON c.record_id = d.patid
JOIN ds_connect dc ON c.record_id = dc.col4
WHERE
c.ehr_access_agree = 1
AND (dx LIKE 'F32%'
OR dx LIKE 'F33%'
OR dx LIKE 'F31%'
OR dx LIKE '296.2%'
OR dx LIKE '296.3%'
OR dx LIKE '296%')
INTERSECT
SELECT
dc.col4
FROM
ds_connect dc
JOIN consented c ON c.record_id = dc.col4
WHERE
c.dsconnect_access_agree = 1
AND (col192 = '1'
OR col198 = '1'
OR col897 = 'Currently a problem'
OR col909 = 'Currently a problem')