Add a sequester_project and unsequester_project functions to the rcc.billing package.
sequester_project
sequester_project needs to set three columns across two tables. This is not tricky but the function also needs to know how many times it has sequestered a project and write that into a message for the REDCap Admins so they can identify abusers. This last bit is tricky as it requires querying the log tables, then summarizing the query results.
sequester_project should do these things:
[x] accept a vector of project_ids as input
[x] query redcap_entity_project_ownership to read sequestered for projects in project_ids
[x] query redcap_projects to read completed_time, completed_by, and log_event_table for projects in project_ids
[x] for (log_table in log_event_tables) query log_table for projects in project_ids and event == "MANAGE" & page == "ProjectGeneral/change_project_status.php" & str_starts_with("Project moved from Completed status back to"), then bind the query rows into single data frame and filter for ts in the last 3 months, then count(project_id, name="moved_from_completed_status_events") to summary the log data.
[x] join these three data frames together setting moved_from_completed_status_events = 0 where it is NA.
[x] set sequestered = 1 in the table redcap_entity_project_ownership
[x] in the redcap_projects table, set completed_time = get_script_run_time(), completed_by = paste("Sequestered by", get_script_name(), "- Previously sequestered", moved_from_completed_status_events, "times") .
[x] exit gracefully if the vector of project_ids is empty
[x] Use redcapcustodian::sync_table2 to make updates to the tables
[x] Return a vector of project_ids modified or as.numeric(NA) if none.
unsequester_project
unsequester_project should do these things:
[ ] set sequestered = 0 in the table redcap_entity_project_ownership
[ ] set completed_time = NA, completed_by = NA in the redcap_projects table.
[ ] accept a vector of project_ids as input
[ ] exit gracefully if the vector of project_ids is empty
[ ] Use redcapcustodian::sync_table2 to make updates to the tables
[ ] Return a vector of project_ids modified or as.numeric(NA) if none.
For a project state reference see the behavior of REDCap's ProjectGeneral/change_project_status.php.
I'm not averse to this being one function named sequester_project with an option unsequester = FALSE
Add a
sequester_project
andunsequester_project
functions to thercc.billing
package.sequester_project
sequester_project
needs to set three columns across two tables. This is not tricky but the function also needs to know how many times it has sequestered a project and write that into a message for the REDCap Admins so they can identify abusers. This last bit is tricky as it requires querying the log tables, then summarizing the query results.sequester_project
should do these things:redcap_entity_project_ownership
to readsequestered
for projects inproject_ids
redcap_projects
to readcompleted_time
,completed_by
, and log_event_table for projects inproject_ids
for (log_table in log_event_tables)
query log_table for projects inproject_ids
andevent == "MANAGE" & page == "ProjectGeneral/change_project_status.php" & str_starts_with("Project moved from Completed status back to")
, then bind the query rows into single data frame and filter forts
in the last 3 months, thencount(project_id, name="moved_from_completed_status_events")
to summary the log data.moved_from_completed_status_events
= 0 where it is NA.sequestered = 1
in the tableredcap_entity_project_ownership
redcap_projects
table, setcompleted_time = get_script_run_time(), completed_by = paste("Sequestered by", get_script_name(), "- Previously sequestered", moved_from_completed_status_events, "times")
.as.numeric(NA)
if none.unsequester_project
unsequester_project
should do these things:sequestered = 0
in the tableredcap_entity_project_ownership
completed_time = NA, completed_by = NA
in theredcap_projects
table.as.numeric(NA)
if none.For a project state reference see the behavior of REDCap's
ProjectGeneral/change_project_status.php
.I'm not averse to this being one function named
sequester_project
with an optionunsequester = FALSE