This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resourcelister.php
159 lines (137 loc) · 3.94 KB
/
resourcelister.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/*
* resourcelister
*
* Lists selected FHIR resource types from a FHIR endpoint
*/
// load configuration and initialize
require_once './config.inc.php';
$errors = [];
$outputData = [];
// retrieve data
foreach ($cfgFhirEndpoints as $endpoint) {
foreach ($cfgResources as $resource) {
// build URL
list($url, $isExtension) = buildUrl($endpoint['base'], $resource);
// connect and get the data
if (! $ch = curl_init($url)) {
$errors[] = "$url: Could not init connection!";
continue;
}
curl_setopt($ch, CURLOPT_HTTPHEADER,[
'Content-Type: application/fhir+json',
'Accept: application/fhir+json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsonData = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatus) {
$errors[] = "$url: HTTP status $httpStatus";
continue;
}
// TODO yes, we could do some more error handling here
$data = json_decode($jsonData);
// workaround for Simplifier bug
if ($isExtension) {
$data = filterForExtensions($data);
}
// disconnect
curl_close($ch);
// store relevant data
foreach ($data->entry as $entry) {
$outputData[] = [
'endpoint' => $endpoint,
'fullUrl' => $entry->fullUrl,
'resource' => $entry->resource
];
}
}
}
////////////////////////////////////////////////////////////////////////////////
// builds an URL
function buildUrl($base, $resource) {
$isExtension = false; // workaround for Simplifier bug
$url = $base . '/' . $resource['resource'] . '?';
if ('StructureDefinition' === $resource['resource']) {
if (! empty($resource['type'])) {
if ('Extension' === $resource['type']) {
$isExtension = true; // workaround for Simplifier bug
} else {
$url .= 'type=' . $resource['type'] . '&';
}
}
}
$url .= '_count=100000';
return [$url, $isExtension];
}
////////////////////////////////////////////////////////////////////////////////
// filters out extensions from a Bundle of StructureDefinitions
function filterForExtensions($data) {
foreach ($data->entry as $i => $entry) {
if ('StructureDefinition' !== $entry->resource->resourceType) {
unset($data->entry[$i]);
continue;
}
if ('Extension' !== $entry->resource->type) {
unset($data->entry[$i]);
continue;
}
}
return $data;
}
////////////////////////////////////////////////////////////////////////////////
// output
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>resourcelister</title>
<link rel="stylesheet" href="./resourcelister.css" />
</head>
<body>
<?php if (0 < count($errors)): ?>
<h1>Errors</h1>
<ul>
<?php foreach ($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<h1>Resources</h1>
<table>
<thead>
<tr>
<th>title</th>
<th>canonical URL</th>
<th>version</th>
<th>status</th>
<th>experimental</th>
<th>fhirVersion</th>
<th>description</th>
<th>contextType</th>
<th>context</th>
<th>project</th>
<th>publisher</th>
</tr>
</thead>
<tbody>
<?php foreach ($outputData as $cur): ?>
<tr>
<td><a href="<?php echo $cur['fullUrl']; ?>"><?php echo $cur['resource']->title; ?></a></td>
<td><a href="<?php echo $cur['resource']->url; ?>"><?php echo $cur['resource']->url; ?></a></td>
<td><?php echo $cur['resource']->version; ?></td>
<td><?php echo $cur['resource']->status; ?></td>
<td><?php echo $cur['resource']->experimental; ?></td>
<td><?php echo $cur['resource']->fhirVersion; ?></td>
<td><?php echo $cur['resource']->description; ?></td>
<td><?php echo $cur['resource']->contextType; ?></td>
<td><?php echo implode(', ', $cur['resource']->context); ?></td>
<td><?php echo $cur['endpoint']['name']; ?></td>
<td><?php echo $cur['resource']->publisher; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>