forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncounterRestController.php
More file actions
184 lines (154 loc) · 6.46 KB
/
EncounterRestController.php
File metadata and controls
184 lines (154 loc) · 6.46 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* EncounterRestController
*
* @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\Services\EncounterService;
use OpenEMR\RestControllers\RestControllerHelper;
class EncounterRestController
{
private $encounterService;
/**
* White list of patient search fields
*/
private const SUPPORTED_SEARCH_FIELDS = array(
"pid",
"provider_id"
);
public function __construct()
{
$this->encounterService = new EncounterService();
}
/**
* Process a HTTP POST request used to create a encounter record.
* @param $puuid - The patient identifier used to lookup the existing record.
* @param $data - array of encounter fields.
* @return a 201/Created status code and the encounter identifier if successful.
*/
public function post($puuid, $data)
{
$data['user'] = $_SESSION['authUser'];
$data['group'] = $_SESSION['authProvider'];
$processingResult = $this->encounterService->insertEncounter($puuid, $data);
return RestControllerHelper::handleProcessingResult($processingResult, 201);
}
/**
* Processes a HTTP PUT request used to update an existing encounter record.
* @param $puuid - The patient identifier used to lookup the existing record.
* @param $euuid - The encounter identifier used to lookup the existing record.
* @param $data - array of encounter fields (full resource).
* @return a 200/Ok status code and the encounter resource.
*/
public function put($puuid, $euuid, $data)
{
$processingResult = $this->encounterService->updateEncounter($puuid, $euuid, $data);
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Fetches a single encounter resource by pid and eid.
* @param $puuid The patient identifier used to lookup the existing record.
* @param $euuid The encounter identifier to fetch.
* @return a 200/Ok status code and the encounter resource.
*/
public function getOne($puuid, $euuid)
{
$processingResult = $this->encounterService->getEncounter($euuid, $puuid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Returns all encounter resources which match (pid) patient identifier.
* @param $puuid The patient identifier used to lookup the existing record.
* @return a 200/Ok status code and the encounter resource.
*/
public function getAll($puuid)
{
$processingResult = $this->encounterService->search([], true, $puuid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200, true);
}
public function postVital($pid, $eid, $data)
{
$validationResult = $this->encounterService->validateVital($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->encounterService->insertVital($pid, $eid, $data);
return RestControllerHelper::responseHandler(
$serviceResult,
array(
'vid' => $serviceResult[0],
'fid' => $serviceResult[1]
),
201
);
}
public function putVital($pid, $eid, $vid, $data)
{
$validationResult = $this->encounterService->validateVital($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->encounterService->updateVital($pid, $eid, $vid, $data);
return RestControllerHelper::responseHandler($serviceResult, array('vid' => $vid), 200);
}
public function getVitals($pid, $eid)
{
$serviceResult = $this->encounterService->getVitals($pid, $eid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getVital($pid, $eid, $vid)
{
$serviceResult = $this->encounterService->getVital($pid, $eid, $vid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getSoapNotes($pid, $eid)
{
$serviceResult = $this->encounterService->getSoapNotes($pid, $eid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getSoapNote($pid, $eid, $sid)
{
$serviceResult = $this->encounterService->getSoapNote($pid, $eid, $sid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function postSoapNote($pid, $eid, $data)
{
$validationResult = $this->encounterService->validateSoapNote($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->encounterService->insertSoapNote($pid, $eid, $data);
return RestControllerHelper::responseHandler(
$serviceResult,
array(
'sid' => $serviceResult[0],
'fid' => $serviceResult[1]
),
201
);
}
public function putSoapNote($pid, $eid, $sid, $data)
{
$validationResult = $this->encounterService->validateSoapNote($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->encounterService->updateSoapNote($pid, $eid, $sid, $data);
return RestControllerHelper::responseHandler($serviceResult, array('sid' => $sid), 200);
}
}