-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFhirCrudServlet.java
357 lines (297 loc) · 12.6 KB
/
FhirCrudServlet.java
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
/**
* Servlet implementation class FhirCrudServlet
*/
@WebServlet("/FhirCrudServlet")
public class FhirCrudServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FhirCrudServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//String serverURL=request.getParameter("server");
//try
//{
// String filename= "C:/Users/Phil standard/My Documents/ServerURL.txt";
//String filename="/home/phil/fhir/ServerURL.txt";
// FileWriter fw = new FileWriter(filename,false); //the false doesnt append the new data
// fw.write(serverURL);
// fw.close();
//}
//catch(IOException ioe)
//{
//System.err.println("IOException: " + ioe.getMessage());
//}
ServletContext context = getServletContext();
PrintWriter out = response.getWriter();
response.setContentType("text/html");
//get fields from .jsp
String crudResponse=request.getParameter("crud");
if(crudResponse.equals("addAPatient")) {
//HapiFhirPatient.createPatient(true);
response.sendRedirect("patient.jsp");
}
if(crudResponse.equals("addAPractitioner")) {
//HapiFhirPatient.createPatient(true);
response.sendRedirect("practitioner.jsp");
}
if(crudResponse.equals("listPatient")) {
response.sendRedirect("listPatients.jsp");
}
if(crudResponse.equals("listPractitioners")) {
ArrayList<String> listPracId = new ArrayList<String>();
ArrayList<String> listPracFamilyName = new ArrayList<String>();
ArrayList<String> listPracGiven = new ArrayList<String>();
MultiValuedMap<String, String> qualification = new HashSetValuedHashMap<String,String>();
String message = null;
SearchPatient.listPractitioners();
listPracId.addAll(SearchPatient.practitionerListId);
listPracFamilyName.addAll(SearchPatient.practitionerListFamilyName);
listPracGiven.addAll(SearchPatient.practitionerListGiven);
qualification=(SearchPatient.practitionerListDiscipline);
try {
SearchPatient.listPractitioners();
listPracId=(SearchPatient.practitionerListId);
listPracFamilyName=(SearchPatient.practitionerListFamilyName);
listPracGiven=(SearchPatient.practitionerListGiven);
qualification=(SearchPatient.practitionerListDiscipline);
message=SearchPatient.message;
} catch (Exception e) {
System.out.println(e.getMessage());
}
out.println(
" \r\n" +
" \r\n" +
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n" +
"\r\n" +
" \r\n" +
"<html>\r\n" +
"<script type=\"text/javascript\">\r\n" +
"\r\n" +
"//input the user data page\r\n" +
"\r\n" +
"\r\n" +
"//validate fields for acuity max 16 min 0\r\n" +
"function minmax(value) \r\n" +
"{\r\n" +
" \r\n" +
" if(parseInt(value) < 0 || isNaN(parseInt(value))) \r\n" +
" return \"\"; \r\n" +
" else if(parseInt(value) > 16) \r\n" +
" return 16; \r\n" +
" else return value;\r\n" +
"}\r\n" +
"//validate fields for not empty\r\n" +
"window.onload = function () {\r\n" +
" var form = document.getElementById('patientForm');\r\n" +
" form.button.onclick = function (){\r\n" +
" for(var i=0; i < form.elements.length; i++){\r\n" +
" if(form.elements[i].value === '' && form.elements[i].hasAttribute('required')){\r\n" +
" alert('There are some required fields!');\r\n" +
" return false;\r\n" +
" }\r\n" +
" }\r\n" +
" }; \r\n" +
" };\r\n" +
"</script>\r\n" +
"\r\n" +
"<head>\r\n" +
"<!-- Global site tag (gtag.js) - Google Analytics -->\r\n" +
"<script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-111678682-1\"></script>\r\n" +
"<script>\r\n" +
" window.dataLayer = window.dataLayer || [];\r\n" +
" function gtag(){dataLayer.push(arguments);}\r\n" +
" gtag('js', new Date());\r\n" +
"\r\n" +
" gtag('config', 'UA-111678682-1');\r\n" +
" \r\n" +
" \r\n" +
"</script>\r\n" +
"\r\n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\r\n" +
"<title>Hapi Fhir client</title>\r\n" +
"<link type=\"text/css\" rel=\"stylesheet\" href=\""+request.getContextPath()+ "/style/drop.css\">\r\n" +
"<link rel=\"stylesheet\" type=\"text/css\" href=\"https://fonts.googleapis.com/css?family=Open+Sans|Space+Mono\">\r\n" +
"<link href=\"https://fonts.googleapis.com/css?family=Open+Sans|Space+Mono\" rel=\"stylesheet\">\r\n" +
"</head>\r\n" +
"<body background=\""+request.getContextPath()+ "/images/rockBackground.gif\">\r\n" +
"<script language=\"javascript\" type=\"text/javascript\"></script>\r\n" +
"\r\n" +
"<table border=\"0\" align=\"center\" width=\"1000\">\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"<tr>\r\n" +
"<td><img src=\""+request.getContextPath()+ "/images/banner1.jpg\"></td>\r\n" +
"</tr>\r\n" +
"\r\n" +
" <tr>\r\n" +
" <td colspan=\"2\" bgcolor=\"#a7c7fc\">\r\n" +
"<div align=\"center\" class=\"menu-wrap\">\r\n" +
"\r\n" +
" <nav class=\"menu\">\r\n" +
" <ul class=\"clearfix\">\r\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/index.jsp\">Home</a></li>\n" +
" <li>\n" +
" <a href=\"#\">Demonstrations <span class=\"arrow\">▼</span></a>\n" +
" \n" +
" <ul class=\"sub-menu\">\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/out.jsp\">ICD-10AM search</a></li>\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/reasoning.jsp\">AI Reasoning</a></li>\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/IcnpInitServlet\">ICNP text suggester</a></li> \n" +
" <li><a href=\"http://114.142.160.89:8080/ic/jsonindex.jsp\">JSON and FHIR</a></li> \n" +
" </ul>\n" +
" </li>\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/about.jsp\">About</a></li>\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/contact.jsp\">Contact</a></li>\n" +
" <li> <a href=\"http://114.142.160.89:8080/ic/publications.jsp\">Publications</a></li>\n" +
" <li><a href=\"http://114.142.160.89:8080/ic/whatis.jsp\">What's an ontology?</a></li>\n"+
" </ul>\r\n" +
" </nav>\r\n" +
" \r\n" +
"</div>\r\n" +
"</td>\r\n" +
"</tr>\r\n" +
"</table>\r\n" +
"\r\n" +
"\r\n" +
"<form name=\"queryForm\" id=\"patientForm\" method=\"post\" action=\"FhirCrudServlet\">\r\n" +
"\r\n" +
"<p>\r\n" +
"\r\n" +
"<c:set var=\"qualificationCount\" value=\"0\" scope=\"page\" />\r\n" +
"\r\n" +
"<div align=\"left\">\r\n" +
" <center>\r\n" +
" <table border=\"1\" width=\"1000\" bgcolor=\"lightblue\">\r\n" +
" <tr>\r\n" +
" <td width=\"500\" valign=\"top\">\r\n" +
" <b><font color=\"blue\">Do things with patients and practitioners</font></b><p><br>\r\n" +
"\r\n" +
"<b><font color = \"red\">");
out.println(message);
out.println("</font></b><br><p>\r\n" +
" <p>\r\n" +
"\r\n" +
"<p>"+
"<div>\r\n" +
"<b><font color=\"blue\">Create</font></b><br>\r\n" +
"\r\n" +
"<input type = \"radio\" name=\"crud\" value=\"addAPatient\">Add a patient<br>\r\n" +
"<p>\r\n" +
"<p>\r\n" +
"<input type = \"radio\" name=\"crud\" value=\"addAPractitioner\">Add a practitioner<br>\r\n" +
"<p>\r\n" +
"<p>\r\n" +
" \r\n" +
" <b><font color=\"blue\">Search</font></b><br>\r\n" +
" <input type = \"radio\" name=\"crud\" value=\"searchAPatient\">Display a patient using id number<br>\r\n" +
"<p>\r\n" +
"<input type = \"radio\" name=\"crud\" value=\"searchAPractitioner\">Display a practitioner using id number<br>\r\n" +
"<p>\r\n" +
" \r\n" +
" <input type = \"radio\" name=\"crud\" value=\"listPatient\">List patients with the surname<br>\r\n" +
"\r\n" +
"<p>\r\n" +
"<input type = \"radio\" name=\"crud\" value=\"listPractitioners\">List practitioners<br>\r\n" +
" <p>\r\n" +
"<p>\r\n" +
" \r\n" +
"\r\n" +
" \r\n" +
" \r\n" +
"</div>\r\n" +
"</td>\r\n" +
" <td width=\"500\" valign=\"top\">\r\n" +
" \r\n" +
" <textarea readonly name=\"listResults\" id= \"listTxtArea\" style=\"width:500px; height:250px;\" rows=\"2\" cols=\"10\">\r\n" +
" \r\n" +
" </textarea>\r\n" +
" <textarea readonly name=\"listPrac\" id= \"listPrac\" style=\"width:500px; height:250px;\" rows=\"2\" cols=\"10\">\r\n" +
" \r\n" );
for(int i=0; i<listPracId.size();i++) {
out.println(listPracId.get(i));
out.println(listPracGiven.get(i));
out.println(listPracFamilyName.get(i));
for (Entry<String, String> entry : qualification.entries()) {
if(listPracId.get(i)==entry.getKey()) {
out.println("Qualification = " + entry.getValue());
}
}
out.println("--------------");
out.println("");
out.println("");
}
out.println(" \r\n" +
" \r\n"+
" </textarea>\r\n" +
" </td> \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
"</tr>\r\n" +
"\r\n" +
"<tr>\r\n" +
"<td width= \"1000\">\r\n" +
" <input type=\"submit\" value=\"Submit\" name=\"aScores\"><input type=\"reset\" value=\"Reset\" name=\"B2\"> \r\n" +
"</td>\r\n" +
"</tr>\r\n" +
"\r\n" +
" </table>\r\n" +
" \r\n" +
" \r\n" +
" </center>\r\n" +
"</div>\r\n" +
"\r\n" +
"</form>\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"<p align=\"center\"><a href=\""+request.getContextPath()+"/http://114.142.160.89:8080/hapi-fhir-jpaserver/\">HAPI-FHIR server</a>\r\n" +
"application.</p>\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"</body>\r\n" +
"\r\n"
);
}
if(crudResponse.equals("searchAPatient")) {
//SearchPatient.listPractitioners(); //load up practitioner array for later use
response.sendRedirect("findPatient.jsp");
//get fields from index.jsp
}
if(crudResponse.equals("searchAPractitioner")) {
response.sendRedirect("findPractitioner.jsp");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}