1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.platform.camel.ihe.fhir.pcc44;
18
19 import ca.uhn.fhir.context.FhirContext;
20 import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
21 import org.apache.camel.Exchange;
22 import org.apache.camel.builder.RouteBuilder;
23 import org.apache.camel.support.ExpressionAdapter;
24 import org.hl7.fhir.dstu3.model.Bundle;
25 import org.openehealth.ipf.platform.camel.ihe.fhir.test.FhirTestContainer;
26
27 import java.io.InputStreamReader;
28 import java.util.stream.Collectors;
29
30
31
32
33 public class Pcc44TestRouteBuilder extends RouteBuilder {
34
35 private final boolean returnError;
36
37 public Pcc44TestRouteBuilder(boolean returnError) {
38 this.returnError = returnError;
39 }
40
41 @Override
42 public void configure() {
43
44 from("direct:input")
45 .toF("qedm-pcc44:localhost:%d", FhirTestContainer.DEMO_APP_PORT);
46
47 from("qedm-pcc44:translation?audit=true&options=OBSERVATIONS")
48 .errorHandler(noErrorHandler())
49 .transform(new Pcc44Responder());
50 }
51
52
53 private class Pcc44Responder extends ExpressionAdapter {
54
55 @Override
56 public Object evaluate(Exchange exchange) {
57 if (!returnError) {
58 Bundle resource = FhirContext.forDstu3().newXmlParser()
59 .parseResource(Bundle.class, new InputStreamReader(getClass().getResourceAsStream("/ObservationResponse.xml")));
60
61 return resource.getEntry().stream()
62 .map(Bundle.BundleEntryComponent::getResource)
63 .collect(Collectors.toList());
64 } else {
65 throw new InternalErrorException("Something went wrong");
66 }
67 }
68 }
69
70 }