Skip to content

Commit

Permalink
Merge pull request #174 from pbchase/allow_multiple_ehr_ids
Browse files Browse the repository at this point in the history
Allow multiple EHR IDs in get_hipaa_disclosure_log_from_ehr_fhir_logs()
  • Loading branch information
saipavan10-git authored Dec 11, 2024
2 parents 5590ed4 + b4acef1 commit 6915ff2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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)
})

0 comments on commit 6915ff2

Please sign in to comment.