-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgetters.jl
854 lines (575 loc) · 21.6 KB
/
getters.jl
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
"""
GetDatabasePersonIDs(conn; tab = person)
Get all unique `person_id`'s from a database.
# Arguments:
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `ids::Vector{Int64}` - the list of persons
"""
function GetDatabasePersonIDs(conn; tab=person)
ids = DBInterface.execute(conn, String(GetDatabasePersonIDs(tab=tab))) |> DataFrame
return convert(Vector{Int}, ids.person_id)
end
"""
GetDatabaseYearRange(conn; tab = observation_period)
Get the years for which data is available from a database.
# Arguments:
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Observation Period table; default `observation_period`
# Returns
- `year_range::NamedTuple{(:first_year, :last_year), Tuple{Int64, Int64}}` - a NamedTuple where `first_year` is the first year data from the database was available and `last_year` where the last year data from the database was available
"""
function GetDatabaseYearRange(conn; tab=observation_period)
years = DBInterface.execute(conn, String(GetDatabaseYearRange(tab=tab))) |> DataFrame
return (first_year=first(years.first_year), last_year=first(years.last_year))
end
"""
GetDatabaseYearRange(; tab = observation_period)
Return SQL to find the years for which data is available from a database.
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Observation Period table; default `observation_period`
# Returns
- `year_range::NamedTuple{(:first_year, :last_year), Tuple{Int64, Int64}}` - a NamedTuple where `first_year` is the first year data from the database was available and `last_year` where the last year data from the database was available
"""
function GetDatabaseYearRange(; tab=observation_period)
sql = From(tab) |>
Group() |>
Select(:first_year => Agg.min(Get.observation_period_end_date),
:last_year => Agg.max(Get.observation_period_end_date)) |>
q -> render(q, dialect=OMOPCDMCohortCreator.dialect)
return String(sql)
end
"""
GetDatabasePersonIDs(; tab = person)
Return SQL statement that gets all unique `person_id`'s from a database.
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `sql::String` - Prepared SQL statement as a `String`
"""
function GetDatabasePersonIDs(; tab=person)
sql =
From(tab) |>
Group(Get.person_id) |>
q ->
render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientState(ids, conn; tab = location, join_tab = person)
Given a list of person IDs, find their home state.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Location table; default `location`
- `join_tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:state`
"""
function GetPatientState(
ids,
conn;
tab=location,
join_tab=person
)
df = DBInterface.execute(conn, GetPatientState(ids; tab=tab, join_tab=join_tab)) |> DataFrame
return df
end
"""
GetPatientState(ids; tab = location, join_tab = person)
Return SQL statement where if given a list of person IDs, find their home state.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Location table; default `location`
- `join_tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:state`
"""
function GetPatientState(
ids;
tab=location,
join_tab=person
)
sql =
From(tab) |>
Select(Get.location_id, Get.state) |>
Join(:join => join_tab, Get.location_id .== Get.join.location_id) |>
Where(Fun.in(Get.join.person_id, ids...)) |>
Select(Get.join.person_id, Get.state) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientGender(ids, conn; tab = person)
Given a list of person IDs, find their gender.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:gender_concept_id`
"""
function GetPatientGender(
ids,
conn;
tab=person
)
df = DBInterface.execute(conn, GetPatientGender(ids; tab=tab)) |> DataFrame
return df
end
"""
GetPatientGender(ids; tab = person)
Return SQL statement that gets the `gender_concept_id` for a given list of `person_id`'s
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:gender_concept_id`
"""
function GetPatientGender(
ids;
tab=person
)
sql =
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Select(Get.person_id, Get.gender_concept_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientEthnicity(ids, conn; tab = person)
Given a list of person IDs, find their ethnicity.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:ethnicity_concept_id`
"""
function GetPatientEthnicity(
ids,
conn;
tab=person
)
df = DBInterface.execute(conn, GetPatientEthnicity(ids; tab=tab)) |> DataFrame
return df
end
"""
GetPatientEthnicity(ids, conn; tab = person)
Return SQL statement that gets the `ethnicity_concept_id` for a given list of `person_id`'s
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:ethnicity_concept_id`
"""
function GetPatientEthnicity(ids; tab=person)
sql =
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Select(Get.person_id, Get.ethnicity_concept_id) |>
q ->
render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientRace(ids, conn; tab = person)
Given a list of person IDs, find their race.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:race_concept_id`
"""
function GetPatientRace(ids, conn; tab=person)
df = DBInterface.execute(conn, GetPatientRace(ids; tab=tab)) |> DataFrame
return df
end
"""
GetPatientRace(ids; tab = person)
Return SQL statement that gets the `race_concept_id` for a given list of `person_id`'s
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:race_concept_id`
"""
function GetPatientRace(ids; tab=person)
sql =
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Select(Get.person_id, Get.race_concept_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientAgeGroup(
ids, conn;
minuend = :now,
age_groupings = [
[0, 9],
[10, 19],
[20, 29],
[30, 39],
[40, 49],
[50, 59],
[60, 69],
[70, 79],
[80, 89],
],
tab = person,
)
Finds all individuals in age groups as specified by `age_groupings`.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `age_groupings` - a vector of age groups of the form `[[10, 19], [20, 29],]` denoting an age group of 10 - 19 and 20 - 29 respectively; age values must subtype of `Integer`
- `minuend` - the year that a patient's `year_of_birth` variable is subtracted from; default `:now`. There are two different options that can be set:
- `:now` - the year as of the day the code is executed given in UTC time
- any year provided by a user as long as it is an `Integer` (such as 2022, 1998, etc.)
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:age_group`
# Note
Age can be difficult to be calculated consistently.
In this case, there are some assumptions made to ensure consistency:
1. According to the OMOP CDM v5.4, only the variable `year_of_birth` is guaranteed for a given patient. This is one of three options used as the minuend in age calculations.
2. The subtrahend is based on what one chooses for the `minuend` key word argument.
The age is then calculated following what is selected based on 1 and 2.
This flexibility is encoded to allow a user to choose how they want age groups calculated as well as clear up an ambiguity on how this is determined.
"""
function GetPatientAgeGroup(
ids,
conn;
minuend=:now,
age_groupings=[
[0, 9],
[10, 19],
[20, 29],
[30, 39],
[40, 49],
[50, 59],
[60, 69],
[70, 79],
[80, 89],
],
tab=person
)
df = DBInterface.execute(conn, GetPatientAgeGroup(ids; minuend=minuend, age_groupings=age_groupings, tab=tab)) |> DataFrame
return df
end
"""
GetPatientAgeGroup(
ids;
minuend = :now,
age_groupings = [
[0, 9],
[10, 19],
[20, 29],
[30, 39],
[40, 49],
[50, 59],
[60, 69],
[70, 79],
[80, 89],
],
tab = person,
)
Return SQL statement that assigns an age group to each patient in a given patient list.
Customized age groupings can be provided as a list.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `age_groupings` - a vector of age groups of the form `[[10, 19], [20, 29],]` denoting an age group of 10 - 19 and 20 - 29 respectively; age values must subtype of `Integer`
- `minuend` - the year that a patient's `year_of_birth` variable is subtracted from; default `:now`. There are two different options that can be set:
- `:now` - the year as of the day the code is executed given in UTC time
- any year provided by a user as long as it is an `Integer` (such as 2022, 1998, etc.)
- `tab` - the `SQLTable` representing the Person table; default `person`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:age_group`
# Note
Age can be difficult to be calculated consistently.
In this case, there are some assumptions made to ensure consistency:
1. According to the OMOP CDM v5.4, only the variable `year_of_birth` is guaranteed for a given patient. This is one of three options used as the minuend in age calculations.
2. The subtrahend is based on what one chooses for the `minuend` key word argument.
The age is then calculated following what is selected based on 1 and 2.
This flexibility is encoded to allow a user to choose how they want age groups calculated as well as clear up an ambiguity on how this is determined.
"""
function GetPatientAgeGroup(
ids;
minuend=:now,
age_groupings=[
[0, 9],
[10, 19],
[20, 29],
[30, 39],
[40, 49],
[50, 59],
[60, 69],
[70, 79],
[80, 89],
],
tab=person
)
minuend = _determine_calculated_year(minuend)
age_arr = []
for grp in age_groupings
push!(age_arr, Get.age .< grp[2] + 1)
push!(age_arr, "$(grp[1]) - $(grp[2])")
end
sql = From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Select(Get.person_id, :age => minuend .- Get.year_of_birth) |>
Define(:age_group => Fun.case(age_arr...)) |>
Select(Get.person_id, Get.age_group) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetPatientVisits(ids, conn; tab = visit_occurrence)
Given a list of person IDs, find all their visits.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Visit Occurrence table; default `visit_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:visit_occurrence_id`
"""
function GetPatientVisits(
ids,
conn;
tab=visit_occurrence
)
df = DBInterface.execute(conn, GetPatientVisits(ids; tab=tab)) |> DataFrame
return df
end
"""
GetPatientVisits(ids; tab = visit_occurrence)
Return SQL statement that returns all `visit_occurrence_id` for a given patient list
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Visit Occurrence table; default `visit_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:visit_occurrence_id`
"""
function GetPatientVisits(
ids;
tab=visit_occurrence
)
sql =
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Select(Get.person_id, Get.visit_occurrence_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetMostRecentConditions(ids, conn; tab = condition_occurrence)
Given a list of person IDs, find their last recorded conditions.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `condition_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:condition_concept_id`
"""
function GetMostRecentConditions(
ids,
conn;
tab=condition_occurrence
)
df = DBInterface.execute(conn, GetMostRecentConditions(ids; tab=tab)) |> DataFrame
return df
end
"""
GetMostRecentConditions(ids; tab = condition_occurrence)
Produces SQL statement that, given a list of person IDs, finds their last recorded conditions.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `condition_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:condition_concept_id`
"""
function GetMostRecentConditions(
ids;
tab=condition_occurrence
)
sql =
From(tab) |>
Join(
:date_tab =>
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Group(Get.person_id) |>
Select(Get.person_id, :last_date => Agg.max(Get.condition_end_date)),
on=Fun.and(
Get.person_id .== Get.date_tab.person_id,
Get.condition_end_date .== Get.date_tab.last_date,
),
) |>
Select(Get.person_id, Get.condition_concept_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetMostRecentVisit(ids, conn; tab = visit_occurrence)
Given a list of person IDs, find their last recorded visit.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Visit Occurrence table; default `visit_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:visit_occurrence_id`
"""
function GetMostRecentVisit(
ids,
conn;
tab=visit_occurrence
)
df = DBInterface.execute(conn, GetMostRecentVisit(ids; tab=tab)) |> DataFrame
return df
end
"""
GetMostRecentVisit(ids, conn; tab = visit_occurrence)
Produces SQL statement that, given a list of person IDs, finds their last recorded visit.
# Arguments:
- `ids` - list of `person_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Visit Occurrence table; default `visit_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:person_id` and `:visit_occurrence_id`
"""
function GetMostRecentVisit(
ids;
tab=visit_occurrence
)
sql =
From(tab) |>
Join(
:date_tab =>
From(tab) |>
Where(Fun.in(Get.person_id, ids...)) |>
Group(Get.person_id) |>
Select(Get.person_id, :last_date => Agg.max(Get.visit_end_date)),
on=Fun.and(
Get.person_id .== Get.date_tab.person_id,
Get.visit_end_date .== Fun.cast(Get.date_tab.last_date, "date"),
),
) |>
Group(Get.person_id) |>
Select(Get.person_id, :visit_occurrence_id => Agg.max(Get.visit_occurrence_id)) |> # ASSUMPTION: IF MULTIPLE VISITS IN ONE DAY, SELECT MOST RECENT visit_occurrence_id
q -> render(q, dialect=dialect)
return String(sql)
end
"""
GetVisitCondition(visit_ids, conn; tab = visit_occurrence)
Given a list of visit IDs, find their corresponding conditions.
# Arguments:
- `visit_ids` - list of `visit_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `condition_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:visit_occurrence_id` and `:condition_concept_id`
"""
function GetVisitCondition(
visit_ids,
conn;
tab=condition_occurrence
)
df = DBInterface.execute(conn, GetVisitCondition(visit_ids; tab=tab)) |> DataFrame
return df
end
"""
GetVisitCondition(visit_ids; tab = visit_occurrence)
Produces SQL statement that, given a list of `visit_id`'s, finds the conditions diagnosed associated with that visit.
# Arguments:
- `visit_ids` - list of `visit_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `condition_occurrence`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:visit_occurrence_id` and `:condition_concept_id`
"""
function GetVisitCondition(
visit_ids;
tab=condition_occurrence
)
sql =
From(tab) |>
Where(Fun.in(Get.visit_occurrence_id, visit_ids...)) |>
Select(Get.visit_occurrence_id, Get.condition_concept_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
#= TODO: Write tests for GetVisitPlaceOfService
Only needs one or two tests; may be difficult to test as I do not think Eunomia has anything other than missing
labels: tests, good first issue
assignees: VarshC
=#
"""
GetVisitPlaceOfService(visit_ids, conn; tab = visit_occurrence, join_tab = care_site)
Given a list of visit IDs, find their place of service
# Arguments:
- `visit_ids` - list of `visit_id`'s; each ID must be of subtype `Integer`
- `conn` - database connection using DBInterface
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `visit_occurrence`
- `join_tab` - the `SQLTable` representing the Person table; default `care_site`
# Returns
- `df::DataFrame` - a two column `DataFrame` comprised of columns: `:visit_occurrence_id` and `:condition_concept_id`
"""
function GetVisitPlaceOfService(
visit_ids,
conn;
tab=visit_occurrence,
join_tab=care_site
)
df = DBInterface.execute(conn, GetVisitPlaceOfService(visit_ids; tab=tab, join_tab=join_tab)) |> DataFrame
return df
end
"""
GetVisitPlaceOfService(visit_ids; tab = visit_occurrence, join_tab = care_site)
Produces SQL statement that, given a list of visit IDs, find their place of service
# Arguments:
- `visit_ids` - list of `visit_id`'s; each ID must be of subtype `Integer`
# Keyword Arguments:
- `tab` - the `SQLTable` representing the Condition Occurrence table; default `visit_occurrence`
- `join_tab` - the `SQLTable` representing the Person table; default `care_site`
# Returns
- `sql::String` - Prepared SQL statement as a `String`
"""
function GetVisitPlaceOfService(
visit_ids;
tab=visit_occurrence,
join_tab=care_site
)
sql =
From(tab) |>
Where(Fun.in(Get.visit_occurrence_id, visit_ids...)) |>
Select(Get.visit_occurrence_id, Get.care_site_id) |>
Join(:join => join_tab, Get.care_site_id .== Get.join.care_site_id) |>
Select(Get.visit_occurrence_id, Get.join.place_of_service_concept_id) |>
q -> render(q, dialect=dialect)
return String(sql)
end
export GetDatabasePersonIDs, GetPatientState, GetPatientGender, GetPatientRace, GetPatientAgeGroup, GetPatientVisits, GetMostRecentConditions, GetMostRecentVisit, GetVisitCondition, GetPatientEthnicity, GetDatabaseYearRange, GetVisitPlaceOfService