var participantOverview={}; participantOverview.init= function(cb=null){ let that=this; let action=function(){that.scriptsLoaded(cb);}; LABKEY.Utils.requiresScript(["crfDORA/crfSetup.js","crfDORA/crfData.js","crfDORA/crfHTML.js"],action); } participantOverview.scriptsLoaded= function(cb=null){ //if other script need init, just stack the init scripts //let action=function(){runQuery.init(cb);} crfData.setSetup(crfSetup); crfHTML.init(); let initData=function(){crfData.init(cb);}; crfSetup.init(initData); } participantOverview.print= function(msg){ console.log(msg); } participantOverview.addObjectToIdFormMap= function(object,map,id,form){ if (!(id in map)) map[id]=new Object(); let fMap=map[id]; if (!(form in fMap)) fMap[form]=new Array(); fMap[form].push(object); } participantOverview.generateParticipantArray= function(){ let fName='generateParticipantArray'; this.print(fName); let that=this; let makeArray=function(){that.makeArray();}; let setRegistration=function(){crfData.setRegistration(makeArray);}; let action=function(){crfSetup.parseSetup(setRegistration);} crfSetup.setContainers(action); } participantOverview.matchRegistration= function(entry){ let fName='matchRegistration'; let sF='participantStudyId'; let studyRegMap=crfData.getRegistrationEntryMap(sF);//should be unique for registration let nS=Object.keys(studyRegMap).length; //this.print(fName+' study registration entries '+nS); let lF='participantLocalId'; let localRegMap=crfData.getRegistrationEntryMap(lF);//should be unique for registration let nL=Object.keys(localRegMap).length; //this.print(fName+' local registration entries '+nL); if (entry[sF]){ if (entry[sF] in studyRegMap){ return studyRegMap[entry[sF]]; } //failed to match study id } if (entry[lF]){ if (entry[lF] in localRegMap){ return localRegMap[entry[lF]]; } //failed to match local id } return null; } participantOverview.makeArray= function(){ let fName='makeArray'; let entries=crfSetup.getEntryMap('crfEntries'); let n=Object.keys(entries).length; this.print(fName+' entries '+n); let idField='participantStudyId'; let entryMap=new Object(); let statusMap=crfSetup.getEntryMap('formStatusAll'); let i=0; let site=-1; if (this.searchParams.has("site")){ site=this.searchParams.get("site"); } for (let key in entries){ let entry=entries[key]; let formStatus=statusMap[entry['FormStatus']]['formStatus']; if (formStatus=='Deleted'){ continue; } if (site!=-1 && entry['Site']!=site) continue; let regEntry=this.matchRegistration(entry); if (!regEntry){ //skip mismatched crfEntry this.print(fName+' ['+entry['Key']+'] no match found '); i++; continue; } //link crfEntry to registration row let idLabel=crfSetup.getParticipantLabel(regEntry); let form=entry['Form']; this.addObjectToIdFormMap(entry,entryMap,idLabel,form); } this.print('Found '+(n-i)+'/'+n+' participants'); this.showArray(entryMap); //for (let idLabel in entryMap){ } participantOverview.showArray= function(entryMap){ let table=crfHTML.createTable('formDiv'); crfHTML.addStyle(table,"tOverview"); let formRows=crfSetup.getRows('dataForms'); let row=table.insertRow(); let cell=row.insertCell(); let stMap=crfSetup.getEntryMap('formStatusAll'); let that=this; for (let i=0;i