Skip to content

Commit

Permalink
Added GetVisitPlaceOfService getter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCedarPrince committed Nov 6, 2022
1 parent 32fe5d4 commit 3a17f4c
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion src/getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -774,4 +774,81 @@ function GetVisitCondition(

end

export GetDatabasePersonIDs, GetPatientState, GetPatientGender, GetPatientRace, GetPatientAgeGroup, GetPatientVisits, GetMostRecentConditions, GetMostRecentVisit, GetVisitCondition, GetPatientEthnicity, GetDatabaseYearRange
#= 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

0 comments on commit 3a17f4c

Please sign in to comment.