View Javadoc
1   /*
2    * Copyright 2016 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.openehealth.ipf.platform.camel.ihe.fhir.iti78;
18  
19  import ca.uhn.hl7v2.model.Message;
20  import org.apache.camel.builder.RouteBuilder;
21  import org.openehealth.ipf.commons.ihe.fhir.iti78.PdqResponseToPdqmResponseTranslator;
22  import org.openehealth.ipf.commons.ihe.fhir.iti78.PdqmRequestToPdqQueryTranslator;
23  import org.openehealth.ipf.commons.ihe.fhir.translation.UriMapper;
24  import org.openehealth.ipf.platform.camel.ihe.fhir.test.FhirTestContainer;
25  
26  import static org.openehealth.ipf.platform.camel.ihe.fhir.core.FhirCamelTranslators.translateFhir;
27  import static org.openehealth.ipf.platform.camel.ihe.fhir.core.FhirCamelTranslators.translateToFhir;
28  import static org.openehealth.ipf.platform.camel.ihe.mllp.PixPdqCamelValidators.itiValidator;
29  
30  /**
31   *
32   */
33  public class Iti78TestRouteBuilder extends RouteBuilder {
34  
35      private final PdqmRequestToPdqQueryTranslator requestTranslator;
36      private final PdqResponseToPdqmResponseTranslator responseTranslator;
37  
38      private ResponseCase responseCase = ResponseCase.OK;
39  
40      public Iti78TestRouteBuilder(UriMapper uriMapper) {
41          super();
42          this.requestTranslator = new PdqmRequestToPdqQueryTranslator(uriMapper);
43          requestTranslator.setPdqSupplierResourceIdentifierUri("urn:oid:1.2.3.4.5.6");
44          this.responseTranslator = new PdqResponseToPdqmResponseTranslator(uriMapper);
45          responseTranslator.setPdqSupplierResourceIdentifierUri("urn:oid:1.2.3.4.5.6");
46      }
47  
48      public void setResponse(ResponseCase responseCase) {
49          this.responseCase = responseCase;
50      }
51  
52      @Override
53      public void configure() throws Exception {
54  
55          from("direct:input")
56                  .toF("pdqm-iti78:localhost:%d", FhirTestContainer.DEMO_APP_PORT);
57  
58          from("pdqm-iti78:translation?audit=true")
59                  // Translate into ITI-9
60                  .errorHandler(noErrorHandler())
61                  .process(translateFhir(requestTranslator))
62                  .process(itiValidator())
63                  // Create some static response
64                  .transform(new Iti21Responder(responseCase))
65                  // Translate back into FHIR
66                  .process(itiValidator())
67                  .process(translateToFhir(responseTranslator, Message.class));
68      }
69  
70  
71  }