From 9a9c2dd23b199e3c9e79b76cc7ae135504147d14 Mon Sep 17 00:00:00 2001 From: Laurence James-Woodley Date: Thu, 16 Jan 2025 17:53:49 -0500 Subject: [PATCH 1/4] use get_user_rights to find project designers --- ...request_correction_of_bad_ownership_data.R | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/report/request_correction_of_bad_ownership_data.R b/report/request_correction_of_bad_ownership_data.R index 9252b1db..f4cb7b83 100644 --- a/report/request_correction_of_bad_ownership_data.R +++ b/report/request_correction_of_bad_ownership_data.R @@ -20,17 +20,16 @@ rc_conn <- connect_to_redcap_db() # rc_conn <- conn # ...and the rcui line below -rcp <- tbl(rc_conn, "redcap_projects") -rcpo <- tbl(rc_conn, "redcap_entity_project_ownership") -rcur <- tbl(rc_conn, "redcap_user_rights") -rcui <- tbl(rc_conn, "redcap_user_information") +rcp <- tbl(rc_conn, "redcap_projects") |> collect() +rcpo <- tbl(rc_conn, "redcap_entity_project_ownership") |> collect() +rcui <- tbl(rc_conn, "redcap_user_information") |> collect() +user_rights_and_info <- get_user_rights_and_info(rc_conn) # Run the line below when testing to make email go to you instead of bouncing # rcui <- tbl(rc_conn, "redcap_user_information") %>% # mutate(across(starts_with("user_email"), ~ if_else(is.na(.), ., paste0(Sys.getenv("USER"), "@ufl.edu")))) redcap_version <- tbl(rc_conn, "redcap_config") %>% filter(field_name == "redcap_version") %>% - collect() %>% pull(value) redcap_project_uri_base <- str_remove(Sys.getenv("URI"), "/api") %>% @@ -46,11 +45,10 @@ projects_with_unresolvable_ownership_issues <- rcp %>% inner_join(rcpo, by = c("project_id" = "pid")) %>% filter(billable == 1) %>% filter(is.na(date_deleted)) %>% - filter(is.na(email) || email == "") %>% - filter(is.na(firstname) || firstname == "") %>% - filter(is.na(lastname) || lastname == "") %>% - filter(is.na(username) || username == "") %>% - collect() %>% + filter(is.na(email) | email == "") %>% + filter(is.na(firstname) | firstname == "") %>% + filter(is.na(lastname) | lastname == "") %>% + filter(is.na(username) | username == "") %>% mutate_columns_to_posixct("updated") %>% filter(get_script_run_time() - ddays(120) < updated) @@ -58,12 +56,12 @@ projects_with_unresolvable_ownership_issues <- rcp %>% # https://stackoverflow.com/a/49201394/7418735 collapse_with_omit_blank <- function(x, sep = " ") paste(x[!is.na(x) & x != ""], collapse = sep) -project_contact_information <- rcur %>% - filter(project_id %in% local(projects_with_unresolvable_ownership_issues$project_id)) %>% +project_contact_information <- user_rights_and_info %>% + filter(project_id %in% projects_with_unresolvable_ownership_issues$project_id) %>% inner_join(rcp, by = "project_id") %>% - inner_join(rcui, by = "username") %>% - select(project_id, username, user_firstname, user_lastname, starts_with("user_email"), app_title, design) %>% - collect() %>% + inner_join(rcui, by = "username") |> + # take user_firstname and user_lastname from user_rights + select(project_id, username, user_firstname.x, user_lastname.x, starts_with("user_email"), app_title, design) |> mutate(link_to_project = paste0(redcap_project_uri_base, project_id)) %>% mutate(app_title = str_replace_all(app_title, '"', "")) %>% mutate(project_hyperlink = paste0("", app_title, "")) %>% From 17f8dfabbbe78847546d6eee41e85aa1802af42e Mon Sep 17 00:00:00 2001 From: Laurence James-Woodley Date: Thu, 16 Jan 2025 17:55:43 -0500 Subject: [PATCH 2/4] swtich to legacy pipe --- report/request_correction_of_bad_ownership_data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report/request_correction_of_bad_ownership_data.R b/report/request_correction_of_bad_ownership_data.R index f4cb7b83..751287ed 100644 --- a/report/request_correction_of_bad_ownership_data.R +++ b/report/request_correction_of_bad_ownership_data.R @@ -59,9 +59,9 @@ collapse_with_omit_blank <- function(x, sep = " ") paste(x[!is.na(x) & x != ""], project_contact_information <- user_rights_and_info %>% filter(project_id %in% projects_with_unresolvable_ownership_issues$project_id) %>% inner_join(rcp, by = "project_id") %>% - inner_join(rcui, by = "username") |> + inner_join(rcui, by = "username") %>% # take user_firstname and user_lastname from user_rights - select(project_id, username, user_firstname.x, user_lastname.x, starts_with("user_email"), app_title, design) |> + select(project_id, username, user_firstname.x, user_lastname.x, starts_with("user_email"), app_title, design) %>% mutate(link_to_project = paste0(redcap_project_uri_base, project_id)) %>% mutate(app_title = str_replace_all(app_title, '"', "")) %>% mutate(project_hyperlink = paste0("", app_title, "")) %>% From 77a2123b40bbef400a0adf1923136030987f0a6d Mon Sep 17 00:00:00 2001 From: Philip Chase Date: Wed, 22 Jan 2025 11:37:55 -0500 Subject: [PATCH 3/4] Handle an empty update in request_correction_of_bad_ownership_data.R Test if sequestered_today_email_df has data before using it. --- ...request_correction_of_bad_ownership_data.R | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/report/request_correction_of_bad_ownership_data.R b/report/request_correction_of_bad_ownership_data.R index 751287ed..8b5d1178 100644 --- a/report/request_correction_of_bad_ownership_data.R +++ b/report/request_correction_of_bad_ownership_data.R @@ -221,25 +221,23 @@ send_sequestered_today_alert_email <- function(row) { return(send_alert_email(row, email_subject = "REDCap project sequestered")) } -sequestered_today_log <- apply( - sequestered_today_email_df, - MARGIN = 1, - FUN = send_sequestered_today_alert_email +if (nrow(sequestered_today_email_df) > 0) { + sequestered_today_log <- apply( + sequestered_today_email_df, + MARGIN = 1, + FUN = send_sequestered_today_alert_email ) %>% - # turn list into dataframe - do.call("rbind", .) %>% - mutate(reason = "sequestered_today") - -############################################################################### -# Cleanup and logging # -############################################################################### - - -activity_log <- bind_rows( - please_fix_log, - sequestered_today_log -) + # turn list into dataframe + do.call("rbind", .) %>% + mutate(reason = "sequestered_today") + + # log the activity + activity_log <- bind_rows( + please_fix_log, + sequestered_today_log + ) -log_job_success(jsonlite::toJSON(activity_log)) + log_job_success(jsonlite::toJSON(activity_log)) +} dbDisconnect(rc_conn) From 7de042eeffe786a3fa1eeab5058bc6852b377dcc Mon Sep 17 00:00:00 2001 From: Philip Chase Date: Wed, 22 Jan 2025 11:41:35 -0500 Subject: [PATCH 4/4] Bump VERSION and update NEWS.md for release 1.46.1 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ VERSION | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c67404be..6935a0de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rcc.billing Title: REDCap Automated Billing -Version: 1.46.0 +Version: 1.46.1 Authors@R: c( person("Philip", "Chase", email = "pbc@ufl.edu", diff --git a/NEWS.md b/NEWS.md index a73d45eb..e93d96d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rcc.billing 1.46.1 (released 2025-01-22) +- Handle an empty update in request_correction_of_bad_ownership_data.R (@pbchase) +- use get_user_rights to find project designers (@ljwoodley, #248, #262) + # rcc.billing 1.46.0 (released 2025-01-15) - Add run_etl and use it (@ljwoodley, #260, #261) diff --git a/VERSION b/VERSION index 0a3db35b..aa3ed3a5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.46.0 +1.46.1