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

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