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

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