Browse Source

Changing formId to be deducted from crfEntry rather than URL, interpretation of addData in specialVariables values allows for slash delimeted pairs where first value is the name in the registration query and the second in crfEntry, for promoting parentCrf as entryId, allow generationConfig to specify initial formStatus of the generated form (to use other than In Progress)

Andrej Studen 2 years ago
parent
commit
1d4aea358d
1 changed files with 40 additions and 12 deletions
  1. 40 12
      web/crfTecant/crfVisit.js

+ 40 - 12
web/crfTecant/crfVisit.js

@@ -1190,8 +1190,13 @@ function addSpecialFieldRow(tb,specFieldSetup,setup){
          gc.addData=new Array();
          gc.addData=new Array();
          for (let v in vars){
          for (let v in vars){
             let s=vars[v]
             let s=vars[v]
-            gc.addData[s]=config.formConfig.crfEntry[s];
-            print(fName+" addData ["+s+"]: "+gc.addData[s]);
+            //variable name can be written as A/B where A is the name in addData and B is the variable name in crfEntry
+            //useful for mocking up crfId from daughter crf-s such as registration
+            let sArray=s.split('/');
+            let sTarget=sArray[0];
+            let sSource=sArray[sArray.length-1];
+            gc.addData[sTarget]=config.formConfig.crfEntry[sSource];
+            print(fName+" addData ["+sTarget+"]: "+gc.addData[sTarget]);
          }
          }
       }
       }
       let row=tb.insertRow();
       let row=tb.insertRow();
@@ -2753,12 +2758,12 @@ function afterData(){
 
 
 }
 }
 
 
-function findSetupRow(queryName){
+function findSetupRow(queryName,formId){
 	let rowsSetup=config.formConfig.formSetupRows;
 	let rowsSetup=config.formConfig.formSetupRows;
 	for (let i=0;i<rowsSetup.length;i++){
 	for (let i=0;i<rowsSetup.length;i++){
 		let e=rowsSetup[i];
 		let e=rowsSetup[i];
 		let queryName1=config.formConfig.queryMap[e['queryName']];
 		let queryName1=config.formConfig.queryMap[e['queryName']];
-		if (e.formName!=config.formId) continue;
+		if (e.formName!=formId) continue;
 		if (queryName1!=queryName) continue;
 		if (queryName1!=queryName) continue;
 		return e;
 		return e;
 	}
 	}
@@ -2769,7 +2774,12 @@ function populateSection(queryName){
 	let fName='[populateSection/'+queryName+']';
 	let fName='[populateSection/'+queryName+']';
 	print(fName);
 	print(fName);
 
 
-	let entry=findSetupRow(queryName);
+   //old setting
+   let formId=config.formId;
+   //new setting
+   formId=config.formConfig.formId;
+
+	let entry=findSetupRow(queryName,formId);
 	//ignore names without associated entry in formSetup
 	//ignore names without associated entry in formSetup
 	if (entry==undefined){
 	if (entry==undefined){
 		print(fName+': no matching FormSetup entry found');
 		print(fName+': no matching FormSetup entry found');
@@ -2946,12 +2956,15 @@ function generateMessage(queryName,msg){
 
 
 function generateForm(data,queryName,mailRecipient){
 function generateForm(data,queryName,mailRecipient){
 
 
-	print('generateForm, recipient: '+mailRecipient);
+   let fName='[generateForm]';
+
+	print(fName+' recipient: '+mailRecipient);
 //	
 //	
 	const nData=data.rows.length;
 	const nData=data.rows.length;
-	print('Registration: '+nData+' rows');
+	print(fName+' Registration: '+nData+' rows');
 
 
 	let formRow=config.formConfig.generateForm[queryName];
 	let formRow=config.formConfig.generateForm[queryName];
+	let formCfg=config.formConfig.generateConfig[queryName];
 
 
 	//we have to generate masterQuery with parentCrf and crfRef 
 	//we have to generate masterQuery with parentCrf and crfRef 
 	//and crfEntry with new entryId and parentCrf equal to crfRef
 	//and crfEntry with new entryId and parentCrf equal to crfRef
@@ -2968,7 +2981,14 @@ function generateForm(data,queryName,mailRecipient){
 	crfEntry.parentCrf=getCRFref();
 	crfEntry.parentCrf=getCRFref();
 	crfEntry["Date"]=new Date();
 	crfEntry["Date"]=new Date();
 	crfEntry["View"]="[VIEW]";
 	crfEntry["View"]="[VIEW]";
+
 	crfEntry.formStatus=1;//In progress
 	crfEntry.formStatus=1;//In progress
+   //checks for both field presence (if not in query, undefined) and field value (if not set, null)
+   print(fName+' setup status: '+formCfg.formStatus);
+   if (formCfg.formStatus){
+      crfEntry.formStatus=formCfg.formStatus;
+   }
+
    //get local Id
    //get local Id
    let pM=getParticipantManagerObject(config);
    let pM=getParticipantManagerObject(config);
    
    
@@ -3073,7 +3093,7 @@ function setFormConfig(){
 	//add object to store form related data
 	//add object to store form related data
 	config.formConfig=new Object();
 	config.formConfig=new Object();
 
 
-	config.formConfig.softwareVersion='T.15.23';
+	config.formConfig.softwareVersion='T.15.27';
 	let debug=true;
 	let debug=true;
 
 
 	if (debug)
 	if (debug)
@@ -3338,19 +3358,27 @@ function fcontinue(){
 	print('Setting operator to: '+config.formConfig.operator);
 	print('Setting operator to: '+config.formConfig.operator);
 	
 	
 	config.formConfig.formRows=config.formConfig.formData.rows;
 	config.formConfig.formRows=config.formConfig.formData.rows;
-	
+
+   //point formId to point to form set in crfEntry
+   config.formConfig.formId=config.formConfig.crfEntry['Form'];
+
+   //old setting, set from URL in visit.html
+   let formId=config.formId;
+   //new setting, set from crfEntry
+   formId=config.formConfig.formId;
+
 	let formRows=config.formConfig.formRows;
 	let formRows=config.formConfig.formRows;
 	//filter out the current form
 	//filter out the current form
 	for (let i=0;i<formRows.length;i++){
 	for (let i=0;i<formRows.length;i++){
-		if (formRows[i].Key==config.formId){
+		if (formRows[i].Key==formId){
 			config.formConfig.form=formRows[i];
 			config.formConfig.form=formRows[i];
 			break;
 			break;
 		}
 		}
 	}
 	}
 	
 	
-	config.formConfig.formSetupRows=selectFormSetupRows(config.formId);
+	config.formConfig.formSetupRows=selectFormSetupRows(formId);
 
 
-	print("Number of datasets for form ["+config.formId+"]: "+
+	print("Number of datasets for form ["+formId+"]: "+
 			config.formConfig.formSetupRows.length);
 			config.formConfig.formSetupRows.length);