forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsuranceCompanyRestController.php
83 lines (69 loc) · 3.09 KB
/
InsuranceCompanyRestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* InsuranceCompanyRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <[email protected]>
* @copyright Copyright (c) 2018 Matthew Vita <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\RestControllers\RestControllerHelper;
use OpenEMR\Services\AddressService;
use OpenEMR\Services\InsuranceCompanyService;
class InsuranceCompanyRestController
{
private $insuranceCompanyService;
private $addressService;
public function __construct()
{
$this->insuranceCompanyService = new InsuranceCompanyService();
$this->addressService = new AddressService();
}
public function getAll()
{
$serviceResult = $this->insuranceCompanyService->getAll();
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getOne($iid)
{
$serviceResult = $this->insuranceCompanyService->getOne($iid);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getInsuranceTypes()
{
$serviceResult = $this->insuranceCompanyService->getInsuranceTypes();
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function post($data)
{
$insuranceCompanyValidationResult = $this->insuranceCompanyService->validate($data);
$insuranceCompanyValidationHandlerResult = RestControllerHelper::validationHandler($insuranceCompanyValidationResult);
if (is_array($insuranceCompanyValidationHandlerResult)) {
return $insuranceCompanyValidationHandlerResult;
}
$addressValidationResult = $this->addressService->validate($data);
$addressValidationHandlerResult = RestControllerHelper::validationHandler($addressValidationResult);
if (is_array($addressValidationHandlerResult)) {
return $addressValidationHandlerResult;
}
$serviceResult = $this->insuranceCompanyService->insert($data);
return RestControllerHelper::responseHandler($serviceResult, array('iid' => $serviceResult), 201);
}
public function put($iid, $data)
{
$insuranceCompanyValidationResult = $this->insuranceCompanyService->validate($data);
$insuranceCompanyValidationHandlerResult = RestControllerHelper::validationHandler($insuranceCompanyValidationResult);
if (is_array($insuranceCompanyValidationHandlerResult)) {
return $insuranceCompanyValidationHandlerResult;
}
$addressValidationResult = $this->addressService->validate($data);
$addressValidationHandlerResult = RestControllerHelper::validationHandler($addressValidationResult);
if (is_array($addressValidationHandlerResult)) {
return $addressValidationHandlerResult;
}
$serviceResult = $this->insuranceCompanyService->update($data, $iid);
return RestControllerHelper::responseHandler($serviceResult, array('iid' => $iid), 200);
}
}