Skip to content
20 changes: 19 additions & 1 deletion data/qc/assayTransformCallback.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,34 @@
# limitations under the License.
##
# Sleeps for the SleepSeconds run property, then queries exp.Data through the API before letting the import finish.
# A CallbackStatus of "report" or "fail" first records the script's working directory in the TransformWorkDirs list; "fail" then rejects the run.
# "edit" moves the Sync Callback Assay results of participant EditedByScript to visit 2, editing the run while its script runs.
suppressMessages(library(Rlabkey));

labkey.setDefaults(apiKey = "${apikey}");

run.props = labkey.transform.readRunPropertiesFile("${runInfo}");
sleep.seconds = as.numeric(labkey.transform.getRunPropertyValue(run.props, "SleepSeconds"));
runprop.output.file = labkey.transform.getRunPropertyValue(run.props, "transformedRunPropertiesFile");
errors.file = labkey.transform.getRunPropertyValue(run.props, "errorsFile");
status = labkey.transform.getRunPropertyValue(run.props, "CallbackStatus");

if (status %in% c("report", "fail"))
labkey.insertRows(baseUrl = "${baseServerURL}", folderPath = "${containerPath}", schemaName = "lists", queryName = "TransformWorkDirs", toInsert = data.frame(WorkDir = dirname("${runInfo}")));

if (identical(status, "edit")) {
results = labkey.selectRows(baseUrl = "${baseServerURL}", folderPath = "${containerPath}", schemaName = "assay.General.Sync Callback Assay", queryName = "Data", colSelect = "RowId", colFilter = makeFilter(c("ParticipantID", "EQUAL", "EditedByScript")), colNameOpt = "fieldname");
if (nrow(results) == 0)
stop("No Sync Callback Assay result for participant EditedByScript to edit");
labkey.updateRows(baseUrl = "${baseServerURL}", folderPath = "${containerPath}", schemaName = "assay.General.Sync Callback Assay", queryName = "Data", toUpdate = data.frame(RowId = results$RowId, VisitID = 2));
}

Sys.sleep(sleep.seconds);

rows = labkey.selectRows(baseUrl = "${baseServerURL}", folderPath = "${containerPath}", schemaName = "exp", queryName = "Data", colSelect = "RowId");

writeLines(c(paste("CallbackStatus", "succeeded", sep = "\t"), paste("runComments", "set by transform", sep = "\t")), runprop.output.file);
if (identical(status, "fail")) {
writeLines(paste("error", "", "Transform script rejected the run", sep = "\t"), errors.file);
} else {
writeLines(c(paste("CallbackStatus", "succeeded", sep = "\t"), paste("runComments", "set by transform", sep = "\t")), runprop.output.file);
}
Loading
Loading