Przeglądaj źródła

Adding crfStaticVariables to formPortal to generate appropriate header

Andrej Studen 2 lat temu
rodzic
commit
eb310ba3cd
1 zmienionych plików z 43 dodań i 22 usunięć
  1. 43 22
      web/crf/formPortal.js

+ 43 - 22
web/crf/formPortal.js

@@ -117,7 +117,7 @@ function generateFormArray(){
 	print("generateFormArray "+getMode());
 	
 	config.formConfig=new Object();
-	config.formConfig.softwareVersion='0.1.7';
+	config.formConfig.softwareVersion='0.1.9';
 	//report software version
 	config.document.getElementById('version').innerText=config.formConfig.softwareVersion;	
 	
@@ -164,6 +164,9 @@ function afterSettings(data){
 
 	//setup queryArray
 	let queryArray=new Array();
+
+   //static variables
+	queryArray.push(makeQuery('data','crfStaticVariables','crfStaticVariables',[]));
 	//Forms
 	queryArray.push(makeQuery('config','Forms','dataForms',[]));
 	//users
@@ -171,12 +174,6 @@ function afterSettings(data){
 	queryArray[queryArray.length-1].schemaName='core';
 	//inputLists
 	queryArray.push(makeQuery('config','inputLists','inputLists',[]));
-	//studyData
-	queryArray.push(makeQuery('data','StudyProperties','studyData',[]));
-	let e=queryArray[queryArray.length-1];
-	e.schemaName='study';
-	e.columns="StudySponsor,StudyCoordinator,EudraCTNumber";
-	e.columns+=',RegulatoryNumber,SubjectColumnName';
 	//crfEditors
 	queryArray.push(makeQuery('config','crfEditors','crfEditors',[]));
 	//crfMonitors
@@ -190,9 +187,30 @@ function afterSettings(data){
 	//crfEntry
 	queryArray.push(makeQuery('data','crfEntry','crfEntries',[]));
 
-	getDataFromQueries(queryArray,fcontinue);
+	getDataFromQueries(queryArray,addStudyData);
+	//getDataFromQueries(queryArray,fcontinue);
 }
 
+function addStudyData(){
+	//setup queryArray
+	let queryArray=new Array();
+	
+	queryArray.push(makeQuery('data','StudyProperties','studyData',[]));
+	let e=queryArray[queryArray.length-1];
+	e.schemaName='study';
+   let columnModel="";
+	let varRows=config.formConfig['crfStaticVariables'].rows;
+	for (let i=0;i<varRows.length;i++){
+      if (i>0) columnModel+=',';
+      columnModel+=varRows[i]['staticVariable'];
+   }
+	e.columns=columnModel;
+   getDataFromQueries(queryArray,fcontinue);
+
+
+}
+
+
 function fcontinue(){
 	let formConfig=config.formConfig;
 
@@ -260,6 +278,7 @@ function fcontinue2(){
 		currentUser=users[i];
 	}
 
+
 	let fList=config.role+'s';
 	let fRows=config.formConfig[fList].rows;
 	//current user must be in the list
@@ -270,6 +289,14 @@ function fcontinue2(){
 		if (fRows[i].User!=currentUser.UserId) continue;
 		currentUserRoles.push(fRows[i]);
 	}
+	let sts=config.formConfig.settings;
+	let vName='allowAllForSite';
+	if (vName in sts){
+		let tempUserRole=new Object();
+		tempUserRole.User=currentUser.UserId;
+		tempUserRole.Site=parseInt(sts[vName]);
+		currentUserRoles.push(tempUserRole);
+	}
 	if (currentUserRoles.length==0){
 		printMessage('User '+currentUser.DisplayName+" can't act as "+config.role);
 		return;
@@ -283,7 +310,7 @@ function fcontinue2(){
 			currentSites.push(siteRows[i]);
 		}
 	}
-
+	config.formConfig.currentSites=currentSites;
 	let msg='User '+currentUser.DisplayName+' acting as '+config.role+' for (';
 	for (let i=0;i<currentSites.length;i++){
 		if (i>0) msg+=', ';
@@ -529,20 +556,14 @@ function createForm(formId){
 	//set other variables
 	//requires studyData as part of formConfig
 	let studyData=formConfig.studyData.rows[0];
-	crfEntry.EudraCTNumber=studyData.EudraCTNumber;
-	crfEntry.StudyCoordinator=studyData.StudyCoordinator;
-	crfEntry.StudySponsor=studyData.StudySponsor;
-	crfEntry.RegulatoryNumber=studyData.RegulatoryNumber;
+   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;
-	//requires crfEditors as part of formConfig
-	for (let i=0;i<formConfig.crfEditors.rows.length;i++){
-		print("Checking user "+formConfig.crfEditors.rows[i].User);
-		if (formConfig.crfEditors.rows[i].User!=crfEntry.UserId) continue;
-		print("Found user");
-		crfEntry.Site=formConfig.crfEditors.rows[i].Site;
-		print("Setting site to id="+crfEntry.Site);
-		break;
-	}	
+	crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
+	print("Setting site to id="+crfEntry.Site);
 	//from argument list
 	crfEntry.Form=formId;