我试图使用camel为hl7v2.x消息设置一个mllp侦听器。
我的环境
此外,我希望避免使用HAPI库,因为我更喜欢用于接收和生成消息的自定义解析器。由于我的客户端都使用不同版本的标准和不同的字段使用,这就是为什么在下面的路由中没有对hl7数据类型进行解组,只需要字符串。我自己来做解析器。
我的路由(所有bean和变量都在代码的其他地方定义,我认为它们不相关)
from("netty4:tcp://0.0.0.0:3333?
encoder=#encoderHl7&decoder=#decoderHl7&sync=true")
.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
.unmarshal().string()
.to("file://" + rutaSalidaFichero)
;首先,作为概念的证明,我只是试图将接收到的所有消息复制到文件系统目录中。这些消息被正确地接收并写入目录。但我不知道如何生成和发送ACK,一个错误的ACK正在自动生成和发送。
如果我从外部/发送系统发送hl7消息,camel组件会发送与ack相同的消息,因此发送系统会发送一个错误,因为它不是ack所期望的。我用hl7,dcm4chee,hapi .结果是一样的。
例如,如果我从外部/发送方系统( MSH|^~\&|LIS|LIS|HIS|HIS|20170412131105||OML^O21|0000000001|P|2.5|||AL|||8859/1|||1.0 PID|1||123456||APELLIDO1&APELLIDO2^NOMBRE|19200101 ORC|RP|009509452919|317018426||||||20170412000000 OBR)发送以下消息,那么OBR/OBR/317018426/317018426/317018426/CULTIVO是从外部/发送方系统发送的。
我收到的信息和发送系统中的密码一样。这是骆驼生成ack作为接收消息MSH|^~\&|LIS|LIS|HIS|HIS|20170412131105||OML^O21|0000000001|P|2.5|||AL|||8859/1|||1.0 PID|1||123456||APELLIDO1&APELLIDO2^NOMBRE|19200101 ORC|RP|009509452919|317018426||||||20170412000000 OBR 1区317018426区317018426\CULTIVO
我还没有在骆驼文档中找到对生成ack的引用,或者如果我可以使用自定义的“东西”来生成它的话。我想改变这种默认行为。
发布于 2017-04-12 16:31:55
正如骆驼hl7组件文档所述(http://camel.apache.org/hl7.html,"HL7确认表达式“),您只需使用
import static org.apache.camel.component.hl7.HL7.ack;
...
from("direct:test1")
// acknowledgement
.transform(ack())这里,"ack()“是对"org.apache.camel.component.hl7.HL7#ack()”的调用。但您可以检查"org.apache.camel.component.hl7.HL7“是否包含其他一些有用的方法,如
org.apache.camel.component.hl7.HL7#ack(ca.uhn.hl7v2.AcknowledgmentCode code)或
org.apache.camel.component.hl7.HL7#ack(ca.uhn.hl7v2.AcknowledgmentCode code, java.lang.String errorMessage, ca.uhn.hl7v2.ErrorCode )您可以使用它们自定义实际的ACK响应。如果我们再深入一点,你就会发现"org.apache.camel.component.hl7.HL7#ack“只是包装
new ValueBuilder(new AckExpression(...))"ack“方法中的大多数参数都直接转到org.apache.camel.component.hl7.AckExpression。实际的ACK生成是在"org.apache.camel.component.hl7.AckExpression#evaluate“中完成的,如下所示
public Object evaluate(Exchange exchange) {
Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
Message msg = exchange.getIn().getBody(Message.class);
try {
HL7Exception hl7e = generateHL7Exception(t);
AcknowledgmentCode code = acknowledgementCode;
if (t != null && code == null) {
code = AcknowledgmentCode.AE;
}
return msg.generateACK(code == null ? AcknowledgmentCode.AA : code, hl7e);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}如果您需要更深入的定制,只需编写您自己的MyCustomAckExpression,它将扩展org.apache.camel.Component.hl7.AckExprestion并实现所需的逻辑,而不是
return msg.generateACK(code == null ? AcknowledgmentCode.AA : code, hl7e);然后把它当作
...
from("direct:test1")
// acknowledgement
.transform(new ValueBuilder(new MyCustomAckExpression()))发布于 2017-04-14 17:24:54
这就是我在我的项目中所做的:
<bean id="hl7Processor" class="com.mediresource.MessageRouting.HL7.HL7Processor" />
<route>
<from uri="mina2:tcp://10.68.124.140:2575?sync=true&codec=#hl7codec" />
<onException>
<exception>org.apache.camel.RuntimeCamelException</exception>
<exception>ca.uhn.hl7v2.HL7Exception</exception>
<redeliveryPolicy maximumRedeliveries="0" />
<handled>
<constant>true</constant>
</handled>
<bean ref="hl7Processor" method="sendACKError" />
</onException>
<bean ref="hl7Processor" method="sendACK" />
</route>在HL7Processor课堂上,我有这样的观点:
public Message sendACK(Message message, Exchange exchange ) throws HL7Exception, IOException {
logger.debug("Entering");
Message ack = message.generateACK();
logger.info("(10-4), End - ACK sent for " + exchange.getExchangeId());
return ack;
}
public Message sendACKError(Message message, Exception ex) throws HL7Exception, IOException {
try {
logger.warn("Internal Error:" + ex);
Message ack = message.generateACK(AcknowledgmentCode.AE, new HL7Exception("Internal Error") );
logger.warn("(10-4), End - NACK");
return ack;
} catch (Exception ex1) {
logger.error("Fatal error on processError! ", ex1);
}
return null;
}https://stackoverflow.com/questions/43369364
复制相似问题