//global config variable const config=new Object(); function print(msg){ config.document.getElementById(config.debugArea).value+="\n"+msg; } function clear(){ config.document.getElementById(config.debugArea).value=""; } function getMode(){ if ("role" in config){ return config.role; } return "crfEditor"; } function doNothing(){ print('doNothing called'); } function makeQuery(containerName,queryName,fieldName,filterArray){ //queryArray should contain elements with //- fieldName to set the data variable //- containerName to select container (data,config,CRF) //- queryName to select query //- filterArray to perform filtering, empty array works //- callback cb to be called with no arguments let e=new Object(); e.containerName=containerName; e.queryName=queryName; e.fieldName=fieldName; e.filterArray=filterArray; return e; } function getDataFromQueries(queryArray,cb){ afterQuery(new Object(),-1,queryArray,cb); } function afterQuery(data,id,queryArray,cb){ print('afterQuery['+id+']: '); if (id>-1){ let fieldName=queryArray[id].fieldName; print('afterQuery['+fieldName+']: '+data.rows.length); //uses config.formConfig config.formConfig[fieldName]=data; } id+=1; if (id==queryArray.length) { cb(); return; } let e=queryArray[id]; let qconfig=new Object(); qconfig.containerPath=getContainer(e.containerName); qconfig.schemaName="lists"; if ("schemaName" in e){ print('afterQuery: schemaName='+e.schemaName); qconfig.schemaName=e.schemaName; } if ("columns" in e){ print('afterQuery: columns='+e.columns); qconfig.columns=e.columns; } qconfig.queryName=e.queryName; //this should point to configuration container //don't filter -> so we can pick up other forms (say registration) later on //qconfig.filterArray=[LABKEY.Filter.create('Key',config.formId)]; if ("filterArray" in e) qconfig.filterArray=e.filterArray; //qconfig.filterArray=[LABKEY.Filter.create('formStatus',1)] qconfig.success=function(data){afterQuery(data,id,queryArray,cb);}; qconfig.failure=doNothing; LABKEY.Query.selectRows(qconfig); } function printMessage(msg){ let txt=config.document.createElement("p"); config.document.getElementById(config.div).appendChild(txt); txt.innerText=msg; } function userName(id){ let formConfig=config.formConfig; for (let i=0;i0) columnModel+=','; columnModel+=varRows[i]['staticVariable']; } e.columns=columnModel; getDataFromQueries(queryArray,fcontinue); } function filterEntry(entry,filter,settings){ if (entry.Form!=filter.form) return false; //only select forms where status matches the target status if (entry.FormStatus!=filter.formStatus){ return false; } print('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){ print('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){ print('Skipping wrong site: '+entry.Site+'/'+potentialSiteNumbers); return false; } return true; } function fcontinue(){ let fName='[fcontinue]'; let formConfig=config.formConfig; print("Number of study data entries: "+formConfig.studyData.rows.length); print("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=getMode()+'Status'; print('accessModeColumn '+accessModeColumn); //cutting down on number of fields //let creatorModeColumn=getMode()+'Creator'; //switch from status based to form based access print("Forms: "+dataForms.length); print("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+=')'; printMessage(msg); let filter=new Object(); filter.role=config.role; filter.userId=currentUser.UserId; filter.sites=currentSites; //browse through forms for (let i=0;i