2017-04-12 38 views
0

我正在尝试使用camel为hl7v2.x消息设置mllp监听器。如何使用apache驼峰生成自定义ack hl7

我的环境

  • Apache的骆驼和组件版本2.18.3

我也想避免使用HAPI库,因为我更喜欢一个自定义的解析器接收和产生消息。由于我的客户都是使用不同版本的标准字段和真正不同的字段用法。这就是为什么在下面的路由中没有对hl7数据类型进行解组的原因,只是为了字符串。我会自己做解析器。

我的路线(所有的豆类和变量在代码的其他地方定义,我认为他们是不相关)

from("netty4:tcp://0.0.0.0:3333? 
encoder=#encoderHl7&decoder=#decoderHl7&sync=true") 
.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") 
.unmarshal().string() 
.to("file://" + rutaSalidaFichero) 
; 

首先,作为证明的概念,我只是想复制所有收到的消息放入文件系统目录。消息被正确接收并写入目录。但我不知道如何产生和发送ACK,不正确的一个正在自动生成并发送。

如果我从外部/发送系统发送hl7消息,驼峰组件发送与ack相同的消息,所以发送系统发送一个错误作为回报,因为它不是预期的ack。我正在用hirth,dcm4chee,hapi发送hl7消息......所有这些都有相同的结果。

例如,如果我发送下面的信息从外/发送器系统 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 | CULT^CULTIVO

我收到了与发送系统中的ack相同的内容。这是骆驼产生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 |||||| 201704.12亿 OBR | 1 | 317018426 | 317018426 | CULT^CULTIVO

我没有在骆驼文档中找到对ack生成的引用,或者如果我可以使用自定义“东西”来生成它。我想改变这种默认行为。

回答

0

般地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(...)) 

,并从“确认”的方法最PARAMS是直接到org.apache.camel.component.hl7.AckExpression。实际ACK产生被“org.apache.camel.component.hl7.AckExpression#评估”完成,看起来像

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.AckExpression和落实所需的逻辑,而不是

return msg.generateACK(code == null ? AcknowledgmentCode.AA : code, hl7e); 

,并使用它像

... 

    from("direct:test1") 
     // acknowledgement 
     .transform(new ValueBuilder(new MyCustomAckExpression())) 
+0

我已经重写的路线,因此现在看起来是这样。 从。( “netty4:TCP://0.0.0.0:3333编码器=#encoderHl7&解码器=#decoderHl7与同步=真”) .unmarshal()的字符串() .onCompletion()modeBeforeConsumer() .transform( ack(AckCode.AA)) .end() .to(“file://”+ rutaSalidaFichero); 如果我不使用onCompletion()。modeBeforeConsumer(),我会丢失路由其余部分的原始消息,并将ack写入文件系统而不是原始消息。评论和建议非常受欢迎。 – usuario

0

这是我对我的项目完成:

<bean id="hl7Processor" class="com.mediresource.MessageRouting.HL7.HL7Processor" /> 

<route> 
    <from uri="mina2:tcp://10.68.124.140:2575?sync=true&amp;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; 
}