added support for facility selection and external patient id
[openemr.git] / acl_upgrade.php
blob93e0eeb1a48dee057baa074d98f6d6d6c4c69223
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
6 //
7 // This script will update the phpGACL database, which include
8 // Access Control Objects(ACO), Groups(ARO), and Access Control
9 // Lists(ACL) created by the the acl_setup.php(2.8.1 onward)
10 // program, to the most recent version.
11 // (this assumes phpGACL has been previously installed)
12 // It will display whether each update already exist
13 // or if it was updated succesfully.
15 // Updates included:
16 // 2.8.2
17 // Section "sensitivities" (Sensitivities):
18 // ADD normal Normal (Administrators, Physicians, Clinicians(addonly))
19 // ADD high High (Administrators, Physicians)
20 // Section "admin" (Administration):
21 // ADD super Superuser (Adminstrators)
22 // 2.8.4
23 // Section "admin" (Administration):
24 // ADD drugs Pharmacy Dispensary (Administrators, Physicians, Clinicians(write))
25 // ADD acl ACL Administration (Administrators)
26 // Section "sensitivities" (Sensitivities):
27 // EDIT high High (ensure the order variable is '20')
28 // Section "acct" (Accounting):
29 // ADD disc Price Discounting (Administrators, Physicians, Accounting(write))
32 //Ensure that phpGACL has been installed
33 include_once('library/acl.inc');
34 if (isset ($phpgacl_location)) {
35 include_once("$phpgacl_location/gacl_api.class.php");
36 $gacl = new gacl_api();
38 else {
39 die("You must first set up library/acl.inc to use phpGACL!");
43 //Collect the ACL ID numbers.
44 echo "<B>Checking to ensure all the proper ACL(access control list) are present:</B></BR>";
45 //Get Administrator ACL ID number
46 $admin_write = getAclIdNumber('Administrators', 'write');
47 //Get Doctor ACL ID Number
48 $doc_write = getAclIdNumber('Physicians', 'write');
49 //Get Clinician ACL with write access ID number
50 $clin_write = getAclIdNumber('Clinicians', 'write');
51 //Get Clinician ACL with addonly access ID number
52 $clin_addonly = getAclIdNumber('Clinicians', 'addonly');
53 //Get Receptionist ACL ID number
54 $front_write = getAclIdNumber('Front Office', 'write');
55 //Get Accountant ACL ID number
56 $back_write = getAclIdNumber('Accounting', 'write');
59 //Add new object Sections
60 echo "<BR/><B>Adding new object sections</B><BR/>";
61 //Add 'Sensitivities' object section (added in 2.8.2)
62 addObjectSectionAcl('sensitivities', 'Sensitivities');
65 //Add new Objects
66 echo "<BR/><B>Adding new objects</B><BR/>";
67 //Add 'Normal' sensitivity object, order variable is default 10 (added in 2.8.2)
68 addObjectAcl('sensitivities', 'Sensitivities', 'normal', 'Normal');
69 //Add 'High' sensitivity object, order variable is set to 20 (added in 2.8.2)
70 addObjectAclWithOrder('sensitivities', 'Sensitivities', 'high', 'High', 20);
71 //Add 'Pharmacy Dispensary' object (added in 2.8.4)
72 addObjectAcl('admin', 'Administration', 'drugs', 'Pharmacy Dispensary');
73 //Add 'ACL Administration' object (added in 2.8.4)
74 addObjectAcl('admin', 'Administration', 'acl', 'ACL Administration');
75 //Add 'Price Discounting' object (added in 2.8.4)
76 addObjectAcl('acct', 'Accounting', 'disc', 'Price Discounting');
79 //Update already existing Objects
80 echo "<BR/><B>Upgrading objects</B><BR/>";
81 //Ensure that 'High' sensitivity object order variable is set to 20
82 editObjectAcl('sensitivities', 'Sensitivities', 'high', 'High', 20);
85 //Add new User Defined Groups (ARO) here
86 //(placemarker, since no new user defined groups since 2.8.1 have been added)
89 //Update the ACLs
90 echo "<BR/><B>Updating the ACLs(Access Control Lists)</B><BR/>";
91 //Insert the 'super' object from the 'admin' section into the Administrators group write ACL (added in 2.8.2)
92 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'super', 'Superuser', 'write');
93 //Insert the 'high' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
94 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
95 //Insert the 'normal' object from the 'sensitivities' section into the Administrators group write ACL (added in 2.8.2)
96 updateAcl($admin_write, 'Administrators', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
97 //Insert the 'high' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
98 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'high', 'High', 'write');
99 //Insert the 'normal' object from the 'sensitivities' section into the Physicians group write ACL (added in 2.8.2)
100 updateAcl($doc_write, 'Physicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'write');
101 //Insert the 'normal' object from the 'sensitivities' section into the Clinicians group addonly ACL (added in 2.8.2)
102 updateAcl($clin_addonly, 'Clinicians', 'sensitivities', 'Sensitivities', 'normal', 'Normal', 'addonly');
103 //Insert the 'drugs' object from the 'admin' section into the Administrators group write ACL (added in 2.8.4)
104 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
105 //Insert the 'drugs' object from the 'admin' section into the Physicians group write ACL (added in 2.8.4)
106 updateAcl($doc_write, 'Physicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
107 //Insert the 'drugs' object from the 'admin' section into the Clinicians group write ACL (added in 2.8.4)
108 updateAcl($clin_write, 'Clinicians', 'admin', 'Administration', 'drugs', 'Pharmacy Dispensary', 'write');
109 //Insert the 'acl' object from the 'admin' section into the Administrators group write ACL (added in 2.8.4)
110 updateAcl($admin_write, 'Administrators', 'admin', 'Administration', 'acl', 'ACL Administration', 'write');
111 //Insert the 'disc' object from the 'acct' section into the Administrators group write ACL (added in 2.8.4)
112 updateAcl($admin_write, 'Administrators', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
113 //Insert the 'disc' object from the 'acct' section into the Accounting group write ACL (added in 2.8.4)
114 updateAcl($back_write, 'Accounting', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
115 //Insert the 'disc' object from the 'acct' section into the Physicians group write ACL (added in 2.8.4)
116 updateAcl($doc_write, 'Physicians', 'acct', 'Accounting', 'disc', 'Price Discounting', 'write');
119 //Function will return an array that contains the ACL ID number.
120 //It will also check to ensure the ACL exist and is not duplicated.
121 // $title = Title(string) of group.
122 // $return_value = What the acl returns (string), usually 'write' or 'addonly'
123 function getAclIdNumber($title, $return_value) {
124 global $gacl;
125 $temp_acl_id_array = $gacl->search_acl(FALSE, FALSE, FALSE, FALSE, $title, FALSE, FALSE, FALSE, $return_value);
126 switch (count($temp_acl_id_array)) {
127 case 0:
128 echo "<B>ERROR</B>, '$title' group '$return_value' ACL does not exist.</BR>";
129 break;
130 case 1:
131 echo "'$title' group '$return_value' ACL is present.</BR>";
132 break;
133 default:
134 echo "<B>ERROR</B>, Multiple '$title' group '$return_value' ACLs are present.</BR>";
135 break;
137 return $temp_acl_id_array;
141 //Function to add a group.
142 //This is just a placeholder function at this point, since have not added another group yet.
143 // $name = Identifier(string) of group
144 // $title = Title(string) of group
145 function addGroupAcl($name, $title) {
146 global $gacl;
147 //if add a group, then will need to add logic here
148 return;
152 //Function to add an object section.
153 //It will check to ensure the object section doesn't already exist.
154 // $name = Identifier(string) of section
155 // $title = Title(string) of object
156 function addObjectSectionAcl($name, $title) {
157 global $gacl;
158 if ($gacl->get_object_section_section_id($title, $name, 'ACO')) {
159 echo "The '$title' object section already exist.</BR>";
161 else {
162 $tmp_boolean = $gacl->add_object_section($title , $name, 10, 0, 'ACO');
163 if ($tmp_boolean) {
164 echo "The '$title' object section has been successfully added.</BR>";
166 else {
167 echo "<B>ERROR</B>,unable to create the '$title' object section.</BR>";
170 return;
174 //Function to add an object.
175 //It will check to ensure the object doesn't already exist.
176 // $section_name = Identifier(string) of section
177 // $section_title = Title(string) of section
178 // $object_name = Identifier(string) of object
179 // $object_title = Title(string) of object
180 function addObjectAcl($section_name, $section_title, $object_name, $object_title) {
181 global $gacl;
182 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
183 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
185 else {
186 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, 10, 0, 'ACO');
187 if ($tmp_boolean) {
188 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
190 else {
191 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
194 return;
198 //Function to add an object and set the 'order' variable.
199 //It will check to ensure the object doesn't already exist.
200 // $section_name = Identifier(string) of section
201 // $section_title = Title(string) of section
202 // $object_name = Identifier(string) of object
203 // $object_title = Title(string) of object
204 // $order_number = number to determine order in list. used in sensitivities to order the choices
205 // in openemr
206 function addObjectAclWithOrder($section_name, $section_title, $object_name, $object_title, $order_number) {
207 global $gacl;
208 if ($gacl->get_object_id($section_name, $object_name, 'ACO')) {
209 echo "The '$object_title' object in the '$section_title' section already exist.</BR>";
211 else {
212 $tmp_boolean = $gacl->add_object($section_name, $object_title, $object_name, $order_number, 0, 'ACO');
213 if ($tmp_boolean) {
214 echo "The '$object_title' object in the '$section_title' section has been successfully added.</BR>";
216 else {
217 echo "<B>ERROR</B>,unable to create the '$object_title' object in the '$section_title' section.</BR>";
220 return;
224 //Function to edit an object and set the 'order' variable.
225 //It will check to ensure the object already exist, and hasn't been upgraded yet.
226 // $section_name = Identifier(string) of section
227 // $section_title = Title(string) of section
228 // $object_name = Identifier(string) of object
229 // $object_title = Title(string) of object
230 // $order_number = number to determine order in list. used in sensitivities to order the choices
231 // in openemr
232 function editObjectAcl($section_name, $section_title, $object_name, $object_title, $order_number) {
233 global $gacl;
234 $tmp_objectID = $gacl->get_object_id($section_name, $object_name, 'ACO');
235 if ($tmp_objectID) {
236 $tmp_object = $gacl->get_object_data($tmp_objectID, 'ACO');
237 if ($tmp_object[0][2] == $order_number &&
238 $tmp_object[0][0] == $section_name &&
239 $tmp_object[0][1] == $object_name &&
240 $tmp_object[0][3] == $object_title) {
241 echo "The '$object_title' object in the '$section_title' section has already been updated.</BR>";
243 else {
244 $tmp_boolean = $gacl->edit_object($tmp_objectID, $section_name, $object_title, $object_name, $order_number, 0, 'ACO');
245 if ($tmp_boolean) {
246 echo "The '$object_title' object in the '$section_title' section has been successfully updated.</BR>";
248 else {
249 echo "<B>ERROR</B>,unable to update the '$object_title' object in the '$section_title' section.</BR>";
253 else {
254 echo "<B>ERROR</B>, the '$object_title' object in the '$section_title' section does not exist.</BR>";
256 return;
260 //Update the ACL
261 //It will check to ensure the ACL hasn't already been updated.
262 // $array_acl_id_number = array containing hopefully one element, which is an integer, and is identifier of acl to be updated.
263 // $group_title = Title(string) of group.
264 // $object_section_name = Identifier(string) of section
265 // $object_section_title = Title(string) of section
266 // $object_name = Identifier(string) of object
267 // $object_title = Title(string) of object
268 // $acl_return_value = What the acl returns (string), usually 'write' or 'addonly'
269 function updateAcl($array_acl_id_number, $group_title, $section_name, $section_title, $object_name, $object_title, $return_value) {
270 global $gacl;
271 $tmp_array = $gacl->search_acl($section_name, $object_name, FALSE, FALSE, $group_title, FALSE, FALSE, FALSE, $return_value);
272 switch (count($tmp_array)) {
273 case 0:
274 $tmp_boolean = @$gacl->append_acl($array_acl_id_number[0], NULL, NULL, NULL, NULL, array($section_name=>array($object_name)));
275 if ($tmp_boolean){
276 echo "Successfully placed the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
278 else {
279 echo "<B>ERROR</B>,unable to place the '$object_title' object of the '$section_title' section into the '$group_title' group '$return_value' ACL.</BR>";
281 break;
282 case 1:
283 echo "The '$object_title' object of the '$section_title' section is already found in the '$group_title' group '$return_value' ACL.</BR>";
284 break;
285 default:
286 echo "<B>ERROR</B>, Multiple '$group_title' group '$return_value' ACLs with the '$object_title' object of the '$section_title' section are present.</BR>";
287 break;
289 return;
292 //All done
293 echo "</BR><B>ALL DONE</B>";