1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.hl7v3;
17
18 import org.apache.camel.Exchange;
19 import org.apache.camel.Message;
20 import org.apache.camel.Processor;
21 import org.openehealth.ipf.commons.ihe.hl7v3.translation.Hl7TranslatorV2toV3;
22 import org.openehealth.ipf.commons.ihe.hl7v3.translation.Hl7TranslatorV3toV2;
23 import org.openehealth.ipf.platform.camel.core.util.Exchanges;
24
25
26
27
28
29 abstract public class PixPdqV3CamelTranslators {
30
31
32
33
34
35 public static final String HL7V3_ORIGINAL_REQUEST_PROPERTY = "hl7v3.original.request";
36
37
38
39
40
41
42 public static Processor translatorHL7v3toHL7v2(final Hl7TranslatorV3toV2 translator) {
43 return exchange -> {
44 ca.uhn.hl7v2.model.Message initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, ca.uhn.hl7v2.model.Message.class);
45 String xmlText = exchange.getIn().getMandatoryBody(String.class);
46 exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, xmlText);
47 Message resultMessage = Exchanges.resultMessage(exchange);
48 resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
49 resultMessage.setBody(translator.translateV3toV2(xmlText, initial));
50 };
51 }
52
53
54
55
56
57
58 public static Processor translatorHL7v2toHL7v3(final Hl7TranslatorV2toV3 translator) {
59 return exchange -> {
60 String initial = exchange.getProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, String.class);
61 ca.uhn.hl7v2.model.Message msg = exchange.getIn().getMandatoryBody(ca.uhn.hl7v2.model.Message.class);
62 exchange.setProperty(HL7V3_ORIGINAL_REQUEST_PROPERTY, msg);
63 Message resultMessage = Exchanges.resultMessage(exchange);
64 String charset = exchange.getProperty(Exchange.CHARSET_NAME, "UTF-8", String.class);
65 resultMessage.getHeaders().putAll(exchange.getIn().getHeaders());
66 resultMessage.setBody(translator.translateV2toV3(msg, initial, charset));
67 };
68 }
69
70 }