forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacilityRestController.php
101 lines (89 loc) · 3.14 KB
/
FacilityRestController.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* FacilityRestController
*
* @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\FacilityService;
use OpenEMR\RestControllers\RestControllerHelper;
class FacilityRestController
{
private $facilityService;
/**
* White list of facility search fields
*/
private const WHITELISTED_FIELDS = array(
"name",
"phone",
"fax",
"street",
"city",
"state",
"postal_code",
"country_code",
"federal_ein",
"website",
"email",
"domain_identifier",
"facility_npi",
"facility_taxonomy",
"facility_code",
"billing_location",
"accepts_assignment",
"oid",
"service_location"
);
public function __construct()
{
$this->facilityService = new FacilityService();
}
/**
* Fetches a single facility resource by id.
* @param $uuid - The facility uuid identifier in string format.
*/
public function getOne($uuid)
{
$processingResult = $this->facilityService->getOne($uuid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Returns facility resources which match an optional search criteria.
*/
public function getAll($search = array())
{
$validSearchFields = $this->facilityService->filterData($search, self::WHITELISTED_FIELDS);
$processingResult = $this->facilityService->getAll($validSearchFields);
return RestControllerHelper::handleProcessingResult($processingResult, 200, true);
}
/**
* Process a HTTP POST request used to create a facility record.
* @param $data - array of facility fields.
* @return a 201/Created status code and the facility identifier if successful.
*/
public function post($data)
{
$filteredData = $this->facilityService->filterData($data, self::WHITELISTED_FIELDS);
$processingResult = $this->facilityService->insert($filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 201);
}
/**
* Processes a HTTP PUT request used to update an existing facility record.
* @param $puuidString - The facility uuid identifier in string format.
* @param $data - array of facility fields (full resource).
* @return a 200/Ok status code and the facility resource.
*/
public function patch($uuid, $data)
{
$filteredData = $this->facilityService->filterData($data, self::WHITELISTED_FIELDS);
$processingResult = $this->facilityService->update($uuid, $filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
}