-
Notifications
You must be signed in to change notification settings - Fork 6
/
r_dataset_snippets_menu_config.smoke_test_setup
345 lines (331 loc) · 15.7 KB
/
r_dataset_snippets_menu_config.smoke_test_setup
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/env Rscript
# This cohort was created using Dataset Builder on 12/09/2021.
#
# Feel free to update it with a new/different cohort, but please follow these two caveats:
# 1) Keep the number of members below 5000 so that the smoke test runs relatively quickly.
# 2) Update dataset prefixes from values like 'dataset_123456789' to 'YOUR_DATASET_NAME'.
# In practice, users of the snippets will do the opposite replacement, but here we want to
# check that the snippets are consistently using the 'YOUR_DATASET_NAME' prefix.
library(bigrquery)
# This query represents dataset "Young hypertensive low BMI" for domain "person" and was generated for All of Us Registered Tier Dataset v5
YOUR_DATASET_NAME_person_sql <- paste("
SELECT
person.person_id,
person.gender_concept_id,
p_gender_concept.concept_name as gender,
person.birth_datetime as date_of_birth,
person.race_concept_id,
p_race_concept.concept_name as race,
person.ethnicity_concept_id,
p_ethnicity_concept.concept_name as ethnicity,
person.sex_at_birth_concept_id,
p_sex_at_birth_concept.concept_name as sex_at_birth
FROM
`person` person
LEFT JOIN
`concept` p_gender_concept
ON person.gender_concept_id = p_gender_concept.concept_id
LEFT JOIN
`concept` p_race_concept
ON person.race_concept_id = p_race_concept.concept_id
LEFT JOIN
`concept` p_ethnicity_concept
ON person.ethnicity_concept_id = p_ethnicity_concept.concept_id
LEFT JOIN
`concept` p_sex_at_birth_concept
ON person.sex_at_birth_concept_id = p_sex_at_birth_concept.concept_id
WHERE
person.PERSON_ID IN (
SELECT
person_id
FROM
`cb_search_person` cb_search_person
WHERE
cb_search_person.person_id IN (
SELECT
person_id
FROM
`cb_search_person` p
WHERE
DATE_DIFF(CURRENT_DATE,dob, YEAR) - IF(EXTRACT(MONTH
FROM
dob)*100 + EXTRACT(DAY
FROM
dob) > EXTRACT(MONTH
FROM
CURRENT_DATE)*100 + EXTRACT(DAY
FROM
CURRENT_DATE),
1,
0) BETWEEN 20 AND 25
AND NOT EXISTS ( SELECT
'x'
FROM
`death` d
WHERE
d.person_id = p.person_id) )
AND cb_search_person.person_id NOT IN (SELECT
criteria.person_id
FROM
(SELECT
DISTINCT person_id,
entry_date,
concept_id
FROM
`cb_search_all_events`
WHERE
(
is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 90.0
AND diastolic <= 60.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 120.0
AND diastolic <= 80.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic BETWEEN 121.0 AND 139.0
AND diastolic BETWEEN 81.0 AND 89.0
OR is_standard = 0
AND concept_id IN (903124)
AND value_as_number >= 20.0
)) criteria ) )", sep="")
YOUR_DATASET_NAME_person_df <- bq_table_download(bq_dataset_query(Sys.getenv("WORKSPACE_CDR"), YOUR_DATASET_NAME_person_sql, billing=Sys.getenv("GOOGLE_PROJECT")), bigint="integer64")
head(YOUR_DATASET_NAME_person_df, 5)
library(bigrquery)
# This query represents dataset "Young hypertensive low BMI" for domain "survey" and was generated for All of Us Registered Tier Dataset v5
YOUR_DATASET_NAME_survey_sql <- paste("
SELECT
answer.person_id,
answer.survey_datetime,
answer.survey,
answer.question_concept_id,
answer.question,
answer.answer_concept_id,
answer.answer,
answer.survey_version_concept_id,
answer.survey_version_name
FROM
`ds_survey` answer
WHERE
(
question_concept_id IN (
1585723, 1585711
)
)
AND (
answer.PERSON_ID IN (
SELECT
person_id
FROM
`cb_search_person` cb_search_person
WHERE
cb_search_person.person_id IN (
SELECT
person_id
FROM
`cb_search_person` p
WHERE
DATE_DIFF(CURRENT_DATE,dob, YEAR) - IF(EXTRACT(MONTH
FROM
dob)*100 + EXTRACT(DAY
FROM
dob) > EXTRACT(MONTH
FROM
CURRENT_DATE)*100 + EXTRACT(DAY
FROM
CURRENT_DATE),
1,
0) BETWEEN 20 AND 25
AND NOT EXISTS ( SELECT
'x'
FROM
`death` d
WHERE
d.person_id = p.person_id) )
AND cb_search_person.person_id NOT IN (SELECT
criteria.person_id
FROM
(SELECT
DISTINCT person_id,
entry_date,
concept_id
FROM
`cb_search_all_events`
WHERE
(
is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 90.0
AND diastolic <= 60.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 120.0
AND diastolic <= 80.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic BETWEEN 121.0 AND 139.0
AND diastolic BETWEEN 81.0 AND 89.0
OR is_standard = 0
AND concept_id IN (903124)
AND value_as_number >= 20.0
)) criteria ) ))", sep="")
YOUR_DATASET_NAME_survey_df <- bq_table_download(bq_dataset_query(Sys.getenv("WORKSPACE_CDR"), YOUR_DATASET_NAME_survey_sql, billing=Sys.getenv("GOOGLE_PROJECT")), bigint="integer64")
head(YOUR_DATASET_NAME_survey_df, 5)
library(bigrquery)
# This query represents dataset "Young hypertensive low BMI" for domain "measurement" and was generated for All of Us Registered Tier Dataset v5
YOUR_DATASET_NAME_measurement_sql <- paste("
SELECT
measurement.person_id,
measurement.measurement_concept_id,
m_standard_concept.concept_name as standard_concept_name,
m_standard_concept.concept_code as standard_concept_code,
m_standard_concept.vocabulary_id as standard_vocabulary,
measurement.measurement_datetime,
measurement.measurement_type_concept_id,
m_type.concept_name as measurement_type_concept_name,
measurement.operator_concept_id,
m_operator.concept_name as operator_concept_name,
measurement.value_as_number,
measurement.value_as_concept_id,
m_value.concept_name as value_as_concept_name,
measurement.unit_concept_id,
m_unit.concept_name as unit_concept_name,
measurement.range_low,
measurement.range_high,
measurement.visit_occurrence_id,
m_visit.concept_name as visit_occurrence_concept_name,
measurement.measurement_source_value,
measurement.measurement_source_concept_id,
m_source_concept.concept_name as source_concept_name,
m_source_concept.concept_code as source_concept_code,
m_source_concept.vocabulary_id as source_vocabulary,
measurement.unit_source_value,
measurement.value_source_value
FROM
( SELECT
*
FROM
`measurement` measurement
WHERE
(
measurement_concept_id IN (
SELECT
DISTINCT c.concept_id
FROM
`cb_criteria` c
JOIN
(
select
cast(cr.id as string) as id
FROM
`cb_criteria` cr
WHERE
domain_id = 'MEASUREMENT'
AND is_standard = 1
AND concept_id IN (
3027018, 3000034, 3036277, 3012888, 3004249, 3025315, 3017250
)
AND is_selectable = 1
AND full_text LIKE '%[measurement_rank1]%'
) a
ON (
c.path LIKE CONCAT('%.',
a.id,
'.%')
OR c.path LIKE CONCAT('%.',
a.id)
OR c.path LIKE CONCAT(a.id,
'.%')
OR c.path = a.id)
WHERE
domain_id = 'MEASUREMENT'
AND is_standard = 1
AND is_selectable = 1
)
)
AND (
measurement.PERSON_ID IN (
SELECT
person_id
FROM
`cb_search_person` cb_search_person
WHERE
cb_search_person.person_id IN (
SELECT
person_id
FROM
`cb_search_person` p
WHERE
DATE_DIFF(CURRENT_DATE,dob, YEAR) - IF(EXTRACT(MONTH
FROM
dob)*100 + EXTRACT(DAY
FROM
dob) > EXTRACT(MONTH
FROM
CURRENT_DATE)*100 + EXTRACT(DAY
FROM
CURRENT_DATE),
1,
0) BETWEEN 20 AND 25
AND NOT EXISTS ( SELECT
'x'
FROM
`death` d
WHERE
d.person_id = p.person_id) )
AND cb_search_person.person_id NOT IN (SELECT
criteria.person_id
FROM
(SELECT
DISTINCT person_id,
entry_date,
concept_id
FROM
`cb_search_all_events`
WHERE
(
is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 90.0
AND diastolic <= 60.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic <= 120.0
AND diastolic <= 80.0
OR is_standard = 0
AND concept_id IN (903118, 903115)
AND systolic BETWEEN 121.0 AND 139.0
AND diastolic BETWEEN 81.0 AND 89.0
OR is_standard = 0
AND concept_id IN (903124)
AND value_as_number >= 20.0
)) criteria ) ))
) measurement
LEFT JOIN
`concept` m_standard_concept
ON measurement.measurement_concept_id = m_standard_concept.concept_id
LEFT JOIN
`concept` m_type
ON measurement.measurement_type_concept_id = m_type.concept_id
LEFT JOIN
`concept` m_operator
ON measurement.operator_concept_id = m_operator.concept_id
LEFT JOIN
`concept` m_value
ON measurement.value_as_concept_id = m_value.concept_id
LEFT JOIN
`concept` m_unit
ON measurement.unit_concept_id = m_unit.concept_id
LEFT JOIn
`visit_occurrence` v
ON measurement.visit_occurrence_id = v.visit_occurrence_id
LEFT JOIN
`concept` m_visit
ON v.visit_concept_id = m_visit.concept_id
LEFT JOIN
`concept` m_source_concept
ON measurement.measurement_source_concept_id = m_source_concept.concept_id", sep="")
YOUR_DATASET_NAME_measurement_df <- bq_table_download(bq_dataset_query(Sys.getenv("WORKSPACE_CDR"), YOUR_DATASET_NAME_measurement_sql, billing=Sys.getenv("GOOGLE_PROJECT")), bigint="integer64")
head(YOUR_DATASET_NAME_measurement_df, 5)