participantOverview.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. var participantOverview={};
  2. participantOverview.init=
  3. function(cb=null){
  4. let that=this;
  5. let action=function(){that.scriptsLoaded(cb);};
  6. LABKEY.Utils.requiresScript(["crfDORA/crfSetup.js","crfDORA/crfData.js","crfDORA/crfHTML.js"],action);
  7. }
  8. participantOverview.scriptsLoaded=
  9. function(cb=null){
  10. //if other script need init, just stack the init scripts
  11. //let action=function(){runQuery.init(cb);}
  12. crfData.setSetup(crfSetup);
  13. crfHTML.init();
  14. let initData=function(){crfData.init(cb);};
  15. crfSetup.init(initData);
  16. }
  17. participantOverview.print=
  18. function(msg){
  19. console.log(msg);
  20. }
  21. participantOverview.addObjectToIdFormMap=
  22. function(object,map,id,form){
  23. if (!(id in map))
  24. map[id]=new Object();
  25. let fMap=map[id];
  26. if (!(form in fMap))
  27. fMap[form]=new Array();
  28. fMap[form].push(object);
  29. }
  30. participantOverview.generateParticipantArray=
  31. function(){
  32. let fName='generateParticipantArray';
  33. this.print(fName);
  34. let that=this;
  35. let makeArray=function(){that.makeArray();};
  36. let setRegistration=function(){crfData.setRegistration(makeArray);};
  37. let action=function(){crfSetup.parseSetup(setRegistration);}
  38. crfSetup.setContainers(action);
  39. }
  40. participantOverview.matchRegistration=
  41. function(entry){
  42. let fName='matchRegistration';
  43. let sF='participantStudyId';
  44. let studyRegMap=crfData.getRegistrationEntryMap(sF);//should be unique for registration
  45. let nS=Object.keys(studyRegMap).length;
  46. //this.print(fName+' study registration entries '+nS);
  47. let lF='participantLocalId';
  48. let localRegMap=crfData.getRegistrationEntryMap(lF);//should be unique for registration
  49. let nL=Object.keys(localRegMap).length;
  50. //this.print(fName+' local registration entries '+nL);
  51. if (entry[sF]){
  52. if (entry[sF] in studyRegMap){
  53. return studyRegMap[entry[sF]];
  54. }
  55. //failed to match study id
  56. }
  57. if (entry[lF]){
  58. if (entry[lF] in localRegMap){
  59. return localRegMap[entry[lF]];
  60. }
  61. //failed to match local id
  62. }
  63. return null;
  64. }
  65. participantOverview.makeArray=
  66. function(){
  67. let fName='makeArray';
  68. let entries=crfSetup.getEntryMap('crfEntries');
  69. let n=Object.keys(entries).length;
  70. this.print(fName+' entries '+n);
  71. let idField='participantStudyId';
  72. let entryMap=new Object();
  73. let statusMap=crfSetup.getEntryMap('formStatusAll');
  74. let i=0;
  75. let site=-1;
  76. if (this.searchParams.has("site")){
  77. site=this.searchParams.get("site");
  78. }
  79. for (let key in entries){
  80. let entry=entries[key];
  81. let formStatus=statusMap[entry['FormStatus']]['formStatus'];
  82. if (formStatus=='Deleted'){
  83. continue;
  84. }
  85. if (site!=-1 && entry['Site']!=site)
  86. continue;
  87. let regEntry=this.matchRegistration(entry);
  88. if (!regEntry){
  89. //skip mismatched crfEntry
  90. this.print(fName+' ['+entry['Key']+'] no match found ');
  91. i++;
  92. continue;
  93. }
  94. //link crfEntry to registration row
  95. let idLabel=crfSetup.getParticipantLabel(regEntry);
  96. let form=entry['Form'];
  97. this.addObjectToIdFormMap(entry,entryMap,idLabel,form);
  98. }
  99. this.print('Found '+(n-i)+'/'+n+' participants');
  100. this.showArray(entryMap);
  101. //for (let idLabel in entryMap){
  102. }
  103. participantOverview.showArray=
  104. function(entryMap){
  105. let table=crfHTML.createTable('formDiv');
  106. crfHTML.addStyle(table,"tOverview");
  107. let formRows=crfSetup.getRows('dataForms');
  108. let row=table.insertRow();
  109. let cell=row.insertCell();
  110. let stMap=crfSetup.getEntryMap('formStatusAll');
  111. let that=this;
  112. for (let i=0;i<formRows.length;i++){
  113. let formName=formRows[i]['formName'];
  114. cell=row.insertCell();
  115. let tNode=crfHTML.createTextNode(formName,null,cell);
  116. crfHTML.addStyle(cell,'small');
  117. }
  118. for (let idLabel in entryMap){
  119. row=table.insertRow();
  120. let cell=crfHTML.createTblHeader(null,row);
  121. crfHTML.createTextNode(idLabel,null,cell);
  122. cell.onclick=function(){that.openParticipant(idLabel);};
  123. for (let i=0;i<formRows.length;i++){
  124. let form=formRows[i]['Key'];
  125. let count=new Object();
  126. if (form in entryMap[idLabel]){
  127. let ar=entryMap[idLabel][form];
  128. for (let i=0;i<ar.length;i++){
  129. let entry=ar[i];
  130. let st=entry['FormStatus'];
  131. if (!(st in count)) count[st]=0;
  132. count[st]+=1;
  133. }
  134. }
  135. let label="";
  136. for (let s in count)
  137. label+=stMap[s]['formStatus']+':'+count[s]+" ";
  138. cell=row.insertCell();
  139. crfHTML.createTextNode(label,null,cell);
  140. crfHTML.addStyle(cell,'small');
  141. }
  142. }
  143. }
  144. participantOverview.openParticipant=
  145. function(idLabel){
  146. let formUrl="participantPortal";
  147. let params=new Object();
  148. params.name=formUrl;
  149. params['participantLabel']=idLabel;
  150. //params.pageId="CRF";
  151. //points to crf container
  152. let containerPath=crfSetup.getContainer('CRF');
  153. // This changes the page after building the URL.
  154. //Note that the wiki page destination name is set in params.
  155. //let homeURL = LABKEY.ActionURL.buildURL("project", formUrl , containerPath, params);
  156. let homeURL = LABKEY.ActionURL.buildURL("crf_dora", formUrl , containerPath, params);
  157. this.print("Redirecting to "+homeURL);
  158. window.location = homeURL;
  159. }