Browse Source

Allowing starting of participantPortal with participantId only (ie, w/o site and role), which requires roleAndSite to also return empty values which are treated as a signal that roleAndSite was not set yet. Provide error text should role and site not be set when form is opened

Andrej Studen 1 year ago
parent
commit
b2bbefdb2f
1 changed files with 18 additions and 9 deletions
  1. 18 9
      web/crf/participantPortal.js

+ 18 - 9
web/crf/participantPortal.js

@@ -112,30 +112,35 @@ function(){
    let that=this;
    let updateParticipants=function(){that.updateParticipants();};
    crfRoleSelector.makePortal(updateParticipants);
+   this.roleError=crfHTML.createParagraph('','formDiv');
    let txt=crfHTML.createParagraph('Select participant','formDiv');
    crfHTML.clearStyle(txt,'center');
    this.participantSelect=crfHTML.createSelect(new Object(),'formDiv');
    this.displayTable=crfHTML.createTable('formDiv');
    this.participantSelect.onchange=function(){that.displayEntries();}
+
+   //start with all patients
+   this.updateParticipants();
    
    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=
 function(){
    let fName='[participantPortal.updateParticipants]';
    let roleAndSite=crfRoleSelector.getRoleAndSite();
-   let ar=roleAndSite.split(':');
-   let site=ar[1];
-   this.print(fName+' site '+site);
+   //clear error
+   this.roleError.innerText='';
+   let site=null;
+   if (roleAndSite){
+      let ar=roleAndSite.split(':');
+      site=ar[1];
+      this.print(fName+' site '+site);
+   }
    let regMap=crfData.getRegistrationEntryMap();
    this.print(fName+' registration '+Object.keys(regMap).length);
    //let idMap=crfData.getRegistrationMap(this.idField);
@@ -147,12 +152,16 @@ function(){
       let label=crfSetup.getParticipantLabel(regMap[q]);
       this.print(fName+' key '+key+' label '+label+' site '+site);
       this.addToKeyMap(key,label);
-      if (regMap[q]['site']!=site) continue;
+      if (site && regMap[q]['site']!=site) continue;
       updatedMap[key]=label;
    }
    updatedMap[1000]='NONE';
    updatedMap[1001]='Add new participant';
    crfHTML.addSelectOptions(this.participantSelect,updatedMap);
+   if (this.searchParams.get('participantLabel')){
+      this.participantSelect.value=this.getFromKeyMap(this.searchParams.get('participantLabel'));
+      this.displayEntries();
+   }
 }
 
 participantPortal.displayEntries=
@@ -204,7 +213,7 @@ function(){
       }
       crfHTML.clear(cell);
       let forms=this.getParticipantArray(selectId,formId);
-      formPortal.displayForms(cell,forms,roleAndSite,formId,selectIdText);
+      formPortal.displayForms(cell,forms,roleAndSite,formId,selectIdText,this.roleError);
       this.print(fName+' ['+selectId+'/'+formId+'] forms '+forms.length);
    }
 }