123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- var participantPortal={};
- participantPortal.print=function(msg){
- console.log(msg);
- }
- participantPortal.idField='participantStudyId';
- participantPortal.init=
- function(cb=null){
- let that=this;
- let action=function(){that.scriptsLoaded(cb);};
- LABKEY.Utils.requiresScript(["crfTecant/crfSetup.js","crfTecant/crfData.js","crfTecant/crfHTML.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);
- crfHTML.init();
- let action=function(){crfData.init(cb);};
- crfSetup.init(action);
- }
- participantPortal.getParticipantMap=
- function(){
- if (!("participantMap" in this)){
- this.participantMap=new Object();
- this.sortByParticipantId();
- }
- return this.participantMap;
- }
-
- 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.getParticipantLabel=
- function(entry){
- let pid=entry['participantStudyId'];
- let loc=entry['participantLocalId'];
- let label='';
- if (pid) label+=pid+' ';
- if (loc) label+='(Local: '+loc+')';
- if (label.length==0) label="NONE";
- return label;
-
- }
- 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=entry[this.idField];
- if (!id) id="NONE";
- let formId=entry['Form'];
- let pArray=this.getParticipantArray(id,formId);
- pArray.push(entry);
- this.print(fName+' pushing '+id+','+formId);
- }
- }
- 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 idMap=crfData.getRegistrationMap(this.idField);
- let updatedMap=new Object();
- for (q in idMap){
- if (!idMap[q]) continue;
- updatedMap[q]=idMap[q];
- }
- updatedMap[1000]='NONE';
- this.participantSelect=crfHTML.makeSelect(updatedMap,'formDiv');
- this.displayTable=crfHTML.createTable('formDiv');
- let that=this;
- this.participantSelect.onchange=function(){that.displayEntries();}
- }
- participantPortal.displayEntries=
- function(){
- let fName='[displayEntries]';
- this.print(fName);
- let formRows=crfSetup.getRows('dataForms');
-
- //let idRows=crfData.getRegistration();
- let selectId=this.participantSelect.options[this.participantSelect.selectedIndex].text;
- //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);
- this.displayForms(cell,forms);
- this.print(fName+' ['+selectId+'/'+formId+'] forms '+forms.length);
- }
- }
- participantPortal.displayForms=
- function(el,formList){
- //formList is a list of crfEntry entries
-
- let table=crfHTML.createTable(null,el);
- let row=table.insertRow();
- let n=formList.length;
- let fn=1;
- if (n>fn) fn=n;
- for (let i=0;i<fn;i++){
- let entry=formList[i];
- let cell=row.insertCell(i);
- crfHTML.addStyle(cell,'stretch');
- let fbox=crfHTML.createBox(null,cell);
- if (n==0){
- crfHTML.addStyle(fbox,'empty');
- break;
- }
- //colormap of formStatus to colors
- let stat=entry['FormStatus'];
- let style=crfSetup.getEntryMap('formStatus')[stat]['color'];
- if (!style) style='gold';
- crfHTML.addStyle(fbox,style);
- let user=crfSetup.getMap('users')[entry['UserId']];
- let idLabel=this.getParticipantLabel(entry);
- let formStatus=crfSetup.getMap('formStatus')[stat];
- let text=[entry['entryId'],user,idLabel,formStatus];
- for (let j=0;j<text.length;j++){
- crfHTML.createParagraph(text[j],null,fbox);
- }
- }
- return table;
-
- }
|