Explorar el Código

Upgrading onGenerate to work with the new structured layout, which was overlooked previously. Also, generateForm uses formPortal's createForm, so slight adjustments around that call were needed

Andrej Studen hace 1 año
padre
commit
bd860e0379
Se han modificado 1 ficheros con 92 adiciones y 84 borrados
  1. 92 84
      web/crf/crfVisitNew.js

+ 92 - 84
web/crf/crfVisitNew.js

@@ -32,6 +32,7 @@ function(cb=null){
    dependencies.push("crf/crfData.js");
    dependencies.push("crf/crfHTML.js");
    dependencies.push("crf/generateRegistration.js");
+   dependencies.push("crf/formPortalNew.js");
    LABKEY.Utils.requiresScript(dependencies,action);
 }
 
@@ -43,11 +44,12 @@ function(cb=null){
    crfPrint.set(this);
    crfData.setSetup(crfSetup);
    crfHTML.init();
-   generateRegistration.init();
+   //generateRegistration.init();
    let initRegistration=function(){generateRegistration.init(cb);};
    let initIdManager=function(){participantIdManager.init(initRegistration);};
-   let action=function(){crfData.init(initIdManager)};
-   crfSetup.init(action);
+   let initCrfData=function(){crfData.init(initIdManager)};
+   let initFormPortal=function(){formPortal.init(initCrfData);};
+   crfSetup.init(initFormPortal);
 }
 
 
@@ -444,7 +446,7 @@ function(sectionId,buttonName){
 		crfHTML.getElement(buttonName).value="Hide";
       let that=this;
 		let cb=function(){that.populateSection(sectionId);};
-		crfData.setData(this.crfRef,cb);
+		crfData.setData(crfData.getCrfRefForData(),cb);
 
   	} else {
     		x.style.display = "none";
@@ -557,7 +559,15 @@ function(tb,field,setup,additionalData){
 	      let lookup=field["lookup"];
 	      //get all values from config.formConfig.lookup[X]
 	      let lObject=crfData.getLookup(lookup.queryName);
-         input = crfHTML.createSelect(lObject.LUT,null,cell1);
+         if (crfSetup.getSettings("useRadioButtons")){
+            this.print('Use radio buttons');
+            //skip generating fields
+            return;
+            
+         }
+         else{
+            input = crfHTML.createSelect(lObject.LUT,null,cell1);
+         }
 
 			break;
 		}
@@ -1193,7 +1203,7 @@ function(data,setup,elementId){
    let that=this;
    let cb=function(){that.populateTable(data.queryName,writeMode,setup);};
 	if ("unique" in setup)
-		crfData.setData(this.crfRef,cb);
+		crfData.setData(crfData.getCrfRefForData(),cb);
 	if ("masterQuery" in setup){
 		let ad=crfSetup.getAdditionalData(setup.masterQuery);
 		this.print('Updating list display: '+setup.queryName+'/'+ad.queryName);
@@ -1278,15 +1288,15 @@ function(){
    let participantId=participantIdManager.getParticipantIdFromCrfEntry('STUDY');
   
    let that=this;
-   let crfRef=this.crfRef;
+   let crfRefForData=crfData.getCrfRefForData();
    
    //load lists and study data
    //check what needs to be updated and upload
    //a (reverse) sequence of functions
    let completeUpload=function(){that.changeFormStatusAndNotify(actionName);};
-   let uploadData=function(){crfData.uploadData(participantId,crfRef,completeUpload);};
-   let loadStudy=function(){crfData.setData(crfRef,uploadData,'study');}
-   crfData.setData(crfRef,loadStudy,'lists');
+   let uploadData=function(){crfData.uploadData(participantId,crfRefForData,completeUpload);};
+   let loadStudy=function(){crfData.setData(crfRefForData,uploadData,'study');}
+   crfData.setData(crfRefForData,loadStudy,'lists');
 }
 
 
@@ -1310,7 +1320,7 @@ function(){
    let that=this;
    let actionName='onSubmit';
    let action=function(){that.verifyData(actionName);};
-	crfData.setData(this.crfRef,action);
+	crfData.setData(crfData.getCrfRefForData(),action);
 	
 
 
@@ -1387,7 +1397,7 @@ function(recipientCode){
 	let parentUser=null;
    if ("parentCrfData" in crfSetup){
 		let parentCrf=crfSetup.getRows('parentCrfData');
-		parentUser=userMap[parentCrf.rows[0].UserId];
+		parentUser=userMap[parentCrf[0].UserId];
 	}
 	
 
@@ -1411,6 +1421,7 @@ function(recipientCode){
 			this.print('Checking '+fRows[i].User+'/'+fRows[i].Site);
 			if (fRows[i].Site!=currentSite.siteNumber) continue;
          let targetUser=userMap[fRows[i].User];
+         if (!targetUser) continue;
 			recipients.push(create(typeTo,targetUser.Email));
 		}
 	}
@@ -1508,13 +1519,14 @@ crfVisit.onRemoveCRF=
 function(){
    let fName='[onRemoveCRF]';
    let crfRef=this.crfRef;
+   let crfRefForData=crfData.getCrfRefForData();
    this.print(fName+' starting loop');
    let actionName='onRemoveCRF';
    let that=this;
    let notify=function(){that.changeFormStatusAndNotify(actionName);};
    //let removeCrfEntry=function(){crfData.removeCrfEntry(notify);}; 
    let removeData=function(){crfData.removeData(notify);};
-   let setStudyData=function(){crfData.setData(crfRef,removeData,'study');};
+   let setStudyData=function(){crfData.setData(crfRefForData,removeData,'study');};
    let action=setStudyData;
    let actionSettings=crfSetup.getActionSettings(actionName);
    if (variableList.hasVariable(actionSettings,'removeWithParentCrf')){
@@ -1527,7 +1539,7 @@ function(){
          action=function(){crfData.setDataForQuery(q,parentCrf,setStudyData1);};
       }
    }
-   crfData.setData(crfRef,action);
+   crfData.setData(crfRefForData,action);
 }
 
 
@@ -1728,7 +1740,7 @@ function(){
 
 	//let functionArray=new Array();
 
-	this.print("Generating buttons for formStatus \""+ formStatus+"\"");
+	this.print(fName+" generating buttons for formStatus \""+ formStatus+"\"");
 
    let allButtonRows=crfSetup.getRows('crfButtons');
 	let buttonRows=new Array();
@@ -1759,7 +1771,7 @@ function(){
 		//}
 	}
 
-	this.print('Here');
+	this.print(fName+' buttons generated.');
 
 
 	//here we should get data. For now, just initialize objects that will hold data
@@ -1775,7 +1787,7 @@ function(){
    let that=this;
    let action=function(){that.afterData();};
    //let action=function(){that.doNothing();};
-	crfData.setData(this.crfRef,action);//callback is afterData
+	crfData.setData(crfData.getCrfRefForData(),action);//callback is afterData
 }
 
 crfVisit.updateRegistration=
@@ -1814,7 +1826,7 @@ function(cb=null,data){
       let doNothing=function(){that.doNothing();};
       let action={name:"updateRegistration",cb:doNothing};
 		let complete=function(data){that.completeWithFlag(data,action);};
-      this.modifyRows('update','lists','crfEntry',[parentCrfEntry],complete,crfSetup.getContainer('CRF'));
+      runQuery.modifyRows('update','lists','crfEntry',[parentCrfEntry],complete,crfSetup.getContainer('CRF'));
 	}
    if (cb) cb(data);
 
@@ -1940,11 +1952,11 @@ function(sectionId){
 	//deal with generate
 	//
 	//already available -> shift to READ mode
-	let divTable=queryName+'Table';
+	let divTable=sectionId+'Table';
 	let divObj=crfHTML.getElement(divTable);
-	let divRev=crfHTML.getElement(queryName+'Review');
-	let divRLi=crfHTML.getElement(queryName+'ReviewList');
-	let divGBu=crfHTML.getElement(queryName+'GenerateButton');
+	let divRev=crfHTML.getElement(sectionId+'Review');
+	let divRLi=crfHTML.getElement(sectionId+'ReviewList');
+	let divGBu=crfHTML.getElement(sectionId+'GenerateButton');
 
 	this.print('div GBU: '+divGBu);
 	divObj.style.display="block";
@@ -1982,10 +1994,10 @@ function(queryName){
 	let cfgRows=crfSetup.getRows('generateConfigData');
 //	//queryName to queryId?
    let qMapInverse=crfSetup.invertMap(crfSetup.getMap('inputLists'));
-	let queryId=qInverseMap[queryName];
+	let queryId=qMapInverse[queryName];
 
 
-	let cfgRow=crfSetup.getEntryMap('generateConfigData')[queryId];
+	let cfgRow=crfSetup.getEntryMap('generateConfigData:queryId')[queryId];
 	
    if (!cfgRow){
 		this.print('generateConfig for queryName['+queryId+']='+queryName+' not found');
@@ -2002,7 +2014,7 @@ crfVisit.checkGenerationFields=
 function(entry){
    //entry is generateConfig row
    let fName='[checkGenerationFields]';
-	let mailRecipient=crfRow.emailRecipient;
+	let mailRecipient=entry.emailRecipient;
 	let qMap=crfSetup.getMap('inputLists');
    let qName=qMap[entry['queryId']];
 	//list of queries that are part of Registration form
@@ -2010,7 +2022,8 @@ function(entry){
 	this.print(fName+' setRecipient: '+mailRecipient);
 	let formId=entry['formId'];
 	this.print(fName+" Checking form w/id "+formId);
-	let formRows=this.selectFormSetupRows(formId);
+	
+   let formRows=crfSetup.selectFormSetupRows(formId);
 	//registration rows
 	for (let i=0;i<formRows.length;i++){
 		let row=formRows[i];
@@ -2018,34 +2031,35 @@ function(entry){
 		if (queryId==entry.queryId) continue;
 		let fQuery=crfData.getQuerySnapshot(qMap[queryId]);
 		this.print('Checking '+qMap[queryId]+' nrows: '+fQuery.rows.length);
+      //this is to check whether sufficient data was provided for monitor 
+      //to make an informed decision whether registration is in order
 		if (fQuery.rows.length==0){ 
 			this.generateError(qName,qMap[queryId]);
 			return;
 		}
 	}
 	this.generateMessage(qName,'Vailidation OK');
-	this.print('callback: set recipient: '+mailRecipient);
    let that=this;
-	let cb=function(){that.prepareForm(entry,mailRecipient);};
+	let cb=function(){that.prepareForm(entry);};
 	this.generateListEntry(entry.formId,qName,cb);
 }
 
 
 crfVisit.prepareForm=
-function(entry,mailRecipient){
+function(entry){
    //entry is generateConfig row
    let fName="[prepareForm]";
    let formId=entry['formId'];
 
-	this.print(fName+' recipient '+mailRecipient);
+	//this.print(fName+' recipient '+mailRecipient);
 
 	//look for existing registration entry
    let that=this;
-	let action=function(data){that.generateForm(data,entry,mailRecipient);};
+	let action=function(data){that.generateForm(data,entry);};
 	let formFilter=LABKEY.Filter.create('Form',formId);
 	let parentCrfFilter=LABKEY.Filter.create('parentCrf',this.crfRef);
    let filters=[formFilter,parentCrfFilter];
-   this.selectRows('lists','crfEntry',filters,action,crfSetup.getContainer('data'));
+   runQuery.selectRows('lists','crfEntry',filters,action,crfSetup.getContainer('data'));
 
 }
 
@@ -2066,62 +2080,64 @@ function(queryName,msg){
 }
 
 crfVisit.generateForm=
-function(data,entry,mailRecipient){
+function(data,entry){
    //entry is generateConfig entry
+   //data is a crfEntry row
 
    let fName='[generateForm]';
 
-	this.print(fName+' recipient: '+mailRecipient);
-//	
 	const nData=data.rows.length;
-	this.print(fName+' Registration: '+nData+' rows');
+
+	let formId=entry['formId'];
+   let formEntry=crfSetup.getEntryMap('dataForms')[formId];
+   let formName=formEntry['formName'];
+	this.print(fName+' crfEntry ('+formName+'): '+nData+' rows');
 
 	//we have to generate masterQuery with parentCrf and crfRef 
 	//and crfEntry with new entryId and parentCrf equal to crfRef
    let queryName=crfSetup.getMap('inputLists')[entry['queryId']];
 	if (nData>0) {
-		this.generateMessage(queryName,'Registration already generated.');
+		this.generateMessage(queryName,formName+' already generated.');
 		return;
 	}
-	let formId=entry['formId'];
-   let formEntry=crfSetup.getMap('dataForms')[formId];
-	let formName=formEntry.formName;
-	let crfBase=crfData.getCrfEntry();
-	let crfEntry=new Object();
-	//add new reference
-	crfEntry.entryId=Date.now();
-	crfEntry.parentCrf=this.crfRef;
-	crfEntry["Date"]=new Date();
-	crfEntry["View"]="[VIEW]";
-
-	crfEntry.formStatus=1;//In progress
+   //use current crfEntry as base
+   let crfBase=crfData.getCrfEntry();
+
+
+   let idLabel=crfSetup.getParticipantLabel(crfBase);
+   //role will appear in crfStatus and will be validated agains crfCreator entry of the form
+   let roleAndSite='generate:'+crfBase.Site;
+
+   //have to overload crfEntry
+   // - parentCrf
+   // - formStatus
+   // - UserId (set to sponsor UserId)
+   //
+   // should provide mail recipient and/or modified cb
+   //
+   //
+   let crfEntryOverload=new Object();
+
+   //parentCrf
+   crfEntryOverload.parentCrf=crfBase.entryId;
+
+   //formStatus
+	crfEntryOverload.formStatus=1;//In progress
    //checks for both field presence (if not in query, undefined) and field value (if not set, null)
    this.print(fName+' setup status: '+entry.formStatus);
    if (entry.formStatus){
-      crfEntry.formStatus=entry.formStatus;
+      crfEntryOverload.formStatus=entry.formStatus;
    }
 
-   //get local Id
-   let pM=this.getIdManager();
-   
-   crfEntry[participantIdManager.getCrfEntryFieldName(pM)]=participantIdManager.getParticipantIdFromCrfEntry(pM);
-//	//set other variables
-	//requires studyData as part of formConfig
-//	let studyData=config.formConfig.studyData;
-	this.print('Adding study: '+crfBase.EudraCTNumber);
-	crfEntry.EudraCTNumber=crfBase.EudraCTNumber;
-	crfEntry.StudyCoordinator=crfBase.StudyCoordinator;
-	crfEntry.StudySponsor=crfBase.StudySponsor;
-	crfEntry.RegulatoryNumber=crfBase.RegulatoryNumber;
-//
-//	//find sponsor for site
+   //	UserId
+   //find sponsor for site
 	let site=crfBase.Site;
 	let crfSponsors=crfSetup.getRows('crfSponsors');
 	let userMap=crfSetup.getEntryMap('users');
    let sponsorId=null;
 	for (let i=0;i<crfSponsors.length;i++){
 		//take first matching sponsor
-		if (crfSponsors[i].Site!=site) contnue;
+		if (crfSponsors[i].Site!=site) continue;
 		sponsorId=crfSponsors[i].User;
 		//finds first
 		break;
@@ -2130,28 +2146,18 @@ function(data,entry,mailRecipient){
 	this.print('Selecting '+sponsor.DisplayName+' as sponsor');
 	//different user than the original form...
 	//should be set to the study sponsor
-	crfEntry.UserId=sponsor.UserId;
-	crfEntry.Site=site;
-//	//set formId to one found through registration search
-	crfEntry.Form=formId;
-////
-
-   let crfStatus=crfData.createCrfStatus(crfEntry);
-   crfStatus.operator=this.role;
-   crfStatus.action='generateForm';
+	crfEntryOverload.UserId=sponsor.UserId;
 
+   let mailRecipient=entry.mailRecipient;
    let that=this;
    let action=function(){that.doNothing();};
-	let cb=function(data){that.sendEmail(data,mailRecipient,action,formName+' generated');}
-   let containerPath=crfSetup.getContainer('data');
-   let pass=function(data){runQuery.insertRows('lists','crfStatus',[crfStatus],cb,containerPath);};
-   runQuery.insertRows('lists','crfEntry',[crfEntry],pass,crfSetup.getContainer('data'));
-
+	let cb=function(data,_crfEntry){that.sendEmail(data,mailRecipient,action,formName+' generated');}
+   formPortal.createForm(formId,roleAndSite,cb,idLabel,crfEntryOverload);
+   
 }
 
 crfVisit.generateListEntry=
 function(formId,queryName,cb){
-
 	//check if registration was already generated
 
 	let formRows=crfSetup.selectFormSetupRows(formId);
@@ -2169,9 +2175,11 @@ function(formId,queryName,cb){
 	e2.crfRef=this.getCrfRef();
 	e2.registrationStatus=0;
 	e2.submissionDate=new Date();
-   e2[participantIdManager.getCrfEntryFieldName(pM)]=participantIdManager.getParticipantIdFromCrfEntry(pM);
+   let idLabel=crfSetup.getParticipantLabel(crfData.getCrfEntry());
+   e2[crfSetup.getLocalIdLabel()]=crfSetup.getLocalId(idLabel);
+   e2[crfSetup.getStudyIdLabel()]=crfSetup.getStudyId(idLabel);
 	this.print('set values');
-
+   e2.site=crfData.getCrfEntry()['Site'];
    runQuery.insertRows('lists',queryName,[e2],cb,crfSetup.getContainer('data'));
 
 }
@@ -2194,12 +2202,12 @@ function(){
 crfVisit.afterCrfEntry=
 function(){
    let fName='[afterCRFEntry]';
-	this.print("Setting crfEntry (x) to "+crfData.getCrfEntry()["entryId"]);
+	this.print(fName+" setting crfEntry (x) to "+crfData.getCrfEntry()["entryId"]);
 	//for empty records or those with parentCrf not set, parentCrf comes up as null
 	//nevertheless, with two equal signs, check against undefined also works
    crfSetup.formStatus=crfData.getCrfEntry()['FormStatus'];
    let parentCrf=crfData.getCrfEntry()['parentCrf'];
-	this.print('parentCrf set to '+parentCrf);
+	this.print(fName+' parentCrf set to '+parentCrf);
    if (parentCrf) crfSetup.parentCrf=parentCrf;
    let that=this;
    let action=function(){that.parseSetup();};