3 * MessageRestController
6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\RestControllers
;
15 use OpenEMR\Services\MessageService
;
16 use OpenEMR\RestControllers\RestControllerHelper
;
18 class MessageRestController
20 private $messageService;
22 public function __construct()
24 $this->messageService
= new MessageService();
27 public function put($pid, $mid, $data)
29 $validationResult = $this->messageService
->validate($data);
31 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
32 if (is_array($validationHandlerResult)) {
33 return $validationHandlerResult; }
35 $serviceResult = $this->messageService
->update($pid, $mid, $data);
36 return RestControllerHelper
::responseHandler($serviceResult, array("mid" => $mid), 200);
39 public function post($pid, $data)
41 $validationResult = $this->messageService
->validate($data);
43 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
44 if (is_array($validationHandlerResult)) {
45 return $validationHandlerResult; }
47 $serviceResult = $this->messageService
->insert($pid, $data);
48 return RestControllerHelper
::responseHandler($serviceResult, array("mid" => $serviceResult), 201);
51 public function delete($pid, $mid)
53 $serviceResult = $this->messageService
->delete($pid, $mid);
54 return RestControllerHelper
::responseHandler($serviceResult, true, 200);