Highway to PSR2
[openemr.git] / interface / super / rules / library / RulesPlanMappingEventHandlers_ajax.php
blob6afba78856423dcaf06d2a20c0b2333cfa2f3b96
1 <?php
2 /**
3 * library/RulesPlanMappingEventHandlers.php database interaction for admin-gui rules plan mappings.
5 * Functions to allow safe database modifications
6 * during changes to rules-plan mapping in Admin UI.
8 * Copyright (C) 2014 Jan Jajalla <Jajalla23@gmail.com>
9 * Copyright (C) 2014 Roberto Vasquez <robertogagliotta@gmail.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Jan Jajalla <jajalla23@gmail.com>
24 * @author Roberto Vasquez <roberto.gagliotta@gmail.com>
25 * @link http://www.open-emr.org
28 require_once(dirname(__FILE__) . "/../../../globals.php");
29 require_once(dirname(__FILE__) . "/RulesPlanMappingEventHandlers.php");
31 $action = $_GET["action"];
32 switch ($action) {
33 case "getNonCQMPlans":
34 $plans = getNonCQMPlans();
36 echo json_encode($plans);
38 break;
40 case "getRulesOfPlan":
41 $rules = getRulesInPlan($_GET["plan_id"]);
43 $rules_list = array();
44 foreach ($rules as $key => $value) {
45 $rule_info = array('rule_id'=>$key, 'rule_title'=>$value);
46 array_push($rules_list, $rule_info);
49 echo json_encode($rules_list);
51 break;
53 case "getRulesNotInPlan":
54 $rules = getRulesNotInPlan($_GET["plan_id"]);
56 $rules_list = array();
57 foreach ($rules as $key => $value) {
58 $rule_info = array('rule_id'=>$key, 'rule_title'=>$value);
59 array_push($rules_list, $rule_info);
62 echo json_encode($rules_list);
64 break;
66 case "getRulesInAndNotInPlan":
67 $rules = getRulesInPlan($_GET["plan_id"]);
69 $rules_list = array();
70 foreach ($rules as $key => $value) {
71 $rule_info = array('rule_id'=>$key, 'rule_title'=>$value, 'selected'=>'true');
72 array_push($rules_list, $rule_info);
75 $rules = getRulesNotInPlan($_GET["plan_id"]);
76 foreach ($rules as $key => $value) {
77 $rule_info = array('rule_id'=>$key, 'rule_title'=>$value, 'selected'=>'false');
78 array_push($rules_list, $rule_info);
81 echo json_encode($rules_list);
83 break;
85 case "commitChanges":
86 $data = json_decode(file_get_contents('php://input'), true);
88 $plan_id = $data['plan_id'];
89 $added_rules = $data['added_rules'];
90 $removed_rules = $data['removed_rules'];
91 $plan_name = $data['plan_name'];
93 if ($plan_id == 'add_new_plan') {
94 try {
95 $plan_id = addNewPlan($plan_name, $added_rules);
96 } catch (Exception $e) {
97 $status_mssg = $e->getMessage();
98 $status_code = '001';
100 if ($e->getMessage() == "002") {
101 //Plan Name Taken
102 $status_code = '002';
103 $status_mssg = xl('Plan Name Already Exists');
104 } else if ($e->getMessage() == "003") {
105 //Already in list options
106 $status_code = '003';
107 $status_mssg = xl('Plan Already in list_options');
110 $status = array('status_code'=>$status_code, 'status_message'=>$status_mssg, 'plan_id'=>$plan_id, 'plan_title'=>$plan_name);
111 echo json_encode($status);
113 break;
115 } else if (strlen($plan_id) > 0) {
116 submitChanges($plan_id, $added_rules, $removed_rules);
119 $status = array('status_code'=>'000', 'status_message'=>'Success', 'plan_id'=>$plan_id, 'plan_title'=>$plan_name);
120 echo json_encode($status);
122 break;
124 case "deletePlan":
125 $plan_id = $_GET["plan_id"];
126 deletePlan($plan_id);
128 break;
130 case "togglePlanStatus":
131 $dataToggle = json_decode(file_get_contents('php://input'), true);
133 $plan_id_toggle = $dataToggle['selected_plan'];
134 $plan_pid_toggle = $dataToggle['selected_plan_pid'];
135 $active_inactive = $dataToggle['plan_status'];
136 if ($active_inactive == 'deactivate') {
137 $nm_flag = 0;
138 } else {
139 $nm_flag = 1;
142 try {
143 togglePlanStatus($plan_id_toggle, $nm_flag);
144 } catch (Exception $e) {
145 if ($e->getMessage() == "007") {
146 $code_back = "007";
147 echo json_encode($code_back);
150 if ($e->getMessage() == "002") {
151 $code_back = "002";
152 echo json_encode($code_back);
155 break;
157 case "getPlanStatus":
158 $plan_id = $_GET["plan_id"];
160 $isPlanActive = isPlanActive($plan_id);
162 $isPlanActive = ($isPlanActive) ? 1 : 0 ;
164 $plan_status = array('plan_id'=>$plan_id, 'is_plan_active'=>$isPlanActive);
165 echo json_encode($plan_status);
167 break;
169 default:
170 break;