diff --git a/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R b/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R index d5f52f3..cac935f 100644 --- a/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R +++ b/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R @@ -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 @@ -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( @@ -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() |> diff --git a/man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd b/man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd index 1bbaef4..d6ee0b6 100644 --- a/man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd +++ b/man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd @@ -13,7 +13,7 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs( \arguments{ \item{conn}{a DBI connection object to the REDCap database} -\item{ehr_id}{the REDCap EHR_ID for the EHR of interest (optional)} +\item{ehr_id}{a vector of REDCap EHR_IDs for the EHR(s) of interest (optional)} \item{start_date}{The first date from which we should return results (optional)} } diff --git a/tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R b/tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R index 51738ca..ae9db3c 100644 --- a/tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R +++ b/tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R @@ -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) })