123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- var participantPortal={};
- participantPortal.print=function(msg){
- console.log(msg);
- }
- participantPortal.idField='participantStudyId';
- participantPortal.localIdField='participantLocalId';
- participantPortal.init=
- function(cb=null){
- let that=this;
- let action=function(){that.scriptsLoaded(cb);};
- LABKEY.Utils.requiresScript(["crfDORA/crfSetup.js","crfDORA/crfData.js","crfDORA/crfHTML.js","crfDORA/crfRoleSelector.js","crfDORA/formPortalNew.js"],action);
- }
- participantPortal.scriptsLoaded=
- function(cb=null){
- //if other script need init, just stack the init scripts
- //let action=function(){runQuery.init(cb);}
- crfData.setSetup(crfSetup);
- crfRoleSelector.set(crfSetup);
- crfHTML.init();
- let initFormPortal=function(){formPortal.init(cb);};
- let initData=function(){crfData.init(initFormPortal);};
- crfSetup.init(initData);
- }
- participantPortal.getParticipantMap=
- function(){
- if (!("participantMap" in this)){
- this.participantMap=new Object();
- this.sortByParticipantId();
- }
- 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){
- let fName='[getParticipantArray/'+id+','+formId+']';
- //this.print(fName);
- let pMap=this.getParticipantMap();
- if (!(id in pMap))
- pMap[id]=new Object();
- if (!(formId in pMap[id]))
- pMap[id][formId]=new Array();
- return pMap[id][formId];
- }
- participantPortal.generateFormArray=
- function(){
- let fName='[generateFormArray]';
- this.print(fName);
- //gang callbacks (last to first)
- let that=this;
- let makePortal=function(){that.makePortal();};
- let setRegistration=function(){crfData.setRegistration(makePortal);};
- let action=function(){crfSetup.parseSetup(setRegistration);}
- crfSetup.setContainers(action);
- }
- participantPortal.sortByParticipantId=
- function(){
- let fName='[sortByParticipantId]';
- //this.print(fName);
- //let pMap=this.getParticipantMap();
- let rows=crfSetup.getRows('crfEntries');
- for (let i=0;i<rows.length;i++){
- let entry=rows[i];
- let id=crfSetup.getParticipantLabel(entry);
- if (!id) id="NONE";
- let formId=entry['Form'];
- let pArray=this.getParticipantArray(id,formId);
- pArray.push(entry);
- this.print(fName+' pushing '+id+','+formId);
- }
- this.printParticipantArray();
- }
- participantPortal.printParticipantArray=
- function(){
- let fName='[printParticipantMap]';
- this.print(fName);
- let pMap=this.getParticipantMap();
- for (let q in pMap){
- for (let x in pMap[q])
- this.print(fName+' ['+q+','+x+'] '+pMap[q][x].length);
- }
- }
- participantPortal.makePortal=
- 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);
- }
- }
- participantPortal.updateParticipants=
- function(){
- let fName='[participantPortal.updateParticipants]';
- let roleAndSite=crfRoleSelector.getRoleAndSite();
- //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);
- //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+' key '+key+' label '+label+' site '+site);
- this.addToKeyMap(key,label);
- 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=
- function(){
- let fName='[displayEntries]';
- let roleAndSite=crfRoleSelector.getRoleAndSite();
- this.print(fName);
- let formRows=crfSetup.getRows('dataForms');
-
- //let idRows=crfData.getRegistration();
- let selectIdText=this.participantSelect.options[this.participantSelect.selectedIndex].text;
- if (selectIdText=='Add new participant'){
- let formId=crfSetup.getSettings('registrationFormId');
- if (!formId){
- alert('registrationFormId not set in settings!');
- return;
- }
- let cb=function(_data,_crfEntry){formPortal.openForm(_crfEntry,roleAndSite);};
- formPortal.createForm(formId,roleAndSite,cb);
- return;
- }
- //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);
- for (let i=0;i<formRows.length;i++){
- let formId=formRows[i]['Key'];
- let row=this.displayTable.rows[i];
- if (!row) row=this.displayTable.insertRow(i);
- let labelCell=row.cells[0];
- let formName=crfSetup.getMap('dataForms')[formId];
- if (!labelCell){
- labelCell=row.insertCell();
- labelCell.innerText=formName;
- crfHTML.addStyle(labelCell,'medium');
- crfHTML.addStyle(labelCell,'center');
- //crfHTML.createParagraph(formName,null,labelCell);
- }
- let cell=row.cells[1];
- if (!cell) {
- cell=row.insertCell();
- crfHTML.addStyle(cell,'stretch');
- }
- crfHTML.clear(cell);
- let forms=this.getParticipantArray(selectId,formId);
- formPortal.displayForms(cell,forms,roleAndSite,formId,selectIdText,this.roleError);
- this.print(fName+' ['+selectId+'/'+formId+'] forms '+forms.length);
- }
- }
|