Skip to content

Instantly share code, notes, and snippets.

@cvicens
Created January 16, 2020 17:33
Show Gist options
  • Save cvicens/fefda9aeb2d645f70406e6a494d28de8 to your computer and use it in GitHub Desktop.
Save cvicens/fefda9aeb2d645f70406e6a494d28de8 to your computer and use it in GitHub Desktop.
import ...
public class HL7ToEvents extends RouteBuilder {
@Override
public void configure() throws Exception {
from("kafka:{{kafka.from.topic}}?brokers={{kafka.bootstrap-servers}}&groupId={{kafka.groupId}}")
.routeId("hl7-to-patient-info")
.onException(Exception.class)
.handled(true)
.log(LoggingLevel.ERROR, "Error connecting to server, please check the application.properties file ${exception.message}")
.end()
.onException(HL7Exception.class)
.handled(true)
.log(LoggingLevel.ERROR, "Error unmarshalling ${exception.message}")
.end()
.log("Route started from Telegram")
.log("body: ${body}")
.process(exchange -> {
String encodedMessage = exchange.getIn().getBody(String.class);
...
String decodedMessage = new String(decodedBytes);
...
HapiContext context = new DefaultHapiContext();
...
Message hapiMessage = p.parse(decodedMessage);
Terser terser = new Terser(hapiMessage);
String sendingApplication = terser.get("/.MSH-3-1");
String msgCode = terser.get("/.MSH-9-1");
String msgTriggerEvent = terser.get("/.MSH-9-2");
...
Map<String, String> data = new HashMap<String, String>();
...
data.put("message", message + " in Black Mountain");
data.put("personalId", personalId);
data.put("patientId", patientId);
exchange.getIn().setBody(data);
})
// marshall to JSON with GSON
.marshal().json(JsonLibrary.Gson)
.log("Converting to JSON data: ${body}")
.convertBodyTo(String.class)
.log("Sending message ${body} to topic {{kafka.to.topic}}")
.to("kafka:{{kafka.to.topic}}?brokers={{kafka.bootstrap-servers}}&groupId={{kafka.groupId}}")
.log("Event sent successfully: ${body}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment