|
@@ -117,7 +117,7 @@ function generateFormArray(){
|
|
|
print("generateFormArray "+getMode());
|
|
|
|
|
|
config.formConfig=new Object();
|
|
|
- config.formConfig.softwareVersion='T.1.11';
|
|
|
+ config.formConfig.softwareVersion='T.1.12';
|
|
|
|
|
|
config.document.getElementById('version').innerText=config.formConfig.softwareVersion;
|
|
|
|
|
@@ -188,7 +188,10 @@ function afterSettings(data){
|
|
|
queryArray.push(makeQuery('config','site','siteData',[]));
|
|
|
|
|
|
queryArray.push(makeQuery('data','crfEntry','crfEntries',[]));
|
|
|
-
|
|
|
+
|
|
|
+ queryArray.push(
|
|
|
+ makeQuery('config','generateConfig','generateConfigData',[]));
|
|
|
+
|
|
|
getDataFromQueries(queryArray,addStudyData);
|
|
|
|
|
|
}
|
|
@@ -457,8 +460,9 @@ function fcontinue(){
|
|
|
|
|
|
cell.appendChild(button);
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ if (config.role=='crfManager')
|
|
|
+ addFormGenerator();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -538,3 +542,211 @@ function createForm(formId){
|
|
|
qconfig.rows=[crfEntry];
|
|
|
LABKEY.Query.insertRows(qconfig);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+function addInputRow(table,header,type){
|
|
|
+ let fName='[addInputRow]';
|
|
|
+ print(fName);
|
|
|
+ let row=table.insertRow();
|
|
|
+ let cell=config.document.createElement('th');
|
|
|
+ let text=config.document.createTextNode(header);
|
|
|
+ cell.appendChild(text);
|
|
|
+ row.appendChild(cell);
|
|
|
+ let input=null;
|
|
|
+
|
|
|
+ if (type=="select")
|
|
|
+ input=config.document.createElement(type);
|
|
|
+
|
|
|
+ if (type=="button"){
|
|
|
+ input=config.document.createElement("input");
|
|
|
+ input.type="button";
|
|
|
+ }
|
|
|
+ let cell1=row.insertCell();
|
|
|
+ cell1.appendChild(input);
|
|
|
+ return input;
|
|
|
+}
|
|
|
+
|
|
|
+function getFormName(formId){
|
|
|
+ let rows=config.formConfig.dataForms.rows;
|
|
|
+ for (let i=0;i<rows.length;i++){
|
|
|
+ if (rows[i]['Key']==formId){
|
|
|
+ return rows[i]['formName'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "NONE";
|
|
|
+}
|
|
|
+
|
|
|
+function getQueryName(queryId){
|
|
|
+ let rows=config.formConfig.inputLists.rows;
|
|
|
+ for (let i=0;i<rows.length;i++){
|
|
|
+ if (rows[i]['Key']==queryId){
|
|
|
+ return rows[i]['queryName'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "NONE";
|
|
|
+}
|
|
|
+
|
|
|
+function getGCRow(formId){
|
|
|
+ let formRows=config.formConfig.generateConfigData.rows;
|
|
|
+ for (let i=0;i<formRows.length;i++){
|
|
|
+ if (formRows[i]['formId']==formId){
|
|
|
+ return formRows[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Object();
|
|
|
+}
|
|
|
+
|
|
|
+function getIdSelectRow(crfRef){
|
|
|
+ let rows=config.formConfig.idSelectRows;
|
|
|
+ for (let i=0;i<rows.length;i++){
|
|
|
+ if (rows[i]['crfRef']==crfRef)
|
|
|
+ return rows[i];
|
|
|
+
|
|
|
+ }
|
|
|
+ return Object();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function addOption(input,name,value){
|
|
|
+ let opt=config.document.createElement("option");
|
|
|
+ opt.text=name;
|
|
|
+ opt.value=value;
|
|
|
+ input.options[input.options.length]=opt;
|
|
|
+}
|
|
|
+
|
|
|
+function clearOptions(input){
|
|
|
+ for(let i = input.options.length; i >= 0; i--) {
|
|
|
+ input.remove(i);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function addFormGenerator(){
|
|
|
+
|
|
|
+ let fName='[addFormGenerator]';
|
|
|
+ print(fName);
|
|
|
+
|
|
|
+ let table=config.document.createElement("table");
|
|
|
+ config.document.getElementById(config.div).appendChild(table);
|
|
|
+ let formSelect=addInputRow(table,'Select form',"select");
|
|
|
+ let idSelect=addInputRow(table,'Selecct id',"select");
|
|
|
+ addOption(formSelect,'<Select>',-1);
|
|
|
+ let formRows=config.formConfig.generateConfigData.rows;
|
|
|
+ for (let i=0;i<formRows.length;i++){
|
|
|
+ let formId=formRows[i]["formId"];
|
|
|
+ let formName=getFormName(formId);
|
|
|
+ print(fName+' '+formRows[i]["formId"]+'/'+formName);
|
|
|
+ addOption(formSelect,formName,formId);
|
|
|
+ }
|
|
|
+ formSelect.onchange=function(){updateIdList(formSelect,idSelect,formRows);};
|
|
|
+ let generateButton=addInputRow(table,'Generate Form','button');
|
|
|
+ generateButton.onclick=function(){createFormWithId(formSelect,idSelect);};
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function createFormWithId(formSelect,idSelect){
|
|
|
+
|
|
|
+ let fName='[createFormWithId]';
|
|
|
+
|
|
|
+ print(fName);
|
|
|
+ let formId=formSelect.options[formSelect.selectedIndex].value;
|
|
|
+ let crfRef=idSelect.options[idSelect.selectedIndex].text;
|
|
|
+ let configRow=getGCRow(formId);
|
|
|
+ let idSelectRow=getIdSelectRow(crfRef);
|
|
|
+ let formConfig=config.formConfig;
|
|
|
+
|
|
|
+ print("Create form w/id "+formId);
|
|
|
+
|
|
|
+ let crfEntry=new Object();
|
|
|
+ crfEntry.entryId=Date.now();
|
|
|
+ crfEntry["Date"]=new Date();
|
|
|
+ crfEntry["View"]="[VIEW]";
|
|
|
+ crfEntry['participantStudyId']=idSelectRow['participantStudyId'];
|
|
|
+ crfEntry['participantLocalId']=idSelectRow['participantLocalId'];
|
|
|
+
|
|
|
+
|
|
|
+ crfEntry.formStatus=configRow['formStatus'];
|
|
|
+
|
|
|
+
|
|
|
+ let studyData=formConfig.studyData.rows[0];
|
|
|
+ let varRows=formConfig['crfStaticVariables'].rows;
|
|
|
+ for (let i=0;i<varRows.length;i++){
|
|
|
+ let varName=varRows[i].staticVariable;
|
|
|
+ crfEntry[varName]=studyData[varName];
|
|
|
+ }
|
|
|
+ crfEntry.UserId=LABKEY.Security.currentUser.id;
|
|
|
+ crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
|
|
|
+ print("Setting site to id="+crfEntry.Site);
|
|
|
+
|
|
|
+ crfEntry.Form=formId;
|
|
|
+ crfEntry.parentCrf=crfRef;
|
|
|
+
|
|
|
+ let qconfig=new Object();
|
|
|
+ qconfig.containerPath=getContainer('data');
|
|
|
+ qconfig.schemaName='lists';
|
|
|
+ qconfig.queryName='crfEntry';
|
|
|
+ qconfig.success=function(data){redirect()};
|
|
|
+ qconfig.rows=[crfEntry];
|
|
|
+ LABKEY.Query.insertRows(qconfig);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function updateIdList(formSelect,idSelect,formRows){
|
|
|
+ let fName='[updateIdList]';
|
|
|
+ let formId=formSelect.options[formSelect.selectedIndex].value;
|
|
|
+ print(fName+' id '+formId);
|
|
|
+
|
|
|
+ clearOptions(idSelect);
|
|
|
+ print(fName+' options cleared');
|
|
|
+
|
|
|
+ let queryId=-1;
|
|
|
+ for (let i=0;i<formRows.length;i++){
|
|
|
+ if (formRows[i]['formId']==formId){
|
|
|
+ queryId=formRows[i]['queryId'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ print(fName+' queryId '+queryId);
|
|
|
+ if (queryId<0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ let qselect=new Object();
|
|
|
+ qselect.containerPath=getContainer('data');
|
|
|
+ qselect.schemaName='lists';
|
|
|
+ qselect.queryName=getQueryName(queryId);
|
|
|
+ qselect.success=function(data){updateIdListWithData(idSelect,data);};
|
|
|
+ LABKEY.Query.selectRows(qselect);
|
|
|
+}
|
|
|
+
|
|
|
+function updateIdListWithData(idSelect,data){
|
|
|
+ let rows=data.rows;
|
|
|
+ config.formConfig.idSelectRows=data.rows;
|
|
|
+ for (let i=0;i<rows.length;i++){
|
|
|
+ addOption(idSelect,rows[i]['crfRef'],i);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function redirect(){
|
|
|
+
|
|
|
+ let debug=false;
|
|
|
+ let formUrl="begin";
|
|
|
+ let params=new Object();
|
|
|
+ params.name=formUrl;
|
|
|
+ params.pageId="CRF";
|
|
|
+
|
|
|
+
|
|
|
+ let containerPath=getContainer('data');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var homeURL = LABKEY.ActionURL.buildURL(
|
|
|
+ "project", formUrl , containerPath, params);
|
|
|
+ print("Redirecting to "+homeURL);
|
|
|
+ if (debug) return;
|
|
|
+ window.location = homeURL;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|