-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.html
More file actions
197 lines (171 loc) · 6.76 KB
/
search.html
File metadata and controls
197 lines (171 loc) · 6.76 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Searching FHIR Patients</title>
<link rel="icon" href="static/styles/common/favicon.ico" />
<script src="static/styles/common/jquery/jquery.min.js"></script>
<script src="static/styles/common/bootstrap/bootstrap.min.js"></script>
<link rel="stylesheet" href="static/styles/common/main.min.css" />
<link rel="stylesheet" href="static/styles/common/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="static/styles/common/rendering/rendering.min.css" />
<script src="static/styles/common/rendering/stu3TreeTable.min.js"></script>
<script src="static/styles/common/rendering/baseTreetable.min.js"></script>
<link rel="stylesheet" href="static/styles/twolevelmenu/style.css?v=1da42fd98e2a000" />
<script src="https://cdn.jsdelivr.net/npm/fhirclient/build/fhir-client.js"></script>
</head>
<body>
<div id="ig-viewer">
<div class="ig-view-content">
<div id="ig-view-twolevelmenu">
<div class="header" role="banner" aria-label="Header">
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">
Training exercises
</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Select <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="retrieve.html">
Retrieve a Patient
</a>
</li>
<li>
<a href="search.html">
Create a Patient
</a>
</li>
<li>
<a href="obs.html">
Add an bundle
</a>
</li>
<li>
<a href="search.html">
Search for Patients
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div class="content container" role="main" aria-label="Main content">
<div class="row">
<div class="col-md-24">
<div id="preview-content">
<h1 id="page-title">Searching FHIR Patients</h1>
Please enter a search parameter name and value, then click 'Search':<br><br>
<label for="search-param">Search parameter </label>
<input type="text" id="search-param" name="search"><br>
<label for="search-val">Search value </label>
<input type="text" id="search-val" name="search-val"><br><br>
<input type="button" id="search" value="Search" />
<br><br>
<div id="bundle"></div>
<br><br>
<input type="button" id="showBtn" value="Show JSON" hidden />
<div id="show"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ig-view-footer" role="contentinfo" aria-label="Footer">
<div class="container">
<div class="row">
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var resource = null;
function displayBundle(data) {
const output = document.getElementById("bundle");
output.innerHTML =
"<i>The Patient type was successfully searched</i><br><br>There are " + getBundleCount(data) + " results on the server.<br>" +
//"<i>The Patient type was successfully searched</i><br><br>" +
"The server has returned these results: <br>" +
getEntryInfo(data);
resource = data;
document.getElementById("show").innerText = null;
document.getElementById("showBtn").hidden = false;
}
function displayError(data) {
const output = document.getElementById("bundle");
if (data.name == "HttpError")
output.innerText = "Error: Patient could not be searched with the details entered, please check your search parameter name";
document.getElementById("showBtn").hidden = true;
document.getElementById("show").innerText = null;
}
function getBundleCount(bdl) {
return bdl.total? bdl.total : (bdl.entry? "an unknown number of": "0");
}
function getEntryInfo(bdl) {
if (bdl.entry) {
var entries = bdl.entry.map(function(entry) {
return "<li>" + getPatientName(entry.resource) + "<br><ul>" + getPatientIdentifier(entry.resource) +"</ul></li>";
});
return "<ul>"+ entries.join("") + "</ul>";
} else {
return "<i>zero results</i>";
}
}
function getPatientName (pt) {
if (pt.name) {
var names = pt.name.map(function(name) {
return name.given?.join(" ") + " " + name.family;
});
return names.join(" / ")
} else {
return "anonymous";
}
}
function getPatientIdentifier (pt) {
if (pt.identifier) {
var names = pt.identifier.map(function(identifier) {
return "<li>" + identifier.system + "|" + identifier.value + "</li>";
});
return names.join("")
} else {
return "<i>no identifiers</i>";
}
}
function showJson(res) {
const output = document.getElementById("show");
output.innerText = JSON.stringify(res, null, 4);
}
const searchBtn = document.getElementById("search");
//const client = FHIR.client("https://hapi.fhir.org/baseR4");
const client = FHIR.client("https://server.fire.ly/R4");
searchBtn.onclick = () => {
document.getElementById("bundle").innerHTML = "Loading...";
//client.request("/Patient?_total=accurate&" + document.getElementById("search-param").value +
// "=" + document.getElementById("search-val").value)
client.request("/Patient?" + document.getElementById("search-param").value +
"=" + document.getElementById("search-val").value)
.then(displayBundle)
.catch(displayError);
}
showBtn.onclick = () => {
showJson(resource);
}
</script>
</html>