stat-tree-report-builder-spec.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. clause
  2. model
  3. label
  4. question
  5. answer
  6. clause_text
  7. position_index // for rendering, no logical consequence
  8. EXAMPLE:
  9. MODEL | QUESTION / LABEL | ANSWER | CLAUSE_TEXT
  10. Client Active? YES (is_active IS TRUE)
  11. Client Active? NO (is_active IS FALSE)
  12. Client MCP assigned? YES (mcp_pro_id IS NOT NULL)
  13. Client MCP assigned? NO (mcp_pro_id IS NULL)
  14. Client Future MCP appointment? YES ()
  15. Client Future MCP appointment? NO ()
  16. Client MCB Primary? YES ()
  17. Client MCB Primary? NO ()
  18. Client Has active RM device? YES ()
  19. Client Has active RM device? NO ()
  20. Client Active device type? Weight ()
  21. Client Active device type? BP ()
  22. Client Active device type? Weight ONLY ()
  23. Client Active device type? BP ONLY ()
  24. Client Active device type? Weight + BP ()
  25. Client Type 2 Diabetic - ()
  26. Pro Active? YES (is_active IS TRUE)
  27. Pro Active? NO (is_active IS FALSE)
  28. Pro Is HCP? YES (is_hcp IS TRUE)
  29. Pro Is HCP? NO (is_hcp IS NOT TRUE)
  30. WORK:::::::::::::::
  31. - FRONTEND: paste a tsv into a textarea and see it as a table.
  32. - BACKEND PHP: take in a tsv, foreach over and spit it back as a JSON.
  33. stat_tree
  34. name
  35. model
  36. slug
  37. max_line_length
  38. last_refreshed_at
  39. tsv_text_for_lines
  40. EXAMPLE tsv_text_for_lines:
  41. Active? YES
  42. MCP assigned? YES
  43. MCB Primary? NO
  44. Has active RM device? YES
  45. MCP assigned? NO
  46. MCB Primary? YES
  47. Active? NO
  48. MCB Primary? YES
  49. Has active RM device? YES
  50. Has active RM device? NO
  51. MCB Primary? NO
  52. Has active RM device? YES
  53. Has active RM device? NO
  54. Has active RM device? YES
  55. Has active RM device? NO
  56. Active? YES
  57. Is HCP? YES
  58. Is HCP? NO
  59. Active? NO
  60. Is HCP? YES
  61. Is HCP? NO
  62. stat_tree_line
  63. stat_tree_id
  64. tree_order_position_index
  65. last_refresh_count
  66. tsv_text_for_report_columns
  67. EXAMPLE tsv_text_for_report_columns:
  68. LABEL | DISPLAY_KEY | DISPLAY_FUNCTION | RECORD_ROUTE_NAME
  69. stat_tree_line_clause
  70. stat_tree_line_id
  71. clause_id
  72. clause_label
  73. position_index
  74. stat_tree_line_report_column
  75. stat_tree_line_id
  76. label
  77. position_index
  78. display_key // if super simple
  79. display_function // if custom on model
  80. record_route_name
  81. ------------------------------------------------------------------------------------------------
  82. api/clause/replaceAll
  83. tsvText
  84. LOGIC:
  85. delete all lines
  86. foreach line, create record
  87. api/statTree/create
  88. name
  89. table
  90. slug
  91. LOGIC:
  92. confirm no duplicate
  93. create statTree
  94. api/statTree/delete
  95. uid
  96. LOGIC:
  97. delete it
  98. api/statTree/updateBasic // can't change table
  99. uid
  100. name
  101. slug
  102. LOGIC:
  103. confirm no duplicate
  104. update
  105. api/statTree/refreshCount
  106. uid
  107. LOGIC:
  108. public function refreshCount($statTreeID){
  109. $statTree = StatTree::get($statTreeID);
  110. foreach($statTree->lines as $line){
  111. this->updateStatTreeLineCount($line);
  112. }
  113. $statTree->last_refreshed_at = now();
  114. }
  115. private function refreshCount($line){
  116. $table = $line->statTree->table;
  117. $query = "SELECT COUNT(*) FROM $table WHERE ";
  118. $allClauses = $line->statTreeLineClauses;
  119. for($i = 0; $i < count($allClauses); $i++){
  120. $query .= $allClauses[$i] . ($i == count($allClauses) - 1 ? '' : ' AND ');
  121. }
  122. $count = runRawSqlSafelyForCount($query);
  123. $line->last_refresh_count = $count;
  124. return count;
  125. }
  126. api/statTree/replaceAllLines
  127. uid
  128. tsvText
  129. LOGIC:
  130. EXAMPLE tsv_text_for_lines:
  131. Active patient? YES
  132. MCP assigned? YES
  133. MCB Primary? NO
  134. Has active RM device? YES
  135. MCP assigned? NO
  136. MCB Primary? YES
  137. Active patient? NO
  138. MCB Primary? YES
  139. Has active RM device? YES
  140. Has active RM device? NO
  141. MCB Primary? NO
  142. Has active RM device? YES
  143. Has active RM device? NO
  144. Has active RM device? YES
  145. Has active RM device? NO
  146. public function replaceAllLines($statTree, $tsvText){
  147. // fill in missing blanks down the rows
  148. // foreach fully filled row, create a stat_tree_line
  149. }
  150. api/statTreeLine/replaceAllReportColumns
  151. uid
  152. tsvText
  153. LOGIC:
  154. EXAMPLE tsv_text_for_report_columns:
  155. LABEL | DISPLAY_KEY | DISPLAY_FUNCTION | RECORD_ROUTE_NAME
  156. public function replaceAllReportColumns($statTreeLine, $tsvText){
  157. // fill in missing blanks down the rows
  158. }
  159. ------------------------------------------------------------------------------------------------
  160. /stat-tree/{{$statTree->slug}}
  161. Stat Tree: {{ $statTree->name }} | Last refreshed: {{ $statTree->last_refreshed_at }}
  162. <table>
  163. <tr>
  164. @for($i = 0; $statTree->max_line_length - 2; $i++)
  165. <th></th>
  166. @endfor
  167. <th>Count</th>
  168. </tr>
  169. @foreach($statTree->lines as $line) // ->lines returns by tree_order_position_index
  170. @for($i = 0; $statTree->max_line_length - 2; $i++)
  171. <td>
  172. {{ $i == $line->all_clauses_length - 1 ? $line->clause->label : '-' }}
  173. </td>
  174. @endfor
  175. <td>{{ $line->last_refresh_count }}</td>
  176. @endforeach
  177. </table>
  178. ------------------------------------------------------------------------------------------------
  179. /dynamic-stat-tree/{{statTree->slug}}?top-level-filters=(BASE64OFTHEM)
  180. Top level filters:
  181. -(WHERE mcp_pro_id=2)
  182. // render same thing as static stat-tree, but with this filter and dynamic count
  183. ------------------------------------------------------------------------------------------------
  184. /stat-tree-line/{{uid}}
  185. Stat Tree: {{ $statTree->name }}
  186. Table: {{ $line-> }}
  187. Line: {{ $line->all_clauses_text }}
  188. @foreach($columns as $column)
  189. <th></th>
  190. @foreach($records as $record)
  191. @foreach($columns as $column)
  192. <td>{{ $record->{{$column->display_function ? $column->display_function : $column->display_key }} }}</td>
  193. (PAGINATE)
  194. ------------------------------------------------------------------------------------------------
  195. /dynamic-stat-tree-line/{{uid}}?top-level-filters=(BASE64OFTHEM)
  196. Top level filters:
  197. -(WHERE mcp_pro_id=2)
  198. // render same thing as static stat-tree-line, but with this filter