123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- //all functions are based off of participantManager (print, config, etc.)
- var participantIdManager={};
- participantIdManager.print=
- function(msg){
- console.log(msg);
- }
- participantIdManager.init=
- function(cb=null){
- let that=this;
- let action=function(){that.afterScripts(cb);};
- LABKEY.requiresScript(['crf/crfHTML.js','crf/generateRegistration.js'],action);
- }
- participantIdManager.afterScripts=
- function(cb=null){
- crfHTML.init();
- generateRegistration.init(cb);
- }
- participantIdManager.set=
- function(setup,data){
- this.setup=setup;
- this.data=data;
- this.updateCrfEntry=function(){;}
- this.mode='STUDY';
- //this.generateTable();
- if (!("readonly" in this)){
- this.readonly=new Object();
- this.readonly['LOCAL']=false;
- this.readonly['STUDY']=false;
- }
- }
- participantIdManager.setMode=
- function(mode){
- this.mode=mode;
- }
- participantIdManager.getMode=
- function(){
- return this.mode;
- }
- participantIdManager.setReadonly=
- function(mode){
- if (mode=="LOCAL"){
- this.readonly[mode]=true;
- return;
- }
- this.readonly['STUDY']=true;
- }
- participantIdManager.clearReadonly=
- function(mode){
- if (mode=='LOCAL'){
- this.readonly[mode]=false;
- return;
- }
- this.readonly['STUDY']=false;
- }
- participantIdManager.isReadonly=
- function(mode){
- if (mode=='LOCAL') return this.readonly['LOCAL'];
- return this.readonly['STUDY'];
- }
- participantIdManager.addSelectOptions=
- function(mode=null){
- if (mode=="LOCAL") return;
-
- let input=this.getInputElement(mode);
- let fName='addParticipantSelectOptions';
- this.print(fName+' input '+input);
- //here the lookup is being populated (registrationData)
- let demoRows=this.setup.getRows('registrationData');
- this.print(fName+" demoRows: "+demoRows.length);
- let opts=new Object();
- for (let i=0;i<demoRows.length;i++){
- opt2[i+1]=this.setup.getParticipantLabel(demoRows[i]);
- }
- crfHTML.addSelectOptions(input,opts);
- }
- participantIdManager.insertRow
- =function(label){
- let row=this.table.insertRow();
-
- //label for local ID
- let cell=crfHTML.createTblHeader(null,row);
- cell.setAttribute("colspan","1");
- cell.style.fontSize="20px";
- cell.style.textAlign="left";
- cell.innerText=label;
- //value
- row.insertCell();
- //button
- row.insertCell();
-
- }
-
- participantIdManager.generateTable=
- function(){
- let fName='[generateParticipantEntryField]:';
- this.print(fName);
- //this is HTML designator of area on page
- let formName=this.masterForm;
- this.print(fName+' master '+formName);
-
- this.table=crfHTML.createTable(formName);
- this.table.className='t2';
- this.insertRow('Local ID');
- this.insertRow('Study ID');
- this.insertRow('ID generator');
- this.insertRow('Reset local ID');
- this.getInputButton('LOCAL');
- this.getInputButton('STUDY');
- let sMap=this.setup.getEntryMap('siteData:siteNumber');
- let sMapEntry=sMap[this.siteNumber];
- let qPar=new Object();
- qPar['queryName']='participantRegistration'+this.siteNumber;
- qPar['codeBase']=sMapEntry['codeBase'];
- qPar['schemaName']='lists';
- qPar['codeField']='registrationCode';
- let genObj=generateRegistration.getObject(qPar,'participantIdManager_localInput');
- let that=this;
- genObj.callback=function(){that.setId('LOCAL');};
- //attach execute to a button
- let cellButton=this.table.rows[2].cells[2];
- cellButton.style.alignItems='center';
- this.generateButton=crfHTML.createButton(null,cellButton);
- this.generateButton.id="participantIdManager_generateIdButton";
- this.generateButton.onclick=function(){generateRegistration.execute(genObj);};
- this.generateButton.value="Generate Local ID";
-
- let cellReset=this.table.rows[3].cells[2];
- this.resetButton=crfHTML.createButton(null,cellReset);
- this.resetButton.id='participantIdManager_resetButton';
- this.resetButton.onclick=function(){that.resetLocal();}
- this.resetButton.value='Reset Local ID';
- this.print(fName+' done');
- }
- participantIdManager.getRow=
- function(mode=null){
- let row=this.table.rows[1];
- if (mode=="LOCAL")
- row=this.table.rows[0];
- return row;
- }
- participantIdManager.getValueCell=
- function(mode="NONE"){
- return this.getRow(mode).cells[1];
- }
- participantIdManager.getButtonCell=
- function(mode="NONE"){
- return this.getRow(mode).cells[2];
- }
- participantIdManager.getValueElement=
- function(mode=null){
- return this.getValueCell(mode).firstChild;
- }
- participantIdManager.getInputElement=
- function(mode=null){
- let fName='[getInputElement]';
- this.print(fName);
- let el=this.getValueElement(mode);
- if (el) return el;
- return this.createInputElement(mode);
- }
- participantIdManager.createInputElement=
- function(mode=null){
- let elementType=this.getInputElementType(mode);
- let cell=this.getValueCell(mode);
-
- if (elementType=="input") {
- el=crfHTML.createTextInput();
- el.id='participantIdManager_localInput';
- }
- if (elementType=="select") el=crfHTML.createSelect(new Object());
- this.print(fName+' input '+el);
- cell.replaceChildren(el);
- this.addSelectOptions(mode);
-
- return el;
- }
- participantIdManager.getInputElementType=
- function(mode=null){
- let fName='[getInputElementType]';
- this.print(fName);
- if (mode=="LOCAL") return "input";
- return "select";
- }
- participantIdManager.getTextElement=
- function(mode=null){
- let fName='[getTextElement]';
- let el=this.getValueElement(mode);
- if (el) return el;
- return createTextElement(mode);
- }
- participantIdManager.createTextElement=
- function(mode=null){
- let el=crfHTML.createParagraph('');
- let cell=this.getValueCell(mode);
- //let oldEl=pM.getInputElement(mode);
- cell.replaceChildren(el);
- return el;
- }
- //get the button, create if not there yet
- participantIdManager.getInputButton=
- function(mode=null){
- let fName='[getInputManage]';
- //this.print(fName);
- //this prevents from having two inputs; it is either local or global from the outset
- let cell=this.getButtonCell(mode);
- let el=cell.firstChild;
- if (el) return el;
- el=crfHTML.createButton(null,cell);
- let that=this;
- el.onclick=function(){that.manageId(mode);};
- return el;
- }
- //callback that splits to edit or set/label mode
- participantIdManager.manageId=
- function(mode){
- let fName='[manageId]';
- this.print(fName);
- //this can happen after object was created, so make sure current
- //elements are used
- //this.updateElements();
- let x=this.getInputButton(mode);
- if (x.value=="Set"){
- this.setId(mode);
- return;
- }
- if (x.value=="Edit"){
- this.editId(mode);
- return;
- }
- }
- //set mode
- participantIdManager.setId=
- function(mode=null){
- let fName='[setId]';
- this.print(fName);
- let el=this.getInputElement(mode);
- this.print(fName+" value: "+el.value);
- let pId=el.value;
- let label=pId;
- if (mode!="LOCAL"){
- //extract from select
- if (el.value<0) return;
- let opt=el.options[el.selectedIndex];
- label=opt.text;
- pId=crfSetup.getStudyId(label);
- //label=label.replace(/ \(Local: /,':');
- //label=label.replace(/\)/,'');
- }
- this.setParticipantIdToCrfEntry(mode,pId);//no argument (should come from mode)
- this.print(fName+" new value "+pId);
- this.setLabelMode(mode,label);
- this.updateCrfEntry();
- }
- participantIdManager.setLabelMode=
- function(mode,label){
- let fName='[setLabelMode1]';
- this.print(fName+' id '+label);
- //this will give two for study and one entry for local
- //let ids=pId.split(':');
- let id=label;
- if (mode!='LOCAL'){
- if (label=='NOT SET')
- id=label;
- else
- id=crfSetup.getStudyId(label);
- }
-
- let textValue=this.createTextElement(mode);
- this.print(fName+' textElement '+textValue);
- textValue.innerText=id;
- if (mode!="LOCAL" && label!='NOT SET'){
- let loc=crfSetup.getLocalId(label);
- this.print(fName+' setting local id '+loc);
- if (this.isValid(loc)){
- //pM.getParticipantIdFromCrfEntry('LOCAL');
- let tValLocal=this.createTextElement('LOCAL');
- tValLocal.innerText=loc;
- }
- //this.setParticipantIdToCrfEntry(pM,loc,'LOCAL');
- }
- let x=this.getInputButton(mode);//getInputManage
- let readonly=this.isReadonly(mode);
- if (readonly){
- x.style.display="none";
- }
- x.value="Edit";
- if (mode=='LOCAL')
- this.generateButton.style.display='none';
-
- }
- //edit mode
- participantIdManager.editId=
- function(mode){
- this.setEditMode(mode);
- }
- participantIdManager.setEditMode=
- function(mode){
- let fName='[setEditMode1]';
- this.print(fName+' pM '+this+' mode '+mode);
- //input
- let el=this.createInputElement(mode);
- let x=this.getInputButton(mode);
- x.value="Set";
- if (mode=='LOCAL'){
- this.generateButton.style.display='block';
- x.style.display='block';
- }
- }
- participantIdManager.resetLocal=
- function(){
- this.clearReadonly('LOCAL');
- this.setEditMode('LOCAL');
- this.resetButton.style.display='none';
- }
- //manage interaction to storage/CRF and study/LabKey
- participantIdManager.getParticipantField=
- function(){
- return this.setup.getRows('studyData')[0]['SubjectColumnName'];
- }
- participantIdManager.getCrfEntryFieldName=
- function(mode=null){
- if (mode=="LOCAL") return crfSetup.getLocalIdLabel();
- return crfSetup.getStudyIdLabel();
- }
- participantIdManager.setParticipantIdToCrfEntry=
- function(mode,pId){
- let id=pId;
- this.data.getCrfEntry()[this.getCrfEntryFieldName(mode)]=id;
- }
- participantIdManager.getParticipantIdFromCrfEntry=
- function(mode=null){
- return this.data.getCrfEntry()[this.getCrfEntryFieldName(mode)];
- }
- participantIdManager.isValid=
- function(name){
- if (!name) return false;
- if (name=="null") return false;
- return true;
- }
- participantIdManager.verifyCrfStudyId=
- function(){
- let fName='[verifyCrfStatusId]';
- //is studyId already set for the crf
- let studyId=this.getParticipantIdFromCrfEntry('STUDY');
- let localId=this.getParticipantIdFromCrfEntry('LOCAL');
- this.print(fName+' studyId '+studyId+' localId '+localId);
- this.resetButton.style.display='none';
- if (!studyId) return;
- let originalMode=this.getMode();
- if (originalMode=='LOCAL' && this.setup.getSettings("allowLocalIdChange")) {
- this.resetButton.style.display='block';
- }
- else{
- this.setReadonly('LOCAL');
- }
- this.setReadonly('STUDY');
- this.setMode("STUDY");
- this.setLabelMode('STUDY',this.setup.getParticipantLabel(this.data.getCrfEntry()));
- //get registration map to fill local id
- let that=this;
- let completeVerification=function(){that.completeVerification(studyId);}
- this.data.setRegistration(completeVerification);
- }
-
- participantIdManager.completeVerification=
- function(studyId){
- let fName='[completeVerification]';
- //subject to content of localId
- let rMapEntry=this.data.getRegistrationEntryMap(this.getCrfEntryFieldName('STUDY'))[studyId];
- //try to set it from registration
- let localId=rMapEntry[this.getCrfEntryFieldName('LOCAL')];
- this.print(fName+' localId '+localId+' isNull '+(localId==null)+' is"null" '+(localId=="null"));
-
- let localIdFromEntry=this.getParticipantIdFromCrfEntry('LOCAL');
- if (localIdFromEntry!=localId){
- //update mismatches
- this.setParticipantIdToCrfEntry('LOCAL',localId);
- this.updateCrfEntry();
- }
- //ignore the one set in the crfEntry, studyId prevails
- //if (!this.isValid(localId)) {
- // let localId=this.getParticipantIdFromCrfEntry('LOCAL');
- //}
- if (this.isValid(localId)) {
- this.setReadonly('LOCAL');
- this.setLabelMode('LOCAL',localId);
- }
- else{
- this.setEditMode('LOCAL');
- }
-
- }
|