我正在尝试读取包含以下消息的 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 消息并从中获取段详细信息。