4 * EncounterRestController
7 * @link http://www.open-emr.org
8 * @author Matthew Vita <matthewvita48@gmail.com>
9 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\RestControllers
;
15 use OpenEMR\Services\EncounterService
;
16 use OpenEMR\RestControllers\RestControllerHelper
;
18 class EncounterRestController
20 private $encounterService;
23 * White list of patient search fields
25 private const SUPPORTED_SEARCH_FIELDS
= array(
30 public function __construct()
32 $this->encounterService
= new EncounterService();
36 * Process a HTTP POST request used to create a encounter record.
37 * @param $puuid - The patient identifier used to lookup the existing record.
38 * @param $data - array of encounter fields.
39 * @return a 201/Created status code and the encounter identifier if successful.
41 public function post($puuid, $data)
43 $processingResult = $this->encounterService
->insertEncounter($puuid, $data);
44 return RestControllerHelper
::handleProcessingResult($processingResult, 201);
48 * Processes a HTTP PUT request used to update an existing encounter record.
49 * @param $puuid - The patient identifier used to lookup the existing record.
50 * @param $euuid - The encounter identifier used to lookup the existing record.
51 * @param $data - array of encounter fields (full resource).
52 * @return a 200/Ok status code and the encounter resource.
54 public function put($puuid, $euuid, $data)
56 $processingResult = $this->encounterService
->updateEncounter($puuid, $euuid, $data);
57 return RestControllerHelper
::handleProcessingResult($processingResult, 200);
61 * Fetches a single encounter resource by pid and eid.
62 * @param $puuid The patient identifier used to lookup the existing record.
63 * @param $euuid The encounter identifier to fetch.
64 * @return a 200/Ok status code and the encounter resource.
66 public function getOne($puuid, $euuid)
68 $processingResult = $this->encounterService
->getEncounter($euuid, $puuid);
70 if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
71 return RestControllerHelper
::handleProcessingResult($processingResult, 404);
74 return RestControllerHelper
::handleProcessingResult($processingResult, 200);
78 * Returns all encounter resources which match (pid) patient identifier.
79 * @param $puuid The patient identifier used to lookup the existing record.
80 * @return a 200/Ok status code and the encounter resource.
82 public function getAll($puuid)
84 $processingResult = $this->encounterService
->getEncountersBySearch([], true, $puuid);
86 if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
87 return RestControllerHelper
::handleProcessingResult($processingResult, 404);
90 return RestControllerHelper
::handleProcessingResult($processingResult, 200, true);
93 public function postVital($pid, $eid, $data)
95 $validationResult = $this->encounterService
->validateVital($data);
97 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
98 if (is_array($validationHandlerResult)) {
99 return $validationHandlerResult;
102 $serviceResult = $this->encounterService
->insertVital($pid, $eid, $data);
103 return RestControllerHelper
::responseHandler(
106 'vid' => $serviceResult[0],
107 'fid' => $serviceResult[1]
113 public function putVital($pid, $eid, $vid, $data)
115 $validationResult = $this->encounterService
->validateVital($data);
117 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
118 if (is_array($validationHandlerResult)) {
119 return $validationHandlerResult;
122 $serviceResult = $this->encounterService
->updateVital($pid, $eid, $vid, $data);
123 return RestControllerHelper
::responseHandler($serviceResult, array('vid' => $vid), 200);
126 public function getVitals($pid, $eid)
128 $serviceResult = $this->encounterService
->getVitals($pid, $eid);
129 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
132 public function getVital($pid, $eid, $vid)
134 $serviceResult = $this->encounterService
->getVital($pid, $eid, $vid);
135 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
138 public function getSoapNotes($pid, $eid)
140 $serviceResult = $this->encounterService
->getSoapNotes($pid, $eid);
141 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
144 public function getSoapNote($pid, $eid, $sid)
146 $serviceResult = $this->encounterService
->getSoapNote($pid, $eid, $sid);
147 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
150 public function postSoapNote($pid, $eid, $data)
152 $validationResult = $this->encounterService
->validateSoapNote($data);
154 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
155 if (is_array($validationHandlerResult)) {
156 return $validationHandlerResult;
159 $serviceResult = $this->encounterService
->insertSoapNote($pid, $eid, $data);
160 return RestControllerHelper
::responseHandler(
163 'sid' => $serviceResult[0],
164 'fid' => $serviceResult[1]
170 public function putSoapNote($pid, $eid, $sid, $data)
172 $validationResult = $this->encounterService
->validateSoapNote($data);
174 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
175 if (is_array($validationHandlerResult)) {
176 return $validationHandlerResult;
179 $serviceResult = $this->encounterService
->updateSoapNote($pid, $eid, $sid, $data);
180 return RestControllerHelper
::responseHandler($serviceResult, array('sid' => $sid), 200);