3 * InsuranceRestController
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\InsuranceService
;
16 use OpenEMR\RestControllers\RestControllerHelper
;
18 class InsuranceRestController
20 private $insuranceService;
22 public function __construct()
24 $this->insuranceService
= new InsuranceService();
27 public function getAll($pid)
29 $serviceResult = $this->insuranceService
->getAll($pid);
30 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
33 public function getOne($pid, $type)
35 $serviceResult = $this->insuranceService
->getOne($pid, $type);
36 return RestControllerHelper
::responseHandler($serviceResult, null, 200);
39 public function put($pid, $type, $data)
41 $data["type"] = $type;
43 $validationResult = $this->insuranceService
->validate($data);
45 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
46 if (is_array($validationHandlerResult)) {
47 return $validationHandlerResult; }
49 $serviceResult = $this->insuranceService
->insert($pid, $type, $data);
50 return RestControllerHelper
::responseHandler($serviceResult, $type, 200);
53 public function post($pid, $type, $data)
55 $data["type"] = $type;
57 $validationResult = $this->insuranceService
->validate($data);
59 $validationHandlerResult = RestControllerHelper
::validationHandler($validationResult);
60 if (is_array($validationHandlerResult)) {
61 return $validationHandlerResult; }
63 $serviceResult = $this->insuranceService
->insert($pid, $type, $data);
64 return RestControllerHelper
::responseHandler($serviceResult, $type, 201);