forked from hapifhir/hapi-hl7v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_non_hapi.html
471 lines (374 loc) · 16.9 KB
/
doc_non_hapi.html
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.7.4 at 2017-06-23
| Rendered using Apache Maven Fluido Skin 1.6
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="James Agnew" />
<meta name="Date-Revision-yyyymmdd" content="20170623" />
<meta http-equiv="Content-Language" content="en" />
<title>HAPI – HL7 over HTTP - API for non-HAPI users</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.6.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/apache-maven-fluido-1.6.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left"><a href="https://hapifhir.github.io/hapi-hl7v2/hapi-hl7overhttp" id="bannerLeft"><img src="images/hapi_hoh_banner.png" alt="HAPI - HL7 over HTTP"/></a></div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2017-06-23<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 2.3<span class="divider">|</span></li>
<li class=""><a href="https://hapifhir.github.io/hapi-hl7v2/" class="externalLink" title="HAPI">HAPI</a><span class="divider">/</span></li>
<li class="active ">HL7 over HTTP - API for non-HAPI users</li>
<li class="pull-right"><span class="divider">|</span>
<a href="http://www.uhn.ca/" class="externalLink" title="University Health Network">University Health Network</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="http://hl7.org/" class="externalLink" title="hl7.org">hl7.org</a></li>
<li class="pull-right"><a href="https://github.com/hapifhir/hapi-hl7v2" class="externalLink" title="GitHub Project Page">GitHub Project Page</a></li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">HAPI</li>
<li><a href="../index.html" title="← HAPI Home"><span class="none"></span>← HAPI Home</a> </li>
<li class="nav-header">HL7 over HTTP</li>
<li><a href="index.html" title="Home"><span class="none"></span>Home</a> </li>
<li><a href="specification.html" title="Specification"><span class="none"></span>Specification</a> </li>
<li class="nav-header">Documentation (Java)</li>
<li><a href="doc_hapi.html" title="For HAPI Users"><span class="none"></span>For HAPI Users</a> </li>
<li class="active"><a href="#"><span class="none"></span>For Non-HAPI Users</a>
</li>
<li><a href="encryption.html" title="Security Profile"><span class="none"></span>Security Profile</a> </li>
<li><a href="signature.html" title="Signature Profile"><span class="none"></span>Signature Profile</a> </li>
<li><a href="apidocs/index.html" title="JavaDocs"><span class="none"></span>JavaDocs</a> </li>
<li><a href="xref/index.html" title="Source Xref"><span class="none"></span>Source Xref</a> </li>
<li class="nav-header">Documentation (Relay)</li>
<li><a href="relay_intro.html" title="Description"><span class="none"></span>Description</a> </li>
<li><a href="relay_install.html" title="Installation"><span class="none"></span>Installation</a> </li>
<li><a href="relay_config.html" title="Configuration"><span class="none"></span>Configuration</a> </li>
<li class="nav-header">Documentation (Keys)</li>
<li><a href="cryptography_and_keystores.html" title="Cryptography 101"><span class="none"></span>Cryptography 101</a> </li>
<li><a href="generating_selfsigned_keys.html" title="Creating Keys"><span class="none"></span>Creating Keys</a> </li>
<li><a href="creating_keystores_by_importing.html" title="Importing Keys"><span class="none"></span>Importing Keys</a> </li>
<li class="nav-header">Testing</li>
<li><a href="testpanel.html" title="TestPanel"><span class="none"></span>TestPanel</a> </li>
<li class="nav-header">More Information</li>
<li><a href="license.html" title="License"><span class="none"></span>License</a> </li>
<li class="nav-header">Developer</li>
<li><a href="cobertura/index.html" title="Cobertura"><span class="none"></span>Cobertura</a> </li>
<li><a href="surefire-report.html" title="Surefire"><span class="none"></span>Surefire</a> </li>
<li><a href="taglist.html" title="Tag List"><span class="none"></span>Tag List</a> </li>
</ul>
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="./" title="Built with Maven 2" class="builtBy"><img class="builtBy" alt="Built with Maven 2" src="../images/logos/maven-feather.png" /></a>
</div>
</div>
</div>
<div id="bodyColumn" class="span10" >
<div class="section">
<h2><a name="Java_API_for_Non-HAPI_Users"></a>Java API for Non-HAPI Users</h2>
<p>
The HL7 over HTTP (HoH) library is a Java based library that provides
an implementation of the
<a href="specification.html">HoH Specification</a>
suitable for use in applications that do not use other parts of
the
<a href="../">HAPI</a>
library.
</p>
<p>
Our purpose is to encourage broad adoption of the HoH transport protocol.
For that reason, this library has been licensed under the very permissive
<a class="externalLink" href="http://www.apache.org/licenses/LICENSE-2.0.txt">Apache Software License</a>.
You are permitted to use the library in your software for free, and are
under no obligations to preserve the license if you wish to reuse or modify
parts of the code in your own applications. Naturally, we would still like to
hear about your successes!
</p>
<div class="section">
<h3><a name="Contents"></a>Contents</h3>
<ul>
<li><a href="#Sending_Messages">Sending Messages</a>
<ul>
<li><a href="#Encryption_Profile">Encryption Profile</a></li></ul></li></ul>
<ul>
<li><a href="#Receiving_Messages">Receiving Messages</a>
<ul>
<li><a href="#Embedding_a_Servlet_Container">Embedding a Servlet Container</a></li></ul></li></ul>
</div>
<div class="section">
<h3><a name="Installing"></a>Installing</h3>
<p>
Maven users may simply add a reference to the library using
the following dependency:
</p>
<div class="source"><pre class="prettyprint"><dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-hl7overhttp</artifactId>
<version>2.3</version>
</dependency></pre></div>
<p>
Non-maven users may download a binary version of the library from
the
<a class="externalLink" href="http://sourceforge.net/projects/hl7api/files/hapi-hl7overhttp/">downloads area</a>.
</p>
<p>
In both cases, the only external dependency that is absolutely required
is
<a class="externalLink" href="http://wwww.slf4j.org">SLF4J</a> (a logging framework which delegates logging messages
to an underlying framework of your choosing, such as LOG4J or JDK1.4 Logging).
<b>There is no dependency on the regular HAPI library</b>
if you are not using other HAPI features!
</p>
</div>
</div>
<div class="section">
<h2><a name="Sending_Messages"></a>Sending Messages</h2>
<p>
To send a raw HL7 message, you first need a raw message, in
string form. Naturally you can use HAPI to create this, but this
document is for users who don't use HAPI.
</p>
<p>
Next, you need a
<a href="apidocs/ca/uhn/hl7v2/hoh/raw/client/AbstractRawClient.html">Raw Client</a>.
The basic implementation is
<a href="apidocs/ca/uhn/hl7v2/hoh/raw/client/HohRawClientSimple.html">HohRawClientSimple</a>,
which is a single threaded message sender, suitable for running embedded
in JEE containers, interface engines, ESBs, etc.
</p>
<p>
The following example shows how to use HohRawClientSimple to send messages.
</p>
<div class="source"><pre class="prettyprint">/*
* http://localhost:8080/AppContext
*/
String host = "localhost";
int port = 8080;
String uri = "/AppContext";
// Create a client
HohRawClientSimple client = new HohRawClientSimple(host, port, uri);
// Optionally, if credentials should be sent, they
// can be provided using a credential callback
IAuthorizationClientCallback authCalback = new SingleCredentialClientCallback("ausername", "somepassword");
client.setAuthorizationCallback(authCalback);
// The ISendable defines the object that provides the actual
// message to send
String message =
"MSH|^~\\&|||||200803051508||ADT^A31|2|P|2.5\r" +
"EVN||200803051509\r" +
"PID|||ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103\r";
ISendable sendable = new RawSendable(message);
try {
// sendAndReceive actually sends the message
IReceivable<String> receivable = client.sendAndReceive(sendable);
// receivavle.getRawMessage() provides the response
System.out.println("Response was:\n" + receivable.getRawMessage());
// IReceivable also stores metadata about the message
String remoteHostIp = (String) receivable.getMetadata().get(MessageMetadataKeys.REMOTE_HOST_ADDRESS);
System.out.println("From:\n" + remoteHostIp);
} catch (DecodeException e) {
// Thrown if the response can't be read
e.printStackTrace();
} catch (IOException e) {
// Thrown if communication fails
e.printStackTrace();
} catch (EncodeException e) {
// Thrown if the message can't be encoded (generally a programming bug)
e.printStackTrace();
}
</pre></div>
<div class="section">
<h3><a name="Encryption_Profile"></a>Encryption Profile</h3>
<p>
In order to support HL7 over HTTP Encryption profile, a
<a href="apidocs/ca/uhn/hl7v2/hoh/sockets/ISocketFactory.html">socket factory</a>
must be provided, like this:
</p>
<div class="source"><pre class="prettyprint">// Create a client
HohRawClientSimple client = new HohRawClientSimple(host, port, uri);
// Set the socket factory to use TLS
client.setSocketFactory(new TlsSocketFactory());</pre></div>
<p>
See the
<a href="encryption.html">Encryption Profile</a>
page for information on different ways to support encryption profile.
</p>
</div>
</div>
<div class="section">
<h2><a name="Receiving_Messages"></a>Receiving Messages</h2>
<p>
HAPI HL7 over HTTP provides a
Servlet
implementation which can be used to receive HL7
messages within a normal Servlet container (e.g. JBOSS, Tomcat, Websphere AS, etc.)
</p>
<p>
The simplest way to take advantage of the HoH Servlet
functionality is to create your own Servlet which extends
<a href="apidocs/ca/uhn/hl7v2/hoh/raw/server/HohRawServlet.html">HohRawServlet</a>.
Here is an example:
</p>
<div class="source"><pre class="prettyprint">/**
* This class illustrates an example HL7 over HTTP
* raw message servlet for receiving and responding to messages
*/
public class ExampleRawHl7OverHttpServlet extends HohRawServlet {
/**
* Constructor
*/
public ExampleRawHl7OverHttpServlet() {
/*
* The servlet must be provided an implementation
* of IMessageHandler<String>, such as the one which
* is nested below
*/
setMessageHandler(new ExampleMessageHandler());
/*
* Optionally, if we want to verify HTTP authentication,
* we can specify an authorization callback
*/
IAuthorizationServerCallback callback =
new SingleCredentialServerCallback("someusername", "apassword");
setAuthorizationCallback(callback);
}
/**
* IMessageHandler defines the interface for the class which receives
* and processes messages which come in
*/
private static class ExampleMessageHandler implements IMessageHandler<String> {
/**
* This method is fired every time a message is received. The return value
* contains the HL7 response value
*/
public IResponseSendable<String> messageReceived(IReceivable<String> theReceived)
throws MessageProcessingException {
String incomingRawMsg = theReceived.getRawMessage();
System.out.println("Received message:\n" + incomingRawMsg);
// ... do some processing ...
/*
* Your application should generate an appropriate
* HL7 ACK message here
*/
String ack = "MSH|.....";
/*
* If something goes horribly wrong, you can throw an
* exception and an HTTP 500 error will be generated.
* However, it is preferable to return a normal HL7 ACK
* message with an "AE" response code to note an error.
*/
boolean somethingFailed = false;
if (somethingFailed) {
throw new MessageProcessingException("");
}
// Return the raw response message
return new RawSendable(ack);
}
}
}</pre></div>
<p>
The servlet may then be placed in a servlet container using a
normal web.xml file, such as this one:
</p>
<div class="source"><pre class="prettyprint"><web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>hl7_listener</servlet-name>
<servlet-class>ca.uhn.hl7v2.examples.hoh.ExampleRawHl7OverHttpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hl7_listener</servlet-name>
<url-pattern>/hl7list</url-pattern>
</servlet-mapping>
</web-app></pre></div>
<div class="section">
<h3><a name="Embedding_a_Servlet_Container"></a>Embedding a Servlet Container</h3>
<p>
If your application does not already have a servlet
container, it may be appropriate to embed a simple one
in your application in order to receive messages. This
is generally not a good idea within a JEE container (since
the JEE specification doesn't allow applications which
manage their own threads), but may be appropriate within
a standalone application.
</p>
<p>
There are several great embeddable servlet containers which
may be used, but a commonly used one is
Jetty. The following example shows how to start a Jetty
server listening for HL7 messages and processing them using
a servlet like the one above.
</p>
<div class="source"><pre class="prettyprint">// The port to listen on
int port = 8080;
// Create a Jetty server instance
Server server = new Server(port);
Context context = new Context(server, "/Hl7Listener", Context.SESSIONS);
Servlet servlet = new ExampleRawHl7OverHttpServlet();
/*
* Adds the servlet to listen at
* http://localhost:8080/Hl7Listener/Incoming
*/
context.addServlet(new ServletHolder(servlet), "/Incoming");
// Start the server
server.start();
// .. let the application run ..
/*
* Later it will probably be appropriate to shut the server
* down.
*/
server.stop();</pre></div>
<p>
Note that doing this requires that you have Jetty-Embedded
on your classpath. Maven users may do this using a single
dependency block:
</p>
<div class="source"><pre class="prettyprint"><dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-embedded</artifactId>
<version>6.1.26</version>
<optional>true</optional>
</dependency></pre></div>
</div>
</div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>Copyright ©2012–2017
<a href="http://www.uhn.ca">University Health Network</a>.
All rights reserved.</p>
</div>
</div>
</footer>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-1395874-4");
pageTracker._trackPageview();
} catch(err) {}</script>
</body >
</html>