|
@@ -1,9 +1,19 @@
|
|
|
function clear(config){
|
|
|
+ let el=config.document.getElementById(config.debugId);
|
|
|
+ if (el===null) {
|
|
|
+ //alert("Debug section not initialized");
|
|
|
+ return;
|
|
|
+ }
|
|
|
config.document.getElementById(config.debugId).value="";
|
|
|
}
|
|
|
|
|
|
function print(config,msg){
|
|
|
- config.document.getElementById(config.debugId).value+="\n"+msg;
|
|
|
+ let el=config.document.getElementById(config.debugId);
|
|
|
+ if (el===null) {
|
|
|
+ //alert("Debug section not initialized. Message: "+msg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ el.value+="\n"+msg;
|
|
|
}
|
|
|
|
|
|
function getCRFref(config){
|
|
@@ -11,6 +21,58 @@ function getCRFref(config){
|
|
|
return config.document.getElementById(config.crfRefId).innerHTML;
|
|
|
}
|
|
|
|
|
|
+function onFailure(errorInfo, options, responseObj){
|
|
|
+
|
|
|
+ if (errorInfo && errorInfo.exception)
|
|
|
+ alert("Failure: " + errorInfo.exception);
|
|
|
+ else
|
|
|
+ alert("Failure: " + responseObj.statusText);
|
|
|
+}
|
|
|
+
|
|
|
+function generateDebugSection(config){
|
|
|
+ //let debug=true;
|
|
|
+ //if (debug) print(config,"generateDebugSection "+sectionName);
|
|
|
+
|
|
|
+ let formName=config.debugDiv;
|
|
|
+ let sectionName="debugSection";
|
|
|
+ let sectionTitle="Debug Messages";
|
|
|
+ let tb=config.document.createElement('table');
|
|
|
+ tb.className='t2';
|
|
|
+ let row=tb.insertRow();
|
|
|
+ let cell=config.document.createElement('th');
|
|
|
+ row.appendChild(cell);
|
|
|
+ cell.setAttribute("colspan","4");
|
|
|
+ cell.style.fontSize="20px";
|
|
|
+ cell.style.textAlign="center";
|
|
|
+ let cellData=config.document.createTextNode(sectionTitle);
|
|
|
+ cell.appendChild(cellData);
|
|
|
+ cell=row.insertCell();
|
|
|
+ let input=config.document.createElement("input");
|
|
|
+ input.type="button";
|
|
|
+ input.value="Show";
|
|
|
+ input.id="toggle"+sectionName+"VisbilityButton";
|
|
|
+ input.onclick=function(){toggleVisibility(config,sectionName,input.id)};
|
|
|
+ cell.appendChild(input);
|
|
|
+ config.document.getElementById(formName).appendChild(tb);
|
|
|
+
|
|
|
+
|
|
|
+ let div=config.document.createElement('div');
|
|
|
+ div.id=sectionName;
|
|
|
+ div.style.display="none";
|
|
|
+ config.document.getElementById(formName).appendChild(div);
|
|
|
+
|
|
|
+ let debugArea=config.document.createElement('textarea');
|
|
|
+ debugArea.rows=10;
|
|
|
+ debugArea.cols=95;
|
|
|
+ debugArea.id=config.debugId;
|
|
|
+ div.appendChild(debugArea);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
function populateBasicData(config,data){
|
|
|
let debug=false;
|
|
|
if (debug)
|
|
@@ -27,12 +89,19 @@ function populateBasicData(config,data){
|
|
|
qconfig.success=function(data){setHTML(config,data,'siteName','siteName')};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
|
|
|
+
|
|
|
+ if (debug)
|
|
|
+ print(config,"set user: "+data.rows[0].UserId);
|
|
|
let qconfig1=new Object();
|
|
|
qconfig1.containerPath=config.containerPath;
|
|
|
qconfig1.schemaName='core';
|
|
|
qconfig1.queryName='Users';
|
|
|
qconfig1.filterArray= [LABKEY.Filter.create('UserId',data.rows[0].UserId)];
|
|
|
qconfig1.success= function(data){setHTML(config,data,'investigatorName','DisplayName')};
|
|
|
+ qconfig1.failure=onFailure;
|
|
|
+ if (debug)
|
|
|
+ print(config,"USER select rows");
|
|
|
+
|
|
|
LABKEY.Query.selectRows(qconfig1);
|
|
|
}
|
|
|
|
|
@@ -74,7 +143,8 @@ function fullAccessSetup(config,listName){
|
|
|
setup.filters['crfRef']=getCRFref(config);
|
|
|
setup.getInputId=function(vName){return listName+"_"+vName;}
|
|
|
setup.addApply="Save";
|
|
|
- setup.unique=true;
|
|
|
+ //not neccesarily unique
|
|
|
+ //setup.unique=true;
|
|
|
//no addApply
|
|
|
return setup;
|
|
|
|
|
@@ -101,24 +171,73 @@ function generateForm(config,data){
|
|
|
if (debug) print(config,"generateForm ["+i+"/"+data.rows.length+"]");
|
|
|
|
|
|
let entry=data.rows[i];
|
|
|
- let queryName=entry["queryName"];
|
|
|
+ //this is actually a pointer into another list (==lookup)
|
|
|
+ //another selectRows is needed to actually get the name for the queryName
|
|
|
+ //
|
|
|
|
|
|
- if (debug) print(config,"entry[queryName]: "+entry["queryName"]);
|
|
|
|
|
|
- if (!(queryName in config.fields))
|
|
|
- config.fields[queryName]=new Object();
|
|
|
|
|
|
- let field=config.fields[queryName];
|
|
|
- field.title=entry["title"];
|
|
|
+ let fields=data.metaData.fields;
|
|
|
+ if (debug) print(config,"generateForm ["+i+"]: fields: "+fields);
|
|
|
+ let field="NONE";
|
|
|
+ //if (debug) printTableSetup(config,data);
|
|
|
+ for (f in fields){
|
|
|
+ if (fields[f]['name']!='queryName') continue;
|
|
|
+ field=fields[f];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (debug) print(config,"generateForm ["+i+"]: field: "+field);
|
|
|
+ let lookup=field.lookup;
|
|
|
+ if (debug) print(config,"generateForm ["+i+"]: lookup: "+lookup);
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.containerPath=config.containerPath;
|
|
|
+ qconfig.schemaName=lookup.schemaName;
|
|
|
+ qconfig.queryName=lookup.queryName;
|
|
|
+ qconfig.filterArray=[LABKEY.Filter.create(lookup.keyColumn,entry['queryName'])];
|
|
|
+ qconfig.success=function(data){generateFormLookup(config,data,entry)};
|
|
|
+ LABKEY.Query.selectRows(qconfig);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- if (debug) print(config,"entry[showFlag]: "+entry["showFlag"]);
|
|
|
|
|
|
- let additionalData=new Object();
|
|
|
- setAdditionalData(config,additionalData,entry);
|
|
|
- generateSection(config,entry["queryName"],entry["title"],
|
|
|
- entry["queryName"], additionalData);
|
|
|
+function generateFormLookup(config,data,entry){
|
|
|
+ //id : entry[queryName]
|
|
|
+ //name: dentry[queryName]
|
|
|
+
|
|
|
+ let debug=true;
|
|
|
+ let queryId=entry['queryName'];
|
|
|
|
|
|
+ if (data.rows.length==0){
|
|
|
+ alert("No rows found for listId: "+entry['queryName']);
|
|
|
+ return;
|
|
|
}
|
|
|
+ let dentry=data.rows[0];
|
|
|
+ if (debug)
|
|
|
+ for (f in dentry) print(config,"generateFormLookup field: "+f+" value: "+dentry[f]);
|
|
|
+
|
|
|
+ let queryName=dentry["queryName"];
|
|
|
+
|
|
|
+ if (debug) print(config,"generateFormLookup: ID: "+queryId+" name: "+queryName);
|
|
|
+
|
|
|
+ //update fields for review
|
|
|
+ if (!(queryName in config.fields))
|
|
|
+ config.fields[queryName]=new Object();
|
|
|
+
|
|
|
+ if (!(queryId in config.queryMap))
|
|
|
+ config.queryMap[queryId]=queryName;
|
|
|
+
|
|
|
+ let field=config.fields[queryName];
|
|
|
+
|
|
|
+ field.title=entry["title"];
|
|
|
+ field.queryId=queryId;
|
|
|
+
|
|
|
+ if (debug) print(config,"entry[showFlag]: "+entry["showFlag"]);
|
|
|
+
|
|
|
+ let additionalData=new Object();
|
|
|
+ setAdditionalData(config,additionalData,entry);
|
|
|
+ generateSection(config,queryName,entry["title"],queryName, additionalData);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function generateSection(config, sectionName, sectionTitle, listName, additionalData){
|
|
@@ -172,6 +291,8 @@ function generateSection(config, sectionName, sectionTitle, listName, additional
|
|
|
if (debug) print(config,"generate master table");
|
|
|
|
|
|
let setup=fullAccessSetup(config,listName);
|
|
|
+ //master table is unique per visit
|
|
|
+ setup.unique=true;
|
|
|
if (config.review)
|
|
|
setup=readonlySetup(config);
|
|
|
generateTable(config,listName,divTable.id,true,additionalData,setup);
|
|
@@ -195,37 +316,46 @@ function generateSection(config, sectionName, sectionTitle, listName, additional
|
|
|
divReview.id=sectionName+"Review";
|
|
|
div.appendChild(divReview);
|
|
|
|
|
|
+
|
|
|
+ //assume we already have listId (content of config.setupQueryName is listId)
|
|
|
+ //we need listName also
|
|
|
let qconfig=new Object();
|
|
|
qconfig.containerPath=config.containerPath;
|
|
|
qconfig.schemaName='lists';
|
|
|
- qconfig.queryName='visitZeroSetup';
|
|
|
+ qconfig.queryName=config.setupQueryName;
|
|
|
qconfig.success=function(data){
|
|
|
generateReview(config,data,divReview.id,divReviewList.id,listName)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
function generateReview(config,data,divReviewId,divReviewListId, listName){
|
|
|
+ let listId=config.fields[listName].queryId;
|
|
|
+
|
|
|
let debug=true;
|
|
|
- if (debug) print(config,"Generate review for: "+listName);
|
|
|
- let listId=-1;
|
|
|
- for (let i=0;i<data.rows.length;i++){
|
|
|
- let entry=data.rows[i];
|
|
|
- if (entry["queryName"]!=listName) continue;
|
|
|
- listId=entry["Key"];
|
|
|
- break;
|
|
|
- }
|
|
|
- if (debug) print(config,"Review: setting listId: "+listId);
|
|
|
+ if (debug) print(config,"Generate review for: "+listId);
|
|
|
+
|
|
|
+ //don't need this
|
|
|
+ //let listId=-1;
|
|
|
+ //for (let i=0;i<data.rows.length;i++){
|
|
|
+ // let entry=data.rows[i];
|
|
|
+ // if (entry["queryName"]!=listName) continue;
|
|
|
+ // listId=entry["Key"];
|
|
|
+ // break;
|
|
|
+ //}
|
|
|
+ //if (debug) print(config,"Review: setting listId: "+listId);
|
|
|
|
|
|
let reviewSetup=new Object();
|
|
|
reviewSetup.readonlyFlag=function(vName){
|
|
|
if (vName=="queryName") return true;
|
|
|
+ if (vName=="queryname") return true;
|
|
|
if (vName=="ModifiedBy") return true;
|
|
|
return false;};
|
|
|
reviewSetup.addApply="Add Review";
|
|
|
reviewSetup.filters=new Object();
|
|
|
reviewSetup.filters["crfRef"]=getCRFref(config);
|
|
|
- reviewSetup.filters["queryName"]=listId;
|
|
|
- reviewSetup.filters["ModifiedBy"]=LABKEY.Security.currentUser.id;
|
|
|
+ reviewSetup.filters["queryName"]=listId;//entry in reviewComments list is queryname, all in small caps
|
|
|
+ //reviewSetup.filters["ModifiedBy"]=LABKEY.Security.currentUser.id;
|
|
|
+ //needs listName, in argument
|
|
|
reviewSetup.getInputId=function(vName){return listName+"_add"+vName};
|
|
|
reviewSetup.divReviewListId=divReviewListId;
|
|
|
|
|
@@ -375,31 +505,34 @@ function generateTable(config,listName,divName,unique,additionalData,setup){
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
+function printTableSetup(config,data){
|
|
|
+ let obj=data.metaData.fields;
|
|
|
+ for (f in obj){
|
|
|
+ print(config,"Data["+f+"]: "+obj[f]);
|
|
|
+ for (g in obj[f]){
|
|
|
+ print(config,"Data.metaData.fields["+f+"]["+g+"]: "+obj[f][g]);
|
|
|
+ }
|
|
|
+ if ("lookup" in obj[f]){
|
|
|
+ for (h in obj[f]["lookup"]){
|
|
|
+ print(config,"Lookup["+h+"]: "+obj[f]["lookup"][h]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
function populateTable(config,data,divName,unique,additionalData,setup){
|
|
|
//generate and populate table with the first suitable entry
|
|
|
let debug=true;
|
|
|
|
|
|
+
|
|
|
if (debug){
|
|
|
print(config,"populateTable Query: "+data.queryName+" divName: "+divName+" setup: "+setup);
|
|
|
|
|
|
|
|
|
- if (0){
|
|
|
- let obj=data.metaData.fields;
|
|
|
- for (f in obj){
|
|
|
- print(config,"Data["+f+"]: "+obj[f]);
|
|
|
- for (g in obj[f]){
|
|
|
- print(config,"Data.metaData.fields["+f+"]["+g+"]: "+obj[f][g]);
|
|
|
- }
|
|
|
- if ("lookup" in obj[f]){
|
|
|
- for (h in obj[f]["lookup"]){
|
|
|
- print(config,"Lookup["+h+"]: "+obj[f]["lookup"][h]);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ if (0) printTableSetup(config,data);
|
|
|
}
|
|
|
+
|
|
|
let crfRef=getCRFref(config);
|
|
|
let entry=new Object();
|
|
|
|
|
@@ -456,7 +589,7 @@ function populateTable(config,data,divName,unique,additionalData,setup){
|
|
|
input = config.document.createElement("input");
|
|
|
input.type="date";
|
|
|
}
|
|
|
- if (vType=="string"){
|
|
|
+ if (vType=="string" && !("lookup" in field)){
|
|
|
if(vName.search("reviewComment")>-1){
|
|
|
input = config.document.createElement("textarea");
|
|
|
input.cols="65";
|
|
@@ -471,12 +604,18 @@ function populateTable(config,data,divName,unique,additionalData,setup){
|
|
|
input = config.document.createElement("input");
|
|
|
input.type="text";
|
|
|
}
|
|
|
-
|
|
|
+ if (vType=="boolean"){
|
|
|
+ input = config.document.createElement("input");
|
|
|
+ input.type="checkbox";
|
|
|
+ print(config,"Creating checkbox");
|
|
|
+ }
|
|
|
+
|
|
|
input.id=setup.getInputId(vName);
|
|
|
- if (vName in entry){
|
|
|
+ if (varValue != "UNDEF"){
|
|
|
if (vType=="string") input.value=varValue;
|
|
|
if (vType=="float") input.value=varValue;
|
|
|
if (vType=="date") input.valueAsDate=varValue;
|
|
|
+ if (vType=="boolean") input.checked=varValue;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -543,6 +682,7 @@ function populateSelect(config,data,parameters,setup,readonlyFlag){
|
|
|
print(config,"ElementId: "+elementId);
|
|
|
print(config,"keyColumn: "+keyColumn);
|
|
|
print(config,"displayColumn: "+displayColumn);
|
|
|
+ print(config,"No of options: " +data.rows.length);
|
|
|
|
|
|
if ("selectedKey" in parameters){
|
|
|
print(config,"SelectedKey: "+parameters["selectedKey"]);
|
|
@@ -563,6 +703,7 @@ function populateSelect(config,data,parameters,setup,readonlyFlag){
|
|
|
opt.text = "<Select>";
|
|
|
opt.value = -1;
|
|
|
el.options[0] = opt;
|
|
|
+ if (debug) print(config, "Adding <Select>");
|
|
|
|
|
|
}
|
|
|
|
|
@@ -667,6 +808,10 @@ function saveReviewToList(config,data,elementId,setup){
|
|
|
entry.queryName=setup.filters["queryName"];
|
|
|
if (debug) print(config,"Setting queryName: "+entry.queryName);
|
|
|
}
|
|
|
+ if ("queryname" in setup.filters) {
|
|
|
+ entry.queryname=setup.filters["queryname"];
|
|
|
+ if (debug) print(config,"Setting queryname: "+entry.queryname);
|
|
|
+ }
|
|
|
let fields=data.metaData.fields;
|
|
|
for (f in fields){
|
|
|
|
|
@@ -678,6 +823,7 @@ function saveReviewToList(config,data,elementId,setup){
|
|
|
|
|
|
if (vName=="crfRef") continue;
|
|
|
if (vName=="queryName") continue;
|
|
|
+ if (vName=="queryname") continue;
|
|
|
|
|
|
let eId=setup.getInputId(vName);
|
|
|
|
|
@@ -717,6 +863,9 @@ function saveReviewToList(config,data,elementId,setup){
|
|
|
if (vType=="float"){
|
|
|
entry[vName]=el.value;
|
|
|
}
|
|
|
+ if (vType=="boolean"){
|
|
|
+ entry[vName]=el.checked;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|
|
@@ -754,97 +903,184 @@ function updateLastSavedFlag(config,data,setup,elementId){
|
|
|
|
|
|
function onDatabaseUpload(config){
|
|
|
print(config,"Database upload");
|
|
|
+ configUpload=new Object();
|
|
|
//figure out the participantId
|
|
|
|
|
|
let qconfig=new Object();
|
|
|
- qconfig.queryName=config.registrationQuery;
|
|
|
+ qconfig.queryName=config.queryMap[config.registrationQueryId];
|
|
|
+ //queryMap holds mapping for queries in visit;
|
|
|
+ //masterQuery should be one of them, so this is safe.
|
|
|
qconfig.schemaName='lists';
|
|
|
qconfig.filterArray=[LABKEY.Filter.create('crfRef',getCRFref(config))];
|
|
|
- qconfig.success=function(data){updateDatabaseWithPatientId(config,data);}
|
|
|
+ qconfig.success=function(data){afterRegistration(config,configUpload,data);}
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
+ //waitForCompleteUpload(config);//
|
|
|
|
|
|
}
|
|
|
|
|
|
-function updateDatabaseWithPatientId(config,data){
|
|
|
+function afterRegistration(config,configUpload,data){
|
|
|
+ print(config,"afterRegistration: rows:"+data.rows.length);
|
|
|
+ configUpload.registration=data;
|
|
|
+ let registrationData=configUpload.registration;
|
|
|
clearErr(config);
|
|
|
- if (data.rows.length!=1){
|
|
|
- let msg="ERROR: Found "+data.rows.length;
|
|
|
+ if (registrationData.rows.length!=1){
|
|
|
+ let msg="ERROR: Found "+registrationData.rows.length;
|
|
|
msg+=" registration entries for crfrefid "+getCRFref(config);
|
|
|
print(config,msg);
|
|
|
return;
|
|
|
}
|
|
|
- participantId=data.rows[0][config.registrationParticipantIdField];
|
|
|
- print(config,"Setting participantId to "+participantId);
|
|
|
+ configUpload.participantId=registrationData.rows[0][config.registrationParticipantIdField];
|
|
|
+ //could be a lookup field
|
|
|
+ let fields=registrationData.metaData.fields;
|
|
|
+ let field="NONE";
|
|
|
+ for (f in fields){
|
|
|
+ if (fields[f]["name"]==config.registrationParticipantIdField)
|
|
|
+ field=fields[f];
|
|
|
+ }
|
|
|
+ if ("lookup" in field){
|
|
|
+ print(config,"Using lookup for participantId: "+configUpload.participantId);
|
|
|
+ let lookup=field["lookup"];
|
|
|
+ print(config,"Lookup: "+lookup);
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.containerPath=config.containerPath;
|
|
|
+ qconfig.schemaName=lookup.schemaName;
|
|
|
+ qconfig.queryName=lookup.queryName;
|
|
|
+ qconfig.filterArray=
|
|
|
+ [LABKEY.Filter.create(lookup.keyColumn,configUpload.participantId)];
|
|
|
+ qconfig.success=function(data){
|
|
|
+ afterRegistrationLookup(config,configUpload,data,lookup.displayColumn)};
|
|
|
+ LABKEY.Query.selectRows(qconfig);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ afterParticipantId(config,configUpload);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function afterRegistrationLookup(config,configUpload,data,displayColumn){
|
|
|
+ print(config,"afterRegistrationLookup");
|
|
|
+ let entry=data.rows[0];
|
|
|
+ configUpload.participantId=entry[displayColumn];
|
|
|
+ afterParticipantId(config,configUpload);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function afterParticipantId(config,configUpload){
|
|
|
+ print(config,"Setting participantId to "+configUpload.participantId);
|
|
|
//another select rows to update all queries from setup
|
|
|
//just use registration for test
|
|
|
- let qconfig=new Array();
|
|
|
+ let qconfig=new Object();
|
|
|
qconfig.schemaName='lists';
|
|
|
qconfig.queryName=config.setupQueryName;
|
|
|
- qconfig.success=function(data){copyDatasetsFromSetup(config,data);}
|
|
|
+ qconfig.success=function(data){afterSetup(config,configUpload,data);}
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function copyDatasetsFromSetup(config,data){
|
|
|
+function afterSetup(config,configUpload,data){
|
|
|
+
|
|
|
+ configUpload.queries=new Array();
|
|
|
|
|
|
for (let i=0;i<data.rows.length;i++){
|
|
|
let entry=data.rows[i];
|
|
|
- copyToDataset(config,entry.queryName,participantId);
|
|
|
- if (entry.showQuery!="NONE"){
|
|
|
- copyToDataset(config,entry.showQuery,participantId);
|
|
|
- }
|
|
|
+ //use lookup table to convert from id to name
|
|
|
+ let queryName=config.queryMap[entry.queryName];
|
|
|
+ configUpload.queries.push({queryName:queryName,queryStatus:"QUEUED"});
|
|
|
+ if (entry.showQuery=="NONE")
|
|
|
+ continue
|
|
|
+ configUpload.queries.push({queryName:entry.showQuery,queryStatus:"QUEUED"});
|
|
|
}
|
|
|
- print(config,"Database updated");
|
|
|
+ //add reviews
|
|
|
+ configUpload.queries.push({queryName:"reviewComments",queryStatus:"QUEUED"});
|
|
|
+ copyToDataset(config,configUpload);
|
|
|
+
|
|
|
+ //config.upload["start"]=true;
|
|
|
+ //for (u in config.upload){
|
|
|
+ // if (u=="start") continue;
|
|
|
+ // if (u=="count") continue;
|
|
|
+ // copyToDataset(config,u,participantId);
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //print(config,"Database updated");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-function copyToDataset(config,queryName,participantId){
|
|
|
- print(config,"copyToDataset");
|
|
|
+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) {
|
|
|
+ updateFlag(config,3);//Approved
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let queryName=configUpload.queries[queryId].queryName;
|
|
|
+ print(config,"copyToDataset["+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){copyDataToDataset(config,queryName,participantId,data)};
|
|
|
+ qconfig.success=function(data){afterListData(config,configUpload,queryId,data)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function copyDataToDataset(config,queryName,participantId,dataList){
|
|
|
- print(config,"copyDataToDataset");
|
|
|
+function afterListData(config,configUpload,queryId,data){
|
|
|
+
|
|
|
+ let queryName=configUpload.queries[queryId].queryName;
|
|
|
+ let msg="copyDataToDataset ["+queryId+"/"+configUpload.queries.length+"] : "+queryName;
|
|
|
+ print(config,msg);
|
|
|
+ configUpload.listData=data;
|
|
|
|
|
|
let qconfig=new Object();
|
|
|
qconfig.queryName=queryName;
|
|
|
qconfig.schemaName="study";
|
|
|
qconfig.filterArray=[LABKEY.Filter.create('crfRef',getCRFref(config))];
|
|
|
- qconfig.filterArray.push(LABKEY.Filter.create('ParticipantId',participantId));
|
|
|
- qconfig.success=function(data){copyDataToDatasetChecked(config,queryName,participantId,dataList,data)};
|
|
|
+ qconfig.filterArray.push(LABKEY.Filter.create('ParticipantId',configUpload.participantId));
|
|
|
+ qconfig.success=function(data){afterStudyData(config,configUpload,queryId,data)};
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
|
|
|
-function copyDataToDatasetChecked(config,queryName,participantId,dataList,dataStudy){
|
|
|
+function afterStudyData(config,configUpload,queryId,data){
|
|
|
+ configUpload.studyData=data;
|
|
|
|
|
|
- print(config,"copyDataToDatasetChecked");
|
|
|
- if (dataStudy.rows.lentgh>0){
|
|
|
+ let queryName=configUpload.queries[queryId].queryName;
|
|
|
+ print(config,"copyDataToDatasetChecked: "+queryName);
|
|
|
+
|
|
|
+ if (configUpload.listData.rows.lentgh>0){
|
|
|
clearErr(config);
|
|
|
- let msg="Dataset "+queryName+" already filled for participant "+participantId;
|
|
|
+ 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
|
|
|
- return;
|
|
|
+ copyToDataset(config,configUpload);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ let dataList=configUpload.listData;
|
|
|
+ if (dataList.rows.length==0){
|
|
|
+ printErr(config,"Dataset "+queryName+" empty.");
|
|
|
+ configUpload.queries[queryId].queryStatus="DONE";
|
|
|
+ copyToDataset(config,configUpload);
|
|
|
+ }
|
|
|
+
|
|
|
//update non-list elements
|
|
|
let seqNumber=getCRFref(config);
|
|
|
|
|
|
let rows=new Array();
|
|
|
for (let i=0;i<dataList.rows.length;i++){
|
|
|
let entry=dataList.rows[i];
|
|
|
- entry.ParticipantId=participantId;
|
|
|
+ entry.ParticipantId=configUpload.participantId;
|
|
|
entry.crfRef=getCRFref(config);
|
|
|
entry.SequenceNum=getCRFref(config);
|
|
|
entry.SequenceNum=entry.SequenceNum % 1000000000;
|
|
|
|
|
|
if (dataList.rows.length>1){
|
|
|
- entry.SequenceNum+=i/10;
|
|
|
+ entry.SequenceNum+=i/100;
|
|
|
}
|
|
|
print(config, "Adding sequence number "+entry.SequenceNum);
|
|
|
rows.push(entry);
|
|
@@ -854,13 +1090,17 @@ function copyDataToDatasetChecked(config,queryName,participantId,dataList,dataSt
|
|
|
qconfig.queryName=queryName;
|
|
|
qconfig.schemaName="study";
|
|
|
qconfig.success=function(data){
|
|
|
- reportCopyDataToDatasetChecked(config,queryName,participantId,data)};
|
|
|
+ copyData(config,configUpload,queryId,data)};
|
|
|
qconfig.rows=rows;
|
|
|
LABKEY.Query.insertRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function reportCopyDataToDatasetChecked(config,queryName,participantId,data){
|
|
|
+function copyData(config,configUpload,queryId,data){
|
|
|
+
|
|
|
+ let queryName=configUpload.queries[queryId].queryName;
|
|
|
printErr(config,"Inserted "+data.rows.length+" rows to "+queryName);
|
|
|
+ configUpload.queries[queryId].queryStatus="DONE";
|
|
|
+ copyToDataset(config,configUpload);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -870,18 +1110,23 @@ function reportCopyDataToDatasetChecked(config,queryName,participantId,data){
|
|
|
//*************************update for further review *************************
|
|
|
|
|
|
function onUpdateForReview(config){
|
|
|
- print(config,"Sent to further review");
|
|
|
+ updateFlag(config,4);//Pending review
|
|
|
+}
|
|
|
+
|
|
|
+function updateFlag(config,flag){
|
|
|
+ if (flag==4)
|
|
|
+ print(config,"Sent to further review");
|
|
|
let qconfig=new Object();
|
|
|
qconfig.schemaName='lists';
|
|
|
qconfig.queryName='crfEntry';
|
|
|
- qconfig.success=function(data){setFlagToReview(config,data);}
|
|
|
+ qconfig.success=function(data){setFlag(config,data,flag);}
|
|
|
qconfig.filterArray=[LABKEY.Filter.create("entryId",getCRFref(config))];
|
|
|
LABKEY.Query.selectRows(qconfig);
|
|
|
}
|
|
|
|
|
|
-function setFlagToReview(config,data){
|
|
|
+function setFlag(config,data,flag){
|
|
|
let debug=true;
|
|
|
- print(config,"setFlagToReview");
|
|
|
+ if (flag==4) print(config,"setFlagToReview");
|
|
|
if (data.rows.length!=1){
|
|
|
let msg="ERROR: Found "+data.rows.length;
|
|
|
msg+=" entries for crfrefid "+getCRFref(config);
|
|
@@ -889,7 +1134,7 @@ function setFlagToReview(config,data){
|
|
|
return;
|
|
|
}
|
|
|
let entry=data.rows[0];
|
|
|
- entry.FormStatus=4;//Pending Review
|
|
|
+ entry.FormStatus=flag;//Pending Review
|
|
|
if (debug)
|
|
|
print(config,"Set form status to "+entry.FormStatus);
|
|
|
|
|
@@ -897,16 +1142,17 @@ function setFlagToReview(config,data){
|
|
|
qconfig.schemaName='lists';
|
|
|
qconfig.queryName='crfEntry';
|
|
|
qconfig.rows=[entry];
|
|
|
- qconfig.success=function(data){completeWithReview(config,data);}
|
|
|
+ qconfig.success=function(data){completeWithFlag(config,data,flag);}
|
|
|
LABKEY.Query.updateRows(qconfig);
|
|
|
|
|
|
}
|
|
|
|
|
|
-function completeWithReview(config,data){
|
|
|
+function completeWithFlag(config,data,flag){
|
|
|
let debug=true;
|
|
|
|
|
|
- if (debug)
|
|
|
- print(config,"complete with review");
|
|
|
+ if (debug){
|
|
|
+ if (flag==4) print(config,"complete with review");
|
|
|
+ }
|
|
|
let formUrl="begin";
|
|
|
var params = {
|
|
|
"name": formUrl, // The destination wiki page. The name of this parameter is not arbitrary.
|
|
@@ -966,7 +1212,7 @@ function finalRedirect(config){
|
|
|
let c1=new Object();
|
|
|
c1.schemaName='lists';
|
|
|
c1.queryName='crfEntry';
|
|
|
- c1.filterArray=[LABKEY.Filter.create('crfRef',getCRFref(config))];
|
|
|
+ c1.filterArray=[LABKEY.Filter.create('entryId',getCRFref(config))];
|
|
|
c1.success=function(data){setSubmitStatus(config,data)};
|
|
|
LABKEY.Query.selectRows(c1);
|
|
|
}
|
|
@@ -1079,7 +1325,12 @@ function checkData(data,config){
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
function generateMasterForm(config){
|
|
|
+
|
|
|
+ generateDebugSection(config);
|
|
|
+
|
|
|
let debug=true;
|
|
|
|
|
|
if (debug)
|
|
@@ -1094,15 +1345,15 @@ function generateMasterForm(config){
|
|
|
//requires populateBasicData
|
|
|
LABKEY.Query.selectRows(selectRows);
|
|
|
|
|
|
-
|
|
|
config.fields=new Object();
|
|
|
+ config.queryMap=new Object();
|
|
|
|
|
|
let configSelectRows=new Object();
|
|
|
configSelectRows.containerPath=config.containerPath;
|
|
|
configSelectRows.schemaName='lists';
|
|
|
configSelectRows.queryName=config.setupQueryName;
|
|
|
configSelectRows.success=function(data){generateForm(config,data);};
|
|
|
- configSelectRows.failure=function(errorTxt){print(config,"generateForm fail")};
|
|
|
+ configSelectRows.failure=onFailure;//function(errorTxt){print(config,"generateForm fail" + errorTxt)};
|
|
|
LABKEY.Query.selectRows(configSelectRows);
|
|
|
|
|
|
if (debug)
|