第 148 章 HL7 DataFormat


可作为 Camel 版本 2.0 提供

HL7 组件用于使用 HL7 MLLP 协议和 HL7 v2 消息,使用 HAPI 库。

这个组件支持以下内容:

  • HL7 MLLP codec,Mina
  • HL7 MLLP codec for Netty4 from Camel 2.15 开始
  • 从/到 HAPI 和字符串的转换器
  • 使用 HAPI 库的 HL7 DataFormat
  • 更加便于使用,因为它与 camel-mina2 组件集成。

Maven 用户需要将以下依赖项添加到其 pom.xml 中:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-hl7</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

148.1. HL7 MLLP 协议

HL7 通常用于 HL7 MLLP 协议,它是一个基于文本的 TCP 套接字协议。此组件附带 Mina 和 Netty4 Codec,它符合 MLLP 协议,因此您可以轻松地公开 HL7 侦听器通过 TCP 传输层接受 HL7 请求。要公开 HL7 侦听器服务,camel-mina2 或 camel-netty4 组件用于 HL7MLLPCodec (mina2)或 HL7MLLPNettyDecoder/HL7MLLPNettyEncoder (Netty4)。

HL7 MLLP codec 可以配置为:

名称默认值描述

startByte

0x0b

跨越 HL7 有效负载的开始字节。

endByte1

0x1c

跨 HL7 有效负载的第一个结束字节。

endByte2

0x0d

整个 HL7 有效负载之间的第二代字节。

charset

JVM 默认

用于 codec 的编码(一个 charset 名称)。如果没有提供,Camel 将使用 JVM 默认 Charset。

produceString

true

(从 Camel 2.14.1 起), 则 codec 使用定义的 charset 创建一个字符串。如果为 false,则 codec 会向路由发送一个纯字节阵列,以便 HL7 数据格式可以确定 HL7 消息内容的实际 charset。

convertLFtoCR

false

将 \n 转换为 \r (0x0d, 13 十进制),并将 HL7 取胜 \r 作为网段术语符。HAPI 库需要使用 \r。

148.1.1. 使用 Mina 公开 HL7 侦听器

在 Spring XML 文件中,我们将一个 mina2 端点配置为在端口 8888 上使用 TCP 侦听 HL7 请求:

<endpoint id="hl7MinaListener" uri="mina2:tcp://localhost:8888?sync=true&amp;codec=#hl7codec"/>

sync=true 表示此侦听器是同步的,因此会返回 HL7 响应到调用者。HL7 codec 使用 codec=#hl7codec 设置。请注意,hl7codec 只是一个 Spring bean ID,因此它可以命名为 mygreatcodecforhl7 或 any。在 Spring XML 文件中也设置了 codec:

<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
    <property name="charset" value="iso-8859-1"/>
</bean>

然后,可以在路由中使用 endpoint hl7MinaLlistener 作为消费者,因为这个 Java DSL 示例演示了:

from("hl7MinaListener")
  .bean("patientLookupService");

这是一个非常简单的路由,它将侦听 HL7,并将其路由到名为 patient LookupService 的服务。这也是 Spring Bean ID,在 Spring XML 中配置,如下所示:

<bean id="patientLookupService" class="com.mycompany.healthcare.service.PatientLookupService"/>

业务逻辑可以在 POJO 类中实施,而这些类不依赖于 Camel,如下所示:

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v24.segment.QRD;

public class PatientLookupService {
    public Message lookupPatient(Message input) throws HL7Exception {
        QRD qrd = (QRD)input.get("QRD");
        String patientId = qrd.getWhoSubjectFilter(0).getIDNumber().getValue();

        // find patient data based on the patient id and create a HL7 model object with the response
        Message response = ... create and set response data
        return response
    }

在 Spring XML 文件中,我们将一个 netty4 端点配置为在端口 8888 上使用 TCP 侦听 HL7 请求:

<endpoint id="hl7NettyListener" uri="netty4:tcp://localhost:8888?sync=true&amp;encoder=#hl7encoder&amp;decoder=#hl7decoder"/>

sync=true 表示此侦听器是同步的,因此会返回 HL7 响应到调用者。HL7 codec 使用 encoder=#hl7encoder*and*decoder=#hl7decoder 设置。请注意,hl7encoder 和 hl7decoder 只是 bean ID,因此可以不同的命名。Bean 可以在 Spring XML 文件中设置:

<bean id="hl7decoder" class="org.apache.camel.component.hl7.HL7MLLPNettyDecoderFactory"/>
<bean id="hl7encoder" class="org.apache.camel.component.hl7.HL7MLLPNettyEncoderFactory"/>

然后,可以在路由中使用 endpoint hl7NettyListener 作为消费者,因为此 Java DSL 示例演示了:

from("hl7NettyListener")
  .bean("patientLookupService");
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部