You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a function, delete_project(project_id) that implements REDCap's normal "soft deletion" as implemented in REDCap's ProjectGeneral/delete_project.php:
$sql = "update redcap_projects set date_deleted = '".NOW."' where project_id = $project_id and date_deleted is null";
...
ToDoList::updateTodoStatus($project_id, 'delete project','completed');
...
Logging::logEvent($sql,"redcap_projects","MANAGE",PROJECT_ID,"project_id = ".PROJECT_ID,"Delete project");
That said, we don't need a ToDo list entry for this, so only implement these two steps:
$sql = "update redcap_projects set date_deleted = '".NOW."' where project_id = $project_id and date_deleted is null";
...
Logging::logEvent($sql,"redcap_projects","MANAGE",PROJECT_ID,"project_id = ".PROJECT_ID,"Delete project");
Params
project_id should be a vector of REDCap project IDs
Tests the function perform
The code should verify:
The project_id exists
The project_id is not already deleted
If either test fails, note it in a status column and do nothing with the project ID. If the tests pass, delete it and note that in the status column.
Returns
The function should return a list of these objects:
n - The number of projects deleted
project_ids_deleted - a vector of the project_ids deleted
data - a tibble containing one row per project id in the project_id parameter. The columns should be project_id (numeric) and status (character). status should have a value of "deleted", "does not exist", "previously deleted" according to the result of the above tests.
Unit tests
Please add a testthat test to verify the code can:
detect non-existent projects
detect previously-deleted projects
update the relevant redcap tables as it deletes the project
I failed to mention important details about redcap_log_event tables. There used to be only one, named redcap_log_event. Now there are 9 such tables. They are enumerated in the package object redcapcustodian::log_event_tables. Each project's log records are in one and only one redcap_log_event table. That table is named in the redcap_projects table, though I don't recall the column name.
The function we are creating in this issue, delete_project() will need to read redcap_projects to get the log event table so it knows which redcap_log_event table to log to.
This has implications for the test data set. When I say "you will need a tiny redcap_projects table and one redcap_log_event table" I am saying you should make sure all of your test projects share the same redcap_log_event table. It simplifies your testing life if you force each project to use the same redcap_log_event table and then provide only that table for the function to write to.
Write a function,
delete_project(project_id)
that implements REDCap's normal "soft deletion" as implemented in REDCap'sProjectGeneral/delete_project.php
:That said, we don't need a ToDo list entry for this, so only implement these two steps:
Params
project_id
should be a vector of REDCap project IDsTests the function perform
The code should verify:
If either test fails, note it in a status column and do nothing with the project ID. If the tests pass, delete it and note that in the status column.
Returns
The function should return a list of these objects:
Unit tests
Please add a
testthat
test to verify the code can:To write that test, you will need a tiny
redcap_projects
table and oneredcap_log_event
table. Steal liberally from https://github.com/ctsit/rcc.billing/blob/main/tests/testthat/get_billable_candidates/make_test_data_for_get_billable_candidates.R to make that data. Steal from https://github.com/ctsit/rcc.billing/blob/main/tests/testthat/test-get_billable_candidates.R to use the test data you made with the previous script.Ask @pbchase for help writing these tests if the examples seem obtuse.
For reference, this work was first discussed in ctsit/rcc.billing#78
The text was updated successfully, but these errors were encountered: