forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentRestController.php
More file actions
92 lines (77 loc) · 3.15 KB
/
AppointmentRestController.php
File metadata and controls
92 lines (77 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* AppointmentRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <matthewvita48@gmail.com>
* @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\Common\Logging\SystemLogger;
use OpenEMR\RestControllers\RestControllerHelper;
use OpenEMR\Services\AppointmentService;
use OpenEMR\Services\PatientService;
use OpenEMR\Validators\ProcessingResult;
class AppointmentRestController
{
private $appointmentService;
public function __construct()
{
$this->appointmentService = new AppointmentService();
}
public function getOne($eid)
{
$serviceResult = $this->appointmentService->getAppointment($eid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getOneForPatient($auuid, $patientUuid)
{
$serviceResult = $this->appointmentService->search(['puuid' => $patientUuid, 'pc_uuid' => $auuid]);
$data = ProcessingResult::extractDataArray($serviceResult);
return RestControllerHelper::responseHandler($data[0] ?? [], null, 200);
}
public function getAll()
{
$serviceResult = $this->appointmentService->getAppointmentsForPatient(null);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getAllForPatientByUuid($puuid)
{
$patientService = new PatientService();
$result = ProcessingResult::extractDataArray($patientService->getOne($puuid));
if (!empty($result)) {
$serviceResult = $this->appointmentService->getAppointmentsForPatient($result[0]['pid']);
} else {
$serviceResult = [];
}
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getAllForPatient($pid)
{
$serviceResult = $this->appointmentService->getAppointmentsForPatient($pid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function post($pid, $data)
{
$data['pid'] = $pid;
$validationResult = $this->appointmentService->validate($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->appointmentService->insert($pid, $data);
return RestControllerHelper::responseHandler(array("id" => $serviceResult), null, 200);
}
public function delete($eid)
{
try {
$serviceResult = $this->appointmentService->delete($eid);
} catch (\Exception $exception) {
(new SystemLogger())->errorLogCaller($exception->getMessage(), ['trace' => $exception->getTraceAsString(), 'eid' => $eid]);
return RestControllerHelper::responseHandler(['message' => 'Failed to delete appointment'], null, 500);
}
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
}