Browse Source

Fleshing out participantOverview, including an option to open participantPortal for a given participant

Andrej Studen 1 year ago
parent
commit
cdebf62d8b
1 changed files with 101 additions and 16 deletions
  1. 101 16
      web/crf/participantOverview.js

+ 101 - 16
web/crf/participantOverview.js

@@ -22,14 +22,17 @@ function(msg){
    console.log(msg);
 }
 
-participantOverview.addObjectToMap=
-function(object,map,id){
-   if (id in map){
-      map[id].push(object);
-      return;
-   }
-   map[id]=new Array();
-   map[id].push(object);
+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);
+
 }
 
 
@@ -83,26 +86,108 @@ function(){
 
    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){
-         //link crfEntry to registration row
-         let idLabel=crfSetup.getParticipantLabel(regEntry);
-         this.addObjectToMap(entry,entryMap,idLabel);
-      }
-      else{
-         let idLabel=crfSetup.getParticipantLabel(entry);
-         this.print(fName+' ['+entry['Key']+'] no match found '+idLabel);
+      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<formRows.length;i++){
+      let formName=formRows[i]['formName'];
+      cell=row.insertCell();
+      let tNode=crfHTML.createTextNode(formName,null,cell);
+      crfHTML.addStyle(cell,'small');
+   }
+
+   for (let idLabel in entryMap){
+      row=table.insertRow();
+      let cell=crfHTML.createTblHeader(null,row);
+      crfHTML.createTextNode(idLabel,null,cell);
+      cell.onclick=function(){that.openParticipant(idLabel);};
+      for (let i=0;i<formRows.length;i++){
+         let form=formRows[i]['Key'];
+         let count=new Object();
+         if (form in entryMap[idLabel]){
+            let ar=entryMap[idLabel][form];
+            for (let i=0;i<ar.length;i++){
+               let entry=ar[i];
+               let st=entry['FormStatus'];
+               if (!(st in count)) count[st]=0;
+               count[st]+=1;
+            }
+         }
+         let label="";
+         for (let s in count)
+            label+=stMap[s]['formStatus']+':'+count[s]+" ";
+         cell=row.insertCell();
+         crfHTML.createTextNode(label,null,cell);
+         crfHTML.addStyle(cell,'small');
+      }
+   }
+
+}
+
+participantOverview.openParticipant=
+function(idLabel){
+	let formUrl="participantPortal";
+	let params=new Object();
+	params.name=formUrl;
+   params['participantLabel']=idLabel;
+
+	//params.pageId="CRF";
+
+	//points to crf container
+	let containerPath=crfSetup.getContainer('CRF');
+        
+	// This changes the page after building the URL. 
+	//Note that the wiki page destination name is set in params.
+        
+	//let homeURL = LABKEY.ActionURL.buildURL("project", formUrl , containerPath, params);
+	let homeURL = LABKEY.ActionURL.buildURL("crf", formUrl , containerPath, params);
+   this.print("Redirecting to "+homeURL);
+	window.location = homeURL;
+
 }