Skip to content

Commit e3d87eb

Browse files
committed
Merge branch 'release/1.27.0'
2 parents da6185f + 63f948a commit e3d87eb

12 files changed

+277
-95
lines changed

.github/workflows/run-tests.yaml

+36-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,45 @@ jobs:
1515

1616
env:
1717
CI: "TRUE"
18+
R_LIBS_USER: /github/home/R/x86_64-pc-linux-gnu-library/4.4
19+
R_LIB_FOR_PAK: /usr/local/lib/R/site-library
1820

1921
steps:
2022
- uses: actions/checkout@v2
2123

22-
- name: Check
24+
# Create directories for R libraries if not already present
25+
- name: Create R Library Paths
26+
run: |
27+
mkdir -p /github/home/R/x86_64-pc-linux-gnu-library/4.4
28+
mkdir -p renv/library
29+
30+
# Restore cache for R dependencies
31+
- name: Restore R Dependencies Cache
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
/github/home/R/x86_64-pc-linux-gnu-library/4.4
36+
renv/library
37+
key: ${{ runner.os }}-r-libs-${{ hashFiles('DESCRIPTION') }}
38+
restore-keys: |
39+
${{ runner.os }}-r-libs-
40+
41+
# Install R dependencies
42+
- name: Install R Dependencies
43+
uses: r-lib/actions/setup-r-dependencies@v2
44+
with:
45+
cache: false
46+
47+
# Run tests
48+
- name: Run Tests
2349
run: devtools::test(stop_on_failure = TRUE)
2450
shell: Rscript {0}
51+
52+
# Save R dependencies to cache
53+
- name: Save R Dependencies Cache
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
/github/home/R/x86_64-pc-linux-gnu-library/4.4
58+
renv/library
59+
key: ${{ runner.os }}-r-libs-${{ hashFiles('DESCRIPTION') }}

DESCRIPTION

+3-2
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.26.2
4+
Version: 1.27.0
55
Authors@R: c(
66
person("Philip", "Chase",
77
email = "pbc@ufl.edu",
@@ -61,7 +61,8 @@ Imports:
6161
vctrs,
6262
jsonlite,
6363
openxlsx,
64-
quarto
64+
quarto,
65+
getip
6566
Suggests:
6667
RSQLite,
6768
digest,

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RUN R -e "install.packages(c( \
2828
'writexl', \
2929
'openxlsx', \
3030
'kableExtra' \
31+
'getip' \
3132
))"
3233

3334
RUN R -e "devtools::install_github('allanvc/mRpostman')"

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# redcapcustodian 1.27.0 (released 2024-12-11)
2+
- Allow multiple EHR IDs in get_hipaa_disclosure_log_from_ehr_fhir_logs() (@pbchase, #173, #174)
3+
- Include dependency setup in gh-action for tests (@saipavan10-git, #171)
4+
- Improve logging for delete_project function (@saipavan10-git, #171)
5+
- Use parameters in get_hipaa_disclosure_log_from_ehr_fhir_logs.R (@pbchase, @saipavan10-git #162)
6+
17
# redcapcustodian 1.26.2 (released 2024-11-20)
28
- Add new production status (@saipavan10-git, #168, #170)
39
- Add log event tables 10,11,12 (@saipavan10-git, #168, #170)

R/delete_project.R

+71-33
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
#' @examples
2020
#' \dontrun{
2121
#' conn <- DBI::dbConnect(...)
22-
#' delete_project(c(1,2,3), conn)
22+
#' delete_project(c(1, 2, 3), conn)
2323
#' }
2424
#' @export
2525

2626
delete_project <- function(project_id, conn) {
27-
2827
redcap_projects <- DBI::dbGetQuery(
2928
conn,
3029
sprintf(
@@ -34,47 +33,86 @@ delete_project <- function(project_id, conn) {
3433
log_event_table
3534
from redcap_projects
3635
where project_id in (%s)",
37-
paste0(project_id, collapse = ",")
36+
paste0(project_id, collapse = ",")
3837
)
3938
)
4039

41-
# select projects for deletion
4240
projects_to_delete <- redcap_projects[is.na(redcap_projects$date_deleted), ]
4341
redcap_project_ids <- projects_to_delete$project_id
4442
redcap_log_tables <- projects_to_delete$log_event_table
4543

44+
4645
if (nrow(projects_to_delete) > 0) {
47-
tryCatch({
48-
deleted_projects <- DBI::dbExecute(
49-
conn,
50-
sprintf(
51-
"update redcap_projects set date_deleted = now() where project_id in (%s)",
52-
paste0(redcap_project_ids, collapse = ",")
53-
)
54-
)
55-
}, error = function(error_message) {
56-
print(error_message)
57-
return(FALSE)
58-
})
46+
delete_sql <- sprintf(
47+
"UPDATE redcap_projects SET date_deleted = NOW() WHERE project_id IN (%s)",
48+
paste0(redcap_project_ids, collapse = ",")
49+
)
5950

60-
# log the event
61-
tryCatch({
62-
inserted_rows <- purrr::map2(
63-
redcap_log_tables,
64-
redcap_project_ids,
65-
~ DBI::dbExecute(
66-
conn,
67-
sprintf(
68-
"insert into %s (object_type, event, project_id, description)
69-
values ('redcap_projects', 'MANAGE', %d, 'delete project')",
70-
.x,
71-
.y)
51+
tryCatch(
52+
{
53+
deleted_projects <- DBI::dbExecute(conn, delete_sql)
54+
},
55+
error = function(error_message) {
56+
print(error_message)
57+
return(FALSE)
58+
}
59+
)
60+
61+
# Define logging parameters
62+
ts <- format(Sys.time(), "%Y%m%d%H%M%S") # Time stamp
63+
user <- ifelse(is.null(get_script_name()), "admin", get_script_name())
64+
ip <- getip::getip("local")
65+
page <- "rcc.billing::delete_abandoned_projects"
66+
event <- "MANAGE"
67+
object_type <- "redcap_projects"
68+
description <- "Delete project"
69+
legacy <- 0
70+
change_reason <- NULL
71+
72+
tryCatch(
73+
{
74+
inserted_rows <- purrr::map2(
75+
redcap_log_tables,
76+
redcap_project_ids,
77+
~ {
78+
pk <- .y
79+
data_values <- sprintf("project_id = %d", .y)
80+
81+
DBI::dbExecute(
82+
conn,
83+
sprintf(
84+
"INSERT INTO %s
85+
(log_event_id, project_id, ts, user, ip, page, event,
86+
object_type, sql_log, pk, event_id, data_values,
87+
description, legacy, change_reason)
88+
VALUES
89+
(NULL, %d, '%s', '%s', '%s', '%s', '%s',
90+
'%s', '%s', '%d', NULL, '%s',
91+
'%s', %d, %s)",
92+
.x, # Log table
93+
.y, # Project ID
94+
ts,
95+
user,
96+
ip,
97+
page,
98+
event,
99+
object_type,
100+
delete_sql,
101+
pk,
102+
data_values,
103+
description,
104+
legacy,
105+
ifelse(is.null(change_reason), "NULL", sprintf("'%s'", change_reason))
106+
)
107+
)
108+
}
72109
)
73-
)
74-
}, error = function(error_message) {
75-
print(error_message)
76-
return(FALSE)
77-
})
110+
},
111+
error = function(error_message) {
112+
print(error_message)
113+
return(FALSE)
114+
}
115+
)
78116
} else {
79117
deleted_projects <- NULL
80118
inserted_rows <- NULL

R/get_hipaa_disclosure_log_from_ehr_fhir_logs.R

+12-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
@@ -30,6 +30,13 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
3030
conn,
3131
ehr_id = NA_real_,
3232
start_date = as.Date(NA)) {
33+
34+
# rename parameters for local use
35+
ehr_id_local <- ehr_id
36+
37+
# determine if ehr_id of interest
38+
ehr_id_is_na <- length(ehr_id_local) == 1 & all(is.na(ehr_id_local))
39+
3340
# make DBI objects for joins
3441
user_information <- dplyr::tbl(conn, "redcap_user_information") |>
3542
dplyr::select(
@@ -49,8 +56,11 @@ get_hipaa_disclosure_log_from_ehr_fhir_logs <- function(
4956
"project_irb_number"
5057
)
5158

52-
disclosures <- dplyr::tbl(conn, "redcap_ehr_fhir_logs") |>
59+
disclosures <-
60+
dplyr::tbl(conn, "redcap_ehr_fhir_logs") |>
5361
dplyr::filter(.data$resource_type == "Patient" & .data$mrn != "") |>
62+
dplyr::filter(is.na(start_date) | .data$created_at >= start_date) |>
63+
dplyr::filter(ehr_id_is_na | .data$ehr_id %in% ehr_id_local) |>
5464
dplyr::left_join(user_information, by = c("user_id" = "ui_id")) |>
5565
dplyr::left_join(projects, by = c("project_id")) |>
5666
dplyr::collect() |>

VERSION

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

man/delete_project.Rd

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

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.

0 commit comments

Comments
 (0)