in fhir/src/main/java/sample/camel/MyCamelRouter.java [37:71]
public void configure() throws Exception {
from("file:{{input}}").routeId("fhir-example")
.onException(ProtocolException.class)
.handled(true)
.log(LoggingLevel.ERROR, "Error connecting to FHIR server with URL:{{serverUrl}}, please check the application.properties file ${exception.message}")
.end()
.onException(HL7Exception.class)
.handled(true)
.log(LoggingLevel.ERROR, "Error unmarshalling ${file:name} ${exception.message}")
.end()
.log("Converting ${file:name}")
// unmarshall file to hl7 message
.unmarshal().hl7()
// very simple mapping from a HLV2 patient to dstu3 patient
.process(exchange -> {
ORU_R01 msg = exchange.getIn().getBody(ORU_R01.class);
final PID pid = msg.getPATIENT_RESULT().getPATIENT().getPID();
String surname = pid.getPatientName()[0].getFamilyName().getFn1_Surname().getValue();
String name = pid.getPatientName()[0].getGivenName().getValue();
String patientId = msg.getPATIENT_RESULT().getPATIENT().getPID().getPatientID().getCx1_ID().getValue();
Patient patient = new Patient();
patient.addName().addGiven(name);
patient.getNameFirstRep().setFamily(surname);
patient.setId(patientId);
exchange.getIn().setBody(patient);
})
// marshall to JSON for logging
.marshal().fhirJson("{{fhirVersion}}")
.convertBodyTo(String.class)
.log("Inserting Patient: ${body}")
// create Patient in our FHIR server
.to("fhir://create/resource?inBody=resourceAsString&serverUrl={{serverUrl}}&fhirVersion={{fhirVersion}}")
// log the outcome
.log("Patient created successfully: ${body}");
}