This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git
The following commit(s) were added to refs/heads/main by this push:
new adfa7c1 fhir-auth-tx: fix bundle resource transaction as endpoint
adfa7c1 is described below
commit adfa7c1ff3af1ce34eea0d630b8d91e075b667ea
Author: Salvatore Mongiardo <[email protected]>
AuthorDate: Wed Jun 18 17:10:05 2025 +0200
fhir-auth-tx: fix bundle resource transaction as endpoint
---
.../src/main/java/sample/camel/MyCamelRouter.java | 52 +++++++++++++---------
.../java/sample/camel/MyCamelApplicationTest.java | 2 +-
2 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java
b/fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java
index 583e466..84568b2 100644
--- a/fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java
+++ b/fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java
@@ -22,7 +22,12 @@ import java.util.List;
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;
/**
@@ -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}");
}
}
diff --git
a/fhir-auth-tx/src/test/java/sample/camel/MyCamelApplicationTest.java
b/fhir-auth-tx/src/test/java/sample/camel/MyCamelApplicationTest.java
index a33a16c..e3726be 100644
--- a/fhir-auth-tx/src/test/java/sample/camel/MyCamelApplicationTest.java
+++ b/fhir-auth-tx/src/test/java/sample/camel/MyCamelApplicationTest.java
@@ -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"));