|
@@ -326,7 +326,10 @@ function generateSection(config, sectionName, sectionTitle, listName, additional
|
|
|
let qconfig=new Object();
|
|
|
qconfig.containerPath=config.containerPath;
|
|
|
qconfig.schemaName='lists';
|
|
|
- qconfig.queryName=config.setupQueryName;
|
|
|
+ //qconfig.queryName=config.setupQueryName;
|
|
|
+ qconfig.queryName="FormSetup";
|
|
|
+ qconfig.filterArray=[LABKEY.Filter.create("formName",config.formId)];
|
|
|
+
|
|
|
qconfig.success=function(data){
|
|
|
generateReview(config,data,divReview.id,divReviewList.id,listName)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
@@ -985,7 +988,9 @@ function afterParticipantId(config,configUpload){
|
|
|
//just use registration for test
|
|
|
let qconfig=new Object();
|
|
|
qconfig.schemaName='lists';
|
|
|
- qconfig.queryName=config.setupQueryName;
|
|
|
+ //qconfig.queryName=config.setupQueryName;
|
|
|
+ qconfig.queryName="FormSetup";
|
|
|
+ qconfig.filterArray=[LABKEY.Filter.create("formName",config.formId)];
|
|
|
qconfig.success=function(data){afterSetup(config,configUpload,data);}
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
@@ -1005,6 +1010,7 @@ function afterSetup(config,configUpload,data){
|
|
|
}
|
|
|
//add reviews
|
|
|
configUpload.queries.push({queryName:"reviewComments",queryStatus:"QUEUED"});
|
|
|
+ configUpload.queryId=0;
|
|
|
copyToDataset(config,configUpload);
|
|
|
|
|
|
//config.upload["start"]=true;
|
|
@@ -1021,32 +1027,25 @@ function afterSetup(config,configUpload,data){
|
|
|
|
|
|
function copyToDataset(config,configUpload){
|
|
|
|
|
|
- let queryId=-1;
|
|
|
- for (let i=0;i<configUpload.queries.length;i++){
|
|
|
- if (configUpload.queries[i].queryStatus=="DONE")
|
|
|
- continue;
|
|
|
- queryId=i;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (queryId<0) {
|
|
|
+ if (configUpload.queryId==configUpload.queries.length) {
|
|
|
updateFlag(config,3);//Approved
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- let queryName=configUpload.queries[queryId].queryName;
|
|
|
- print(config,"copyToDataset["+queryId+"/"+configUpload.queries.length+"]: "+queryName);
|
|
|
+ let queryName=configUpload.queries[configUpload.queryId].queryName;
|
|
|
+ print(config,"copyToDataset["+configUpload.queryId+"/"+configUpload.queries.length+"]: "+queryName);
|
|
|
let qconfig=new Object();
|
|
|
qconfig.queryName=queryName;
|
|
|
qconfig.schemaName="lists";
|
|
|
qconfig.filterArray=[LABKEY.Filter.create('crfRef',getCRFref(config))];
|
|
|
- qconfig.success=function(data){afterListData(config,configUpload,queryId,data)};
|
|
|
+ qconfig.success=function(data){afterListData(config,configUpload,data)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function afterListData(config,configUpload,queryId,data){
|
|
|
+function afterListData(config,configUpload,data){
|
|
|
|
|
|
- let queryName=configUpload.queries[queryId].queryName;
|
|
|
- let msg="copyDataToDataset ["+queryId+"/"+configUpload.queries.length+"] : "+queryName;
|
|
|
+ let queryName=configUpload.queries[configUpload.queryId].queryName;
|
|
|
+ let msg="["+queryName+"/list]: "+data.rows.length+" entries";
|
|
|
print(config,msg);
|
|
|
configUpload.listData=data;
|
|
|
|
|
@@ -1055,66 +1054,104 @@ function afterListData(config,configUpload,queryId,data){
|
|
|
qconfig.schemaName="study";
|
|
|
qconfig.filterArray=[LABKEY.Filter.create('crfRef',getCRFref(config))];
|
|
|
qconfig.filterArray.push(LABKEY.Filter.create('ParticipantId',configUpload.participantId));
|
|
|
- qconfig.success=function(data){afterStudyData(config,configUpload,queryId,data)};
|
|
|
+ qconfig.success=function(data){afterStudyData(config,configUpload,data)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
|
|
|
-function afterStudyData(config,configUpload,queryId,data){
|
|
|
+function afterStudyData(config,configUpload,data){
|
|
|
configUpload.studyData=data;
|
|
|
|
|
|
- let queryName=configUpload.queries[queryId].queryName;
|
|
|
- print(config,"copyDataToDatasetChecked: "+queryName);
|
|
|
+ let queryName=configUpload.queries[configUpload.queryId].queryName;
|
|
|
+ let msg="["+queryName+"/study]: "+data.rows.length+" entries";
|
|
|
+ print(config,msg);
|
|
|
|
|
|
- if (configUpload.listData.rows.lentgh>0){
|
|
|
- clearErr(config);
|
|
|
- let msg="Dataset "+queryName+" already filled for participant ";
|
|
|
- msg+=configUpload.participantId;
|
|
|
- printErr(config,msg);
|
|
|
- configUpload.queris[queryId].queryStatus="DONE";
|
|
|
- //rows with the same crfRef and patientId already inserted - skip
|
|
|
- copyToDataset(config,configUpload);
|
|
|
- }
|
|
|
|
|
|
- let dataList=configUpload.listData;
|
|
|
- if (dataList.rows.length==0){
|
|
|
- printErr(config,"Dataset "+queryName+" empty.");
|
|
|
- configUpload.queries[queryId].queryStatus="DONE";
|
|
|
+ let listRows=configUpload.listData.rows;
|
|
|
+ //skip uploading an empty set
|
|
|
+ if (listRows.length==0){
|
|
|
+ printErr(config,"List "+queryName+" empty.");
|
|
|
+ configUpload.queries[configUpload.queryId].queryStatus="DONE";
|
|
|
+ configUpload.queryId+=1;
|
|
|
copyToDataset(config,configUpload);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
- //update non-list elements
|
|
|
- let seqNumber=getCRFref(config);
|
|
|
+ let studyRows=configUpload.studyData.rows;
|
|
|
|
|
|
+ for (let i=0;i<studyRows.length;i++){
|
|
|
+ let entry=studyRows[i];
|
|
|
+ if (! (i<listRows.length) ) continue;
|
|
|
+ let entryList=listRows[i];
|
|
|
+ //keeps study only variables (ParticipantId, SequenceNum)
|
|
|
+ for (let f in entryList) {
|
|
|
+ entry[f]=entryList[f];
|
|
|
+ print(config,"Copying ["+f+"]: "+entry[f]+"/"+entryList[f]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (studyRows.length>0) {
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.queryName=queryName;
|
|
|
+ qconfig.schemaName="study";
|
|
|
+ qconfig.rows=studyRows;
|
|
|
+ qconfig.success=function(data){afterStudyUpload(config,configUpload,data);}
|
|
|
+ LABKEY.Query.updateRows(qconfig)
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ let data=new Object();
|
|
|
+ data.rows=new Array();
|
|
|
+ afterStudyUpload(config,configUpload,data);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function afterStudyUpload(config,configUpload,data){
|
|
|
+
|
|
|
+ let queryName=configUpload.queries[configUpload.queryId].queryName;
|
|
|
+ printErr(config,"Updated "+data.rows.length+" rows to "+queryName);
|
|
|
+
|
|
|
+ let studyRows=configUpload.studyData.rows;
|
|
|
+ let listRows=configUpload.listData.rows;
|
|
|
+
|
|
|
let rows=new Array();
|
|
|
- for (let i=0;i<dataList.rows.length;i++){
|
|
|
- let entry=dataList.rows[i];
|
|
|
+ //also updating existing rows, if they exist
|
|
|
+ for (let i=studyRows.length;i<listRows.length;i++){
|
|
|
+ let entry=listRows[i];
|
|
|
+
|
|
|
entry.ParticipantId=configUpload.participantId;
|
|
|
entry.crfRef=getCRFref(config);
|
|
|
entry.SequenceNum=getCRFref(config);
|
|
|
entry.SequenceNum=entry.SequenceNum % 1000000000;
|
|
|
|
|
|
- if (dataList.rows.length>1){
|
|
|
+ if (listRows.length>1){
|
|
|
entry.SequenceNum+=i/100;
|
|
|
}
|
|
|
print(config, "Adding sequence number "+entry.SequenceNum);
|
|
|
rows.push(entry);
|
|
|
}
|
|
|
-
|
|
|
- let qconfig=new Object();
|
|
|
- qconfig.queryName=queryName;
|
|
|
- qconfig.schemaName="study";
|
|
|
- qconfig.success=function(data){
|
|
|
- copyData(config,configUpload,queryId,data)};
|
|
|
- qconfig.rows=rows;
|
|
|
- LABKEY.Query.insertRows(qconfig);
|
|
|
+ if (rows.length>0){
|
|
|
+
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.queryName=queryName;
|
|
|
+ qconfig.schemaName="study";
|
|
|
+ qconfig.success=function(data){
|
|
|
+ afterListUpload(config,configUpload,data)};
|
|
|
+ qconfig.rows=rows;
|
|
|
+ LABKEY.Query.insertRows(qconfig);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ let data=new Object();
|
|
|
+ data.rows=rows;
|
|
|
+ afterListUpload(config,configUpload,data);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-function copyData(config,configUpload,queryId,data){
|
|
|
+function afterListUpload(config,configUpload,data){
|
|
|
|
|
|
- let queryName=configUpload.queries[queryId].queryName;
|
|
|
+ let queryName=configUpload.queries[configUpload.queryId].queryName;
|
|
|
printErr(config,"Inserted "+data.rows.length+" rows to "+queryName);
|
|
|
- configUpload.queries[queryId].queryStatus="DONE";
|
|
|
+ configUpload.queries[configUpload.queryId].queryStatus="DONE";
|
|
|
+ configUpload.queryId+=1;
|
|
|
copyToDataset(config,configUpload);
|
|
|
|
|
|
}
|
|
@@ -1486,11 +1523,16 @@ function generateMasterForm(config){
|
|
|
generateButton(config,"submitDiv","Review submission","Ask for further review",onUpdateForReview,config);
|
|
|
generateButton(config,"submitDiv","Remove submission","Remove CRF form",onRemoveCRF,config);
|
|
|
}
|
|
|
+ if (config.reviewMode=="APPROVED"){
|
|
|
+ generateButton(config,"submitDiv","Review submission","Restore form for further review",onUpdateForReview,config);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
else{
|
|
|
generateButton(config,"submitDiv","Complete submission","Submit",onSubmit,config);
|
|
|
generateButton(config,"submitDiv","Remove submission","Remove CRF form",onRemoveCRF,config);
|
|
|
}
|
|
|
+ generateButton(config,"submitDiv","Done","Exit",redirect,config);
|
|
|
|
|
|
}
|
|
|
|