Skip to content

Commit 6915ff2

Browse files
Merge pull request #174 from pbchase/allow_multiple_ehr_ids
Allow multiple EHR IDs in get_hipaa_disclosure_log_from_ehr_fhir_logs()
2 parents 5590ed4 + b4acef1 commit 6915ff2

3 files changed

+10
-3
lines changed

R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' parameters to narrow the returned result.
66
#'
77
#' @param conn a DBI connection object to the REDCap database
8-
#' @param ehr_id the REDCap EHR_ID for the EHR of interest (optional)
8+
#' @param ehr_id a vector of REDCap EHR_IDs for the EHR(s) of interest (optional)
99
#' @param start_date The first date from which we should return results (optional)
1010
#'
1111
#' @return A dataframe suitable for generating a HIPAA disclosure log
@@ -34,6 +34,9 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
3434
# rename parameters for local use
3535
ehr_id_local <- ehr_id
3636

37+
# determine if ehr_id of interest
38+
ehr_id_is_na <- length(ehr_id_local) == 1 & all(is.na(ehr_id_local))
39+
3740
# make DBI objects for joins
3841
user_information <- dplyr::tbl(conn, "redcap_user_information") |>
3942
dplyr::select(
@@ -57,7 +60,7 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
5760
dplyr::tbl(conn, "redcap_ehr_fhir_logs") |>
5861
dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |>
5962
dplyr::filter(is.na(start_date) | .data$created_at >= start_date) |>
60-
dplyr::filter(is.na(ehr_id_local) | ehr_id_local == .data$ehr_id) |>
63+
dplyr::filter(ehr_id_is_na | .data$ehr_id %in% ehr_id_local) |>
6164
dplyr::left_join(user_information, by = c("user_id" = "ui_id")) |>
6265
dplyr::left_join(projects, by = c("project_id")) |>
6366
dplyr::collect() |>

man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R

+4
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,9 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", {
6464
result_future_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, start_date = future_start_date)
6565
testthat::expect_equal(nrow(result_future_date), 0)
6666

67+
# test that we can query with multiple EHR_IDs
68+
result_multiple_filtered_ehr_id <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, ehr_id = c(1,2))
69+
testthat::expect_true(all(result_multiple_filtered_ehr_id$ehr_id %in% c(1,2)))
70+
6771
DBI::dbDisconnect(conn, shutdown = TRUE)
6872
})

0 commit comments

Comments
 (0)