### Example Usage: Basic Client Setup Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/apidocs/src-html/ca/uhn/hl7v2/hoh/raw/client/HohRawClientSimple.html Demonstrates the basic setup of HohRawClientSimple, including setting the host, port, URI, and optionally configuring TLS and authentication. ```java String host = "localhost"; int port = 8080; String uri = "/AppContext"; // Create a client HohRawClientSimple client = new HohRawClientSimple(host, port, uri); // Set the socket factory to use TLS client.setSocketFactory(new TlsSocketFactory()); // 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 ``` -------------------------------- ### Main Method for Server Setup Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/sockets/CustomCertificateTlsSocketFactoryTest.html Sets up and starts an SSL server on a specific port. This method is the entry point for the server execution. ```java Server s = new Server(); SslSelectChannelConnector ssl = new SslSelectChannelConnector(); ssl.setKeystore("src/test/resources/keystore.jks"); ssl.setPassword("changeit"); ssl.setKeyPassword("changeit"); ssl.setPort(60647); s.addConnector(ssl); s.start(); ``` -------------------------------- ### Main Method for Jetty Server Setup Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/sockets/CustomCertificateTlsSocketFactoryTest.html Sets up and starts an embedded Jetty server with an SSL connector using a specified keystore and passwords. ```java public static void main(String\[\] args) throws Exception { Server s = new Server(); SslSelectChannelConnector ssl = new SslSelectChannelConnector(); ssl.setKeystore("src/test/resources/keystore.jks"); ssl.setPassword("changeit"); ssl.setKeyPassword("changeit"); ssl.setPort(60647); s.addConnector(ssl); s.start(); } ``` -------------------------------- ### Setup Test Environment Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/hapi/client/HapiClientTest.html Initializes the test environment by finding a free port, creating a server callback, and starting a test server thread. The test waits for the server to be ready before proceeding. ```java private void setUpTest() throws InterruptedException { ourPort = RandomServerPortProvider.findFreePort(); ourLog.info("Port is: {}", ourPort); ourServerCallback = new SingleCredentialServerCallback("hello", "hapiworld"); ourServerSocketThread = new ServerSocketThreadForTesting(ourPort, ourServerCallback); ourServerSocketThread.start(); ourServerSocketThread.getLatch().await(); } ``` -------------------------------- ### Setup Jetty Server and Servlet Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/raw/server/HohRawServletTest.html Configures and starts a Jetty server with a HohRawServlet. The servlet is set up with an authorization callback and a message handler. This is used for testing the servlet's behavior. ```java public void before() throws Exception { myPort = RandomServerPortProvider.findFreePort(); myServer = new Server(myPort); Context context = new Context(myServer, "/", Context.SESSIONS); HohRawServlet servlet = new HohRawRawServlet(); servlet.setAuthorizationCallback(this); servlet.setMessageHandler(this); context.addServlet(new ServletHolder(servlet), "/*"); myServer.start(); while (myServer.isStarting()) { ourLog.info("Waiting for server to start..."); Thread.sleep(100); } myResponse = null; } ``` -------------------------------- ### Setup HL7v2 over HTTP Server Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/llp/LlpServerTest.html Configures and starts a SimpleServer with an Hl7OverHttpLowerLayerProtocol. Registers the server to handle all message types and registers a connection listener. ```java myPort = RandomServerPortProvider.findFreePort(); myLlp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.SERVER); myServer = new SimpleServer(myPort, myLlp, GenericParser.getInstanceWithNoValidation()); myServer.registerApplication("*", "*", this); myServer.registerConnectionListener(this); myMessage = (Message) null; myResponse = (Message) null; myConnections = 0; ``` -------------------------------- ### Setup Server Socket Thread Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/raw/client/HohRawClientMultithreadedTest.html Sets up the server port, HL7 over HTTP lower layer protocol with client role, and authentication callback. Starts a server socket thread for testing. ```java @Before public void before() throws InterruptedException { myPort = RandomServerPortProvider.findFreePort(); myLlp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT); myLlp.setAuthorizationCallback(new SingleCredentialClientCallback("hello", "hapiworld")); ourServerCallback = new SingleCredentialServerCallback("hello", "hapiworld"); myServerSocketThread = new ServerSocketThreadForTesting(myPort, ourServerCallback); myServerSocketThread.start(); myServerSocketThread.getLatch().await(); } ``` -------------------------------- ### Start and Monitor Server Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/cobertura/ca.uhn.hl7v2.hoh.relay.listener.RelayMllpListener.html Starts the HAPI server and waits for it to become ready. It then logs the startup status and checks if the server exited with an exception, re-throwing it if necessary. ```java ourLog.info("Starting listener on port {}", myPort); myServer.startAndWait(); ourLog.info("Listener on port {} has started, and is ready for processing", myPort); if (myServer.getServiceExitedWithException() != null) { Throwable ex = myServer.getServiceExitedWithException(); ourLog.error("Server failed to start", ex); if (ex instanceof Exception) { throw (Exception) ex; } else { throw new Error(ex); } } ``` -------------------------------- ### Setup HttpSenderTest Environment Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/relay/sender/HttpSenderTest.html Initializes server ports, system properties, and a server callback for testing. This setup is required before running tests that involve network communication. ```java private int myOutPort; private ServerSocketThreadForTesting myServerSocketThread; private SingleCredentialServerCallback ourServerCallback; private int myInPort; private int myInPort2; @Before public void before() throws InterruptedException { // System.setProperty("javax.net.debug", "ssl"); myOutPort = RandomServerPortProvider.findFreePort(); myInPort = RandomServerPortProvider.findFreePort(); myInPort2 = RandomServerPortProvider.findFreePort(); System.setProperty("relay.port.out", Integer.toString(myOutPort)); System.setProperty("relay.port.in", Integer.toString(myInPort)); System.setProperty("relay.port.in.2", Integer.toString(myInPort2)); ourServerCallback = new SingleCredentialServerCallback("hello", "hapiworld"); myServerSocketThread = new ServerSocketThreadForTesting(myOutPort, ourServerCallback); } ``` -------------------------------- ### HTTP Date Header Example Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/specification.html This example shows the format for the HTTP Date header, which indicates the time the message transmission was started. ```http Date: Tue, 15 Nov 1994 08:12:31 GMT ``` -------------------------------- ### HohRawServletTest Server Setup Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/raw/server/HohRawServletTest.html Sets up an embedded Jetty server for testing the HohRawServlet. It configures the server with a specific port, context, and registers the servlet with authorization and message handling callbacks. The server is started and waits until it is ready. ```java @Before public void before() throws Exception { myPort = RandomServerPortProvider.findFreePort(); myServer = new Server(myPort); Context context = new Context(myServer, "/", Context.SESSIONS); HohRawServlet servlet = new HohRawServlet(); servlet.setAuthorizationCallback(this); servlet.setMessageHandler(this); context.addServlet(new ServletHolder(servlet), "/*"); myServer.start(); while (myServer.isStarting()) { ourLog.info("Waiting for server to start..."); Thread.sleep(100); } myResponse = null; } ``` -------------------------------- ### Start Jetty Server for HohServlet Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/hapi/server/HohServletTest.MyReceivingApp.html Configures and starts a Jetty server to host the HohServlet. It binds to a random available port and maps all requests to the servlet. ```java private void startServer(HohServlet theServlet) throws Exception { myPort = RandomServerPortProvider.findFreePort(); myServer = new Server(myPort); Context context = new Context(myServer, "/", Context.SESSIONS); context.addServlet(new ServletHolder(theServlet), "/*"); myServer.start(); while (myServer.isStarting()) { ourLog.info("Waiting for server to start..."); Thread.sleep(100); } } ``` -------------------------------- ### Install Relay as Windows Service Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/relay_install.html Installs the HAPI HL7 over HTTP Relay as a Windows service. The service name and description can be customized in 'wrapper.conf'. ```batch C:\hl7overhttp-relay\bin> hl7overhttp-relay install ``` -------------------------------- ### Start Jetty Server for HohServlet Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/hapi/server/HohServletTest.html Configures and starts an embedded Jetty server to host the HohServlet. This is used for testing the servlet's functionality. ```java private void startServer(HohServlet theServlet) throws Exception { myPort = RandomServerPortProvider.findFreePort(); myServer = new Server(myPort); Context context = new Context(myServer, "/", Context.SESSIONS); context.addServlet(new ServletHolder(theServlet), "/*"); myServer.start(); while (myServer.isStarting()) { ourLog.info("Waiting for server to start..."); Thread.sleep(100); } } ``` -------------------------------- ### Start HAPI HTTP Server Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/hapi/server/HohServletTest.html Starts an embedded Jetty server with a HAPI HL7 over HTTP servlet. This is used to test server-side functionality. ```java private void startServer(HohServlet theServlet) throws Exception { myPort = RandomServerPortProvider.findFreePort(); myServer = new Server(myPort); Context context = new Context(myServer, "/", Context.SESSIONS); context.addServlet(new ServletHolder(theServlet), "/*"); myServer.start(); while (myServer.isStarting()) { ourLog.info("Waiting for server to start..."); Thread.sleep(100); } } ``` -------------------------------- ### Start Relay in Console (Linux/OSX) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/relay_install.html Starts the HAPI HL7 over HTTP Relay in console mode for testing on Linux/OSX. Hit Ctrl+C to stop. ```bash hl7overhttp-relay/bin james$ ./hl7overhttp-relay console ``` -------------------------------- ### Start Relay in Console (Windows) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/relay_install.html Starts the HAPI HL7 over HTTP Relay in console mode for testing on Windows. Hit Ctrl+C to stop. ```batch C:\hl7overhttp-relay\bin> hl7overhttp-relay console ``` -------------------------------- ### Configure Server Keystore Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/sockets/CustomCertificateTlsSocketFactoryTest.html Sets the keystore filename and passphrase for the server. This is typically done before starting the server. ```java goodServer.setKeystoreFilename("src/test/resources/keystore.jks"); goodServer.setKeystorePassphrase("changeit"); return goodServer; ``` -------------------------------- ### Setup BouncyCastleCmsMessageSigner Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/encoder/Hl7OverHttpEncoderTest.html Initializes a BouncyCastleCmsMessageSigner with a keystore, key alias, and password. This is a prerequisite for signing messages. ```java KeyStore keyStore = KeyStore.getInstance("JKS"); InputStream ksStream = BouncyCastleCmsMessageSigner.class.getResourceAsStream("/keystore.jks"); keyStore.load(ksStream, "changeit".toCharArray()); mySigner = new BouncyCastleCmsMessageSigner(); mySigner.setKeyStore(keyStore); mySigner.setKeyAlias("testcert"); mySigner.setAliasPassword("changeit"); ``` -------------------------------- ### Base64 Encoding Example Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/apidocs/src-html/ca/uhn/hl7v2/hoh/util/repackage/Base64.CharEncoding.html Demonstrates basic Base64 encoding of a string. The input string is converted to bytes before encoding. ```Java System.out.println("basic " + encodeBase64String("cgta:d@3r$@TTg2446yhhh2h4".getBytes())); ``` -------------------------------- ### MLLP Server and Client Example Source: https://context7.com/hapifhir/hapi-hl7v2/llms.txt Demonstrates setting up an MLLP server to receive messages and a client to send messages and receive acknowledgments. Requires a `ReceivingApplication` implementation. ```java import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.app.*; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.parser.Parser; import ca.uhn.hl7v2.protocol.ReceivingApplication; HapiContext context = new DefaultHapiContext(); // --- Server side --- int port = 1011; HL7Service server = context.newServer(port, false /* no TLS */); // Register a handler for ADT^A01 messages ReceivingApplication handler = new ExampleReceiverApplication(); server.registerApplication("ADT", "A01", handler); server.registerApplication("*", "*", handler); // catch-all wildcard // Optional: connection lifecycle events server.registerConnectionListener(new ConnectionListener() { public void connectionReceived(Connection c) { System.out.println("New: " + c.getRemoteAddress()); } public void connectionDiscarded(Connection c) { System.out.println("Lost: " + c.getRemoteAddress()); } }); server.startAndWait(); // blocks until server is ready // --- Client side --- String rawMsg = "MSH|^~\\&|HIS|RIH|EKG|EKG|199904140038||ADT^A01|12345|P|2.2\r" + "PID|||00001122||SMITH^JOHN^M|||F\r"; Parser p = context.getPipeParser(); Message adt = p.parse(rawMsg); Connection conn = context.newClient("localhost", port, false); Initiator initiator = conn.getInitiator(); Message response = initiator.sendAndReceive(adt); System.out.println("ACK: " + p.encode(response)); // MSH|^~\&|||||20070218200627||ACK|54|P|2.2 // MSA|AA|12345 conn.close(); server.stopAndWait(); // --- ReceivingApplication implementation --- // public class ExampleReceiverApplication implements ReceivingApplication { // public boolean canProcess(Message in) { return true; } // public Message processMessage(Message msg, Map meta) throws HL7Exception { // System.out.println(new DefaultHapiContext().getPipeParser().encode(msg)); // try { return msg.generateACK(); } catch (IOException e) { throw new HL7Exception(e); } // } // } ``` -------------------------------- ### init Method Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/src/site/resources/conf/constraint_analyzer/javadoc/domparser/Rules/Ruleset.html Initializes the Ruleset. ```APIDOC ## init() ### Description Initializes the Ruleset. ### Method `void init()` ``` -------------------------------- ### Send HL7 Message using HohClientSimple Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/doc_hapi.html Example demonstrating how to configure and use HohClientSimple to send HL7 messages and receive responses. Includes optional authentication setup and error handling. ```java String host = "localhost"; int port = 8080; String uri = "/AppContext"; // Create a parser Parser parser = PipeParser.getInstanceWithNoValidation(); // Create a client HohClientSimple client = new HohClientSimple(host, port, uri, parser); // 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 ADT_A01 adt = new ADT_A01(); adt.initQuickstart("ADT", "A01", "T"); // .. set other values on the message .. // The MessageSendable provides the message to send ISendable sendable = new MessageSendable(adt); try { // sendAndReceive actually sends the message IReceivable receivable = client.sendAndReceiveMessage(sendable); // receivavle.getRawMessage() provides the response Message message = receivable.getMessage(); System.out.println("Response was:\n" + message.encode()); // IReceivable also stores metadata about the message String remoteHostIp = (String) receivable.getMetadata().get(MessageMetadataKeys.REMOTE_HOST_ADDRESS); System.out.println("From:\n" + remoteHostIp); /* * Note that the client may be reused as many times as you like, * by calling sendAndReceiveMessage repeatedly */ } 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(); } ``` -------------------------------- ### MyReceivingApp Constructor Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/ca/uhn/hl7v2/hoh/hapi/server/HohServletTest.MyReceivingApp.html Initializes a new instance of the MyReceivingApp class. ```APIDOC ## MyReceivingApp() ### Description Constructs a new instance of the `MyReceivingApp` class. ### Constructor `MyReceivingApp()` ``` -------------------------------- ### MyReceivingApp Constructor Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/ca/uhn/hl7v2/hoh/hapi/server/HohServletTest.MyReceivingApp.html Initializes a new instance of the MyReceivingApp class. ```APIDOC ## MyReceivingApp() ### Description Constructs a new MyReceivingApp. ### Constructor `public MyReceivingApp()` ``` -------------------------------- ### Initialize DefaultHapiContext and Configure Servers Source: https://context7.com/hapifhir/hapi-hl7v2/llms.txt Demonstrates initializing `DefaultHapiContext` with different validation settings and creating HL7 servers on specified ports. It shows how to disable validation or use default validation rules and supply a custom thread pool. ```java import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.app.HL7Service; import ca.uhn.hl7v2.validation.builder.support.NoValidationBuilder; import ca.uhn.hl7v2.validation.builder.support.DefaultValidationBuilder; import java.util.concurrent.Executors; // Basic context — uses DefaultValidation, shared thread pool HapiContext ctx = new DefaultHapiContext(); // Disable all validation for a lenient parser ctx.setValidationRuleBuilder(new NoValidationBuilder()); // Two servers with independent configurations HapiContext ctx1 = new DefaultHapiContext(); ctx1.setValidationRuleBuilder(new NoValidationBuilder()); HL7Service server1 = ctx1.newServer(8080, false); // port 8080, no TLS HapiContext ctx2 = new DefaultHapiContext(); ctx2.setValidationRuleBuilder(new DefaultValidationBuilder()); HL7Service server2 = ctx2.newServer(8081, false); // port 8081, no TLS // Supply a custom thread pool (optional) ctx.setExecutorService(Executors.newCachedThreadPool()); ``` -------------------------------- ### Handle GET Requests in HohRawServlet Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/apidocs/src-html/ca/uhn/hl7v2/hoh/raw/server/HohRawServlet.html This method handles GET requests by returning a 400 Bad Request error, as GET is not supported by this server. ```java protected void doGet(HttpServletRequest theReq, HttpServletResponse theResp) throws ServletException, IOException { theResp.setStatus(400); theResp.setContentType("text/html"); String message = "GET method is not supported by this server"; HTTPUtils.write400BadRequest(theResp.getOutputStream(), message, false); } ``` -------------------------------- ### Start Server Socket Thread Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref-test/ca/uhn/hl7v2/hoh/raw/client/HohRawClientSimpleTest.html Creates and starts a server socket thread for testing, then waits for it to be ready. ```java myServerSocketThread = new ServerSocketThreadForTesting(myPort, ourServerCallback); myServerSocketThread.start(); myServerSocketThread.getLatch().await(); ``` -------------------------------- ### ACK Message Example (HL7v2.1) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt This is an example of an ACK message with version 2.1, used for acknowledging receipt of a message. ```hl7 MSH|^~\}|RADIOLOGY|MIR1|ADMISSION|ADT1|19930502184808||ACK^|589888ADT30502184808|P|2.1|| MSA|AA|msgCtrlId ``` -------------------------------- ### QRY^Q01 Query Message Example Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt This is an example of a QRY^Q01 message, used for sending queries. It includes MSH, QRD, and DSC segments. ```hl7 MSH|^~\}|RAD RESULTS|RIQ1|RAD RESULTS|RIQ1|19940113085842||QRY^Q01|161875RIQ40113085843|P|2.1|| QRD|19940113085841|D|I|CITBND9HAP|||0^ZO|HILL,R|APN|10|00000000000000000000^| T DSC| ``` ```hl7 MSH|^~\}|RAD RESULTS|RIQ1|RAD RESULTS|RIQ1|19940112233548||QRY^Q01|994983RIQ40112233548|P|2.1|| QRD|19940112233547|D|I|CITBND9HAP|||0^ZO||APN||00109401234000000000^| T DSC| ``` -------------------------------- ### ADT^P01 Message Example with Insurance (HL7v2.1) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt This ADT^P01 message example includes detailed insurance information (IN1 segments) for a patient. ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502185327||BAR^P01|908594ADT30502185327|P|2.4|| EVN|P01|19930502185308|| PID||^^|479305169^1^M10|333811343|CRESWELL^DEBORAH^^^^||19500331|F|^^^^^|U|4534 GIBSON^^ST LOUIS^MO^63110^""|510|(314)531-6718~~|~~||U|B|479305169^1^M10|496-54-6042|^ NK1||CRESWELL^DAVID^^^^|04|4534 GIBSON^^ST.LOUIS^MO^63110^|(314)531-6718 PV1||O|^^|||^^|^^^^^|^^^^^|^^^^^|10|^^||||||^^^^^|||67|||||||||||||||||||1|||^^|^^|||||| GT1|||CRESWELL^DEBORAH^^^^|^^^^^|4534 GIBSON^^ST LOUIS^MO^63110^|(314)531-6718|(314)362-7111|09500331|F||01|496-54-6042||||BARNES HOSPITAL|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110^|(314)362-7111|| IN1|1|901|67|PARTNERS HMO|P.O. BOX 36151^^MINNEAPOLIS^MN^55435-0000^|^^^^^||||00429|BARNES HOSPITAL|||N/A|1|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0||496546042|0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ IN1|2|001|01|PATIENT PAY|^^^^^|^^^^^||||00429|BARNES HOSPITAL|||N/A|7|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0|||0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ ``` -------------------------------- ### AbstractRawClient Constructor (Host, Port, Path) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref/ca/uhn/hl7v2/hoh/raw/client/AbstractRawClient.html Initializes the AbstractRawClient with host, port, and path information. ```APIDOC ## AbstractRawClient(String theHost, int thePort, String thePath) ### Description Constructs an AbstractRawClient instance, setting the host, port, and URI path for communication. ### Method Constructor ### Parameters - **theHost** (String) - The hostname or IP address of the server. - **thePort** (int) - The port number of the server. - **thePath** (String) - The URI path for the HL7 over HTTP endpoint. ``` -------------------------------- ### BAR^P01 Message Example (HL7v2.4) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-osgi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt Example of a BAR^P01 message, typically used for patient admission, discharge, or transfer. This version is HL7v2.4. ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502184808||BAR^P01|589888ADT30502184808|P|2.4|| EVN|P01|19930502184802|| PID||^^|429314294^1^M10|333437208|WASHINGTON-HARPER^VOLA^K^^^||19541218|F|^^^^^|B|2146 E HARRIS^""^ST.LOUIS^MO^63107^""|510|(314)389-8628~~|~~||M|C|429314294^1^M10|500-60-8950|^ NK1||WASHINGTON^STEVE^^^^|26|2146 E HARRIS^^ST.LOUIS^MO^63107^|(314)389-8628 PV1||O|^ER^|||^^|00112^WEDNER^H^J^^|^^^^^|^^^^^|01|^^||||||^^^^^|||60|||||||||||||||||||1|||^^|^^|||||| GT1|||WASHINGTON-HARPER^VOLA^K^^^|^^^^^|2146 E HARRIS^^ST.LOUIS^MO^63107^|(314)389-8628|(314)381-1605|09541218|F||01|500-60-8950||||SPECIAL SCHOOL DIST|12110 CLAYTON RD^^ST LOUIS^MO^63131^|(314)381-1605|| IN1|2|989|60|HEALTHLINK, INC|POB 419104^^ST LOUIS^MO^63141-9104^|CLAIMS DEPT.^^^^^|(314)872-9621||SPEC SCL DST|00000|SPECIAL SCHOOL DIST|||N/A|1|WASHINGTON-HARPER^VOLA^K^^^|01|19541218|^^^^^||||||||||||||0|0||500608950|0.0|0.0|0|0.0|0.0|0|F|12110 CLAYTON RD^^ST LOUIS^MO^63131-0000^ ``` ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502185327||BAR^P01|908594ADT30502185327|P|2.4|| EVN|P01|19930502185308|| PID||^^|479305169^1^M10|333811343|CRESWELL^DEBORAH^^^^||19500331|F|^^^^^|U|4534 GIBSON^^ST LOUIS^MO^63110^""|510|(314)531-6718~~|~~||U|B|479305169^1^M10|496-54-6042|^ NK1||CRESWELL^DAVID^^^^|04|4534 GIBSON^^ST.LOUIS^MO^63110^|(314)531-6718 PV1||O|^^|||^^|^^^^^|^^^^^|^^^^^|10|^^||||||^^^^^|||67|||||||||||||||||||1|||^^|^^|||||| GT1|||CRESWELL^DEBORAH^^^^|^^^^^|4534 GIBSON^^ST LOUIS^MO^63110^|(314)531-6718|(314)362-7111|09500331|F||01|496-54-6042||||BARNES HOSPITAL|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110^|(314)362-7111|| IN1|1|901|67|PARTNERS HMO|P.O. BOX 36151^^MINNEAPOLIS^MN^55435-0000^|^^^^^||||00429|BARNES HOSPITAL|||N/A|1|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0||496546042|0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ IN1|2|001|01|PATIENT PAY|^^^^^|^^^^^||||00429|BARNES HOSPITAL|||N/A|7|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0|||0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ ``` ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502185434||BAR^P01|178260ADT30502185434|P|2.4|| EVN|P01|19930502185345|| PID||^^|479305169^1^M10|000679122|CRESWELL^DEBORAH^^^^||19500331|F|^^^^^|U|4534 GIBSON^""^ST LOUIS^MO^63110^""|510|(314)531-6718~~|~~||U|B|479305169^1^M10|496-54-6042|^ NK1||CRESWELL^DAVID^^^^|04|4534 GIBSON^^ST.LOUIS^MO^63110^|(314)531-6718 PV1||O|^ER^|||^^|00178^WILLIAMS JR^R^J^^|^^^^^|^^^^^|10|^^||||||^^^^^|||67|||||||||||||||||||1|||^^|^^|||||| GT1|||CRESWELL^DEBORAH^^^^|^^^^^|4534 GIBSON^^ST LOUIS^MO^63110^|(314)531-6718|(314)362-7111|09500331|F||01|496-54-6042||||BARNES HOSPITAL|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110^|(314)362-7111|| IN1|1|901|67|PARTNERS HMO|P.O. BOX 36151^^MINNEAPOLIS^MN^55435-0000^|^^^^^|(800)338-4123|||00429|BARNES HOSPITAL|||N/A|1|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0||496546042|0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ IN1|2|001|01|PATIENT PAY|^^^^^|^^^^^||||00429|BARNES HOSPITAL|||N/A|7|CRESWELL^DEBORAH^^^^|01|19500331|^^^^^||||||||||||||0|0|||0.0|0.0|0|0.0|0.0|0|F|BARNES HOSPITAL PLAZ^^ST. LOUIS^MO^63110-0000^ ``` ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502185725||BAR^P01|299419ADT30502185725|P|2.4|| EVN|P01|19930502185713|| PID||429313192^8^M10|109309665^7^M10|000694925|HOESLI^JOHN^F^^^||19211204|M|^^^^^|C|2612 TENNESSEE^^ST. LOUIS^MO^63118^""|510|(314)771-4854~~|~~||M|U|109309665^7^M10|494-05-7099|^ PV1||I|I083^083IC^16|||^^|00148^HOFFMANN^SANDRA^S^^|08946^EMERGENCY^ROOM^R^^|^^^^^|01|^^|||5|||00148^HOFFMANN^SANDRA^S^^|01||||||||||||||||||H|||1|2||^^|^^|19930423192017|19930502185712|||| ``` -------------------------------- ### Main Method for Launcher Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref/ca/uhn/hl7v2/hoh/relay/Launcher.html Entry point for the HAPI HL7 over HTTP Relay. It initializes logging and creates a new Launcher instance. ```java public static void main(String[] args) throws FileNotFoundException { Log4jConfigurer.initLogging("file:conf" + IOUtils.FILE_PATH_SEP + "log4j.xml"); _// System.setProperty("relay.port.in",_ _// RandomServerPortProvider.findFreePort() + "");_ _// System.setProperty("relay.port.out",_ _// RandomServerPortProvider.findFreePort() + "");_ new Launcher(); } ``` -------------------------------- ### ACK Message Example (HL7v2.1) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-osgi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt Example of an ACK message, which is an acknowledgment of a previously sent message. This is a common response in HL7 communication. ```hl7 MSH|^~\}|RADIOLOGY|MIR1|ADMISSION|ADT1|19930502184808||ACK^|589888ADT30502185434|P|2.1|| MSA|AA|msgCtrlId ``` -------------------------------- ### AbstractRawClient Constructor with Host, Port, and Path Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/xref/ca/uhn/hl7v2/hoh/raw/client/AbstractRawClient.html Initializes the client with the host, port, and URI path for HL7 over HTTP communication. ```java public AbstractRawClient(String theHost, int thePort, String thePath) { setHost(theHost); setPort(thePort); setUriPath(thePath); } ``` -------------------------------- ### Initialize HohRawClientSimple with URL Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/raw/client/HohRawClientSimpleTest.html Shows how to create a HohRawClientSimple instance using a URL object. Demonstrates parsing of host, port, and URI path from various URL formats. ```java HohRawClientSimple c = new HohRawClientSimple(new URL("http://somehost/")); assertEquals("somehost", c.getHost()); assertEquals("/", c.getUriPath()); assertEquals(80, c.getPort()); ``` ```java c = new HohRawClientSimple(new URL("http://somehost:8888/")); assertEquals("somehost", c.getHost()); assertEquals("/", c.getUriPath()); assertEquals(8888, c.getPort()); ``` ```java c = new HohRawClientSimple(new URL("http://somehost:8888/someuri/path/test.jsp")); assertEquals("somehost", c.getHost()); assertEquals("/someuri/path/test.jsp", c.getUriPath()); assertEquals(8888, c.getPort()); ``` ```java c = new HohRawClientSimple(new URL("https://somehost/someuri/path/test.jsp")); assertEquals("somehost", c.getHost()); assertEquals("/someuri/path/test.jsp", c.getUriPath()); assertEquals(443, c.getPort()); ``` -------------------------------- ### Setup and Teardown for HttpSender Tests Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/testapidocs/src-html/ca/uhn/hl7v2/hoh/relay/sender/HttpSenderTest.html Provides the @Before and @After methods for setting up and tearing down resources used in HttpSender tests, including random port allocation and server thread initialization. ```java private int myOutPort; private ServerSocketThreadForTesting myServerSocketThread; private SingleCredentialServerCallback ourServerCallback; private int myInPort; private int myInPort2; @After public void after() throws InterruptedException { ourLog.info("Marking done as true"); myServerSocketThread.done(); } @Before public void before() throws InterruptedException { // System.setProperty("javax.net.debug", "ssl"); myOutPort = RandomServerPortProvider.findFreePort(); myInPort = RandomServerPortProvider.findFreePort(); myInPort2 = RandomServerPortProvider.findFreePort(); System.setProperty("relay.port.out", Integer.toString(myOutPort)); System.setProperty("relay.port.in", Integer.toString(myInPort)); System.setProperty("relay.port.in.2", Integer.toString(myInPort2)); ourServerCallback = new SingleCredentialServerCallback("hello", "hapiworld"); myServerSocketThread = new ServerSocketThreadForTesting(myOutPort, ourServerCallback); } ``` -------------------------------- ### Constructor with Keystore Type, Filename, and Passphrase Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/apidocs/ca/uhn/hl7v2/hoh/sockets/CustomCertificateTlsSocketFactory.html Constructor that accepts keystore type, filename, and passphrase. ```APIDOC ## CustomCertificateTlsSocketFactory(String theKeystoreType, String theKeystoreFilename, String theKeystorePass) ### Description Initializes CustomCertificateTlsSocketFactory with keystore type, filename, and passphrase. ### Parameters - **theKeystoreType** (String) - Required - The type of the keystore (e.g., JKS). - **theKeystoreFilename** (String) - Required - The filename of the keystore. - **theKeystorePass** (String) - Required - The passphrase for the keystore. ### Constructor `public CustomCertificateTlsSocketFactory(String theKeystoreType, String theKeystoreFilename, String theKeystorePass)` ``` -------------------------------- ### ADT^P01 Message Example with Inpatient PV1 (HL7v2.1) Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-test/src/test/resources/ca/uhn/hl7v2/util/messages.txt This ADT^P01 message example shows an inpatient scenario with specific PV1 segment details. ```hl7 MSH|^~\}|ADMISSION|ADT1|RADIOLOGY|MIR1|19930502185725||BAR^P01|299419ADT30502185725|P|2.4|| EVN|P01|19930502185713|| PID||429313192^8^M10|109309665^7^M10|000694925|HOESLI^JOHN^F^^^||19211204|M|^^^^^|C|2612 TENNESSEE^^ST. LOUIS^MO^63118^""|510|(314)771-4854~~|~~||M|U|109309665^7^M10|494-05-7099|^ PV1||I|I083^083IC^16|||^^|00148^HOFFMANN^SANDRA^S^^|08946^EMERGENCY^ROOM^R^^|^^^^^|01|^^|||5|||00148^HOFFMANN^SANDRA^S^^|01||||||||||||||||||H|||1|2||^^|^^|19930423192017|19930502185712|||| ``` -------------------------------- ### Binder Configuration Source: https://github.com/hapifhir/hapi-hl7v2/blob/master/hapi-hl7overhttp/apidocs/src-html/ca/uhn/hl7v2/hoh/relay/Binder.html This section details how to configure the Binder by setting its listener and sender properties, and how it initializes by validating these properties and logging the binding configuration. ```APIDOC ## Binder Class ### Description The `Binder` class is responsible for configuring and initializing the relay mechanism in HAPI HL7 over HTTP. It binds an `IRelayListener` to an `IRelaySender` based on specified message routing criteria. ### Methods #### `afterPropertiesSet()` ##### Description This method is called after all properties have been set. It validates that the listener and sender have been configured, logs the binding details, creates an `AppRoutingDataImpl` object, and registers the sender with the listener for the specified message profile. ##### Usage This method is part of the Spring `InitializingBean` interface and is typically called automatically by the Spring container after bean initialization. #### `setListener(IRelayListener theRelayListener)` ##### Description Sets the `IRelayListener` to be used by the binder. This listener will receive incoming HL7 messages. ##### Parameters * **theRelayListener** (IRelayListener) - The listener implementation to set. #### `setSender(IRelaySender theRelaySender)` ##### Description Sets the `IRelaySender` to be used by the binder. This sender will be invoked to send HL7 messages to their destination. ##### Parameters * **theRelaySender** (IRelaySender) - The sender implementation to set. #### `getProductname()` ##### Description Returns the product name and version of the HAPI HL7 over HTTP Relay. ##### Returns * (String) - The product name and version string. ```