Receive HL7 requests with flows

The HL7 healthcare standard can be very easily implemented with Mule and Saddle. In a previous post, we presented how to send HL7 requests using flows. It's time now to implement the server side!

In our scenario, we want to

  • Respond to the caller with message handling
  • Do some backend work with the message, synchronously or asynchronously

Again, we'll use the <response> block from Mule. First, the synchronous solution:

HL7Sync2

The idea is to end with a component, so there is a response back. If you just write a file, the flow will end and nothing is sent back. We use here a Log component, but if you really don't want to do anything, try implementing a custom component that does nothing. In the response, the Scripting component simply returns the String "ACK" to the caller.

Here is the XML configuration:

<?xml version="1.0" encoding="UTF-8"?> 
<mule xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.2/mule-file.xsd /schemas/saddle/hl7/mule32/0.8 /schemas/saddle/hl7/mule32/0.8/saddle-hl7.xsd  http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.2/mule-scripting.xsd  /schemas/saddle/saddleMule320Components/0.8 /schemas/saddle/saddleMule320Components/0.8/saddle.xsd" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hl7="/schemas/saddle/hl7/mule32/0.8" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:management="http://www.mulesoft.org/schema/mule/management" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"> 
    <flow name="sync"> 
        <hl7:inbound-endpoint name="ReceiveHL7" host="127.0.0.1" port="4242" exchange-pattern="request-response"/>
        <byte-array-to-string-transformer name="ReqToString"/> 
        <response> 
            <scripting:component> 
                <scripting:script name="makeACK" engine="groovy">
                    return "ACK";
                </scripting:script> 
            </scripting:component>
        </response>
        <file:outbound-endpoint name="WriteFile" path="/home/user/Test/Out/" outputPattern="outFROMServer.txt"/>
        <log-component/>
    </flow>
</mule>

Now, the asynchronous solution:

HL7Async3

Nothing much to explain here: when the flow reaches the entry of AsyncWrite, it wil trigger the response back.

Here is the XML configuration:

<?xml version="1.0" encoding="UTF-8"?>
<mule xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.2/mule-file.xsd /schemas/saddle/hl7/mule32/0.8 /schemas/saddle/hl7/mule32/0.8/saddle-hl7.xsd  http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.2/mule-scripting.xsd  /schemas/saddle/saddleMule320Components/0.8 /schemas/saddle/saddleMule320Components/0.8/saddle.xsd" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hl7="/schemas/saddle/hl7/mule32/0.8" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:management="http://www.mulesoft.org/schema/mule/management" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting">
    <flow name="async">
        <hl7:inbound-endpoint name="ReceiveHL7" host="127.0.0.1" port="4242" exchange-pattern="request-response"/>
        <byte-array-to-string-transformer name="ReqToString"/>
        <response>
            <scripting:component>
                <scripting:script name="makeACK" engine="groovy">
                     return "ACK";
                </scripting:script>
            </scripting:component>
        </response>
        <async name="AsyncWrite">
            <file:outbound-endpoint name="WriteFile" path="/home/user/Test/Out/" outputPattern="outFROMServer.txt"/>     
        </async> 
    </flow> 
</mule>

You may wonder why we're using a specific <response> block and not putting the response directly into the inbound-endpoint. That would work as well, but you're quite limited to the possible blocks inside (e.g. no components), so we decided to show the most flexible solution.

There are of course several other possibilities to solve this use case, and you can enhance this with validation, complex business logic...

We hope that this will help you implementing HL7 servers, and we welcome any comment or feedback.

Add comment

Security code
Refresh