forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserRestController.php
More file actions
99 lines (89 loc) · 2.65 KB
/
UserRestController.php
File metadata and controls
99 lines (89 loc) · 2.65 KB
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
<?php
/**
* UserRestController - REST API for user related operations
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <matthewvita48@gmail.com>
* @author Yash Bothra <yashrajbothra786gmail.com>
* @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
* @copyright Copyright (c) 2023 Discover and Change, Inc. <snielson@discoverandchange.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\RestControllers\RestControllerHelper;
use OpenEMR\Services\PractitionerService;
use OpenEMR\Services\UserService;
use OpenEMR\Validators\ProcessingResult;
class UserRestController
{
/**
* @var UserService $userService
*/
private $userService;
/**
* White list of practitioner search fields
*/
private const WHITELISTED_FIELDS = array(
"id",
"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",
"username"
);
public function __construct()
{
$this->userService = new UserService();
}
/**
* Fetches a single user resource by id.
* @param $uuid- The user uuid identifier in string format.
*/
public function getOne($uuid)
{
$processingResult = new ProcessingResult();
$user = $this->userService->getUserByUUID($uuid);
if (!empty($user)) {
$processingResult->setData([$user]);
}
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200);
}
/**
* Returns user resources which match an optional search criteria.
*/
public function getAll($search = array())
{
$validKeys = array_combine(self::WHITELISTED_FIELDS, self::WHITELISTED_FIELDS);
$validSearchFields = array_intersect_key($search, $validKeys);
$result = $this->userService->search($validSearchFields, true);
return RestControllerHelper::handleProcessingResult($result, 200, true);
}
}