Setup script bootstrapped with new theme selector - Take 2 (#2139)
[openemr.git] / rest_controllers / InsuranceRestController.php
blobca927ac8bef7154b7b3b9de8b881d0dc4dbae101
1 <?php
2 /**
3 * InsuranceRestController
5 * @package OpenEMR
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;
42 $data["pid"] = $pid;
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;
56 $data["pid"] = $pid;
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);