1 /*
2 * Copyright 2015 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 package org.openehealth.ipf.platform.camel.ihe.fhir.translation;
17
18 import ca.uhn.hl7v2.model.Message;
19 import org.apache.camel.Processor;
20 import org.openehealth.ipf.commons.ihe.fhir.translation.FhirTranslator;
21 import org.openehealth.ipf.commons.ihe.fhir.translation.ToFhirTranslator;
22 import org.openehealth.ipf.platform.camel.core.util.Exchanges;
23
24 import java.util.Map;
25
26 /**
27 * Camel processors for translation of messages between FHIR and HL7v2
28 *
29 * @author Christian Ohr
30 * @since 3.1
31 *
32 * @deprecated use {@link org.openehealth.ipf.platform.camel.ihe.fhir.core.FhirCamelTranslators}
33 */
34 public final class FhirCamelTranslators {
35
36 private FhirCamelTranslators() {
37
38 }
39
40 /**
41 * Returns a processor for translating FHIR messages to Hl7v2
42 * using the given translator instance.
43 */
44 public static Processor translatorFhirToHL7v2(final FhirTranslator<Message> translator) {
45 return exchange -> {
46 // ca.uhn.hl7v2.model.Message initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, ca.uhn.hl7v2.model.Message.class);
47 Object fhir = exchange.getIn().getBody();
48 Map<String, Object> parameters = exchange.getIn().getHeaders();
49 // exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, xmlText);
50 org.apache.camel.Message resultMessage = Exchanges.resultMessage(exchange);
51 resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
52 resultMessage.setBody(translator.translateFhir(fhir, parameters));
53 };
54 }
55
56
57 /**
58 * Returns a processor for translating HL7v2 messages to FHIR
59 * using the given translator instance.
60 */
61 public static Processor translatorHL7v2ToFhir(final ToFhirTranslator<Message> translator) {
62 return exchange -> {
63 // String initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, String.class);
64 ca.uhn.hl7v2.model.Message msg = exchange.getIn().getMandatoryBody(ca.uhn.hl7v2.model.Message.class);
65 Map<String, Object> parameters = exchange.getIn().getHeaders();
66 // exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, msg);
67 org.apache.camel.Message resultMessage = Exchanges.resultMessage(exchange);
68 resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
69 resultMessage.setBody(translator.translateToFhir(msg, parameters));
70 };
71 }
72
73 }