Parcourir la source

Removing the old updateFlag and replacing it with one that uses crfEntry from memory

Andrej Studen il y a 2 ans
Parent
commit
fb92cd3911
1 fichiers modifiés avec 24 ajouts et 64 suppressions
  1. 24 64
      web/crf/crfVisit.js

+ 24 - 64
web/crf/crfVisit.js

@@ -1849,44 +1849,6 @@ function onUpdateForReview(){
 }
 
 function updateFlag(flag,action){
-	let qconfig=new Object();
-	qconfig.schemaName='lists';
-	qconfig.queryName='crfEntry';
-	qconfig.containerPath=getContainer('data');
-	qconfig.success=function(data){setFlag(data,flag,action);}
-	qconfig.filterArray=[LABKEY.Filter.create("entryId",getCRFref())];
-	LABKEY.Query.selectRows(qconfig);
-}
-
-function setFlag(data,flag,action){
-	let fName='[setFlag]';
-	let debug=true;
-	if (data.rows.length!=1){
-		let msg=fName+": ERROR: Found "+data.rows.length;
-		msg+=" entries for crfrefid "+getCRFref();
-		print(msg);
-		return;
-	}
-	let entry=data.rows[0];
-	entry.FormStatus=flag;
-	let uId=config.formConfig.currentUser.UserId;
-	entry[config.formConfig.operator]=uId;
-
-	print(fName+': Form: '+entry.Form);
-	print(fName+": set form status to "+entry.FormStatus);
-	
-	let qconfig=new Object();
-	qconfig.schemaName='lists';
-	qconfig.queryName='crfEntry';
-	qconfig.containerPath=getContainer('data');
-	qconfig.rows=[entry];
-	//qconfig.success=function(data){completeWithFlag(data,flag);}
-	qconfig.success=function(data){completeWithFlag(data,action);};
-	LABKEY.Query.updateRows(qconfig);
-	
-}
-
-function updateFlag1(flag,action){
 	let fName='[updateFlag 1]';
 	let debug=true;
 
@@ -2598,32 +2560,29 @@ function afterData(){
 	let accessMode=config.formConfig.operator+'Mode';
 	let rowsSetup=config.formConfig.formSetupRows;
 
-   let allowNewLocalId=config.formConfig.form['allowNewLocalId'];
+   let idMode=config.formConfig.form['idMode'];
    //set default value if no value is in the list (read value is null)
-   if (!allowNewLocalId) allowNewLocalId="FALSE";
+   if (!idMode) idMode="STUDY:EDIT";
 
-   print(fName+': '+'generatePariticpantEntry '+allowNewLocalId);
+   print(fName+': idMode '+idMode);
    //generateParticipantEntryField();
    //add print to config so participantManager can use it
    config.print=print;
    let pM=getParticipantManagerObject(config);
    //if (allowNewLocalId=="TRUE") pM.allowNewLocalId=true;
-   if (allowNewLocalId=="TRUE") {
+   let idModeArray=idMode.split(':');
+   if (idModeArray.includes("LOCAL")) {
       pM.mode="LOCAL";
    }
    else {
       pM.mode="STUDY";
    }
-
-   pM.updateCrfEntry=function(){updateFlag1(config.formConfig.crfEntry['FormStatus'],doNothing);};   
+   if (idModeArray.includes("READONLY")){
+      pM.readOnly="TRUE";
+   }
+   pM.updateCrfEntry=function(){updateFlag(config.formConfig.crfEntry['FormStatus'],doNothing);};   
    
-   print(fName+': pariticpantManager: '+pM+' config '+pM.config);
-   //check if ParticipantId is set in crfEntry
-   //let pId=pM.getParticipantIdFromCrfEntry('Study');
-   //if (pM.allowNewLocalId) 
-   //   pId=pM.getParticipantIdFromCrfEntry('Local');
    let pId=pM.getParticipantIdFromCrfEntry();
-   print(fName+' pId '+pId+' config '+pM.config);
    if (!pId){
       pM.setEditMode();
    }
@@ -2744,7 +2703,8 @@ function populateSection(queryName){
 //*******    generateQuery infrastructure *********************
 
 function onGenerateQuery(queryName){
-	print('onGenerateQuery '+queryName);
+   let fName='[onGenerateQuery]';
+	print(fName+' '+queryName);
 //
 	let cfgRows=config.formConfig.generateConfigData.rows;
 //	//queryName to queryId?
@@ -2786,15 +2746,16 @@ function onGenerateQuery(queryName){
 }
 
 function checkGenerationFields(queryName){
+   let fName='[checkGenerationFields]';
 	let genForm=config.formConfig.generateForm[queryName];
 	let genCfg=config.formConfig.generateConfig[queryName];
 	let mailRecipient=genCfg.emailRecipient;
 	
 	//list of queries that are part of Registration form
-	print('checkRegistrationFields');	
-	print('setRecipient: '+mailRecipient);
+	print(fName);	
+	print(fName+' setRecipient: '+mailRecipient);
 	let formId=genForm.Key;
-	print("Checking form w/id "+formId);
+	print(fName+" Checking form w/id "+formId);
 	let selectGenerationRows=selectFormSetupRows(formId);
 	//registration rows
 	for (let i=0;i<selectGenerationRows.length;i++){
@@ -2851,7 +2812,7 @@ function generateMessage(queryName,msg){
 
 function generateForm(data,queryName,mailRecipient){
 
-	print('generateForm, recpioent: '+mailRecipient);
+	print('generateForm, recipient: '+mailRecipient);
 //	
 	const nData=data.rows.length;
 	print('Registration: '+nData+' rows');
@@ -2874,6 +2835,10 @@ function generateForm(data,queryName,mailRecipient){
 	crfEntry["Date"]=new Date();
 	crfEntry["View"]="[VIEW]";
 	crfEntry.formStatus=1;//In progress
+   //get local Id
+   let pM=getParticipantManagerObject(config);
+   
+   crfEntry[pM.getCrfEntryFieldName()]=pM.getParticipantIdFromCrfEntry();
 //	//set other variables
 	//requires studyData as part of formConfig
 //	let studyData=config.formConfig.studyData;
@@ -2930,20 +2895,15 @@ function generateListEntry(formId,queryName,cb){
 	}
 	let nData=config.formConfig.dataQueries[queryName].rows.length
 	if (nData>0) return;
-	//only generate record for parentCrfRef
-	
-	//let qArray=new Array();
-	//let e1=new Object();
-	//e1.crfRef=data.rows[0].entryId;
-	//e1.submissionDate=new Date();
-	//only for registration
-	//e1.registrationStatus=0;
-	//qArray.push(e1);
 	
+   let pM=getParticipantManagerObject(config);
+   
+
 	let e2=new Object();
 	e2.crfRef=getCRFref();
 	e2.registrationStatus=0;
 	e2.submissionDate=new Date();
+   e2[pM.getCrfEntryFieldName()]=pM.getParticipantIdFromCrfEntry();
 	print('set values');
 	
 	let qconfig=new Object();