Browse Source

Removed reference to masterQuery and demographicData, changed creator coding to string variable creator in Forms for formPortal.js

Andrej Studen 2 years ago
parent
commit
fe57092a27
1 changed files with 37 additions and 64 deletions
  1. 37 64
      web/crf/formPortal.js

+ 37 - 64
web/crf/formPortal.js

@@ -217,44 +217,6 @@ function fcontinue(){
 	print("Number of study data entries: "+formConfig.studyData.rows.length);
 	print("ParticipantId: "+formConfig.studyData.rows[0].SubjectColumnName);
 
-	let qconfig=new Object();
-
-	qconfig.containerPath=getContainer('data');
-	qconfig.schemaName="study";
-	let demographicDataId=formConfig.dataForms.rows[0].masterQuery;
-	let demographicDataQuery="NONE";
-	for (let i=0;i<formConfig.inputLists.rows.length;i++){
-		let entry=formConfig.inputLists.rows[i];
-		print("inputList ["+i+"] ["+entry.Key+"] "+entry.queryName);
-		if (entry.Key==demographicDataId){
-			demographicDataQuery=entry.queryName;
-			break;
-		}
-	}
-	print('Setting demographic query to '+demographicDataQuery);
-
-
-
-	qconfig.queryName=demographicDataQuery;
-	//qconfig.queryName="demographicData";
-	
-	qconfig.success=afterPopulatingDemographicData;
-	LABKEY.Query.selectRows(qconfig);
-}
-
-function afterPopulatingDemographicData(data){	
-	let formConfig=config.formConfig;
-	formConfig.demographicData=data;
-	print("afterPopulatingDemographic");
-	print("Number of patients: "+formConfig.demographicData.rows.length);
-	
-	fcontinue2();
-
-}	
-
-function fcontinue2(){
-
-	let formConfig=config.formConfig;
 	let dataForms=formConfig.dataForms.rows;
 
 	formConfig.table=config.document.createElement("table");
@@ -262,7 +224,8 @@ function fcontinue2(){
 
 	let accessModeColumn=getMode()+'Status';
 	print('accessModeColumn '+accessModeColumn);
-	let creatorModeColumn=getMode()+'Creator';
+	//cutting down on number of fields
+   //let creatorModeColumn=getMode()+'Creator';
 
 
 	//switch from status based to form based access
@@ -278,17 +241,21 @@ function fcontinue2(){
 		currentUser=users[i];
 	}
 
-
+   //determine the role filter
 	let fList=config.role+'s';
+   //check for users that fit the role, 
+   //fRows lists all users for role
 	let fRows=config.formConfig[fList].rows;
 	//current user must be in the list
-	//
+	
 	let currentUserRoles=new Array();
 	//the same user can act for multiple sites
 	for (let i=0;i<fRows.length;i++){
 		if (fRows[i].User!=currentUser.UserId) continue;
 		currentUserRoles.push(fRows[i]);
 	}
+
+   //cludge for public sites where all users can act as anything
 	let sts=config.formConfig.settings;
 	let vName='allowAllForSite';
 	if (vName in sts){
@@ -297,11 +264,14 @@ function fcontinue2(){
 		tempUserRole.Site=parseInt(sts[vName]);
 		currentUserRoles.push(tempUserRole);
 	}
+
+   //currentUser was not matched in fRows
 	if (currentUserRoles.length==0){
 		printMessage('User '+currentUser.DisplayName+" can't act as "+config.role);
 		return;
 	}
 
+   //currentUser should be also attached to the site of the document
 	let currentSites=new Array();
 	let siteRows=config.formConfig.siteData.rows;
 	for (let i=0;i<siteRows.length;i++){
@@ -310,6 +280,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++){
@@ -319,42 +290,37 @@ function fcontinue2(){
 	msg+=')';
 	printMessage(msg);
 
+   //browse through forms
 	for (let i=0;i<dataForms.length;i++){
+
+      //dataForms is Forms
 		let qForm=dataForms[i];
 		let formKey=qForm.Key;
 		
-		//figure out master query name
-		let masterQuery="NONE";
-		let mID=qForm.masterQuery;
-		for (let i2=0;i2<formConfig.inputLists.rows.length;i2++){
-			//queryName
-			if (formConfig.inputLists.rows[i2].Key!=mID)
-				continue;
-			
-			masterQuery=formConfig.inputLists.rows[i2].queryName;
-			print("Setting master query "+masterQuery);
-			break;
-		}
 		//add row for each form
 		let row=formConfig.table.insertRow(i);
 		let formName=qForm.formName;
 		print("["+i+"/"+formKey+']: '+formName);
+
+      //column counter
 		let k=0;
+
+      //get the target status
 		let formStatus=qForm[accessModeColumn];
 		print('target formStatus '+formStatus);
 
 		for (let j=0;j<fEntries.length;j++){
 			let entry=fEntries[j];
 			let formId=entry.Form;
-			//print("Row["+j+"] formId: "+formId);
-			if (formId!=formKey)
+			
+         if (formId!=formKey)
 				continue;
-			//should we consider this form
 			
+         //only select forms where status matches the target status
 			if (entry.FormStatus!=formStatus){
-				//print('Form status mismatch :'+entry.FormStatus);
 				continue;
 			}
+
 			print('Candidate '+entry.entryId);
 			//TODO: smart filter on user (now we get to see all)
 			//
@@ -363,7 +329,8 @@ function fcontinue2(){
 				print('Skipping identity mismatch: '+entry.UserId+'/'+currentUser.UserId);  
 				continue;
 			}
-
+         
+         //for others
 			let matchingSite=-1;
 			let potentialSiteNumbers="[";
 			for (let k=0;k<currentSites.length;k++){
@@ -378,6 +345,7 @@ function fcontinue2(){
 				print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers);
 				continue;
 			}
+
 			//insert form
 			//
 
@@ -438,9 +406,14 @@ function fcontinue2(){
 			k++;
 		}
 		print('finished checking existing forms');
-		//only those that are allowed to create formsa
-		print('Status: '+qForm[creatorModeColumn]);
-		if (qForm[creatorModeColumn]!='TRUE') continue;
+
+		//only those that are allowed to create forms
+		//print('Status: '+qForm[creatorModeColumn]);
+		
+      let creator=qForm['creator'];
+      if (!creator) continue;
+      if (creator!=getMode()) continue;
+      //if (qForm[creatorModeColumn]!='TRUE') continue;
 
 		let fbox=config.document.createElement("div");
 		fbox.classList.add("box","red");
@@ -505,10 +478,10 @@ function openForm(crfEntry){
 
 	//"formSetupQuery":formEntry["setupQuery"],
 	let containerPath= LABKEY.ActionURL.getContainer();
-        // This changes the page after building the URL. 
+   // This changes the page after building the URL. 
 	//Note that the wiki page destination name is set in params.
-        var wikiURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
-        print("Redirecting to "+wikiURL);
+   var wikiURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
+   print("Redirecting to "+wikiURL);
 
 		 
 	window.location = wikiURL;