|
@@ -6,18 +6,13 @@ function addSelectOptions(){
|
|
|
let config=pM.config;
|
|
|
|
|
|
let fName='addParticipantSelectOptions';
|
|
|
- pM.print(fName);
|
|
|
+ pM.print(fName+' input '+input);
|
|
|
let opt=config.document.createElement("option");
|
|
|
opt.value=-1;
|
|
|
|
|
|
opt.text="<Select>";
|
|
|
input.options[input.options.length]=opt;
|
|
|
|
|
|
- let opt1=config.document.createElement("option");
|
|
|
- opt1.value=0;
|
|
|
- opt1.text="New";
|
|
|
- input.options[input.options.length]=opt1;
|
|
|
-
|
|
|
let demoRows=config.formConfig['demographicData'].rows;
|
|
|
pM.print(fName+" demoRows: "+demoRows.length);
|
|
|
for (let i=0;i<demoRows.length;i++){
|
|
@@ -33,15 +28,22 @@ function addSelectOptions(){
|
|
|
|
|
|
function updateElements(){
|
|
|
let pM=this;
|
|
|
+ let fName='[updateElements]';
|
|
|
//reset all values (some might be different depending on the call timing)
|
|
|
+
|
|
|
+ //selector is with study
|
|
|
pM.cellSelector=config.document.getElementById(pM.cellSelectorId);
|
|
|
pM.inputSelector=config.document.getElementById(pM.inputSelectorId);
|
|
|
- pM.textSelector=config.document.getElementById(pM.textSelectorId);
|
|
|
+ pM.textStudy=config.document.getElementById(pM.textStudyId);
|
|
|
+
|
|
|
+ pM.print(fName+' selector '+pM.inputSelector+' id '+pM.inputSelectorId);
|
|
|
+ //value is with local
|
|
|
pM.cellValue=config.document.getElementById(pM.cellValueId);
|
|
|
pM.inputValue=config.document.getElementById(pM.inputValueId);
|
|
|
- pM.textValue=config.document.getElementById(pM.textValueId);
|
|
|
+ pM.textLocal=config.document.getElementById(pM.textLocalId);
|
|
|
|
|
|
- pM.inputManage=config.document.getElementById(pM.inputManageId);
|
|
|
+ //pM.inputManageLocal=config.document.getElementById(pM.inputManageLocalId);
|
|
|
+ //pM.inputManageStudy=config.document.getElementById(pM.inputManageStudyId);
|
|
|
}
|
|
|
|
|
|
function generateEntryField(){
|
|
@@ -59,151 +61,254 @@ function generateEntryField(){
|
|
|
tb.className='t2';
|
|
|
let row=tb.insertRow();
|
|
|
|
|
|
- //header
|
|
|
+ //label for local ID
|
|
|
let cell=config.document.createElement('th');
|
|
|
row.appendChild(cell);
|
|
|
cell.setAttribute("colspan","1");
|
|
|
cell.style.fontSize="20px";
|
|
|
cell.style.textAlign="left";
|
|
|
//Use study coding for participant field
|
|
|
- cell.innerText=pM.participantField;
|
|
|
-
|
|
|
-
|
|
|
- //selector
|
|
|
- let cellSelector=row.insertCell();
|
|
|
- cellSelector.id=pM.cellSelectorId;
|
|
|
+ cell.innerText='Local ID';
|
|
|
+ //cell.innerText=pM.participantField;
|
|
|
|
|
|
|
|
|
//value
|
|
|
let cellValue=row.insertCell();
|
|
|
cellValue.id=pM.cellValueId;
|
|
|
|
|
|
- //manage
|
|
|
- let cellManage=row.insertCell();
|
|
|
- let inputManage=config.document.createElement("input");
|
|
|
- inputManage.type="button";
|
|
|
- //initially in set mode
|
|
|
- inputManage.onclick=function(){pM.manageParticipantId();};
|
|
|
- inputManage.id=pM.inputManageId;
|
|
|
- cellManage.appendChild(inputManage);
|
|
|
+ pM.cellManageLocal=row.insertCell();
|
|
|
+
|
|
|
+ //second row for study id
|
|
|
+ let rowStudy=tb.insertRow();
|
|
|
+
|
|
|
+ //label for study ID
|
|
|
+ let cellStudy=config.document.createElement('th');
|
|
|
+ rowStudy.appendChild(cellStudy);
|
|
|
+ cellStudy.setAttribute("colspan","1");
|
|
|
+ cellStudy.style.fontSize="20px";
|
|
|
+ cellStudy.style.textAlign="left";
|
|
|
+ //Use study coding for participant field
|
|
|
+ cellStudy.innerText='Study ID';
|
|
|
|
|
|
+ //selector for study id
|
|
|
+ let cellSelector=rowStudy.insertCell();
|
|
|
+ cellSelector.id=pM.cellSelectorId;
|
|
|
+
|
|
|
+ //manage
|
|
|
+ pM.cellManageStudy=rowStudy.insertCell();
|
|
|
config.document.getElementById(formName).appendChild(tb);
|
|
|
|
|
|
}
|
|
|
|
|
|
-//callback
|
|
|
-function manageParticipantId(){
|
|
|
+//reslovers which operate depending on mode
|
|
|
+function getInputId(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getInputId]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return pM.inputValueId;
|
|
|
+ return pM.inputSelectorId;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function getInputCell(){
|
|
|
let pM=this;
|
|
|
- let fName='[manageParticipantId]';
|
|
|
+ let fName='[getInputCell]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return pM.cellValue;
|
|
|
+ return pM.cellSelector;
|
|
|
+}
|
|
|
+
|
|
|
+function getInputElement(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getInputElement]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return pM.inputValue;
|
|
|
+ return pM.inputSelector;
|
|
|
+}
|
|
|
+
|
|
|
+function getInputElementType(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getInputElementType]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return "input";
|
|
|
+ return "select";
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function getTextFieldId(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getTextFieldId]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return pM.textLocalId;
|
|
|
+ return pM.textStudyId;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function getTextElement(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getTextElement]';
|
|
|
+ pM.print(fName);
|
|
|
+ if (pM.mode=="LOCAL") return pM.textLocal;
|
|
|
+ return pM.textStudy;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//get the button, create if not there yet
|
|
|
+function getInputManage(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[getInputManage]';
|
|
|
+ //pM.print(fName);
|
|
|
+ let config=pM.config;
|
|
|
+ //this prevents from having two inputs; it is either local or global from the outset
|
|
|
+ if ("inputManage" in pM) return pM.inputManage;
|
|
|
+
|
|
|
+ pM.inputManage=config.document.createElement("input");
|
|
|
+ let inputManage=pM.inputManage;
|
|
|
+ inputManage.type="button";
|
|
|
+ inputManage.onclick=function(){pM.manageId();};
|
|
|
+ //inputManageLocal.id=pM.inputManageLocalId;
|
|
|
+ let cell=pM.cellManageStudy;
|
|
|
+ if (pM.mode=="LOCAL") cell=pM.cellManageLocal;
|
|
|
+ //pM.print(fName+' inputManage '+pM.inputManage+' cell '+cell+' mode '+pM.mode);
|
|
|
+ cell.appendChild(inputManage);
|
|
|
+ return inputManage;
|
|
|
+}
|
|
|
+
|
|
|
+//callback that splits to edit or set/label mode
|
|
|
+function manageId(){
|
|
|
+ let pM=this;
|
|
|
+ let fName='[manageId]';
|
|
|
pM.print(fName);
|
|
|
//this can happen after object was created, so make sure current
|
|
|
//elements are used
|
|
|
pM.updateElements();
|
|
|
- if (pM.inputManage.value=="Set"){
|
|
|
- pM.setParticipantId();
|
|
|
+ let x=pM.getInputManage();
|
|
|
+
|
|
|
+ if (x.value=="Set"){
|
|
|
+ pM.setId();
|
|
|
return;
|
|
|
}
|
|
|
- if (pM.inputManage.value=="Edit"){
|
|
|
- pM.editParticipantId();
|
|
|
+ if (x.value=="Edit"){
|
|
|
+ pM.editId();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//set mode
|
|
|
-function setParticipantId(){
|
|
|
+function setId(){
|
|
|
let pM=this;
|
|
|
- let fName='[setParticipantId]';
|
|
|
+ let fName='[setId]';
|
|
|
pM.print(fName);
|
|
|
- //update to current elements
|
|
|
- pM.print(fName+" select value: "+pM.inputSelector.value+" value: "+pM.inputValue.value);
|
|
|
- if (pM.inputSelector.value<0) return;
|
|
|
- let pId=pM.inputValue.value;
|
|
|
- let opt=pM.inputSelector.options[pM.inputSelector.selectedIndex];
|
|
|
- if (pM.inputSelector.value>0)
|
|
|
- pId=opt.text;
|
|
|
+ let el=pM.getInputElement();
|
|
|
|
|
|
+ pM.print(fName+" value: "+el.value);
|
|
|
+ let pId=el.value;
|
|
|
+ if (pM.mode!="LOCAL"){
|
|
|
+ if (el.value<0) return;
|
|
|
+ let opt=el.options[el.selectedIndex];
|
|
|
+ pId=opt.text;
|
|
|
+ }
|
|
|
+ pM.setParticipantIdToCrfEntry(pId);//no argument (should come from mode)
|
|
|
+ pM.updateCrfEntry();
|
|
|
pM.print(fName+" new value "+pId);
|
|
|
- pM.setParticipantManagerToLabelMode(pId,opt.text);
|
|
|
+ pM.setLabelMode(pId);//setLabel{Study,Local}Mode
|
|
|
}
|
|
|
|
|
|
-function setParticipantManagerToLabelMode(pId,optText){
|
|
|
+function setLabelMode(pId){
|
|
|
+ let fName='[setLabelMode1]';
|
|
|
let pM=this;
|
|
|
let config=pM.config;
|
|
|
- //set crfEntry and upload it to labkey
|
|
|
+
|
|
|
+ pM.print(fName+' config '+config);
|
|
|
+
|
|
|
let textValue=config.document.createElement("p");
|
|
|
+ pM.print(fName+' id1 ');
|
|
|
textValue.innerText=pId;
|
|
|
- textValue.id=pM.textValueId;
|
|
|
- if (pM.inputValue!=undefined)
|
|
|
- pM.cellValue.replaceChild(textValue,pM.inputValue);
|
|
|
- else
|
|
|
- pM.cellValue.appendChild(textValue);
|
|
|
-
|
|
|
+ let id=pM.getTextFieldId();
|
|
|
+ let el=pM.getInputElement();
|
|
|
+ let cell=pM.getInputCell();
|
|
|
|
|
|
- let textSelector=config.document.createElement("p");
|
|
|
- textSelector.innerText=optText;
|
|
|
- textSelector.id=pM.textSelectorId;
|
|
|
- if (pM.inputSelector!=undefined)
|
|
|
- pM.cellSelector.replaceChild(textSelector,pM.inputSelector);
|
|
|
+ pM.print(fName+' mode '+pM.mode+' id '+id+' cell '+cell+' el '+el);
|
|
|
+
|
|
|
+ textValue.id=id;//getTextId
|
|
|
+ if (el!=undefined)
|
|
|
+ cell.replaceChild(textValue,el);
|
|
|
else
|
|
|
- pM.cellSelector.appendChild(textSelector);
|
|
|
+ cell.appendChild(textValue);
|
|
|
|
|
|
- //addStaticData(participantField,participantField,pid);
|
|
|
-
|
|
|
- pM.inputManage.value="Edit";
|
|
|
+ let x=pM.getInputManage();//getInputManage
|
|
|
+ if ("readOnly" in pM)
|
|
|
+ x.style.display="none";
|
|
|
+ x.value="Edit";
|
|
|
}
|
|
|
|
|
|
-function editParticipantId(){
|
|
|
+//edit mode
|
|
|
+function editId(){
|
|
|
let pM=this;
|
|
|
- pM.setParticipantManagerToEditMode();
|
|
|
+ pM.setEditMode();
|
|
|
}
|
|
|
|
|
|
-function setParticipantManagerToEditMode(){
|
|
|
+function setEditMode(){
|
|
|
let pM=this;
|
|
|
let config=pM.config;
|
|
|
|
|
|
- let fName='[setParticipantManagerToEditMode]';
|
|
|
- pM.print(fName);
|
|
|
+ let fName='[setEditMode1]';
|
|
|
+ pM.print(fName+' pM '+pM+' mode '+pM.mode);
|
|
|
//input
|
|
|
- let inputValue=config.document.createElement("input");
|
|
|
- inputValue.id=pM.inputValueId;
|
|
|
- pM.print(fName+" value old "+pM.textValue+" new "+inputValue);
|
|
|
- if (pM.textValue!=undefined)
|
|
|
- pM.cellValue.replaceChild(inputValue,pM.textValue);
|
|
|
- else
|
|
|
- pM.cellValue.appendChild(inputValue);
|
|
|
-
|
|
|
- //select
|
|
|
- let inputSelector = config.document.createElement("select");
|
|
|
- inputSelector.id=pM.inputSelectorId;
|
|
|
- pM.inputSelector=inputSelector;
|
|
|
- pM.addSelectOptions();
|
|
|
- pM.print(fName+" select old "+pM.textSelector+" new "+inputSelector);
|
|
|
- if (pM.textSelector!=undefined)
|
|
|
- pM.cellSelector.replaceChild(inputSelector,pM.textSelector);
|
|
|
- else
|
|
|
- pM.cellSelector.appendChild(inputSelector);
|
|
|
+ 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;
|
|
|
+
|
|
|
|
|
|
- pM.inputManage.value="Set";
|
|
|
+ //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 x=pM.getInputManage();
|
|
|
+ x.value="Set";
|
|
|
|
|
|
}
|
|
|
|
|
|
+//manage interaction to storage/CRF and study/LabKey
|
|
|
function getParticipantField(config){
|
|
|
return config.formConfig['studyDataAll'].rows[0]['SubjectColumnName'];
|
|
|
}
|
|
|
|
|
|
-function getParticipantId(){
|
|
|
+function getCrfEntryFieldName(){
|
|
|
let pM=this;
|
|
|
- //let participantField=config.formConfig['studyDataAll'].rows[0]['SubjectColumnName'];
|
|
|
- return pM.textValue.innerText;
|
|
|
+ let variable="Study";
|
|
|
+ if (pM.mode=="LOCAL") variable="Local";
|
|
|
+ return 'participant'+variable+'Id';
|
|
|
}
|
|
|
|
|
|
+function setParticipantIdToCrfEntry(pId){
|
|
|
+ let pM=this;
|
|
|
+ let config=pM.config;
|
|
|
+ config.formConfig.crfEntry[pM.getCrfEntryFieldName()]=pId;
|
|
|
+}
|
|
|
|
|
|
+function getParticipantIdFromCrfEntry(){
|
|
|
+ let pM=this;
|
|
|
+ let config=pM.config;
|
|
|
+ return config.formConfig.crfEntry[pM.getCrfEntryFieldName()];
|
|
|
+}
|
|
|
|
|
|
//main interface. Use this to generate object and to refer to it later on
|
|
|
function getParticipantManagerObject(config){
|
|
|
|
|
|
let fName='[getParticipantManagerObject]';
|
|
|
-
|
|
|
+ config.print(fName);
|
|
|
if ("participantManager" in config) {
|
|
|
let pM=config.participantManager;
|
|
|
pM.updateElements();
|
|
@@ -223,24 +328,53 @@ function getParticipantManagerObject(config){
|
|
|
|
|
|
pM.cellSelectorId=pM.participantField+"_cellSelect";
|
|
|
pM.inputSelectorId=pM.participantField+"_Select";
|
|
|
- pM.textSelectorId=pM.participantField+"_textSelect";
|
|
|
+ pM.textStudyId=pM.participantField+"_textStudy";
|
|
|
|
|
|
pM.cellValueId=pM.participantField+"_cellValue";
|
|
|
pM.inputValueId=pM.participantField+"_Value";
|
|
|
- pM.textValueId=pM.participantField+"_textValue";
|
|
|
+ pM.textLocalId=pM.participantField+"_textLocal";
|
|
|
+
|
|
|
+ pM.inputManageLocalId=pM.participantField+"_ManageLocal";
|
|
|
+ pM.inputManageStudyId=pM.participantField+"_ManageStudy";
|
|
|
+
|
|
|
+ pM.mode="LOCAL";//or "STUDY"
|
|
|
|
|
|
- pM.inputManageId=pM.participantField+"_Manage";
|
|
|
//add methods
|
|
|
+
|
|
|
+ //global methods that are not subject to mode modifier
|
|
|
pM.updateElements=updateElements;
|
|
|
pM.addSelectOptions=addSelectOptions;
|
|
|
pM.generateEntryField=generateEntryField;
|
|
|
- pM.manageParticipantId=manageParticipantId;
|
|
|
- pM.setParticipantId=setParticipantId;
|
|
|
- pM.editParticipantId=editParticipantId;
|
|
|
- pM.setParticipantManagerToLabelMode=setParticipantManagerToLabelMode;
|
|
|
- pM.setParticipantManagerToEditMode=setParticipantManagerToEditMode;
|
|
|
- pM.getParticipantId=getParticipantId;
|
|
|
|
|
|
+ //getters subject to mode
|
|
|
+ pM.getInputId=getInputId;
|
|
|
+ pM.getInputCell=getInputCell;
|
|
|
+ pM.getInputElement=getInputElement;
|
|
|
+ pM.getInputElementType=getInputElementType;
|
|
|
+
|
|
|
+ pM.getTextFieldId=getTextFieldId;
|
|
|
+ pM.getTextElement=getTextElement;
|
|
|
+
|
|
|
+ pM.getInputManage=getInputManage;
|
|
|
+
|
|
|
+ //callback
|
|
|
+ pM.manageId=manageId;
|
|
|
+
|
|
|
+ //set/label mode
|
|
|
+ pM.setId=setId;
|
|
|
+ pM.setLabelMode=setLabelMode;
|
|
|
+
|
|
|
+ //edit mode
|
|
|
+ pM.editId=editId;
|
|
|
+ pM.setEditMode=setEditMode;
|
|
|
+
|
|
|
+ //interact with storage/CRF and study/LabKey
|
|
|
+ pM.setParticipantIdToCrfEntry=setParticipantIdToCrfEntry;
|
|
|
+ pM.getParticipantIdFromCrfEntry=getParticipantIdFromCrfEntry;
|
|
|
+ pM.getCrfEntryFieldName=getCrfEntryFieldName;
|
|
|
+
|
|
|
+
|
|
|
+ //init
|
|
|
pM.generateEntryField();
|
|
|
pM.updateElements();
|
|
|
return pM;
|