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 cac935f..341ce47 100644 --- a/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R +++ b/R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R @@ -56,6 +56,14 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function( "project_irb_number" ) + redcap_ehr_settings <- dplyr::tbl(conn, "redcap_ehr_settings") |> + dplyr::select( + "ehr_id", + "ehr_name", + "fhir_base_url", + "patient_identifier_string" + ) + disclosures <- dplyr::tbl(conn, "redcap_ehr_fhir_logs") |> dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |> @@ -63,6 +71,7 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function( 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::left_join(redcap_ehr_settings, by = c("ehr_id")) |> dplyr::collect() |> dplyr::mutate(disclosure_date = lubridate::floor_date(.data$created_at, unit = "day")) |> dplyr::select(-c("id", "created_at")) |> @@ -73,6 +82,10 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function( "disclosure_date", "fhir_id", "mrn", + "ehr_id", + "ehr_name", + "fhir_base_url", + "patient_identifier_string", "project_irb_number", "project_pi_firstname", "project_pi_mi", diff --git a/tests/testthat/hipaa_disclosure_log/make_hipaa_disclosure_log_test_data.R b/tests/testthat/hipaa_disclosure_log/make_hipaa_disclosure_log_test_data.R index 51cae8c..4bd97d3 100644 --- a/tests/testthat/hipaa_disclosure_log/make_hipaa_disclosure_log_test_data.R +++ b/tests/testthat/hipaa_disclosure_log/make_hipaa_disclosure_log_test_data.R @@ -49,10 +49,25 @@ redcap_projects <- dplyr::tbl(conn, "redcap_projects") |> ) |> collect() +redcap_ehr_settings <- dplyr::tbl(rc_conn, "redcap_ehr_settings") |> + dplyr::select( + "ehr_id", + "ehr_name", + "fhir_base_url", + "patient_identifier_string" + ) |> + collect() |> + dplyr::mutate( + ehr_name = "ehrnameEHRName", + fhir_base_url = "https://fhir.example.com", + patient_identifier_string = "mrnaabbccc" + ) + # Save our test tables test_tables <- c( "redcap_ehr_fhir_logs", "redcap_user_information", - "redcap_projects" + "redcap_projects", + "redcap_ehr_settings" ) purrr::walk(test_tables, write_rds_to_test_dir, "hipaa_disclosure_log") diff --git a/tests/testthat/hipaa_disclosure_log/redcap_ehr_settings.rds b/tests/testthat/hipaa_disclosure_log/redcap_ehr_settings.rds new file mode 100644 index 0000000..c30beea Binary files /dev/null and b/tests/testthat/hipaa_disclosure_log/redcap_ehr_settings.rds differ 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 ae9db3c..97fdbce 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 @@ -12,7 +12,8 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", { test_tables <- c( "redcap_ehr_fhir_logs", "redcap_user_information", - "redcap_projects" + "redcap_projects", + "redcap_ehr_settings" ) conn <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:") @@ -34,8 +35,8 @@ testthat::test_that("get_hipaa_disclosure_log_from_ehr_fhir_logs works", { # Required column names required_names <- c( - "disclosure_date", "fhir_id", "mrn", "project_irb_number" - ) + "disclosure_date", "fhir_id", "mrn", "project_irb_number", + "ehr_id", "ehr_name", "fhir_base_url", "patient_identifier_string") result <- get_hipaa_disclosure_log_from_ehr_fhir_logs(conn)