Bladeren bron

decoupled registration selection for ID setting and list of available patients

Andrej Studen 2 jaren geleden
bovenliggende
commit
63b119694f
1 gewijzigde bestanden met toevoegingen van 90 en 18 verwijderingen
  1. 90 18
      web/crfTecant/crfVisit.js

+ 90 - 18
web/crfTecant/crfVisit.js

@@ -1150,11 +1150,17 @@ function parseVariables(pars){
    let q=new Object();
    for (let i=0;i<pA.length;i++){
       let vA=pA[i].split('=');
-      q[vA[0]]=vA[1];
+      q[vA[0]]=vA[vA.length-1];
    }
    return q;
 }
 
+function printVariables(q){
+	let fName="[printVariables]";
+	for (let x in q){
+		print(fName+" ["+x+"] "+q[x]);
+	}
+}
 
 
 function addSpecialFieldRow(tb,specFieldSetup,setup){
@@ -1943,6 +1949,19 @@ function onUpdateForReview(){
 	updateFlag(targetStatus,action);
 }
 
+function updateEntry(entry,schema,query,container,action){
+	let fName="[updateEntry]";
+	print(fName);
+	let qconfig=new Object();
+	qconfig.schemaName=schema;
+	qconfig.queryName=query;
+	qconfig.containerPath=container;
+	qconfig.rows=[entry];
+	qconfig.success=action;
+	LABKEY.Query.updateRows(qconfig);
+	print(fName+" done");
+}
+
 function updateFlag(flag,action){
 	let fName='[updateFlag 1]';
 	let debug=true;
@@ -1955,18 +1974,13 @@ function updateFlag(flag,action){
 	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);
-	
+	let cb=function(data){completeWithFlag(data,action);};
+	updateEntry(entry,'lists','crfEntry',getContainer('data'),cb);
+		
 }
 
 
+
 function completeWithFlag(data,action){
 	let fName='[completeWithFlag]';
 	print(fName+': nrows '+data.rows.length);
@@ -2024,14 +2038,22 @@ function verifyData(){
 			return false;
 		}
 	}
+	//this is necessary only for Generated to Generation completed step
+	let actionSettings=config.formConfig.actionSettings['onSubmit'];	
+	if (actionSettings && "updateRegistration" in actionSettings){
+		updateRegistration();
+	}
 	let targetStatus=config.formConfig.targetStatus['onSubmit'];	
 	let targetRecipient=config.formConfig.targetRecipient['onSubmit'];
 	print('verifyStatus: targetStatus: '+targetStatus);
-	let fName='verifyStatus';
-	//useful for debug
-	//let finalStep=doNothing;
-	//production mode
+	
 	let finalStep=redirect;
+	if (actionSettings && "finalStep" in actionSettings){
+		//set to doNothing to remain on submit window
+		if (actionSettings.finalStep=="doNothing"){
+			finalStep=doNothing;
+		}
+	}
 	
 	let action=new Object();
 	action.name='onSubmit';
@@ -2616,6 +2638,7 @@ function afterConfig(){
 	let rows=config.formConfig.crfButtons.rows;
 	config.formConfig.targetStatus=new Array();
 	config.formConfig.targetRecipient=new Array();
+	config.formConfig.actionSettings=new Array();
 
 	for (let i=0; i<rows.length; i++){
 		let action=rows[i].action;//String
@@ -2623,6 +2646,14 @@ function afterConfig(){
 		let trecip=rows[i].targetRecipient;
 		config.formConfig.targetStatus[action]=tstatus;
 		config.formConfig.targetRecipient[action]=trecip;
+		//allow for settings to be promoted with each action (and potentially parsed and acted upon)
+		config.formConfig.actionSettings[action]=undefined;
+		let aSet=rows[i].actionSettings;
+		if (aSet){
+			config.formConfig.actionSettings[action]=parseVariables(aSet);
+			printVariables(config.formConfig.actionSettings[action]);
+		}
+
 	}
 	let formStatus=config.formConfig.formStatus;
 
@@ -2685,6 +2716,47 @@ function verifyRegistration(pM){
    pM.updateCrfEntry();
 }
 
+function updateRegistration(){
+	let fName="[updateRegistration]";
+	print(fName);
+	let pM=getParticipantManagerObject(config);
+	let idFieldName=pM.getCrfEntryFieldName("STUDY");
+	//have to reload query data
+	let regQueryPars=parseVariables(config.formConfig.settings['registrationQuery']);
+    let regQuery=regQueryPars['query'];
+	let fQuery=config.formConfig.dataQueries[regQuery];
+
+	if (fQuery.rows.length==0) {
+		print(fName+" registration is empty");
+		return; //registration is empty
+	}
+	let regEntry=fQuery.rows[0];
+
+	for (x in regEntry){
+		print(fName+" ["+x+"] "+regEntry[x]);
+	}
+
+
+	let studyId=fQuery.rows[0][idFieldName];
+	if (!studyId) {
+		print(fName+" study id not set ("+idFieldName+'/'+studyId+")");
+		return; //study id not set
+	}
+	
+	//set 
+	pM.setParticipantIdToCrfEntry(studyId,"STUDY");
+	//this will only update crfEntry in memory, but not on LabKey, 
+	//we are counting on updateFlag to follow updateRegistration
+
+	//update parentCRF as well, here we schedule update of data entry as well
+	if ("parentCrfData" in config.formConfig){
+		let parentCrfEntry=config.formConfig.parentCrfData.rows[0];
+		parentCrfEntry[idFieldName]=studyId;
+		let cb=function(data){completeWithFlag(data,doNothing);};
+		updateEntry(parentCrfEntry,'lists','crfEntry',getContainer('data'),cb);
+	}
+}
+
 function afterData(){
 	let fName='afterData';
 	//operatorBasedAccessMode	
@@ -2707,7 +2779,8 @@ function afterData(){
       pM.mode="LOCAL";
       //OK, but check if CRF or registration indicate that study id is already set
       verifyCrfStudyId(pM);
-      verifyRegistration(pM);
+	  //study id should already be set by updateRegistration
+      //verifyRegistration(pM);
    }
    if (idModeArray.includes("READONLY")){
       pM.readOnly="TRUE";
@@ -3093,7 +3166,7 @@ function setFormConfig(){
 	//add object to store form related data
 	config.formConfig=new Object();
 
-	config.formConfig.softwareVersion='T.15.27';
+	config.formConfig.softwareVersion='T.15.34';
 	let debug=true;
 
 	if (debug)
@@ -3283,8 +3356,7 @@ function addStudyData(){
    if ('schema' in regQueryPars){
       regSchema=regQueryPars['schema'];
    }
-   let crfFilter=LABKEY.Filter.create('crfRef',getCRFref());
-   queryArray.push(makeQuery(targetObject,'data',regQuery,'registrationData',[crfFilter]));
+   queryArray.push(makeQuery(targetObject,'data',regQuery,'registrationData',[]));
    queryArray[queryArray.length-1].schemaName=regSchema;