Browse Source

Modifying formPortal.createForm so it can be used in crfVisit.generateForm; added callback as a function parameter, adding overload to crfEntry

Andrej Studen 1 year ago
parent
commit
33e2766fdd
1 changed files with 22 additions and 5 deletions
  1. 22 5
      web/crf/formPortalNew.js

+ 22 - 5
web/crf/formPortalNew.js

@@ -233,7 +233,8 @@ function(el,formList,roleAndSite,formId=null,idLabel=null){
    crfHTML.addStyle(cell,'stretch');
    let fbox=crfHTML.createBox(null,cell);
    crfHTML.addStyle(fbox,'empty');
-   fbox.onclick=function(){that.createForm(formId,roleAndSite,idLabel);};
+   let cb=function(xdata,xcrfEntry){that.openForm(xcrfEntry,roleAndSite);};
+   fbox.onclick=function(){that.createForm(formId,roleAndSite,cb,idLabel);};
    return table;
    
 }
@@ -277,7 +278,10 @@ function(crfEntry,roleAndSite){
 }
 
 formPortal.createForm=
-function(formId,roleAndSite,idLabel=null){
+function(formId,roleAndSite,cb=null,idLabel=null,crfEntryOverload=null){
+   //cb takes arguments (data,crfEntry)
+   
+
    let fName="[createForm]";
    
    let formRow=crfSetup.getEntryMap('dataForms')[formId];
@@ -302,6 +306,12 @@ function(formId,roleAndSite,idLabel=null){
 	crfEntry["Date"]=new Date();
 	crfEntry["View"]="[VIEW]";
 	crfEntry.formStatus=1;//In progress
+
+   let fStatus=formRow['initialStatus'];
+   if (fStatus)
+      crfEntry.formStatus=fStatus;
+
+
 	//set other variables
 	//requires studyData as part of formConfig
 	let studyData=crfSetup.getRows('studyData')[0];
@@ -319,16 +329,23 @@ function(formId,roleAndSite,idLabel=null){
       crfEntry[crfSetup.getLocalIdLabel()]=crfSetup.getLocalId(idLabel);
       crfEntry[crfSetup.getStudyIdLabel()]=crfSetup.getStudyId(idLabel);
    }
-
+   //overload entries
+   if (crfEntryOverload){
+      for (f in crfEntryOverload){
+         crfEntry[f]=crfEntryOverload[f];
+      }
+   }
 
 
    let crfStatus=crfData.createCrfStatus(crfEntry);
    crfStatus.operator=role;
    crfStatus.action='createForm';
    let that=this;
-   let cb=function(data){that.openForm(crfEntry,roleAndSite);};
+   //let cb=function(data){that.openForm(crfEntry,roleAndSite);}
+   this.print(fName+' '+cb);
+   let callback=function(data){cb(data,crfEntry);};
    let containerPath=crfSetup.getContainer('data');
-   let pass=function(data){runQuery.insertRows('lists','crfStatus',[crfStatus],cb,containerPath);};
+   let pass=function(data){runQuery.insertRows('lists','crfStatus',[crfStatus],callback,containerPath);};
    runQuery.insertRows('lists','crfEntry',[crfEntry],pass,containerPath);
 }