Browse Source

Provide alternate versions of getInputElement, getTextElement that take mode as an argument, have both routine create elements if not available, setLabelMode also sets local id if available

Andrej Studen 2 years ago
parent
commit
50d92aafe6
1 changed files with 89 additions and 66 deletions
  1. 89 66
      web/crf/participantIdManager.js

+ 89 - 66
web/crf/participantIdManager.js

@@ -2,7 +2,9 @@
 
 
 function addSelectOptions(){
 function addSelectOptions(){
    let pM=this;
    let pM=this;
-   let input=pM.inputSelector;
+   if (pM.mode=="LOCAL") return;
+   
+   let input=pM.getInputElement();
    let config=pM.config;
    let config=pM.config;
 
 
    let fName='addParticipantSelectOptions';
    let fName='addParticipantSelectOptions';
@@ -13,12 +15,14 @@ function addSelectOptions(){
    opt.text="<Select>";
    opt.text="<Select>";
    input.options[input.options.length]=opt;
    input.options[input.options.length]=opt;
 
 
-   let demoRows=config.formConfig['demographicData'].rows;
+   let demoRows=config.formConfig['registrationData'].rows;
    pM.print(fName+" demoRows: "+demoRows.length);
    pM.print(fName+" demoRows: "+demoRows.length);
    for (let i=0;i<demoRows.length;i++){
    for (let i=0;i<demoRows.length;i++){
       let opt2=config.document.createElement("option");
       let opt2=config.document.createElement("option");
       opt2.value=i+1;
       opt2.value=i+1;
-      opt2.text=demoRows[i][pM.participantField];
+      let id=demoRows[i][pM.getCrfEntryFieldName()];
+      let loc=demoRows[i][pM.getCrfEntryFieldName('LOCAL')];
+      opt2.text=id+' (Local: '+loc+')';
       input.options[input.options.length]=opt2;
       input.options[input.options.length]=opt2;
       pM.print(fName+' '+pM.participantField+' '+demoRows[i][pM.participantField]);
       pM.print(fName+' '+pM.participantField+' '+demoRows[i][pM.participantField]);
    }
    }
@@ -97,64 +101,93 @@ function generateEntryField(){
    //manage
    //manage
    pM.cellManageStudy=rowStudy.insertCell();
    pM.cellManageStudy=rowStudy.insertCell();
    config.document.getElementById(formName).appendChild(tb);
    config.document.getElementById(formName).appendChild(tb);
+   pM.print(fName+' done');
+
+}
 
 
+function getMode(mode="NONE"){
+   let pM=this;
+   if (mode=="NONE") return pM.mode;
+   return mode;
 }
 }
 
 
 //reslovers which operate depending on mode
 //reslovers which operate depending on mode
-function getInputId(){
+function getInputId(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getInputId]';
    let fName='[getInputId]';
    pM.print(fName);
    pM.print(fName);
-   if (pM.mode=="LOCAL") return pM.inputValueId;
+   if (pM.getMode(mode)=="LOCAL") return pM.inputValueId;
    return pM.inputSelectorId;
    return pM.inputSelectorId;
 }
 }
 
 
 
 
-function getInputCell(){
+function getInputCell(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getInputCell]';
    let fName='[getInputCell]';
-   pM.print(fName);
-   if (pM.mode=="LOCAL") return pM.cellValue;
+   pM.print(fName+' mode '+mode+' getMode '+pM.getMode(mode));
+   if (pM.getMode(mode)=="LOCAL") return pM.cellValue;
    return pM.cellSelector;
    return pM.cellSelector;
 }
 }
 
 
-function getInputElement(){
+function getInputElement(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getInputElement]';
    let fName='[getInputElement]';
    pM.print(fName);
    pM.print(fName);
-   if (pM.mode=="LOCAL") return pM.inputValue;
-   return pM.inputSelector;
+   let elementType=pM.getInputElementType(mode);
+   let id=pM.getInputId(mode);
+   let cell=pM.getInputCell(mode);
+   let el=pM.config.document.getElementById(id);
+   pM.print(fName+' mode '+pM.getMode(mode)+' type '+elementType+' id '+id+' cell '+cell+' el '+el);
+   if (el) return el;
+
+   el=pM.config.document.createElement(elementType);
+   print(fName+' input '+el);
+   el.id=id;
+
+   cell.replaceChildren(el);
+   pM.addSelectOptions();
+ 
+   return el;
 }
 }
 
 
-function getInputElementType(){
+function getInputElementType(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getInputElementType]';
    let fName='[getInputElementType]';
    pM.print(fName);
    pM.print(fName);
-   if (pM.mode=="LOCAL") return "input";
+   if (pM.getMode(mode)=="LOCAL") return "input";
    return "select";
    return "select";
 }
 }
 
 
 
 
-function getTextFieldId(){
+function getTextFieldId(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getTextFieldId]';
    let fName='[getTextFieldId]';
    pM.print(fName);
    pM.print(fName);
-   if (pM.mode=="LOCAL") return pM.textLocalId;
+   if (pM.getMode(mode)=="LOCAL") return pM.textLocalId;
    return pM.textStudyId;
    return pM.textStudyId;
 }
 }
 
 
   
   
-function getTextElement(){
+function getTextElement(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getTextElement]';
    let fName='[getTextElement]';
-   pM.print(fName);
-   if (pM.mode=="LOCAL") return pM.textLocal;
-   return pM.textStudy;
+   pM.print(fName+' mode '+mode);
+   let id=pM.getTextFieldId(mode);
+   pM.print(fName+' id '+id);
+   let el=pM.config.document.getElementById(id);
+   pM.print(fName+' el '+el);
+   if (el) return el;
+   el=config.document.createElement("p");
+   el.id=id;
+   let cell=pM.getInputCell(mode);
+   //let oldEl=pM.getInputElement(mode);
+   cell.replaceChildren(el);
+   return el;
 }
 }
 
 
 
 
 //get the button, create if not there yet
 //get the button, create if not there yet
-function getInputManage(){
+function getInputManage(mode="NONE"){
    let pM=this;
    let pM=this;
    let fName='[getInputManage]';
    let fName='[getInputManage]';
    //pM.print(fName);
    //pM.print(fName);
@@ -168,7 +201,7 @@ function getInputManage(){
    inputManage.onclick=function(){pM.manageId();};
    inputManage.onclick=function(){pM.manageId();};
    //inputManageLocal.id=pM.inputManageLocalId;
    //inputManageLocal.id=pM.inputManageLocalId;
    let cell=pM.cellManageStudy;
    let cell=pM.cellManageStudy;
-   if (pM.mode=="LOCAL") cell=pM.cellManageLocal;
+   if (pM.getMode(mode)=="LOCAL") cell=pM.cellManageLocal;
    //pM.print(fName+' inputManage '+pM.inputManage+' cell '+cell+' mode '+pM.mode);
    //pM.print(fName+' inputManage '+pM.inputManage+' cell '+cell+' mode '+pM.mode);
    cell.appendChild(inputManage);
    cell.appendChild(inputManage);
    return inputManage;
    return inputManage;
@@ -203,15 +236,19 @@ function setId(){
 
 
    pM.print(fName+" value: "+el.value);
    pM.print(fName+" value: "+el.value);
    let pId=el.value;
    let pId=el.value;
+   let label=pId;
    if (pM.mode!="LOCAL"){
    if (pM.mode!="LOCAL"){
       if (el.value<0) return;
       if (el.value<0) return;
       let opt=el.options[el.selectedIndex];
       let opt=el.options[el.selectedIndex];
-      pId=opt.text;
+      label=opt.text;
+      pId=label.replace(/\(.*\)/,'');
+      label=label.replace(/ \(Local: /,':');
+      label=label.replace(/\)/,'');
    }
    }
    pM.setParticipantIdToCrfEntry(pId);//no argument (should come from mode)
    pM.setParticipantIdToCrfEntry(pId);//no argument (should come from mode)
-   pM.updateCrfEntry();
    pM.print(fName+" new value "+pId);
    pM.print(fName+" new value "+pId);
-   pM.setLabelMode(pId);//setLabel{Study,Local}Mode
+   pM.setLabelMode(label);
+   pM.updateCrfEntry();
 }
 }
 
 
 function setLabelMode(pId){
 function setLabelMode(pId){
@@ -219,27 +256,29 @@ function setLabelMode(pId){
    let pM=this;
    let pM=this;
    let config=pM.config;
    let config=pM.config;
 
 
-   pM.print(fName+' config '+config);
+   pM.print(fName+' id '+pId);
+   ids=pId.split(':');
 
 
-   let textValue=config.document.createElement("p");
-   pM.print(fName+' id1 ');
-   textValue.innerText=pId;
-   let id=pM.getTextFieldId();
-   let el=pM.getInputElement();
-   let cell=pM.getInputCell();
-   
-   pM.print(fName+' mode '+pM.mode+' id '+id+' cell '+cell+' el '+el);
- 
-   textValue.id=id;//getTextId
-   if (el!=undefined)
-      cell.replaceChild(textValue,el);
-   else
-      cell.appendChild(textValue);
+   let textValue=pM.getTextElement();
+   pM.print(fName+' textElement '+textValue);
+   textValue.innerText=ids[0];
+
+   if (pM.mode=="STUDY"){
+      let loc=ids[1];
+      //pM.getParticipantIdFromCrfEntry('LOCAL');
+      pM.print(fName+' setting local id '+loc);
+      let tValLocal=pM.getTextElement('LOCAL');
+      tValLocal.innerText=loc;
+      pM.setParticipantIdToCrfEntry(loc,'LOCAL');
+   }
 
 
    let x=pM.getInputManage();//getInputManage
    let x=pM.getInputManage();//getInputManage
-   if ("readOnly" in pM)
+   if ("readOnly" in pM){
       x.style.display="none";
       x.style.display="none";
+   }
    x.value="Edit";
    x.value="Edit";
+
+   
 }
 }
 
 
 //edit mode
 //edit mode
@@ -255,26 +294,8 @@ function setEditMode(){
    let fName='[setEditMode1]';
    let fName='[setEditMode1]';
    pM.print(fName+' pM '+pM+' mode '+pM.mode);
    pM.print(fName+' pM '+pM+' mode '+pM.mode);
    //input
    //input
-   let elementType=pM.getInputElementType();
-   let id=pM.getInputId();
-   let el=pM.getTextElement();
-   let cell=pM.getInputCell();
-   pM.print(fName+' mode '+pM.mode+' type '+elementType+' id '+id+' cell '+cell+' el '+el);
-   let input=config.document.createElement(elementType);
-   print(fName+' input '+input);
-   input.id=id;
-
-
-   //this sets pM.inputSelector and/or pM.inputValue;
-   pM.print(fName+" value old "+el+" new "+input);
-
-   if (el!=undefined)
-      cell.replaceChild(input,el);
-   else
-      cell.appendChild(input);
-   
-   pM.updateElements();
-   if (pM.mode!="LOCAL") pM.addSelectOptions();
+   let el=pM.getInputElement();
+
    let x=pM.getInputManage();
    let x=pM.getInputManage();
    x.value="Set";
    x.value="Set";
 
 
@@ -285,23 +306,24 @@ function getParticipantField(config){
    return config.formConfig['studyDataAll'].rows[0]['SubjectColumnName'];
    return config.formConfig['studyDataAll'].rows[0]['SubjectColumnName'];
 }
 }
 
 
-function getCrfEntryFieldName(){
+function getCrfEntryFieldName(mode="NONE"){
    let pM=this;
    let pM=this;
    let variable="Study";
    let variable="Study";
-   if (pM.mode=="LOCAL") variable="Local";
+   if (mode=="NONE") mode=pM.mode;
+   if (mode=="LOCAL") variable="Local";
    return 'participant'+variable+'Id';
    return 'participant'+variable+'Id';
 }
 }
 
 
-function setParticipantIdToCrfEntry(pId){
+function setParticipantIdToCrfEntry(pId,mode="NONE"){
    let pM=this;
    let pM=this;
    let config=pM.config;
    let config=pM.config;
-   config.formConfig.crfEntry[pM.getCrfEntryFieldName()]=pId;
+   config.formConfig.crfEntry[pM.getCrfEntryFieldName(mode)]=pId;
 }
 }
 
 
-function getParticipantIdFromCrfEntry(){
+function getParticipantIdFromCrfEntry(mode="NONE"){
    let pM=this;
    let pM=this;
    let config=pM.config;
    let config=pM.config;
-   return config.formConfig.crfEntry[pM.getCrfEntryFieldName()];
+   return config.formConfig.crfEntry[pM.getCrfEntryFieldName(mode)];
 }
 }
 
 
 //main interface. Use this to generate object and to refer to it later on
 //main interface. Use this to generate object and to refer to it later on
@@ -340,6 +362,7 @@ function getParticipantManagerObject(config){
    pM.mode="LOCAL";//or "STUDY"
    pM.mode="LOCAL";//or "STUDY"
 
 
    //add methods
    //add methods
+   pM.getMode=getMode;
 
 
    //global methods that are not subject to mode modifier
    //global methods that are not subject to mode modifier
    pM.updateElements=updateElements;
    pM.updateElements=updateElements;