Skip to content

Commit f7adf0f

Browse files
committed
Merge branch 'release/1.28.0'
2 parents e3d87eb + 15b668f commit f7adf0f

9 files changed

+68
-14
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: redcapcustodian
22
Type: Package
33
Title: Data automation for R-centric workflows with a nod towards REDCap
4-
Version: 1.27.0
4+
Version: 1.28.0
55
Authors@R: c(
66
person("Philip", "Chase",
77
email = "pbc@ufl.edu",

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# redcapcustodian 1.28.0 (released 2025-02-20)
2+
- Update get_hipaa_disclosure_log_from_ehr_fhir_logs() (@pbchase, #176)
3+
- Add redcap_ehr_settings values to the disclosures (@saipavan10-git, #172, #175)
4+
15
# redcapcustodian 1.27.0 (released 2024-12-11)
26
- Allow multiple EHR IDs in get_hipaa_disclosure_log_from_ehr_fhir_logs() (@pbchase, #173, #174)
37
- Include dependency setup in gh-action for tests (@saipavan10-git, #171)

R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#' given a DBI connection object to the REDCap database and some optional
55
#' parameters to narrow the returned result.
66
#'
7+
#' Optionally filter the data with the data range `[start_date, end_date)`.
8+
#'
79
#' @param conn a DBI connection object to the REDCap database
810
#' @param ehr_id a vector of REDCap EHR_IDs for the EHR(s) of interest (optional)
911
#' @param start_date The first date from which we should return results (optional)
12+
#' @param end_date The last date (non-inclusive) from which we should return results (optional)
1013
#'
1114
#' @return A dataframe suitable for generating a HIPAA disclosure log
1215
#' @export
@@ -29,7 +32,8 @@
2932
get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
3033
conn,
3134
ehr_id = NA_real_,
32-
start_date = as.Date(NA)) {
35+
start_date = as.Date(NA),
36+
end_date = as.Date(NA)) {
3337

3438
# rename parameters for local use
3539
ehr_id_local <- ehr_id
@@ -56,13 +60,23 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
5660
"project_irb_number"
5761
)
5862

63+
redcap_ehr_settings <- dplyr::tbl(conn, "redcap_ehr_settings") |>
64+
dplyr::select(
65+
"ehr_id",
66+
"ehr_name",
67+
"fhir_base_url",
68+
"patient_identifier_string"
69+
)
70+
5971
disclosures <-
6072
dplyr::tbl(conn, "redcap_ehr_fhir_logs") |>
6173
dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |>
6274
dplyr::filter(is.na(start_date) | .data$created_at >= start_date) |>
75+
dplyr::filter(is.na(end_date) | .data$created_at < end_date) |>
6376
dplyr::filter(ehr_id_is_na | .data$ehr_id %in% ehr_id_local) |>
6477
dplyr::left_join(user_information, by = c("user_id" = "ui_id")) |>
6578
dplyr::left_join(projects, by = c("project_id")) |>
79+
dplyr::left_join(redcap_ehr_settings, by = c("ehr_id")) |>
6680
dplyr::collect() |>
6781
dplyr::mutate(disclosure_date = lubridate::floor_date(.data$created_at, unit = "day")) |>
6882
dplyr::select(-c("id", "created_at")) |>
@@ -73,6 +87,10 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
7387
"disclosure_date",
7488
"fhir_id",
7589
"mrn",
90+
"ehr_id",
91+
"ehr_name",
92+
"fhir_base_url",
93+
"patient_identifier_string",
7694
"project_irb_number",
7795
"project_pi_firstname",
7896
"project_pi_mi",

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.27.0
1+
1.28.0

man/get_hipaa_disclosure_log_from_ehr_fhir_logs.Rd

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

redcapcustodian.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 2cfe0968-c181-4bdc-a53a-43442dbeb736
23

34
RestoreWorkspace: Default
45
SaveWorkspace: Default

tests/testthat/hipaa_disclosure_log/make_hipaa_disclosure_log_test_data.R

+16-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,25 @@ redcap_projects <- dplyr::tbl(conn, "redcap_projects") |>
4949
) |>
5050
collect()
5151

52+
redcap_ehr_settings <- dplyr::tbl(rc_conn, "redcap_ehr_settings") |>
53+
dplyr::select(
54+
"ehr_id",
55+
"ehr_name",
56+
"fhir_base_url",
57+
"patient_identifier_string"
58+
) |>
59+
collect() |>
60+
dplyr::mutate(
61+
ehr_name = "ehrnameEHRName",
62+
fhir_base_url = "https://fhir.example.com",
63+
patient_identifier_string = "mrnaabbccc"
64+
)
65+
5266
# Save our test tables
5367
test_tables <- c(
5468
"redcap_ehr_fhir_logs",
5569
"redcap_user_information",
56-
"redcap_projects"
70+
"redcap_projects",
71+
"redcap_ehr_settings"
5772
)
5873
purrr::walk(test_tables, write_rds_to_test_dir, "hipaa_disclosure_log")
Binary file not shown.

tests/testthat/test-get_hipaa_disclosure_log_from_ehr_fhir_logs.R

+20-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", {
1212
test_tables <- c(
1313
"redcap_ehr_fhir_logs",
1414
"redcap_user_information",
15-
"redcap_projects"
15+
"redcap_projects",
16+
"redcap_ehr_settings"
1617
)
1718

1819
conn <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:")
@@ -25,33 +26,43 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", {
2526
head(n = 30) |>
2627
dplyr::collect() |>
2728
dplyr::mutate(
28-
ehr_id = sample(1:3, n(), replace = TRUE),
29-
created_at = seq.Date(from = Sys.Date() - 10, to = Sys.Date(), length.out = n())
29+
ehr_id = sample(1:3, dplyr::n(), replace = TRUE),
30+
created_at = seq.Date(from = Sys.Date() - 10, to = Sys.Date(), length.out = dplyr::n())
3031
)
3132

3233
# Write the mutated data back to the database
33-
duckdb_register(conn, "redcap_ehr_fhir_logs", redcap_ehr_fhir_logs)
34+
duckdb::duckdb_register(conn, "redcap_ehr_fhir_logs", redcap_ehr_fhir_logs)
3435

3536
# Required column names
3637
required_names <- c(
37-
"disclosure_date", "fhir_id", "mrn", "project_irb_number"
38-
)
38+
"disclosure_date", "fhir_id", "mrn", "project_irb_number",
39+
"ehr_id", "ehr_name", "fhir_base_url", "patient_identifier_string")
3940

4041
result <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn)
4142

4243
testthat::expect_contains(names(result), required_names)
4344
testthat::expect_gt(nrow(result), 0)
4445
testthat::expect_equal(
4546
nrow(result),
46-
result |> distinct(disclosure_date, fhir_id, mrn, project_irb_number, username) |> nrow()
47+
result |> dplyr::distinct(disclosure_date, fhir_id, mrn, project_irb_number, username) |> nrow()
4748
)
4849

4950
result_filtered_ehr_id <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, ehr_id = 1)
5051
testthat::expect_true(all(result_filtered_ehr_id$ehr_id == 1))
5152

5253
start_date <- Sys.Date() - 5
53-
result_filtered_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, start_date = start_date)
54-
testthat::expect_true(all(result_filtered_date$disclosure_date >= start_date))
54+
result_filtered_start_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, start_date = start_date)
55+
testthat::expect_true(all(result_filtered_start_date$disclosure_date >= start_date))
56+
57+
end_date <- Sys.Date() - 5
58+
result_filtered_end_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, end_date = end_date)
59+
testthat::expect_true(all(result_filtered_end_date$disclosure_date < end_date))
60+
61+
start_date <- Sys.Date() - 7
62+
end_date <- Sys.Date() - 5
63+
result_filtered_start_and_end_date <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, start_date = start_date, end_date = end_date)
64+
testthat::expect_true(all(result_filtered_start_and_end_date$disclosure_date >= start_date))
65+
testthat::expect_true(all(result_filtered_start_and_end_date$disclosure_date < end_date))
5566

5667
result_combined_filters <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn, ehr_id = 2, start_date = start_date)
5768
testthat::expect_true(all(result_combined_filters$ehr_id == 2))

0 commit comments

Comments
 (0)