var formPortal={}; //global config variable formPortal.config=new Object(); formPortal.setDebug= function(debug=null){ if (debug){ this.print=function(msg){debug.print(msg);}; this.clear=function(){debug.clear();} return; } //provide default functions if not debug object is available this.print=function(msg){console.log(msg);} this.clear=function(){;} } formPortal.setDebug(); formPortal.getMode= function(){ if ("role" in this.config){ return this.config.role; } return "crfEditor"; } formPortal.doNothing= function(){ this.print('doNothing called'); } //load runQuery.js formPortal.printMessage= function(msg){ let txt=this.config.document.createElement("p"); this.config.document.getElementById(this.config.div).appendChild(txt); txt.innerText=msg; } formPortal.userName= function(id){ let formConfig=this.config.formConfig; for (let i=0;i0) columnModel+=','; columnModel+=varRows[i]['staticVariable']; } e.columns=columnModel; let that=this; let action=function(){that.fcontinue();}; runQuery.getDataFromQueries(this,queryArray,action); } formPortal.filterEntry= function(entry,filter,settings){ let fName="[filterEntry]"; if (entry.Form!=filter.form) return false; //only select forms where status matches the target status if (entry.FormStatus!=filter.formStatus){ //check for additionalStates let addStates=filter.additionalVisibilityStates[filter.role]; this.print(fName+' addState['+filter.role+'/'+entry.FormStatus+'] '+addStates); if (!addStates) return false; let ar=addStates.split(','); this.print(fName+" ar "+ar.length); let v=String(entry.FormStatus); if (!(ar.includes(v))) return false; this.print(fName+" allowed for state "+entry.FormStatus); } this.print(fName+' 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){ this.print(fName+' skipping identity mismatch: '+entry.UserId+'/'+filter.userId); return false; } //for others let matchingSite=-1; let potentialSiteNumbers="["; for (let k=0;k0) 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){ this.print(fName+' skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers); return false; } return true; } formPortal.fcontinue= function(){ let fName='[fcontinue]'; let config=this.config; let formConfig=config.formConfig; this.print(fName+" number of study data entries: "+formConfig.studyData.rows.length); this.print(fName+" participantId: "+formConfig.studyData.rows[0].SubjectColumnName); let dataForms=formConfig.dataForms.rows; formConfig.table=config.document.createElement("table"); config.document.getElementById(config.div).appendChild(formConfig.table); let accessModeColumn=this.getMode()+'Status'; this.print(fName+' accessModeColumn '+accessModeColumn); //cutting down on number of fields //let creatorModeColumn=getMode()+'Creator'; //switch from status based to form based access this.print(fName+" forms: "+dataForms.length); this.print(fName+" entries: "+formConfig.crfEntries.rows.length); let fEntries=formConfig.crfEntries.rows; let users=formConfig.users.rows; let currentUserId=LABKEY.Security.currentUser.id; let currentUser=undefined; for (let i=0;i0) msg+=', '; msg+=currentSites[i].siteName; } msg+=')'; this.printMessage(msg); let filter=new Object(); filter.role=config.role; filter.userId=currentUser.UserId; filter.sites=currentSites; //make a formStatus map let formStatusMap=new Object(); this.print(fName+' formStatusMap: '+config.formConfig.formStatusg.rows.length); for (let i=0;i