2017-04-12 40 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; 
}