PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/interface/super/rules/controllers/edit/controller.php

https://github.com/md-tech/openemr
PHP | 301 lines | 241 code | 48 blank | 12 comment | 27 complexity | a3d1b06835a313abe0e38fb75eaa5ad8 MD5 | raw file
  1. <?php
  2. // Copyright (C) 2010-2011 Aron Racho <aron@mi-squred.com>
  3. //
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // as published by the Free Software Foundation; either version 2
  7. // of the License, or (at your option) any later version.
  8. class Controller_edit extends BaseController {
  9. function _action_summary() {
  10. $ruleId = _get('id');
  11. $rule = $this->getRuleManager()->getRule( $ruleId );
  12. if (is_null($rule)) {
  13. $rule = $this->getRuleManager()->newRule();
  14. }
  15. $this->viewBean->rule = $rule;
  16. $this->set_view( "summary.php" );
  17. }
  18. function _action_submit_summary() {
  19. $ruleId = _post('id');
  20. $types = _post('fld_ruleTypes');
  21. $title = _post('fld_title');
  22. if ( is_null($rule_id)) {
  23. // its a new rule submit
  24. $ruleId = $this->getRuleManager()->updateSummary( $ruleId, $types, $title );
  25. // redirect to the intervals page
  26. $this->redirect("index.php?action=edit!intervals&id=$ruleId");
  27. } else {
  28. $this->redirect("index.php?action=detail!view&id=$ruleId");
  29. }
  30. }
  31. function _action_intervals() {
  32. $ruleId = _get('id');
  33. $rule = $this->getRuleManager()->getRule( $ruleId );
  34. $this->viewBean->rule = $rule;
  35. $this->set_view( "intervals.php" );
  36. }
  37. function _action_submit_intervals() {
  38. // parse results from response
  39. $ruleId = _post('id');
  40. $rule = $this->getRuleManager()->getRule($ruleId );
  41. // new intervals object
  42. $intervals = new ReminderIntervals();
  43. $change = false;
  44. foreach( ReminderIntervalType::values() as $type ) {
  45. foreach( ReminderIntervalRange::values() as $range ) {
  46. $amtKey = $type->code . "-" . $range->code;
  47. $timeKey = $amtKey . "-timeunit";
  48. $amt = _post($amtKey);
  49. $timeUnit = TimeUnit::from( _post($timeKey) );
  50. if ( $amt && $timeUnit ) {
  51. $detail = new ReminderIntervalDetail($type, $range, $amt, $timeUnit );
  52. $intervals->addDetail($detail);
  53. $change = true;
  54. }
  55. }
  56. }
  57. if ( $change ) {
  58. $this->getRuleManager()->updateIntervals( $rule, $intervals );
  59. }
  60. $this->redirect("index.php?action=detail!view&id=$ruleId");
  61. }
  62. function _action_filter() {
  63. $ruleId = _get('id');
  64. $rule = $this->getRuleManager()->getRule( $ruleId );
  65. $guid = _get('guid');
  66. $criteria = $this->getRuleManager()->getRuleFilterCriteria( $rule, $guid );
  67. $this->viewBean->type = "filter";
  68. $this->viewBean->rule = $rule;
  69. $this->viewBean->criteria = $criteria;
  70. $this->addHelper("common.php");
  71. $this->set_view( $criteria->getView(), "criteria.php" );
  72. }
  73. function _action_delete_filter() {
  74. $ruleId = _get('id');
  75. $rule = $this->getRuleManager()->getRule( $ruleId );
  76. $guid = _get('guid');
  77. $this->getRuleManager()->deleteRuleFilter( $rule, $guid );
  78. $this->redirect("index.php?action=detail!view&id=$ruleId");
  79. }
  80. function _action_target() {
  81. $ruleId = _get('id');
  82. $rule = $this->getRuleManager()->getRule( $ruleId );
  83. $guid = _get('guid');
  84. $criteria = $this->getRuleManager()->getRuleTargetCriteria($rule, $guid);
  85. $this->viewBean->type = "target";
  86. $this->viewBean->rule = $rule;
  87. $this->viewBean->criteria = $criteria;
  88. $this->addHelper("common.php");
  89. $this->set_view( $criteria->getView(), "criteria.php" );
  90. }
  91. function _action_delete_target() {
  92. $ruleId = _get('id');
  93. $rule = $this->getRuleManager()->getRule( $ruleId );
  94. $guid = _get('guid');
  95. $this->getRuleManager()->deleteRuleTarget( $rule, $guid );
  96. $this->redirect("index.php?action=detail!view&id=$ruleId");
  97. }
  98. function _action_codes() {
  99. $search = _get('q');
  100. $codes = $this->getCodeManager()->search( $search );
  101. foreach( $codes as $code ) {
  102. echo $code->display() . "|". $code->id . "\n";
  103. }
  104. }
  105. function _action_categories() {
  106. $stmts = sqlStatement( "SELECT option_id, title FROM list_options WHERE list_id='rule_action_category'" );
  107. for($iter=0; $row=sqlFetchArray($stmts); $iter++) {
  108. $columns[] = array( "code" => $row['option_id'], "lbl" => $row['title'] );
  109. }
  110. $this->emit_json($columns);
  111. }
  112. function _action_items() {
  113. $stmts = sqlStatement( "SELECT option_id, title FROM list_options WHERE list_id='rule_action'" );
  114. for($iter=0; $row=sqlFetchArray($stmts); $iter++) {
  115. $columns[] = array( "code" => $row['option_id'], "lbl" => $row['title'] );
  116. }
  117. $this->emit_json($columns);
  118. }
  119. function _action_columns() {
  120. $columns = array();
  121. $table = _get('table');
  122. $stmts = sqlStatement( "SHOW COLUMNS FROM " . $table );
  123. for($iter=0; $row=sqlFetchArray($stmts); $iter++) {
  124. $columns[] = $row['Field'];
  125. }
  126. $this->emit_json($columns);
  127. }
  128. function _action_submit_criteria() {
  129. // parse results from response
  130. $ruleId = _post('id');
  131. $groupId = _post('group_id');
  132. $rule = $this->getRuleManager()->getRule($ruleId );
  133. $guid = _post('guid');
  134. $type = _post('type');
  135. if ( $type == "filter" ) {
  136. $criteria = $this->getRuleManager()->getRuleFilterCriteria( $rule, $guid );
  137. } else {
  138. $criteria = $this->getRuleManager()->getRuleTargetCriteria( $rule, $guid );
  139. }
  140. if ( is_null($criteria) ) {
  141. $criteriaType = RuleCriteriaType::from(_post('criteriaTypeCode'));
  142. $criteria = $this->getRuleManager()->createFilterRuleCriteria($rule, $criteriaType);
  143. }
  144. if ( !is_null($criteria) ) {
  145. $dbView = $criteria->getDbView();
  146. $criteria->updateFromRequest();
  147. $dbView = $criteria->getDbView();
  148. if ( $type == "filter" ) {
  149. $this->ruleManager->updateFilterCriteria( $rule, $criteria );
  150. } else {
  151. $this->ruleManager->updateTargetCriteria( $rule, $criteria );
  152. }
  153. }
  154. $this->redirect("index.php?action=detail!view&id=$ruleId");
  155. }
  156. function _action_action() {
  157. $ruleId = _get('id');
  158. $rule = $this->getRuleManager()->getRule( $ruleId );
  159. $guid = _get('guid');
  160. $action = $this->getRuleManager()->getRuleAction( $rule, $guid );
  161. $this->viewBean->action = $action;
  162. $this->viewBean->rule = $rule;
  163. $this->addHelper("common.php");
  164. $this->set_view( "action.php" );
  165. }
  166. function _action_delete_action() {
  167. $ruleId = _get('id');
  168. $rule = $this->getRuleManager()->getRule( $ruleId );
  169. $guid = _get('guid');
  170. $action = $this->getRuleManager()->deleteRuleAction( $rule, $guid );
  171. $this->redirect("index.php?action=detail!view&id=$ruleId");
  172. }
  173. function _action_add_action() {
  174. $ruleId = _get('id');
  175. $groupId = _get('group_id');
  176. $rule = $this->getRuleManager()->getRule( $ruleId );
  177. $action = new RuleAction();
  178. $action->id = $ruleId;
  179. $action->groupId = $groupId;
  180. $this->viewBean->action = $action;
  181. $this->viewBean->rule = $rule;
  182. $this->addHelper("common.php");
  183. $this->set_view( "action.php" );
  184. }
  185. function _action_submit_action() {
  186. $ruleId = _post('id');
  187. $rule = $this->getRuleManager()->getRule( $ruleId );
  188. $groupId = _post('group_id');
  189. $guid = _post('guid');
  190. $category = _post("fld_category");
  191. $categoryLbl = _post("fld_category_lbl");
  192. $item = _post("fld_item");
  193. $itemLbl = _post("fld_item_lbl");
  194. $link = _post("fld_link");
  195. $message = _post("fld_message");
  196. $fld_target_guid = _post("fld_target");
  197. $customOption = _post("fld_custom_input") == "yes" ? 1 : 0;
  198. $action = $this->getRuleManager()->getRuleAction($rule, $guid);
  199. if ( is_null( $action ) ) {
  200. $action = new RuleAction();
  201. $action->id = $ruleId;
  202. }
  203. // update from post
  204. $action->category = $category;
  205. $action->categoryLbl = $categoryLbl;
  206. $action->item = $item;
  207. $action->itemLbl = $itemLbl;
  208. $action->groupId = $groupId;
  209. $action->customRulesInput = $customOption;
  210. $action->reminderLink = $link;
  211. $action->reminderMessage = $message;
  212. $action->targetCriteria = $fld_target_criteria;
  213. $this->getRuleManager()->updateRuleAction( $action );
  214. $this->redirect("index.php?action=detail!view&id=$ruleId");
  215. }
  216. function _action_add_criteria() {
  217. $type = _get("criteriaType");
  218. $id = _get("id");
  219. $groupId = _get("group_id");
  220. if ( $type == "filter" ) {
  221. $allowed = $this->getRuleManager()->getAllowedFilterCriteriaTypes();
  222. }
  223. if ( $type == "target" ) {
  224. $allowed = $this->getRuleManager()->getAllowedTargetCriteriaTypes();
  225. }
  226. $this->viewBean->allowed = $allowed;
  227. $this->viewBean->id = $id;
  228. $this->viewBean->groupId = $groupId;
  229. $this->viewBean->type = $type;
  230. $this->addHelper("common.php");
  231. $this->set_view( "add_criteria.php" );
  232. }
  233. function _action_choose_criteria() {
  234. $type = _get("type");
  235. $id = _get("id");
  236. $groupId = _get("group_id");
  237. $criteriaType = RuleCriteriaType::from(_get("criteriaType"));
  238. $rule = $this->getRuleManager()->getRule($id);
  239. if ( $type == "filter") {
  240. $criteria = $this->getRuleManager()->createFilterRuleCriteria( $rule, $criteriaType );
  241. }
  242. if ( $type == "target") {
  243. $criteria = $this->getRuleManager()->createTargetRuleCriteria( $rule, $criteriaType );
  244. }
  245. $criteria->groupId = $groupId;
  246. $this->viewBean->type = $type;
  247. $this->viewBean->rule = $rule;
  248. $this->viewBean->criteria = $criteria;
  249. $this->addHelper("common.php");
  250. $this->set_view( $criteria->getView(), "criteria.php" );
  251. }
  252. }
  253. ?>