forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListRestController.php
82 lines (66 loc) · 2.58 KB
/
ListRestController.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
<?php
/**
* ListRestController
*
* @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\Services\ListService;
use OpenEMR\RestControllers\RestControllerHelper;
class ListRestController
{
private $listService;
public function __construct()
{
$this->listService = new ListService();
}
public function getAll($pid, $list_type)
{
$serviceResult = $this->listService->getAll($pid, $list_type);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getOne($pid, $list_type, $list_id)
{
$serviceResult = $this->listService->getOne($pid, $list_type, $list_id);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function getOptions($list_name)
{
$serviceResult = $this->listService->getOptionsByListName($list_name);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function post($pid, $list_type, $data)
{
$data['type'] = $list_type;
$data['pid'] = $pid;
$validationResult = $this->listService->validate($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->listService->insert($data);
return RestControllerHelper::responseHandler($serviceResult, array('id' => $serviceResult), 201);
}
public function put($pid, $list_id, $list_type, $data)
{
$data['type'] = $list_type;
$data['pid'] = $pid;
$data['id'] = $list_id;
$validationResult = $this->listService->validate($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->listService->update($data);
return RestControllerHelper::responseHandler($serviceResult, array('id' => $list_id), 200);
}
public function delete($pid, $list_id, $list_type)
{
$serviceResult = $this->listService->delete($pid, $list_id, $list_type);
return RestControllerHelper::responseHandler($serviceResult, true, 200);
}
}