Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple EHR IDs in get_hipaa_disclosure_log_from_ehr_fhir_logs() #174

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' parameters to narrow the returned result.
#'
#' @param conn a DBI connection object to the REDCap database
#' @param ehr_id the REDCap EHR_ID for the EHR of interest (optional)
#' @param ehr_id a vector of REDCap EHR_IDs for the EHR(s) of interest (optional)
#' @param start_date The first date from which we should return results (optional)
#'
#' @return A dataframe suitable for generating a HIPAA disclosure log
Expand Down Expand Up @@ -34,6 +34,9 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
# rename parameters for local use
ehr_id_local <- ehr_id

# determine if ehr_id of interest
ehr_id_is_na <- length(ehr_id_local) == 1 & all(is.na(ehr_id_local))

# make DBI objects for joins
user_information <- dplyr::tbl(conn, "redcap_user_information") |>
dplyr::select(
Expand All @@ -57,7 +60,7 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
dplyr::tbl(conn, "redcap_ehr_fhir_logs") |>
dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |>
dplyr::filter(is.na(start_date) | .data$created_at >= start_date) |>
dplyr::filter(is.na(ehr_id_local) | ehr_id_local == .data$ehr_id) |>
dplyr::filter(ehr_id_is_na | .data$ehr_id %in% ehr_id_local) |>
dplyr::left_join(user_information, by = c("user_id" = "ui_id")) |>
dplyr::left_join(projects, by = c("project_id")) |>
dplyr::collect() |>
Expand Down
2 changes: 1 addition & 1 deletion man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", {
result_future_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, start_date = future_start_date)
testthat::expect_equal(nrow(result_future_date), 0)

# test that we can query with multiple EHR_IDs
result_multiple_filtered_ehr_id <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, ehr_id = c(1,2))
testthat::expect_true(all(result_multiple_filtered_ehr_id$ehr_id %in% c(1,2)))

DBI::dbDisconnect(conn, shutdown = TRUE)
})
Loading