forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PractitionerRestController.php
111 lines (99 loc) · 3.41 KB
/
PractitionerRestController.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
102
103
104
105
106
107
108
109
110
111
<?php
/**
* PractitionerRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <[email protected]>
* @author Yash Bothra <yashrajbothra786gmail.com>
* @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\PractitionerService;
use OpenEMR\RestControllers\RestControllerHelper;
class PractitionerRestController
{
private $practitionerService;
/**
* White list of practitioner search fields
*/
private const WHITELISTED_FIELDS = array(
"title",
"fname",
"lname",
"mname",
"federaltaxid",
"federaldrugid",
"upin",
"facility_id",
"facility",
"npi",
"email",
"specialty",
"billname",
"url",
"assistant",
"organization",
"valedictory",
"street",
"streetb",
"city",
"state",
"zip",
"phone",
"fax",
"phonew1",
"phonecell",
"notes",
"state_license_number"
);
public function __construct()
{
$this->practitionerService = new PractitionerService();
}
/**
* Fetches a single practitioner resource by id.
* @param $uuid- The practitioner uuid identifier in string format.
*/
public function getOne($uuid)
{
$processingResult = $this->practitionerService->getOne($uuid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Returns practitioner resources which match an optional search criteria.
*/
public function getAll($search = array())
{
$validSearchFields = $this->practitionerService->filterData($search, self::WHITELISTED_FIELDS);
$processingResult = $this->practitionerService->getAll($validSearchFields);
return RestControllerHelper::handleProcessingResult($processingResult, 200, true);
}
/**
* Process a HTTP POST request used to create a practitioner record.
* @param $data - array of practitioner fields.
* @return a 201/Created status code and the practitioner identifier if successful.
*/
public function post($data)
{
$filteredData = $this->practitionerService->filterData($data, self::WHITELISTED_FIELDS);
$processingResult = $this->practitionerService->insert($filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 201);
}
/**
* Processes a HTTP PATCH request used to update an existing practitioner record.
* @param $uuid - The practitioner uuid identifier in string format.
* @param $data - array of practitioner fields (full resource).
* @return a 200/Ok status code and the practitioner resource.
*/
public function patch($uuid, $data)
{
$filteredData = $this->practitionerService->filterData($data, self::WHITELISTED_FIELDS);
$processingResult = $this->practitionerService->update($uuid, $filteredData);
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
}