Skip to content

Commit adfa7c1

Browse files
smongiarCroway
authored andcommitted
fhir-auth-tx: fix bundle resource transaction as endpoint
1 parent 8ad4826 commit adfa7c1

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

fhir-auth-tx/src/main/java/sample/camel/MyCamelRouter.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
import org.apache.camel.LoggingLevel;
2323
import org.apache.camel.builder.RouteBuilder;
2424
import org.apache.http.ProtocolException;
25+
26+
import org.hl7.fhir.dstu3.model.Bundle;
27+
import org.hl7.fhir.dstu3.model.Identifier;
2528
import org.hl7.fhir.dstu3.model.Patient;
29+
import org.hl7.fhir.dstu3.model.Resource;
30+
import org.hl7.fhir.instance.model.api.IBaseResource;
2631
import org.springframework.stereotype.Component;
2732

2833
/**
@@ -36,29 +41,34 @@ public class MyCamelRouter extends RouteBuilder {
3641
@Override
3742
public void configure() throws Exception {
3843
from("file:{{input}}").routeId("fhir-example")
39-
.onException(ProtocolException.class)
44+
.onException(ProtocolException.class)
4045
.handled(true)
4146
.log(LoggingLevel.ERROR, "Error connecting to FHIR server with URL:{{serverUrl}}, please check the application.properties file ${exception.message}")
42-
.end()
43-
.log("Converting ${file:name}")
44-
.unmarshal().csv()
45-
.process(exchange -> {
46-
List<Patient> bundle = new ArrayList<>();
47-
@SuppressWarnings("unchecked")
48-
List<List<String>> patients = (List<List<String>>) exchange.getIn().getBody();
49-
for (List<String> patient: patients) {
50-
Patient fhirPatient = new Patient();
51-
fhirPatient.setId(patient.get(0));
52-
fhirPatient.addName().addGiven(patient.get(1));
53-
fhirPatient.getNameFirstRep().setFamily(patient.get(2));
54-
bundle.add(fhirPatient);
55-
}
56-
exchange.getIn().setBody(bundle);
57-
})
58-
// create Patient in our FHIR server
59-
.to("fhir://transaction/withResources?inBody=resources&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}")
60-
// log the outcome
61-
.log("Patients created successfully: ${body}");
47+
.end()
48+
.log("Converting ${file:name}")
49+
.unmarshal().csv()
50+
.process(exchange -> {
51+
52+
Bundle bundleTest = new Bundle();
53+
bundleTest.setId("bundle-simplified-001");
54+
bundleTest.setIdentifier(new Identifier().setValue("001"));
55+
bundleTest.setType(org.hl7.fhir.dstu3.model.Bundle.BundleType.TRANSACTION);
56+
57+
@SuppressWarnings("unchecked")
58+
List<List<String>> patients = (List<List<String>>) exchange.getIn().getBody();
59+
for (List<String> patient: patients) {
60+
Patient fhirPatient = new Patient();
61+
fhirPatient.setId(patient.get(0));
62+
fhirPatient.addName().addGiven(patient.get(1));
63+
fhirPatient.getNameFirstRep().setFamily(patient.get(2));
64+
bundleTest.addEntry().setResource(fhirPatient).getRequest().setMethod(Bundle.HTTPVerb.POST);
65+
}
66+
exchange.getIn().setBody(bundleTest);
67+
})
68+
// create Patient in our FHIR server
69+
.to("fhir://transaction/withBundle?inBody=bundle&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}")
70+
// log the outcome
71+
.log("Patients created successfully: ${body}");
6272
}
6373

6474
}

fhir-auth-tx/src/test/java/sample/camel/MyCamelApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class MyCamelApplicationTest {
3838

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

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

0 commit comments

Comments
 (0)