Skip to content

Commit

Permalink
Merge branch 'release/1.46.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Jan 22, 2025
2 parents e9d1e9f + 7de042e commit 15844d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.46.0
1.46.1
62 changes: 29 additions & 33 deletions report/request_correction_of_bad_ownership_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") %>%
Expand All @@ -46,24 +45,23 @@ 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)

# ["foo", "", NA, "bar", NA] -> "foo,bar"
# 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("<a href=\"", paste0(redcap_project_uri_base, project_id), "\">", app_title, "</a>")) %>%
Expand Down Expand Up @@ -223,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)

0 comments on commit 15844d4

Please sign in to comment.