Переглянути джерело

Adding specialFields for automated ID generation

Andrej Studen 2 роки тому
батько
коміт
8d3926f8a0
2 змінених файлів з 96 додано та 27 видалено
  1. 3 1
      views/visit.view.xml
  2. 93 26
      web/crfTecant/crfVisit.js

+ 3 - 1
views/visit.view.xml

@@ -1,9 +1,11 @@
 <view xmlns="http://labkey.org/data/xml/view" title="CRF Form (Tecant)">
 	<dependencies>
       <dependency path="crfTecant/runQuery.js"/>
+      <dependency path="crfTecant/generateRegistration.js"/>
       <dependency path="crfTecant/participantIdManager.js"/>
       <dependency path="crfTecant/crfVisit.js"/>
-		<dependency path="crfTecant/crfReview.js"/>
+      <dependency path="crfTecant/crfReview.js"/>
+
 		<!--local copy of pdfkit, version 0.10.0-->
 		<!--https://github.com/devongovett/pdfkit/releases/download/v0.10.0/pdfkit.standalone.js-->
 		<dependency path="crfTecant/pdfkit.standalone.js" />

+ 93 - 26
web/crfTecant/crfVisit.js

@@ -999,16 +999,6 @@ function addFieldRow(tb,field,setup,additionalData){
 	let isLookup=("lookup" in field);
 	print(fName+": ["+vName+"/"+vType+'/'+isLookup+"]");
 
-   let detailsRow=config.formConfig['variableDetails'].rows;
-   let details=undefined;
-   for (let i=0;i<detailsRow.length;i++){
-      if (detailsRow[i]['variableName']==field.name){
-         print(fName+": ["+vName+"]: details "+detailsRow[i].description);
-         details=detailsRow[i].description;
-         break;
-      }
-   }
-	
 	let row=tb.insertRow();
 	let cell=config.document.createElement('th');
    cell.style.width='300px';
@@ -1020,12 +1010,6 @@ function addFieldRow(tb,field,setup,additionalData){
 	
 	let input=null;
    let colSpan="3";
-   if (details!=undefined){
-      let cell2=row.insertCell();
-      cell2.colSpan="2";
-      cell2.innerText=details;
-      colSpan="1";
-   }
 	let cell1=row.insertCell();
 	cell1.colSpan=colSpan;
 	let readonlyFlag=setup.readonlyFlag(vName);
@@ -1160,6 +1144,63 @@ function addFieldRow(tb,field,setup,additionalData){
 	input.selectedIndex=0;	
 
 }
+
+function parseVariables(pars){
+   let pA=pars.split(";");
+   let q=new Object();
+   for (let i=0;i<pA.length;i++){
+      let vA=pA[i].split('=');
+      q[vA[0]]=vA[1];
+   }
+   return q;
+}
+
+
+
+function addSpecialFieldRow(tb,specFieldSetup,setup){
+   //tb is the table, specFieldSetup is a row from the table where special fields are being setup
+   //the first column is fieldUID, which is a colon joined amalgation of queryName:fieldName
+   let fieldUID=specFieldSetup["fieldUID"];
+   let x=fieldUID.split(':');
+   let fieldName=x[1];
+   let fName="[addSpecialFieldRow/"+fieldUID+"]";
+   let q=parseVariables(specFieldSetup['actionParameters']);
+   print(fName);
+   if (specFieldSetup['actionType']=='textArea'){
+      let row=tb.insertRow();
+      let cell1=row.insertCell();
+      cell1.colSpan="4";
+      cell1.style.textAlign="justify";
+      cell1.style.padding="10px";
+      cell1.style.backgroundColor="#e0e0e0";
+      cell1.innerText=q['description'];
+      return;
+   }
+   if (specFieldSetup['actionType']=='generationObject'){
+      //only in EDIT mode!!
+      let ro=setup.readonlyFlag(fieldName);
+      if (ro) return;
+      config.print=print;
+      let gc=getGenerationObject(config,q,setup.getInputId(fieldName));
+      gc.inspect();
+      gc.execute();
+      let row=tb.insertRow();
+      let cell=config.document.createElement('th');
+      row.appendChild(cell);
+      let text = config.document.createTextNode("Automatic ID generator");
+      cell.appendChild(text);
+      let cell1=row.insertCell();
+      cell1.colSpan="3";
+      let b=config.document.createElement("input");
+      b.type="button";
+      b.id="generateIdButton";
+      b.onclick=function(){gc.execute();};
+      b.value="Generate ID";
+      cell1.appendChild(b);
+
+   }
+}
+
 		
 function populateFieldRow(entry,field,setup){
 	populateField(entry,field,setup);
@@ -1365,15 +1406,22 @@ function generateTable(listName,divName,additionalData,setup){
 		
 	for (f in fields){
 		let field=fields[f];
+      let fieldUID=listName+":"+field.name;
 		//each field is a new row
-		print(fName+": Adding field: "+f+'/'+field.name);
+		print(fName+": Adding field: "+f+'/'+field.name+' ('+fieldUID+').');
+      //unique name
 		if (field.hidden) continue;
 		if (field.name=="crfRef") continue;
 		addFieldRow(tb,field,setup,additionalData);
 		populateFieldRow(entry,field,setup);
+      if (fieldUID in config.formConfig["specialFields"]){
+         let specFieldSetup=config.formConfig["specialFields"][fieldUID];
+         addSpecialFieldRow(tb,specFieldSetup,setup);
+      }
+
 		
 	}
-	//add comment field	
+   //finish of if apply button is not required
 	if (!("addApply" in setup)) {
 		print(fName+"populateTable: done");
 		return;
@@ -2987,7 +3035,7 @@ function setFormConfig(){
 	//add object to store form related data
 	config.formConfig=new Object();
 
-	config.formConfig.softwareVersion='0.15.10';
+	config.formConfig.softwareVersion='T.15.18';
 	let debug=true;
 
 	if (debug)
@@ -3014,14 +3062,29 @@ function setFormConfig(){
 }
 
 
+function convertToDictionary(rows){
+   let x=new Array();
+	for (let i=0;i<rows.length;i++){
+		let n=rows[i]['name'];
+		let v=rows[i]['value'];
+		x[n]=v;
+	}
+   return x;
+}
+   
+function convertToAssociatedArray(rows,fieldName="name"){
+   let fName="[convertToAssociatedArray]";
+   let x=new Object();
+	for (let i=0;i<rows.length;i++){
+		let n=rows[i][fieldName];
+		x[n]=rows[i];
+	}
+   return x;
+}
+ 
 function afterSettings(data){
 
-	config.formConfig.settings=new Array();
-	for (let i=0;i<data.rows.length;i++){
-		let n=data.rows[i]['name'];
-		let v=data.rows[i]['value'];
-		config.formConfig.settings[n]=v;
-	}
+	config.formConfig.settings=convertToDictionary(data.rows);
 
 	let st=config.formConfig.settings;
 	print('afterSettings');
@@ -3085,7 +3148,7 @@ function collectData(){
    queryArray.push(
       makeQuery(targetObject,'data','crfStaticVariables','crfStaticVariables',[]));
 
-   queryArray.push(makeQuery(targetObject,'data','variableDetails','variableDetails',[]));
+   queryArray.push(makeQuery(targetObject,'data','specialFields','specialFieldsQuery',[]));
 	//study
 	queryArray.push(makeQuery(targetObject,'data','Study','studyDataAll1',[]));
 	let e=queryArray[queryArray.length-1];
@@ -3126,6 +3189,10 @@ function collectData(){
 
 function addStudyData(){
    let fName='addStudyData';
+
+   //convert specialFields to array
+   let q=config.formConfig["specialFieldsQuery"].rows;
+   config.formConfig.specialFields=convertToAssociatedArray(q,"fieldUID");
    print(fName);
 	let queryArray=new Array();