2 /** @package OpenHealthEMR::Controller */
6 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
8 * LICENSE: This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Jerry Padgett <sjpadgett@gmail.com>
23 * @link http://www.open-emr.org
26 /** import supporting libraries */
27 require_once("AppBaseController.php");
28 require_once("Model/User.php");
31 * UserController is the controller class for the User object. The
32 * controller is responsible for processing input from the user, reading/updating
33 * the model as necessary and displaying the appropriate view.
35 * @package OpenHealthEMR::Controller
36 * @author ClassBuilder
39 class UserController
extends AppBaseController
43 * Override here for any controller-specific functionality
47 protected function Init()
51 // TODO: add controller-wide bootstrap code
53 // TODO: if authentiation is required for this entire controller, for example:
54 // $this->RequirePermission(SecureApp::$PERMISSION_USER,'SecureApp.LoginForm');
58 * Displays a list view of User objects
60 public function ListView()
63 if (isset($_GET['id']) )
64 $rid = (int) $_GET['id'];
65 $this->Assign ( 'recid', $rid );
70 * API Method queries for User records and render as JSON
72 public function Query()
76 $criteria = new UserCriteria();
77 $recnum = RequestUtil
::Get ( 'recId' );
78 $criteria->Id_Equals
= $recnum;
80 $output = new stdClass();
82 // if a sort order was specified then specify in the criteria
83 $output->orderBy
= RequestUtil
::Get('orderBy');
84 $output->orderDesc
= RequestUtil
::Get('orderDesc') != '';
85 if ($output->orderBy
) $criteria->SetOrder($output->orderBy
, $output->orderDesc
);
87 $page = RequestUtil
::Get('page');
90 $users = $this->Phreezer
->Query('User',$criteria);
91 $output->rows
= $users->ToObjectArray(true, $this->SimpleObjectParams());
92 $output->totalResults
= count($output->rows
);
93 $output->totalPages
= 1;
94 $output->pageSize
= $output->totalResults
;
95 $output->currentPage
= 1;
97 $this->RenderJSON($output, $this->JSONPCallback());
101 $this->RenderExceptionJSON($ex);
106 * API Method retrieves a single User record and render as JSON
108 public function Read()
112 $pk = $this->GetRouter()->GetUrlParam('id');
113 $user = $this->Phreezer
->Get('User',$pk);
114 $this->RenderJSON($user, $this->JSONPCallback(), true, $this->SimpleObjectParams());
116 catch (Exception
$ex)
118 $this->RenderExceptionJSON($ex);
123 * API Method inserts a new User record and render response as JSON
125 public function Create()
130 $json = json_decode(RequestUtil
::GetBody());
134 throw new Exception('The request body does not contain valid JSON');
137 $user = new User($this->Phreezer
);
139 // TODO: any fields that should not be inserted by the user should be commented out
141 // this is an auto-increment. uncomment if updating is allowed
142 // $user->Id = $this->SafeGetVal($json, 'id');
144 $user->Username
= $this->SafeGetVal($json, 'username');
145 $user->Password
= $this->SafeGetVal($json, 'password');
146 $user->Authorized
= $this->SafeGetVal($json, 'authorized');
147 $user->Info
= $this->SafeGetVal($json, 'info');
148 $user->Source
= $this->SafeGetVal($json, 'source');
149 $user->Fname
= $this->SafeGetVal($json, 'fname');
150 $user->Mname
= $this->SafeGetVal($json, 'mname');
151 $user->Lname
= $this->SafeGetVal($json, 'lname');
152 $user->Federaltaxid
= $this->SafeGetVal($json, 'federaltaxid');
153 $user->Federaldrugid
= $this->SafeGetVal($json, 'federaldrugid');
154 $user->Upin
= $this->SafeGetVal($json, 'upin');
155 $user->Facility
= $this->SafeGetVal($json, 'facility');
156 $user->FacilityId
= $this->SafeGetVal($json, 'facilityId');
157 $user->SeeAuth
= $this->SafeGetVal($json, 'seeAuth');
158 $user->Active
= $this->SafeGetVal($json, 'active');
159 $user->Npi
= $this->SafeGetVal($json, 'npi');
160 $user->Title
= $this->SafeGetVal($json, 'title');
161 $user->Specialty
= $this->SafeGetVal($json, 'specialty');
162 $user->Billname
= $this->SafeGetVal($json, 'billname');
163 $user->Email
= $this->SafeGetVal($json, 'email');
164 $user->EmailDirect
= $this->SafeGetVal($json, 'emailDirect');
165 $user->EserUrl
= $this->SafeGetVal($json, 'eserUrl');
166 $user->Assistant
= $this->SafeGetVal($json, 'assistant');
167 $user->Organization
= $this->SafeGetVal($json, 'organization');
168 $user->Valedictory
= $this->SafeGetVal($json, 'valedictory');
169 $user->Street
= $this->SafeGetVal($json, 'street');
170 $user->Streetb
= $this->SafeGetVal($json, 'streetb');
171 $user->City
= $this->SafeGetVal($json, 'city');
172 $user->State
= $this->SafeGetVal($json, 'state');
173 $user->Zip
= $this->SafeGetVal($json, 'zip');
174 $user->Street2
= $this->SafeGetVal($json, 'street2');
175 $user->Streetb2
= $this->SafeGetVal($json, 'streetb2');
176 $user->City2
= $this->SafeGetVal($json, 'city2');
177 $user->State2
= $this->SafeGetVal($json, 'state2');
178 $user->Zip2
= $this->SafeGetVal($json, 'zip2');
179 $user->Phone
= $this->SafeGetVal($json, 'phone');
180 $user->Fax
= $this->SafeGetVal($json, 'fax');
181 $user->Phonew1
= $this->SafeGetVal($json, 'phonew1');
182 $user->Phonew2
= $this->SafeGetVal($json, 'phonew2');
183 $user->Phonecell
= $this->SafeGetVal($json, 'phonecell');
184 $user->Notes
= $this->SafeGetVal($json, 'notes');
185 $user->CalUi
= $this->SafeGetVal($json, 'calUi');
186 $user->Taxonomy
= $this->SafeGetVal($json, 'taxonomy');
187 $user->SsiRelayhealth
= $this->SafeGetVal($json, 'ssiRelayhealth');
188 $user->Calendar
= $this->SafeGetVal($json, 'calendar');
189 $user->AbookType
= $this->SafeGetVal($json, 'abookType');
190 $user->PwdExpirationDate
= date('Y-m-d H:i:s',strtotime($this->SafeGetVal($json, 'pwdExpirationDate')));
191 $user->PwdHistory1
= $this->SafeGetVal($json, 'pwdHistory1');
192 $user->PwdHistory2
= $this->SafeGetVal($json, 'pwdHistory2');
193 $user->DefaultWarehouse
= $this->SafeGetVal($json, 'defaultWarehouse');
194 $user->Irnpool
= $this->SafeGetVal($json, 'irnpool');
195 $user->StateLicenseNumber
= $this->SafeGetVal($json, 'stateLicenseNumber');
196 $user->NewcropUserRole
= $this->SafeGetVal($json, 'newcropUserRole');
197 $user->Cpoe
= $this->SafeGetVal($json, 'cpoe');
198 $user->PhysicianType
= $this->SafeGetVal($json, 'physicianType');
201 $errors = $user->GetValidationErrors();
203 if (count($errors) > 0)
205 $this->RenderErrorJSON('Please check the form for errors',$errors);
210 $this->RenderJSON($user, $this->JSONPCallback(), true, $this->SimpleObjectParams());
214 catch (Exception
$ex)
216 $this->RenderExceptionJSON($ex);
221 * API Method updates an existing User record and render response as JSON
223 public function Update()
228 $json = json_decode(RequestUtil
::GetBody());
232 throw new Exception('The request body does not contain valid JSON');
235 $pk = $this->GetRouter()->GetUrlParam('id');
236 $user = $this->Phreezer
->Get('User',$pk);
238 // TODO: any fields that should not be updated by the user should be commented out
240 // this is a primary key. uncomment if updating is allowed
241 // $user->Id = $this->SafeGetVal($json, 'id', $user->Id);
243 $user->Username
= $this->SafeGetVal($json, 'username', $user->Username
);
244 $user->Password
= $this->SafeGetVal($json, 'password', $user->Password
);
245 $user->Authorized
= $this->SafeGetVal($json, 'authorized', $user->Authorized
);
246 $user->Info
= $this->SafeGetVal($json, 'info', $user->Info
);
247 $user->Source
= $this->SafeGetVal($json, 'source', $user->Source
);
248 $user->Fname
= $this->SafeGetVal($json, 'fname', $user->Fname
);
249 $user->Mname
= $this->SafeGetVal($json, 'mname', $user->Mname
);
250 $user->Lname
= $this->SafeGetVal($json, 'lname', $user->Lname
);
251 $user->Federaltaxid
= $this->SafeGetVal($json, 'federaltaxid', $user->Federaltaxid
);
252 $user->Federaldrugid
= $this->SafeGetVal($json, 'federaldrugid', $user->Federaldrugid
);
253 $user->Upin
= $this->SafeGetVal($json, 'upin', $user->Upin
);
254 $user->Facility
= $this->SafeGetVal($json, 'facility', $user->Facility
);
255 $user->FacilityId
= $this->SafeGetVal($json, 'facilityId', $user->FacilityId
);
256 $user->SeeAuth
= $this->SafeGetVal($json, 'seeAuth', $user->SeeAuth
);
257 $user->Active
= $this->SafeGetVal($json, 'active', $user->Active
);
258 $user->Npi
= $this->SafeGetVal($json, 'npi', $user->Npi
);
259 $user->Title
= $this->SafeGetVal($json, 'title', $user->Title
);
260 $user->Specialty
= $this->SafeGetVal($json, 'specialty', $user->Specialty
);
261 $user->Billname
= $this->SafeGetVal($json, 'billname', $user->Billname
);
262 $user->Email
= $this->SafeGetVal($json, 'email', $user->Email
);
263 $user->EmailDirect
= $this->SafeGetVal($json, 'emailDirect', $user->EmailDirect
);
264 $user->EserUrl
= $this->SafeGetVal($json, 'eserUrl', $user->EserUrl
);
265 $user->Assistant
= $this->SafeGetVal($json, 'assistant', $user->Assistant
);
266 $user->Organization
= $this->SafeGetVal($json, 'organization', $user->Organization
);
267 $user->Valedictory
= $this->SafeGetVal($json, 'valedictory', $user->Valedictory
);
268 $user->Street
= $this->SafeGetVal($json, 'street', $user->Street
);
269 $user->Streetb
= $this->SafeGetVal($json, 'streetb', $user->Streetb
);
270 $user->City
= $this->SafeGetVal($json, 'city', $user->City
);
271 $user->State
= $this->SafeGetVal($json, 'state', $user->State
);
272 $user->Zip
= $this->SafeGetVal($json, 'zip', $user->Zip
);
273 $user->Street2
= $this->SafeGetVal($json, 'street2', $user->Street2
);
274 $user->Streetb2
= $this->SafeGetVal($json, 'streetb2', $user->Streetb2
);
275 $user->City2
= $this->SafeGetVal($json, 'city2', $user->City2
);
276 $user->State2
= $this->SafeGetVal($json, 'state2', $user->State2
);
277 $user->Zip2
= $this->SafeGetVal($json, 'zip2', $user->Zip2
);
278 $user->Phone
= $this->SafeGetVal($json, 'phone', $user->Phone
);
279 $user->Fax
= $this->SafeGetVal($json, 'fax', $user->Fax
);
280 $user->Phonew1
= $this->SafeGetVal($json, 'phonew1', $user->Phonew1
);
281 $user->Phonew2
= $this->SafeGetVal($json, 'phonew2', $user->Phonew2
);
282 $user->Phonecell
= $this->SafeGetVal($json, 'phonecell', $user->Phonecell
);
283 $user->Notes
= $this->SafeGetVal($json, 'notes', $user->Notes
);
284 $user->CalUi
= $this->SafeGetVal($json, 'calUi', $user->CalUi
);
285 $user->Taxonomy
= $this->SafeGetVal($json, 'taxonomy', $user->Taxonomy
);
286 $user->SsiRelayhealth
= $this->SafeGetVal($json, 'ssiRelayhealth', $user->SsiRelayhealth
);
287 $user->Calendar
= $this->SafeGetVal($json, 'calendar', $user->Calendar
);
288 $user->AbookType
= $this->SafeGetVal($json, 'abookType', $user->AbookType
);
289 $user->PwdExpirationDate
= date('Y-m-d H:i:s',strtotime($this->SafeGetVal($json, 'pwdExpirationDate', $user->PwdExpirationDate
)));
290 $user->PwdHistory1
= $this->SafeGetVal($json, 'pwdHistory1', $user->PwdHistory1
);
291 $user->PwdHistory2
= $this->SafeGetVal($json, 'pwdHistory2', $user->PwdHistory2
);
292 $user->DefaultWarehouse
= $this->SafeGetVal($json, 'defaultWarehouse', $user->DefaultWarehouse
);
293 $user->Irnpool
= $this->SafeGetVal($json, 'irnpool', $user->Irnpool
);
294 $user->StateLicenseNumber
= $this->SafeGetVal($json, 'stateLicenseNumber', $user->StateLicenseNumber
);
295 $user->NewcropUserRole
= $this->SafeGetVal($json, 'newcropUserRole', $user->NewcropUserRole
);
296 $user->Cpoe
= $this->SafeGetVal($json, 'cpoe', $user->Cpoe
);
297 $user->PhysicianType
= $this->SafeGetVal($json, 'physicianType', $user->PhysicianType
);
300 $errors = $user->GetValidationErrors();
302 if (count($errors) > 0)
304 $this->RenderErrorJSON('Please check the form for errors',$errors);
309 $this->RenderJSON($user, $this->JSONPCallback(), true, $this->SimpleObjectParams());
314 catch (Exception
$ex)
318 $this->RenderExceptionJSON($ex);
323 * API Method deletes an existing User record and render response as JSON
325 public function Delete()
330 // TODO: if a soft delete is prefered, change this to update the deleted flag instead of hard-deleting
332 $pk = $this->GetRouter()->GetUrlParam('id');
333 $user = $this->Phreezer
->Get('User',$pk);
337 $output = new stdClass();
339 $this->RenderJSON($output, $this->JSONPCallback());
342 catch (Exception
$ex)
344 $this->RenderExceptionJSON($ex);