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

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