Merge pull request #2107 from stephenwaite/forum-fix
[openemr.git] / rest_controllers / InsuranceCompanyRestController.php
blobced53b5b62e0703ce4be56b9f43a4df59075a876
1 <?php
2 /**
3 * InsuranceCompanyRestController
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\InsuranceCompanyService;
16 use OpenEMR\Services\AddressService;
17 use OpenEMR\RestControllers\RestControllerHelper;
19 class InsuranceCompanyRestController
21 private $insuranceCompanyService;
22 private $addressService;
24 public function __construct()
26 $this->insuranceCompanyService = new InsuranceCompanyService();
27 $this->addressService = new AddressService();
30 public function getAll()
32 $serviceResult = $this->insuranceCompanyService->getAll();
33 return RestControllerHelper::responseHandler($serviceResult, null, 200);
36 public function getInsuranceTypes()
38 $serviceResult = $this->insuranceCompanyService->getInsuranceTypes();
39 return RestControllerHelper::responseHandler($serviceResult, null, 200);
42 public function post($data)
44 $insuranceCompanyValidationResult = $this->insuranceCompanyService->validate($data);
45 $insuranceCompanyValidationHandlerResult = RestControllerHelper::validationHandler($insuranceCompanyValidationResult);
46 if (is_array($insuranceCompanyValidationHandlerResult)) {
47 return $insuranceCompanyValidationHandlerResult; }
49 $addressValidationResult = $this->addressService->validate($data);
50 $addressValidationHandlerResult = RestControllerHelper::validationHandler($addressValidationResult);
51 if (is_array($addressValidationHandlerResult)) {
52 return $addressValidationHandlerResult; }
54 $serviceResult = $this->insuranceCompanyService->insert($data);
55 return RestControllerHelper::responseHandler($serviceResult, array('iid' => $serviceResult), 201);
58 public function put($iid, $data)
60 $insuranceCompanyValidationResult = $this->insuranceCompanyService->validate($data);
61 $insuranceCompanyValidationHandlerResult = RestControllerHelper::validationHandler($insuranceCompanyValidationResult);
62 if (is_array($insuranceCompanyValidationHandlerResult)) {
63 return $insuranceCompanyValidationHandlerResult; }
65 $addressValidationResult = $this->addressService->validate($data);
66 $addressValidationHandlerResult = RestControllerHelper::validationHandler($addressValidationResult);
67 if (is_array($addressValidationHandlerResult)) {
68 return $addressValidationHandlerResult; }
70 $serviceResult = $this->insuranceCompanyService->update($data, $iid);
71 return RestControllerHelper::responseHandler($serviceResult, array('iid' => $iid), 200);