Skip to content

fhir-auth-tx: fix bundle resource transaction as endpoint #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.http.ProtocolException;

import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Identifier;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.stereotype.Component;

/**
Expand All @@ -36,29 +41,34 @@ public class MyCamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file:{{input}}").routeId("fhir-example")
.onException(ProtocolException.class)
.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()
.log("Converting ${file:name}")
.unmarshal().csv()
.process(exchange -> {
List<Patient> bundle = new ArrayList<>();
@SuppressWarnings("unchecked")
List<List<String>> patients = (List<List<String>>) exchange.getIn().getBody();
for (List<String> patient: patients) {
Patient fhirPatient = new Patient();
fhirPatient.setId(patient.get(0));
fhirPatient.addName().addGiven(patient.get(1));
fhirPatient.getNameFirstRep().setFamily(patient.get(2));
bundle.add(fhirPatient);
}
exchange.getIn().setBody(bundle);
})
// create Patient in our FHIR server
.to("fhir://transaction/withResources?inBody=resources&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}")
// log the outcome
.log("Patients created successfully: ${body}");
.end()
.log("Converting ${file:name}")
.unmarshal().csv()
.process(exchange -> {

Bundle bundleTest = new Bundle();
bundleTest.setId("bundle-simplified-001");
bundleTest.setIdentifier(new Identifier().setValue("001"));
bundleTest.setType(org.hl7.fhir.dstu3.model.Bundle.BundleType.TRANSACTION);

@SuppressWarnings("unchecked")
List<List<String>> patients = (List<List<String>>) exchange.getIn().getBody();
for (List<String> patient: patients) {
Patient fhirPatient = new Patient();
fhirPatient.setId(patient.get(0));
fhirPatient.addName().addGiven(patient.get(1));
fhirPatient.getNameFirstRep().setFamily(patient.get(2));
bundleTest.addEntry().setResource(fhirPatient).getRequest().setMethod(Bundle.HTTPVerb.POST);
}
exchange.getIn().setBody(bundleTest);
})
// create Patient in our FHIR server
.to("fhir://transaction/withBundle?inBody=bundle&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}")
// log the outcome
.log("Patients created successfully: ${body}");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MyCamelApplicationTest {

@Test
public void shouldPushConvertedHl7toFhir() throws Exception {
MockEndpoint mock = camelContext.getEndpoint("mock:fhir:transaction/withResources", MockEndpoint.class);
MockEndpoint mock = camelContext.getEndpoint("mock:fhir:transaction/withBundle", MockEndpoint.class);
mock.expectedMessageCount(1);

FileUtils.copyDirectory(new File("src/main/data"), new File("target/work/fhir/testinput"));
Expand Down
Loading