The HL7v2 model uses Java objects from the HAPI library. Using this library, we can encode and decode from the EDI format (ER7) that is mostly used with HL7v2. With this model you can code with Java objects instead of the EDI based HL7 format that can be hard for humans to read and understand.
The sample below is a request to lookup a patient with the patient ID 0101701234.
Using the HL7 model we can work with the data as a ca.uhn.hl7v2.model.Message object. To retrieve the patient ID in the message above, you can do this in Java code:
Message msg = exchange.getIn().getBody(Message.class); QRD qrd = (QRD)msg.get("QRD"); String patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();
Camel has built-in type converters, so when this operation is invoked:
Message msg = exchange.getIn().getBody(Message.class);
If you know the message type in advance, you can be more type-safe:
QRY_A19 msg = exchange.getIn().getBody(QRY_A19.class); String patientId = msg.getQRD().getWhoSubjectFilter(0).getIDNumber().getValue();
Camel will convert the received HL7 data from String to Message. This is powerful when combined with the HL7 listener, then you as the end-user don't have to work with byte, String or any other simple object formats. You can just use the HAPI HL7v2 model objects.