Browse Source

Adding local/global names to participantPortal

Andrej Studen 1 year ago
parent
commit
54967823c9
1 changed files with 39 additions and 7 deletions
  1. 39 7
      web/crf/participantPortal.js

+ 39 - 7
web/crf/participantPortal.js

@@ -34,7 +34,25 @@ function(){
    }
    return this.participantMap;
 }
-   
+  
+participantPortal.clearKeyMap=
+function(){
+   if (!("participantKeyMap" in this)){
+      this.participantKeyMap=new Object();
+      return;
+   }
+   Object.keys(this.participantKeyMap).forEach(key => delete this.participantKeyMap[key]);
+}
+
+participantPortal.addToKeyMap=
+function(key,value){
+   this.participantKeyMap[value]=key;
+}
+
+participantPortal.getFromKeyMap=
+function(value){
+   return this.participantKeyMap[value];
+}
 
 participantPortal.getParticipantArray=
 function(id,formId){
@@ -68,7 +86,7 @@ function(){
    let rows=crfSetup.getRows('crfEntries');
    for (let i=0;i<rows.length;i++){
       let entry=rows[i];
-      let id=entry[this.idField];
+      let id=crfSetup.getParticipantLabel(entry);
       if (!id) id="NONE";
       let formId=entry['Form'];
       let pArray=this.getParticipantArray(id,formId);
@@ -97,6 +115,16 @@ function(){
    this.participantSelect=crfHTML.createSelect(new Object(),'formDiv');
    this.displayTable=crfHTML.createTable('formDiv');
    this.participantSelect.onchange=function(){that.displayEntries();}
+   
+   if (this.searchParams.get("role") && this.searchParams.get("site")){
+      let label=this.searchParams.get("role")+':'+this.searchParams.get("site");
+      crfRoleSelector.setRoleAndSite(label);
+      crfRoleSelector.onChange(updateParticipants);
+   }
+   if (this.searchParams.get('participantLabel')){
+      this.participantSelect.value=this.getFromKeyMap(this.searchParams.get('participantLabel'));
+      this.displayEntries();
+   }
 }
 
 participantPortal.updateParticipants=
@@ -110,16 +138,19 @@ function(){
    this.print(fName+' registration '+Object.keys(regMap).length);
    //let idMap=crfData.getRegistrationMap(this.idField);
    //let idLocalMap=crfData.getRegistrationMap(this.localIdField);
+   this.clearKeyMap();
    let updatedMap=new Object();
    for (q in regMap){
+      let key=regMap[q]['Key'];
       let label=crfSetup.getParticipantLabel(regMap[q]);
-      this.print(fName+' label '+label+' site '+site);
+      this.print(fName+' key '+key+' label '+label+' site '+site);
+      this.addToKeyMap(key,label);
       if (regMap[q]['site']!=site) continue;
-      updatedMap[q]=label;
+      updatedMap[key]=label;
             //idMap[q]+':Local '+idLocalMap[q];
    }
    updatedMap[1000]='NONE';
-   updatedMap[1001]='Add new user';
+   updatedMap[1001]='Add new participant';
    crfHTML.addSelectOptions(this.participantSelect,updatedMap);
 }
 
@@ -133,7 +164,7 @@ function(){
 
    //let idRows=crfData.getRegistration();
    let selectIdText=this.participantSelect.options[this.participantSelect.selectedIndex].text;
-   if (selectIdText=='Add new user'){
+   if (selectIdText=='Add new participant'){
       let formId=crfSetup.getSettings('registrationFormId');
       if (!formId){
          alert('registrationFormId not set in settings!');
@@ -144,7 +175,8 @@ function(){
    }
 
 
-   let selectId=crfSetup.getStudyId(selectIdText);
+   //let selectId=crfSetup.getStudyId(selectIdText);
+   let selectId=selectIdText;
    //let formId=formIds[Object.keys(formIds)[0]];
    //this.printParticipantArray();
    this.print(fName+' rows '+this.displayTable.rows.length);