1

我正在尝试读取包含以下消息的 hl7 文件

MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.3
QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||

使用 Apache camel、Hapi 和 Spring 框架(Java 配置)。我想解析上述消息并从中获取段详细信息。我正在使用 HL7 2.3 版。以下是我的 RouteBuilder 课程;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
import example.springcamel.processors.Hl7MessageProcessor;

@Component
public class SimpleRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("file://E:/projects/hl7/file_to_read/input/")
            .process(new Hl7MessageProcessor())
            .end();
        }
    }

E:/projects/hl7/file_to_read/input/这是我有一个名为 hl7_message.hl7 的文件的位置,其中包含上述消息。

以下是处理器类;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import ca.uhn.hl7v2.model.Message;

public class Hl7MessageProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
       Message message = exchange.getIn().getBody(Message.class);
       System.out.println("Original message: " + message);
    }
}

从上面的代码中,我得到的原始消息为空。我正在关注 Apache Camel http://camel.apache.org/hl7.html在此链接中给出的文档

以下是配置文件和主要应用程序:

SpringConfiguration.java

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "example.springcamel")
public class SpringConfiguration {

}

RoutesConfiguration.java

import org.apache.camel.spring.javaconfig.CamelConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages = "example.springcamel.routes")
public class RoutesConfiguration extends CamelConfiguration {

}

MainApplication.java

import org.apache.camel.CamelContext;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import example.springcamel.configuration.SpringConfiguration;

public class MainApplication {
    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws Exception {
        AbstractApplicationContext springContext = new 
                AnnotationConfigApplicationContext(SpringConfiguration.class);
        CamelContext camelContext = SpringCamelContext.springCamelContext(springContext, false);
        try {
            camelContext.start();
            Thread.sleep(3000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            camelContext.stop();
            springContext.close();
        }
    }   
}

我对 HL7 完全陌生,请有人帮助我解析上述 HL7 消息并从中获取段详细信息。

4

1 回答 1

3

我认为您在路线中缺少一些步骤。尝试将您的文件消息转换为Stringfirst 然后将其解组为 HL7:

from("file:src/test/resources/hl7?noop=true")
    .convertBodyTo(String.class)
    .unmarshal()
    .hl7(false)
    .log("The Message body is: ${body}")
    .process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            final Message message = exchange.getIn().getBody(Message.class);
            System.out.println("Original message: " + message);
        }
    })
    .to("mock:result");

也就是说,我试图处理你的输出,但我得到了这个错误:

ca.uhn.hl7v2.HL7Exception: The HL7 version 2.3 QRD is not recognized

我想我错过了\r行尾的角色。但我用这条消息验证了测试:

MSH|^~\&|HL7ABLAB|HNA500|HNAM|HNAM|20090911132151||ADT^A01|
Q30235031T29347435X328970|A|2.3|123
EVN|A01|20090911132100|||^DRONE_PM1^DRONE_PM^^^^^^^Personnel
PID|1||1357920591||IntFace1101A^WinTask^^^^^Current||19801117|M||||||||||
10000476524^^^FIN^FIN NBR|100000451||||||0
PV1|1|Inpatient|CD:16067689^CD:16067691^CD:16067741^Uniontown Hospit^^Bed(s)
^Uniontown Hospit||||||||||||||501455^Orr^Maggi^^^^^^External ID^Personnel^^^
External
Identifier~25584^Orr^Maggi^^^^^^PERSONNEL PRIMARY
IDENTIFIER^Personnel^^^Personnel Primary Identifier|Inpatient|||||||||||||||||||
||
Uniontown Hospit||Active|||20090911132100

考试:

@Test
public void test() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodyReceived().body(Message.class);

    assertMockEndpointsSatisfied();
}

结果:

Original message: MSH|^~\&|HL7ABLAB|HNA500|HNAM|HNAM|20090911132151||ADT^A01|Q30235031T29347435X328970|A|2.3|123
EVN|A01|20090911132100|||^DRONE_PM1^DRONE_PM^^^^^^^Personnel
PID|1||1357920591||IntFace1101A^WinTask^^^^^Current||19801117|M||||||||||
10000476524^^^FIN^FIN NBR|100000451||||||0
PV1|1|Inpatient|CD:16067689^CD:16067691^CD:16067741^Uniontown Hospit^^Bed(s)
^Uniontown Hospit||||||||||||||501455^Orr^Maggi^^^^^^External ID^Personnel^^^
External
Identifier~25584^Orr^Maggi^^^^^^PERSONNEL PRIMARY
IDENTIFIER^Personnel^^^Personnel Primary Identifier|Inpatient|||||||||||||||||||
||
Uniontown Hospit||Active|||20090911132100

依赖项:

<dependency>
    <groupId>ca.uhn.hapi</groupId> 
    <artifactId>hapi-structures-v23</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-hl7</artifactId>
</dependency>

你可以在这个 repo 中访问完整的测试。

干杯!

于 2017-12-06T16:39:03.753 回答