搜索

第 76 章 HL7

download PDF

HL7 组件用于使用 HAPI 库 处理 HL7 MLLP 协议和 HL7 v2 消息

这个组件支持以下内容:

  • Mina的 HL7 MLLP codec
  • 用于 Netty的 HL7 MLLP codec
  • 从/到 HAPI 和字符串输入 Converter
  • 使用 HAPI 库的 HL7 DataFormat

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

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

76.1. HL7 MLLP 协议

HL7 通常与 HL7 MLLP 协议一起使用,该协议是一个基于文本的基于 TCP 套接字的协议。此组件提供了 Mina 和 Netty Codec,它符合 MLLP 协议,以便您可以轻松地公开可以接受通过 TCP 传输层的 HL7 请求的 HL7 侦听器。要公开 HL7 侦听器服务,camel-mina 或 link:camel-netty 组件与 HL7MLLPCodec (mina)或 HL7MLLPNettyDecoder/HL7MLLPNettyEncoder (Netty)一起使用。

HL7 MLLP codec 可以配置如下:

Name默认值描述

startByte

0x0b

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

endByte1

0x1c

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

endByte2

0x0d

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

charset

JVM 默认

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

produceString

true

如果为 true,则 codec 会使用定义的 charset 创建一个字符串。如果为 false,则 codec 会将普通字节数组发送到路由,以便 HL7 Data Format 可以决定 HL7 消息内容的实际 charset。

convertLFtoCR

false

\n 转换为 \r (0x0d, 13 十进制),作为 HL7 stipulates \r 作为片段术语器。HAPI 库需要使用 \r

76.1.1. 使用 Mina 公开 HL7 侦听程序

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

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

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

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

端点 hl7MinaLlistener 可作为消费者在路由中使用,如这个 Java DSL 示例演示了:

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

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

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

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

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
    }

76.1.2. 使用 Netty 公开 HL7 侦听器(可从 Camel 2.15 开始使用)

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

<endpoint id="hl7NettyListener" uri="netty:tcp://localhost:8888?sync=true&amp;encoders=#hl7encoder&amp;decoders=#hl7decoder"/>

sync=true 表示此监听程序是同步的,因此会将 HL7 响应返回给调用者。HL7 codec 是带有 encoders=114hl7encoder598andödecoders=114hl7decoder 的设置。请注意,hl7encoderhl7decoder 只是 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"/>

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

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

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.