forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllergyIntoleranceRestController.php
81 lines (68 loc) · 2.62 KB
/
AllergyIntoleranceRestController.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
<?php
/**
* AllergyIntoleranceRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Yash Bothra <[email protected]>
* @copyright Copyright (c) 2020 Yash Bothra <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\Services\AllergyIntoleranceService;
use OpenEMR\RestControllers\RestControllerHelper;
class AllergyIntoleranceRestController
{
private $allergyIntoleranceService;
/**
* White list of search/insert fields
*/
private const WHITELISTED_FIELDS = array(
'title',
'begdate',
'enddate',
'diagnosis'
);
public function __construct()
{
$this->allergyIntoleranceService = new AllergyIntoleranceService();
}
/**
* Fetches a single allergyIntolerance resource by id.
* @param $uuid - The allergyIntolerance uuid identifier in string format.
*/
public function getOne($uuid)
{
$processingResult = $this->allergyIntoleranceService->getOne($uuid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Returns allergyIntolerance resources which match an optional search criteria.
*/
public function getAll($search = array())
{
$processingResult = $this->allergyIntoleranceService->getAll($search);
return RestControllerHelper::handleProcessingResult($processingResult, 200, true);
}
public function post($puuid, $data)
{
$filteredData = $this->allergyIntoleranceService->filterData($data, self::WHITELISTED_FIELDS);
$filteredData['puuid'] = $puuid;
$processingResult = $this->allergyIntoleranceService->insert($filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 201);
}
public function put($puuid, $uuid, $data)
{
$filteredData = $this->allergyIntoleranceService->filterData($data, self::WHITELISTED_FIELDS);
$processingResult = $this->allergyIntoleranceService->update($uuid, $filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
public function delete($puuid, $uuid)
{
$processingResult = $this->allergyIntoleranceService->delete($puuid, $uuid);
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
}