-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdm_cut.sql
201 lines (165 loc) · 3.68 KB
/
cdm_cut.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
/**
* CDM cut for DS-DETERMINED cohort
*/
DROP TABLE IF EXISTS condition;
CREATE TABLE condition AS
SELECT
c.*
FROM
cdm60_deid_dataset."condition" c
JOIN pcornet_trial pt ON pt.patid = c.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS death;
CREATE TABLE death AS
SELECT
d.*
FROM
cdm60_deid_dataset."death" d
JOIN pcornet_trial pt ON pt.patid = d.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS death_cause;
CREATE TABLE death_cause AS
SELECT
d.*
FROM
cdm60_deid_dataset."death_cause" d
JOIN pcornet_trial pt ON pt.patid = d.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS demographic;
CREATE TABLE demographic AS
SELECT
d.*
FROM
cdm60_deid_dataset."demographic" d
JOIN pcornet_trial pt ON pt.patid = d.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS diagnosis;
CREATE TABLE diagnosis AS
SELECT
d.*
FROM
cdm60_deid_dataset."diagnosis" d
JOIN pcornet_trial pt ON pt.patid = d.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS dispensing;
CREATE TABLE dispensing AS
SELECT
d.*
FROM
cdm60_deid_dataset."dispensing" d
JOIN pcornet_trial pt ON pt.patid = d.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS encounter;
CREATE TABLE encounter AS
SELECT
e.*
FROM
cdm60_deid_dataset."encounter" e
JOIN pcornet_trial pt ON pt.patid = e.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS enrollment;
CREATE TABLE enrollment AS
SELECT
e.*
FROM
cdm60_deid_dataset."enrollment" e
JOIN pcornet_trial pt ON pt.patid = e.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS immunization;
CREATE TABLE immunization AS
SELECT
i.*
FROM
cdm60_deid_dataset."immunization" i
JOIN pcornet_trial pt ON pt.patid = i.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS lab_result_cm;
CREATE TABLE lab_result_cm AS
SELECT
l.*
FROM
cdm60_deid_dataset."lab_result_cm" l
JOIN pcornet_trial pt ON pt.patid = l.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS lds_address_history;
CREATE TABLE lds_address_history AS
SELECT
l.*
FROM
cdm60_deid_dataset."lds_address_history" l
JOIN pcornet_trial pt ON pt.patid = l.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS med_admin;
CREATE TABLE med_admin AS
SELECT
m.*
FROM
cdm60_deid_dataset."med_admin" m
JOIN pcornet_trial pt ON pt.patid = m.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS obs_clin;
CREATE TABLE obs_clin AS
SELECT
o.*
FROM
cdm60_deid_dataset."obs_clin" o
JOIN pcornet_trial pt ON pt.patid = o.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS obs_gen;
CREATE TABLE obs_gen AS
SELECT
o.*
FROM
cdm60_deid_dataset."obs_gen" o
JOIN pcornet_trial pt ON pt.patid = o.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS prescribing;
CREATE TABLE prescribing AS
SELECT
p.*
FROM
cdm60_deid_dataset."prescribing" p
JOIN pcornet_trial pt ON pt.patid = p.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS PROCEDURES;
CREATE TABLE PROCEDURES AS
SELECT
p.*
FROM
cdm60_deid_dataset."procedures" p
JOIN pcornet_trial pt ON pt.patid = p.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS tumor;
CREATE TABLE tumor AS
SELECT
t.*
FROM
cdm60_deid_dataset."tumor" t
JOIN pcornet_trial pt ON pt.patid = t.patid
WHERE
pt.trialid = 'DS-DETERMINED';
DROP TABLE IF EXISTS vital;
CREATE TABLE vital AS
SELECT
v.*
FROM
cdm60_deid_dataset."vital" v
JOIN pcornet_trial pt ON pt.patid = v.patid
WHERE
pt.trialid = 'DS-DETERMINED';