Repository navigation
Expand file tree
/
Copy pathscope_resources.php
More file actions
66 lines (57 loc) · 1.94 KB
/
Copy pathscope_resources.php
File metadata and controls
66 lines (57 loc) · 1.94 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
<?php
// scope_resources.php
session_start();
// Guarded: this file answers JSON, and an "Undefined array key" notice would be emitted
// into the response body, breaking the parse rather than producing a readable error.
if (!empty($_GET['api_site'])) {
$api_site = $_GET['api_site'];
$_SESSION['selectedSite'] = $api_site;
}
require_once 'config.php';
$scopes = null;
$fhir = [];
$standard = [];
$public = [];
// Fallback: use known scopes if not set
if (!$scopes) {
$scopes = '';
$grantType = $_GET['grant_type'] ?? '';
$clientType = $_GET['client_type'] ?? '';
if ($grantType === 'client_credentials') {
$scopes = SYSTEM_SCOPES;
} elseif ($clientType === 'smart') {
$scopes = SMART_SCOPES;
} elseif ($clientType === 'public') {
$scopes = PUBLIC_SCOPES;
} else {
$scopes = LIMITED_SCOPES;
}
}
// Detect FHIR/standard resources from legacy and SMART v2 granular scopes.
preg_match_all('/(?:user|system|patient)\/([A-Za-z][A-Za-z0-9]*)\.(?:read|r|rs|crus|cruds)/', $scopes, $matches);
foreach ($matches[1] as $resource) {
if (ctype_upper($resource[0])) {
$fhir[] = $resource;
} else {
$standard[] = $resource;
}
}
// If system grant, include $export scopes as FHIR resources
if (($_GET['grant_type'] ?? '') === 'client_credentials') {
preg_match_all('/system\/([A-Za-z*]+)\.\$export/', SYSTEM_SCOPES, $matchesExport);
foreach ($matchesExport[1] as $res) {
// Group/$export needs a real group id; the Bulk $export panel lists them and runs it.
if ($res === 'Group') {
continue;
}
$fhir[] = ($res === '*') ? '$export' : "$res/\$export";
}
}
// Public
preg_match_all('/patient\/([A-Za-z]+)\.read/', PUBLIC_SCOPES, $matchesPublic);
$public = array_unique($matchesPublic[1]);
echo json_encode([
'fhir' => array_values(array_unique($fhir)),
'standard' => array_values(array_unique($standard)),
'public' => $public,
]);