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

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