Просмотр исходного кода

Modifying crfVisit.js to send emails, and making sure study id gets copied to crfEntry, and combining entry filters to a common function to simplify switching filters on and off

Andrej Studen 2 лет назад
Родитель
Сommit
2e0bb4f108
2 измененных файлов с 69 добавлено и 46 удалено
  1. 18 10
      web/crfTecant/crfVisit.js
  2. 51 36
      web/crfTecant/formPortal.js

+ 18 - 10
web/crfTecant/crfVisit.js

@@ -2084,7 +2084,7 @@ function sendEmail(data,recipient='crfEditor',cb=redirect,subj='Form submitted')
 			return;
 		}
 	}
-	if (recpient==null){
+	if (recipient==null){
       print('Skipping sending emails w/ no recipients');
       cb();
       return;
@@ -2651,10 +2651,11 @@ function verifyRegistration(pM){
    //if registration is in, 
    //then local id should not be changed any longer
    let idFieldName=pM.getCrfEntryFieldName("STUDY");
-   let registrationQuery=config.formConfig.settings['registrationQuery'];
-   if (!registrationQuery) return; //LOCAL is OK
-   let fQuery=config.formConfig.dataQueries[registrationQuery];
-   if (!fQuery) return; //no registration query, then it should be ignored
+   //let registrationQuery=config.formConfig.settings['registrationQuery'];
+   //if (!registrationQuery) return; //LOCAL is OK
+   //let fQuery=config.formConfig.dataQueries[registrationQuery];
+   //if (!fQuery) return; //no registration query, then it should be ignored
+   let fQuery=config.formConfig.registrationData;
    if (fQuery.rows.length==0) return; //registration is empty
 
    let studyId=fQuery.rows[0][idFieldName];
@@ -3060,7 +3061,7 @@ function setFormConfig(){
 	//add object to store form related data
 	config.formConfig=new Object();
 
-	config.formConfig.softwareVersion='T.15.20';
+	config.formConfig.softwareVersion='T.15.23';
 	let debug=true;
 
 	if (debug)
@@ -3242,10 +3243,17 @@ function addStudyData(){
 
    //also collect ids already in study
    //registrationQuery should be a dataset
-   let demoQuery=config.formConfig.settings['registrationQuery'];
-
-   queryArray.push(makeQuery(targetObject,'data',demoQuery,'registrationData',[]));
-   queryArray[queryArray.length-1].schemaName='study';
+   //since monitors can review late, it might be profitable to use lists
+   //rather than study
+   let regQueryPars=parseVariables(config.formConfig.settings['registrationQuery']);
+   let regQuery=regQueryPars['query'];
+   let regSchema='study';
+   if ('schema' in regQueryPars){
+      regSchema=regQueryPars['schema'];
+   }
+   let crfFilter=LABKEY.Filter.create('crfRef',getCRFref());
+   queryArray.push(makeQuery(targetObject,'data',regQuery,'registrationData',[crfFilter]));
+   queryArray[queryArray.length-1].schemaName=regSchema;
       
 	
 	getDataFromQueries(queryArray,fcontinue);

+ 51 - 36
web/crfTecant/formPortal.js

@@ -117,7 +117,7 @@ function generateFormArray(){
 	print("generateFormArray "+getMode());
 	
 	config.formConfig=new Object();
-	config.formConfig.softwareVersion='0.1.9';
+	config.formConfig.softwareVersion='T.1.11';
 	//report software version
 	config.document.getElementById('version').innerText=config.formConfig.softwareVersion;	
 	
@@ -212,6 +212,44 @@ function addStudyData(){
 
 }
 
+function filterEntry(entry,filter,settings){
+
+   if (entry.Form!=filter.form)
+      return false;
+
+   //only select forms where status matches the target status
+   if (entry.FormStatus!=filter.formStatus){
+      return false;
+   }
+
+   print('Candidate '+entry.entryId);
+   //TODO: smart filter on user (now we get to see all)
+   //
+   //for editors
+
+   if ("filterUser" in settings && filter.role=='crfEditor' && entry.UserId!=filter.userId){
+      print('Skipping identity mismatch: '+entry.UserId+'/'+filter.userId);  
+      return false;
+   }
+
+   //for others
+   let matchingSite=-1;
+   let potentialSiteNumbers="[";
+   for (let k=0;k<filter.sites.length;k++){
+      if (k>0) potentialSiteNumbers+=',';
+      potentialSiteNumbers+=filter.sites[k].siteNumber;
+      //skip mismatching sites
+      if (entry.Site!=filter.sites[k].siteNumber) continue;
+      matchingSite=filter.sites[k].siteNumber;
+      break;
+   }
+   potentialSiteNumbers+=']';
+   if (matchingSite==-1){
+      print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers);
+      return false;
+   }
+   return true;
+}
 
 function fcontinue(){
    let fName='[fcontinue]';
@@ -294,12 +332,19 @@ function fcontinue(){
 	msg+=')';
 	printMessage(msg);
 
+   let filter=new Object();
+   filter.role=config.role;
+   filter.userId=currentUser.UserId;
+   filter.sites=currentSites;
+
    //browse through forms
 	for (let i=0;i<dataForms.length;i++){
 
       //dataForms is Forms
 		let qForm=dataForms[i];
 		let formKey=qForm.Key;
+      filter.form=qForm.Key;
+      
 		
 		//add row for each form
 		let row=formConfig.table.insertRow(i);
@@ -311,44 +356,14 @@ function fcontinue(){
 
       //get the target status
 		let formStatus=qForm[accessModeColumn];
+      filter.formStatus=qForm[accessModeColumn];
 		print('target formStatus '+formStatus);
 
-		for (let j=0;j<fEntries.length;j++){
-			let entry=fEntries[j];
-			let formId=entry.Form;
-			
-         if (formId!=formKey)
-				continue;
-			
-         //only select forms where status matches the target status
-			if (entry.FormStatus!=formStatus){
-				continue;
-			}
 
-			print('Candidate '+entry.entryId);
-			//TODO: smart filter on user (now we get to see all)
-			//
-			//for editors
-			if (config.role=='crfEditor' && entry.UserId!=currentUser.UserId){
-				print('Skipping identity mismatch: '+entry.UserId+'/'+currentUser.UserId);  
-				continue;
-			}
-         
-         //for others
-			let matchingSite=-1;
-			let potentialSiteNumbers="[";
-			for (let k=0;k<currentSites.length;k++){
-				if (k>0) potentialSiteNumbers+=',';
-				potentialSiteNumbers+=currentSites[k].siteNumber;
-				if (entry.Site!=currentSites[k].siteNumber) continue;
-				matchingSite=currentSites[k].siteNumber;
-				break;
-			}
-			potentialSiteNumbers+=']';
-			if (matchingSite==-1){
-				print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers);
-				continue;
-			}
+		for (let j=0;j<fEntries.length;j++){
+         let entry=fEntries[j];
+			if (!filterEntry(entry,filter,config.formConfig.settings))
+            continue;
 
 			//insert form
 			//