participantPortal.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. var participantPortal={};
  2. participantPortal.print=function(msg){
  3. console.log(msg);
  4. }
  5. participantPortal.idField='participantStudyId';
  6. participantPortal.init=
  7. function(cb=null){
  8. let that=this;
  9. let action=function(){that.scriptsLoaded(cb);};
  10. LABKEY.Utils.requiresScript(["crfTecant/crfSetup.js","crfTecant/crfData.js","crfTecant/crfHTML.js"],action);
  11. }
  12. participantPortal.scriptsLoaded=
  13. function(cb=null){
  14. //if other script need init, just stack the init scripts
  15. //let action=function(){runQuery.init(cb);}
  16. crfData.setSetup(crfSetup);
  17. crfHTML.init();
  18. let action=function(){crfData.init(cb);};
  19. crfSetup.init(action);
  20. }
  21. participantPortal.getParticipantMap=
  22. function(){
  23. if (!("participantMap" in this)){
  24. this.participantMap=new Object();
  25. this.sortByParticipantId();
  26. }
  27. return this.participantMap;
  28. }
  29. participantPortal.getParticipantArray=
  30. function(id,formId){
  31. let fName='[getParticipantArray/'+id+','+formId+']';
  32. //this.print(fName);
  33. let pMap=this.getParticipantMap();
  34. if (!(id in pMap))
  35. pMap[id]=new Object();
  36. if (!(formId in pMap[id]))
  37. pMap[id][formId]=new Array();
  38. return pMap[id][formId];
  39. }
  40. participantPortal.getParticipantLabel=
  41. function(entry){
  42. let pid=entry['participantStudyId'];
  43. let loc=entry['participantLocalId'];
  44. let label='';
  45. if (pid) label+=pid+' ';
  46. if (loc) label+='(Local: '+loc+')';
  47. if (label.length==0) label="NONE";
  48. return label;
  49. }
  50. participantPortal.generateFormArray=
  51. function(){
  52. let fName='[generateFormArray]';
  53. this.print(fName);
  54. //gang callbacks (last to first)
  55. let that=this;
  56. let makePortal=function(){that.makePortal();};
  57. let setRegistration=function(){crfData.setRegistration(makePortal);};
  58. let action=function(){crfSetup.parseSetup(setRegistration);}
  59. crfSetup.setContainers(action);
  60. }
  61. participantPortal.sortByParticipantId=
  62. function(){
  63. let fName='[sortByParticipantId]';
  64. //this.print(fName);
  65. //let pMap=this.getParticipantMap();
  66. let rows=crfSetup.getRows('crfEntries');
  67. for (let i=0;i<rows.length;i++){
  68. let entry=rows[i];
  69. let id=entry[this.idField];
  70. if (!id) id="NONE";
  71. let formId=entry['Form'];
  72. let pArray=this.getParticipantArray(id,formId);
  73. pArray.push(entry);
  74. this.print(fName+' pushing '+id+','+formId);
  75. }
  76. }
  77. participantPortal.printParticipantArray=
  78. function(){
  79. let fName='[printParticipantMap]';
  80. this.print(fName);
  81. let pMap=this.getParticipantMap();
  82. for (let q in pMap){
  83. for (let x in pMap[q])
  84. this.print(fName+' ['+q+','+x+'] '+pMap[q][x].length);
  85. }
  86. }
  87. participantPortal.makePortal=
  88. function(){
  89. let idMap=crfData.getRegistrationMap(this.idField);
  90. let updatedMap=new Object();
  91. for (q in idMap){
  92. if (!idMap[q]) continue;
  93. updatedMap[q]=idMap[q];
  94. }
  95. updatedMap[1000]='NONE';
  96. this.participantSelect=crfHTML.makeSelect(updatedMap,'formDiv');
  97. this.displayTable=crfHTML.createTable('formDiv');
  98. let that=this;
  99. this.participantSelect.onchange=function(){that.displayEntries();}
  100. }
  101. participantPortal.displayEntries=
  102. function(){
  103. let fName='[displayEntries]';
  104. this.print(fName);
  105. let formRows=crfSetup.getRows('dataForms');
  106. //let idRows=crfData.getRegistration();
  107. let selectId=this.participantSelect.options[this.participantSelect.selectedIndex].text;
  108. //let formId=formIds[Object.keys(formIds)[0]];
  109. //this.printParticipantArray();
  110. this.print(fName+' rows '+this.displayTable.rows.length);
  111. for (let i=0;i<formRows.length;i++){
  112. let formId=formRows[i]['Key'];
  113. let row=this.displayTable.rows[i];
  114. if (!row) row=this.displayTable.insertRow(i);
  115. let labelCell=row.cells[0];
  116. let formName=crfSetup.getMap('dataForms')[formId];
  117. if (!labelCell){
  118. labelCell=row.insertCell();
  119. labelCell.innerText=formName;
  120. crfHTML.addStyle(labelCell,'medium');
  121. crfHTML.addStyle(labelCell,'center');
  122. //crfHTML.createParagraph(formName,null,labelCell);
  123. }
  124. let cell=row.cells[1];
  125. if (!cell) {
  126. cell=row.insertCell();
  127. crfHTML.addStyle(cell,'stretch');
  128. }
  129. crfHTML.clear(cell);
  130. let forms=this.getParticipantArray(selectId,formId);
  131. this.displayForms(cell,forms);
  132. this.print(fName+' ['+selectId+'/'+formId+'] forms '+forms.length);
  133. }
  134. }
  135. participantPortal.displayForms=
  136. function(el,formList){
  137. //formList is a list of crfEntry entries
  138. let table=crfHTML.createTable(null,el);
  139. let row=table.insertRow();
  140. let n=formList.length;
  141. let fn=1;
  142. if (n>fn) fn=n;
  143. for (let i=0;i<fn;i++){
  144. let entry=formList[i];
  145. let cell=row.insertCell(i);
  146. crfHTML.addStyle(cell,'stretch');
  147. let fbox=crfHTML.createBox(null,cell);
  148. if (n==0){
  149. crfHTML.addStyle(fbox,'empty');
  150. break;
  151. }
  152. //colormap of formStatus to colors
  153. let stat=entry['FormStatus'];
  154. let style=crfSetup.getEntryMap('formStatus')[stat]['color'];
  155. if (!style) style='gold';
  156. crfHTML.addStyle(fbox,style);
  157. let user=crfSetup.getMap('users')[entry['UserId']];
  158. let idLabel=this.getParticipantLabel(entry);
  159. let formStatus=crfSetup.getMap('formStatus')[stat];
  160. let text=[entry['entryId'],user,idLabel,formStatus];
  161. for (let j=0;j<text.length;j++){
  162. crfHTML.createParagraph(text[j],null,fbox);
  163. }
  164. }
  165. return table;
  166. }