2 /** @package Patient Portal::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
27 * import supporting libraries
29 require_once("AppBaseController.php");
30 require_once("Model/Patient.php");
33 * PatientController is the controller class for the Patient object.
35 * controller is responsible for processing input from the user, reading/updating
36 * the model as necessary and displaying the appropriate view.
38 * @package Patient Portal::Controller
39 * @author ClassBuilder
42 class PortalPatientController
extends AppBaseController
46 * Override here for any controller-specific functionality
50 protected function Init()
54 // $this->RequirePermission(SecureApp::$PERMISSION_USER,'SecureApp.LoginForm');
58 * Displays a list view of Patient objects
60 public function ListView()
62 $rid = $pid = $user = $encounter = 0;
63 if (isset($_GET['id'])) {
64 $rid = ( int ) $_GET['id'];
67 if (isset($_GET['pid'])) {
68 $pid = ( int ) $_GET['pid'];
71 if (isset($_GET['user'])) {
72 $user = $_GET['user'];
75 if (isset($_GET['enc'])) {
76 $encounter = $_GET['enc'];
79 $this->Assign('recid', $rid);
80 $this->Assign('cpid', $pid);
81 $this->Assign('cuser', $user);
82 $this->Assign('encounter', $encounter);
87 * API Method queries for Patient records and render as JSON
89 public function Query()
92 $criteria = new PatientCriteria();
93 $recnum = RequestUtil
::Get('patientId');
94 $criteria->Pid_Equals
= $recnum;
96 $output = new stdClass();
98 // if a sort order was specified then specify in the criteria
99 $output->orderBy
= RequestUtil
::Get('orderBy');
100 $output->orderDesc
= RequestUtil
::Get('orderDesc') != '';
101 if ($output->orderBy
) {
102 $criteria->SetOrder($output->orderBy
, $output->orderDesc
);
105 $page = RequestUtil
::Get('page');
107 // return all results
108 $patientdata = $this->Phreezer
->Query('PatientReporter', $criteria);
109 $output->rows
= $patientdata->ToObjectArray(true, $this->SimpleObjectParams());
110 $output->totalResults
= count($output->rows
);
111 $output->totalPages
= 1;
112 $output->pageSize
= $output->totalResults
;
113 $output->currentPage
= 1;
115 $this->RenderJSON($output, $this->JSONPCallback());
116 } catch (Exception
$ex) {
117 $this->RenderExceptionJSON($ex);
122 * API Method retrieves a single Patient record and render as JSON
124 public function Read()
127 $pk = $this->GetRouter()->GetUrlParam('id');
128 $ppid = RequestUtil
::Get('patientId');
129 // $patient = $this->Phreezer->Get( 'Patient', $pk );
130 $appsql = new ApplicationTable();
131 $edata = $appsql->getPortalAudit($ppid, 'review');
132 $changed = unserialize($edata['table_args']);
134 foreach ($changed as $key => $val) {
135 $newv[lcfirst(ucwords(preg_replace_callback("/(\_(.))/", create_function('$matches', 'return strtoupper($matches[2]);'), strtolower($key))))] = $val;
138 $this->RenderJSON($newv, $this->JSONPCallback(), false, $this->SimpleObjectParams());
139 } catch (Exception
$ex) {
140 $this->RenderExceptionJSON($ex);
145 * API Method updates an existing Patient record and render response as JSON
147 public function Update()
150 $json = json_decode(RequestUtil
::GetBody());
153 throw new Exception('The request body does not contain valid JSON');
156 $pk = $this->GetRouter()->GetUrlParam('id');
157 $patient = $this->Phreezer
->Get('Patient', $pk);
159 $patient->Title
= $this->SafeGetVal($json, 'title', $patient->Title
);
160 $patient->Language
= $this->SafeGetVal($json, 'language', $patient->Language
);
161 $patient->Financial
= $this->SafeGetVal($json, 'financial', $patient->Financial
);
162 $patient->Fname
= $this->SafeGetVal($json, 'fname', $patient->Fname
);
163 $patient->Lname
= $this->SafeGetVal($json, 'lname', $patient->Lname
);
164 $patient->Mname
= $this->SafeGetVal($json, 'mname', $patient->Mname
);
165 $patient->Dob
= date('Y-m-d', strtotime($this->SafeGetVal($json, 'dob', $patient->Dob
)));
166 $patient->Street
= $this->SafeGetVal($json, 'street', $patient->Street
);
167 $patient->PostalCode
= $this->SafeGetVal($json, 'postalCode', $patient->PostalCode
);
168 $patient->City
= $this->SafeGetVal($json, 'city', $patient->City
);
169 $patient->State
= $this->SafeGetVal($json, 'state', $patient->State
);
170 $patient->CountryCode
= $this->SafeGetVal($json, 'countryCode', $patient->CountryCode
);
171 $patient->DriversLicense
= $this->SafeGetVal($json, 'driversLicense', $patient->DriversLicense
);
172 $patient->Ss
= $this->SafeGetVal($json, 'ss', $patient->Ss
);
173 $patient->Occupation
= $this->SafeGetVal($json, 'occupation', $patient->Occupation
);
174 $patient->PhoneHome
= $this->SafeGetVal($json, 'phoneHome', $patient->PhoneHome
);
175 $patient->PhoneBiz
= $this->SafeGetVal($json, 'phoneBiz', $patient->PhoneBiz
);
176 $patient->PhoneContact
= $this->SafeGetVal($json, 'phoneContact', $patient->PhoneContact
);
177 $patient->PhoneCell
= $this->SafeGetVal($json, 'phoneCell', $patient->PhoneCell
);
178 $patient->PharmacyId
= $this->SafeGetVal($json, 'pharmacyId', $patient->PharmacyId
);
179 $patient->Status
= $this->SafeGetVal($json, 'status', $patient->Status
);
180 $patient->ContactRelationship
= $this->SafeGetVal($json, 'contactRelationship', $patient->ContactRelationship
);
181 $patient->Date
= date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'date', $patient->Date
)));
182 $patient->Sex
= $this->SafeGetVal($json, 'sex', $patient->Sex
);
183 $patient->Referrer
= $this->SafeGetVal($json, 'referrer', $patient->Referrer
);
184 $patient->Referrerid
= $this->SafeGetVal($json, 'referrerid', $patient->Referrerid
);
185 $patient->Providerid
= $this->SafeGetVal($json, 'providerid', $patient->Providerid
);
186 $patient->RefProviderid
= $this->SafeGetVal($json, 'refProviderid', $patient->RefProviderid
);
187 $patient->Email
= $this->SafeGetVal($json, 'email', $patient->Email
);
188 $patient->EmailDirect
= $this->SafeGetVal($json, 'emailDirect', $patient->EmailDirect
);
189 $patient->Ethnoracial
= $this->SafeGetVal($json, 'ethnoracial', $patient->Ethnoracial
);
190 $patient->Race
= $this->SafeGetVal($json, 'race', $patient->Race
);
191 $patient->Ethnicity
= $this->SafeGetVal($json, 'ethnicity', $patient->Ethnicity
);
192 $patient->Religion
= $this->SafeGetVal($json, 'religion', $patient->Religion
);
193 $patient->Interpretter
= $this->SafeGetVal($json, 'interpretter', $patient->Interpretter
);
194 $patient->Migrantseasonal
= $this->SafeGetVal($json, 'migrantseasonal', $patient->Migrantseasonal
);
195 $patient->FamilySize
= $this->SafeGetVal($json, 'familySize', $patient->FamilySize
);
196 $patient->MonthlyIncome
= $this->SafeGetVal($json, 'monthlyIncome', $patient->MonthlyIncome
);
197 $patient->BillingNote
= $this->SafeGetVal($json, 'billingNote', $patient->BillingNote
);
198 $patient->Homeless
= $this->SafeGetVal($json, 'homeless', $patient->Homeless
);
199 $patient->FinancialReview
= date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'financialReview', $patient->FinancialReview
)));
200 $patient->Pubpid
= $this->SafeGetVal($json, 'pubpid', $patient->Pubpid
);
201 $patient->Pid
= $this->SafeGetVal($json, 'pid', $patient->Pid
);
202 $patient->HipaaMail
= $this->SafeGetVal($json, 'hipaaMail', $patient->HipaaMail
);
203 $patient->HipaaVoice
= $this->SafeGetVal($json, 'hipaaVoice', $patient->HipaaVoice
);
204 $patient->HipaaNotice
= $this->SafeGetVal($json, 'hipaaNotice', $patient->HipaaNotice
);
205 $patient->HipaaMessage
= $this->SafeGetVal($json, 'hipaaMessage', $patient->HipaaMessage
);
206 $patient->HipaaAllowsms
= $this->SafeGetVal($json, 'hipaaAllowsms', $patient->HipaaAllowsms
);
207 $patient->HipaaAllowemail
= $this->SafeGetVal($json, 'hipaaAllowemail', $patient->HipaaAllowemail
);
208 $patient->Squad
= $this->SafeGetVal($json, 'squad', $patient->Squad
);
209 $patient->Fitness
= $this->SafeGetVal($json, 'fitness', $patient->Fitness
);
210 $patient->ReferralSource
= $this->SafeGetVal($json, 'referralSource', $patient->ReferralSource
);
211 $patient->Pricelevel
= $this->SafeGetVal($json, 'pricelevel', $patient->Pricelevel
);
212 $patient->Regdate
= date('Y-m-d', strtotime($this->SafeGetVal($json, 'regdate', $patient->Regdate
)));
213 $patient->Contrastart
= date('Y-m-d', strtotime($this->SafeGetVal($json, 'contrastart', $patient->Contrastart
)));
214 $patient->CompletedAd
= $this->SafeGetVal($json, 'completedAd', $patient->CompletedAd
);
215 $patient->AdReviewed
= date('Y-m-d', strtotime($this->SafeGetVal($json, 'adReviewed', $patient->AdReviewed
)));
216 $patient->Vfc
= $this->SafeGetVal($json, 'vfc', $patient->Vfc
);
217 $patient->Mothersname
= $this->SafeGetVal($json, 'mothersname', $patient->Mothersname
);
218 $patient->Guardiansname
= $this->SafeGetVal($json, 'guardiansname', $patient->Guardiansname
);
219 $patient->AllowImmRegUse
= $this->SafeGetVal($json, 'allowImmRegUse', $patient->AllowImmRegUse
);
220 $patient->AllowImmInfoShare
= $this->SafeGetVal($json, 'allowImmInfoShare', $patient->AllowImmInfoShare
);
221 $patient->AllowHealthInfoEx
= $this->SafeGetVal($json, 'allowHealthInfoEx', $patient->AllowHealthInfoEx
);
222 $patient->AllowPatientPortal
= $this->SafeGetVal($json, 'allowPatientPortal', $patient->AllowPatientPortal
);
223 $patient->CareTeam
= $this->SafeGetVal($json, 'careTeam', $patient->CareTeam
);
224 $patient->County
= $this->SafeGetVal($json, 'county', $patient->County
);
225 $patient->Industry
= $this->SafeGetVal($json, 'industry', $patient->Industry
);
226 $patient->Note
= $this->SafeGetVal($json, 'note', $patient->Note
);
227 $patient->Validate();
228 $errors = $patient->GetValidationErrors();
230 if (count($errors) > 0) {
231 $this->RenderErrorJSON('Please check the form for errors', $errors);
233 self
::SaveAudit($patient);
234 // $patient->Save(); //active records save
235 $this->RenderJSON($patient, $this->JSONPCallback(), true, $this->SimpleObjectParams());
237 } catch (Exception
$ex) {
238 $this->RenderExceptionJSON($ex);
241 public function SaveAudit($p)
243 $appsql = new ApplicationTable();
244 $ja = $p->GetArray();
245 $ja['note'] = $p->Note
;
248 // date("Y-m-d H:i:s");
249 $audit['patient_id'] = $ja['pid'];
250 $audit['activity'] = "profile";
251 $audit['require_audit'] = "1";
252 $audit['pending_action'] = "review";
253 $audit['action_taken'] = "";
254 $audit['status'] = "waiting";
255 $audit['narrative'] = "Patient request changes to demographics.";
256 $audit['table_action'] = "";
257 $audit['table_args'] = $ja; // edited record
258 $audit['action_user'] = "0";
259 $audit['action_taken_time'] = "";
260 $audit['checksum'] = "0";
262 $edata = $appsql->getPortalAudit($ja['pid'], 'review');
263 $audit['date'] = $edata['date'];
264 if ($edata['id'] > 0) {
265 $appsql->portalAudit('update', $edata['id'], $audit);
267 $appsql->portalAudit('insert', '', $audit);
269 } catch (Exception
$ex) {
270 $this->RenderExceptionJSON($ex);
274 * API Method deletes an existing Patient record and render response as JSON
276 public function Delete()
279 // TODO: if a soft delete is prefered, change this to update the deleted flag instead of hard-deleting
281 $pk = $this->GetRouter()->GetUrlParam('id');
282 $patient = $this->Phreezer
->Get('Patient', $pk);
286 $output = new stdClass();
288 $this->RenderJSON($output, $this->JSONPCallback());
289 } catch (Exception
$ex) {
290 $this->RenderExceptionJSON($ex);