In this post we are going to outline the code snippets you require to build an HL7 MLLP receiver with Springboot, Camel and HAPI. The Minimum Lower Layer Protocol (MLLP) is a low level TCP protocol that has traditionally been used to transit HL7 messages over networks. For those not familiar with HL7, the following is an example of an admission message:
MSH|^~\&|AccMgr|1|||20050110045504||ADT^A01|599102|P|2.3||| EVN|A01|20200110045502||||| PID|1||10006579^^^1^MRN^1||SMITH^JOE^D||19241010|M||1| 111 DUCK ST^^FOWL^CA^999990000^^M|1|8885551212|8885551212|1|2||40007716^^^AccMgr^VN^1|123121234|||||||||||NO NK1|1|DUCK^HUEY|SO|3583 DUCK RD^^FOWL^CA^999990000|8885552222||Y|||||||||||||| PV1|1|I|PREOP^101^1^1^^^S|3|||37^AMCO^WILLIAM^^^^^^AccMgr^^^^CI|||01||||1|||37^DISNEY^WALT^^^^^^AccMgr^^^^CI|2|40007716^^^AccMgr^VN|4|||||||||||||||||||1||G|||20050110045253|||||| DG1|1|I9|71596^OSTEOARTHROS NOS-L/LEG ^I9|OSTEOARTHROS NOS-L/LEG ||A| IN1|1|MEDICARE|3|MEDICARE|||||||Cartoon Ducks Inc|19891001|||4|DUCK^DONALD^D|1|19241010|111^DUCK ST^^FOWL^CA^999990000|||||||||||||||||123121234A||||||PT|M|111 DUCK ST^^FOWL^CA^999990000|||||8291
For the first part, we need to set up the route and the handler:
import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import cloud.alarta.core.adt.AppConfig; @Component public class HL7Listener extends RouteBuilder { @Autowired AppConfig config; @Override public void configure() throws Exception { String url = "mina2:tcp://" + config.getEndpointServer() + ":" + config.getEndpointPort() + "?sync=true&codec=#myhl7codec"; from(url) .routeId("route_hl7listener") .startupOrder(997) .unmarshal().hl7(false) .to("bean:respondACK?method=process") .end(); } }