简体   繁体   English

向Java实现HL7解析器侦听器

[英]Implementing a Hl7 parser listener to java

Background 背景

I'm writing a medical record app for a friend who is a Doctor. 我正在为一位医生的朋友编写病历应用程序。 I was told to write a listener in the app that awaits HL7 messages. 有人告诉我在等待HL7消息的应用程序中编写一个侦听器。 That way a hospital can send out HL7 messages and my listener will catch them. 这样,医院就可以发送HL7消息,而我的听众会抓住它们。 So I came to the HAPI site and viewed this example . 因此,我来​​到了HAPI网站并查看了此示例 What I understand from it is that it's creating a server to listen for a message. 我从中了解到,它正在创建一个服务器来侦听消息。

I'm developing this in Eclipse using JSF 2.0 on Tomcat 7.0. 我正在Tomcat 7.0上使用JSF 2.0在Eclipse中进行开发。 Where does one normally put this kind of listener in a project with JSF? 通常,使用JSF在项目中将这种侦听器放在哪里? I've tried searching online for this answer and found nothing! 我尝试在线搜索此答案,但一无所获!

My question 我的问题

I know this code goes inside a class. 我知道这段代码放在一个类中。 When the class gets called the socket will be "turned on" and it's going to wait for a response. 当该类被调用时,套接字将被“打开”,它将等待响应。 So I want to call this class as soon as the project is deployed. 因此,我想在项目部署后立即调用此类。 How is that done? 怎么做的? How do I call that class only once (when the app is starting) in order to turn on the listener? 我如何仅一次(应用程序启动时)调用该类,以打开侦听器?

Any and all help is greatly appreciated! 非常感谢任何和所有的帮助! And if I'm not being clear on something let me know! 如果我不清楚某件事,请告诉我!

You don't normally get port listeners running inside an application hosted in Tomcat. 通常,您不会在Tomcat托管的应用程序中运行端口侦听器。 You're usually best to keep the two things separated. 通常最好将这两件事分开。 In the main, web servers aren't meant to run separate threads of execution outside of their control. 总的来说,Web服务器并不是要在其控制范围之外运行单独的执行线程。

You could consider using something like Spring Integration, JBossESB or Apache Camel to receive the messages and process them into a database, file folder (or whatever) that your Tomcat hosted web application then allowed you to manipulate. 您可以考虑使用诸如Spring Integration,JBossESB或Apache Camel之类的消息来接收消息,并将消息处理到Tomcat托管的Web应用程序允许您对其进行操作的数据库,文件夹(或其他内容)中。 The ESB container could be hosted in the same JVM process as Tomcat but I wouldn't take that approach myself - I'd have a separate one doing the message processing and another running the webapp. ESB容器可以与Tomcat托管在同一JVM进程中,但我自己不会采用这种方法-我需要一个单独的容器执行消息处理,另一个要运行webapp。

If you really wanted a "single application" you could consider creating a Java application that kicked off a listener as per the example you have, then started up an embedded version of Tomcat. 如果您确实想要“单个应用程序”,则可以考虑根据您的示例创建一个启动监听器的Java应用程序,然后启动嵌入式Tomcat版本。

If you really really wanted to run it inside Tomcat, as part of web application itself, you could create a class which did the listening and get it loaded into the Application context of the web application. 如果您真的想在Tomcat内部运行它(作为Web应用程序本身的一部分),则可以创建一个类来进行侦听并将其加载到Web应用程序的Application上下文中。 You can do this by adding an instance of it into the appl context within an autoloaded servlet - use <load-on-startup>1</load-on-startup> within the servlet definition. 您可以通过将其实例添加到自动加载的servlet的appl上下文中来实现此目的-在servlet定义中使用<load-on-startup>1</load-on-startup> You'd code the servlet to check if there was already an instance in context before adding a new one (on the off-chance it was ever manually invoked), or go down the Spring container route to manage this object as a singleton. 您可以对servlet进行编码,以在添加新实例之前检查上下文中是否存在实例(以偶然的方式曾经手动调用过该实例),或者沿着Spring容器路线进行操作,以单例方式管理该对象。

* EDIT: 20120114T004300Z * *编辑:20120114T004300Z *

Apache Camel is an example of a routing engine that might be used by an Enterprise Service Bus (ESB) such as Apache ServiceMix which allows multiple applications to interoperate by exchanging messages. Apache Camel是路由引擎的一个示例, 企业引擎可以通过Apache ServiceMix等企业服务总线 (ESB)使用该引擎,该引擎允许多个应用程序通过交换消息进行互操作。 You'd only use a fraction of the functionality availability for this app by the sounds of it. 听起来,您只会使用此应用程序的一部分功能。 For what you're doing you might just be able to use Camel capability embedded in Spring, for example. 例如,对于您正在做的事情,您可能仅能够使用嵌入在Spring中的Camel功能。

In essence, the ESB runs "adapters" (or endpoints) - one types of which would by the socket "listener" you talk about here, or might be watching a folder for files to arrive, or polling a database table for rows to appear, or waiting on a JMS queue, etc. The transport (the means by which the "message" (in your case the HL7 file) arrives becomes abstracted away from the functionality of the application itself. The adapter puts the message onto a channel which can be configure to transform the message en-route. Camel actually ships with a HL7 component which can understand the HL7 file format and unmarshal it into a HL7 model. (It also gives you the listener/adapter you need). You'd then set up routing in the ESB to pass that model into a "consumer" Java class that does whatever you need to do with it. 本质上,ESB运行“适配器”(或端点)-一种类型是您在此谈论的套接字“侦听器”,或者可能正在监视文件夹中是否有文件到达,或者在数据库表中轮询要出现的行,或等待JMS队列等。传输(到达“消息”(在您的情况下为HL7文件)的方式)从应用程序本身的功能中被抽象出来。适配器将消息放在一个通道上,可以配置为在途中转换消息。骆驼实际上附带了一个HL7组件 ,该组件可以理解HL7文件格式并将其解组为HL7模型(还为您提供了所需的侦听器/适配器)。在ESB中设置路由,以将该模型传递给“消费者” Java类,该类可以完成您需要执行的任何操作。

If you're dealing with "standard" transports, protocols and message types most of the file receipt, parsing, and routing is just handled by declarative configuration of the ESB rather than coding. 如果要处理“标准”传输,协议和消息类型,则大多数文件接收,解析和路由都仅通过ESB的声明性配置而不是编码来处理。

Your Tomcat webapp can run completely autonomously to this message handling. 您的Tomcat Web应用程序可以完全自主地运行以处理此消息。 As mentioned, there are various deployment options as to how exactly you'd do this - including loading Camel inside a Spring container hosted in Tomcat by your webapp if you want to. 如前所述,有多种部署选项可以精确地实现此目的-包括将Camel加载到webapp托管在Tomcat托管的Spring容器中。

Apologies if this is a bit woffley. 抱歉,这有点令人遗憾。 Take some time to read around the subject on the web, given that HL7 is a standard you'll probably find a lot of code/components already out there that might save you a lot of time in re-implementing the basic file handling so you can concentrate on the value-add webapp for your friend. 花一些时间阅读网络上的主题,因为HL7是一个标准,您可能已经发现了很多代码/组件,这些代码/组件可以为您节省大量时间来重新实现基本的文件处理,因此您可以专注于为您的朋友提供增值Web应用程序。

A "Listener" is just a class which listens on an open port. “侦听器”只是在开放端口上侦听的类。 In Java, this is mostly done through the Socket API, although you may find a library that better suits your purpose. 在Java中,这通常是通过Socket API完成的,尽管您可能会找到更适合您目的的库。

The Java Tutorial has some examples here: http://docs.oracle.com/javase/tutorial/networking/sockets/index.html Java教程在此处提供了一些示例: http : //docs.oracle.com/javase/tutorial/networking/sockets/index.html

In this case, you'd be writing a server (the listening half of a client-server arrangement), whereas the Hospital system sending the message would play the role of client. 在这种情况下,您将要编写一台服务器(客户端与服务器之间的监听一半),而发送消息的医院系统将扮演客户端的角色。

Once you're listening on the port, then HL7 messages arrive as plain text onto that socket's inputstream. 一旦您在端口上侦听,HL7消息就会以纯文本形式到达该套接字的输入流。 You can either hand-parse the message (viable if you're only interested in one or two details from a message) or if you're planning on handling dozens of types of messages you can look into one of the HL7 parsing libraries out there. 您可以手动解析消息(如果只对消息中的一个或两个详细信息感兴趣,则可以使用),或者如果您打算处理数十种消息,则可以查看其中的HL7解析库之一。

Keep in mind though, that different implementors of HL7 messages can sometimes send data in subtly different arrangements. 但是请记住,HL7消息的不同实现者有时可以以不同的方式发送数据。 (Many users treat HL7 as a 'recommendation' rather than a 'standard', unfortunately!) If you're planning on supporting lots of different feeds from lots of different providers, you'd be much better off using a middleware layer like MirthConnect to handle the parsing and translation of messages into something your application is designed to understand. (许多用户把HL7作为一个“建议”,而不是“标准”的,可惜!)如果你是从许多不同供应商的支持许多不同的饲料的计划,你会好得多使用像MirthConnect中间件层处理消息的解析和转换为应用程序旨在理解的内容。

Over a year old so you probably figured it all out, but an Enterprise Service Bus (ESB) is a type of middleware (when you think of software, there is back-end ie Database/Analytics/Admin Tools and front-end ie App/WebApp/GUI displayed to and interacted with end-user), middleware sits in between and helps perform integration or separation/coordination of tasks. 已有一年多的历史了,您可能已经想通了,但是企业服务总线(ESB)是一种中间件(当您想到软件时,有后端(即数据库/分析/管理工具)和前端(即应用程序) / WebApp / GUI显示给最终用户并与之交互),中间件位于两者之间,并有助于执行任务的集成或分离/协调。 Apache ServiceMix (an ESB which contains Apache Camel routing engine) is probably what you want and can be used to implement a number of different Enterprise Integration Patterns such as "Message Routing" (the one you want). Apache ServiceMix(包含Apache Camel路由引擎的ESB)可能就是您想要的,并且可用于实现多种不同的企业集成模式,例如“消息路由”(您想要的一种)。

Apache Camel has a built-in HL7 v2 Message parser (uses HAPI) which is the Tab-Separated variant of HL7: http://camel.apache.org/hl7.html Apache Camel具有内置的HL7 v2消息解析器(使用HAPI),它是HL7的Tab分隔变体: http : //camel.apache.org/hl7.html

For HL7 v3 messages which are in XML format you can use the toolkits available here under v3 utilities: http://www.hl7.org/participate/toolsandresources.cfm?ref=nav 对于XML格式的HL7 v3消息,您可以使用v3实用程序下的此处提供的工具包: http ://www.hl7.org/participate/toolsandresources.cfm?ref= nav

There are both server (message listening and reading) and client (message creation and sending) examples. 有服务器(消息侦听和阅读)和客户端(消息创建和发送)示例。

"Listener" is usually an event listener in Java. “ Listener”通常是Java中的事件侦听器。

In the example you posted a link to, you have a server class, which handles the business of opening a network socket and waiting for messages to arrive. 在示例中,您发布了指向的链接,您拥有一个服务器类,该类处理打开网络套接字并等待消息到达的事务。

The Application objects are the event listeners. Application对象是事件侦听器。 These are added to an internal collection of the server class (in this case, with additional parameters that tell the server which listeners to route which classes of HL7 message to). 这些被添加到服务器类的内部集合中(在这种情况下,带有告诉服务器哪些侦听器将HL7消息的哪些类路由到的附加参数)。

Each Application class must implement a particular interface - this constitutes the event listener. 每个Application类必须实现一个特定的接口-这构成了事件侦听器。 The SimpleServer class will call the methods of this interface ; SimpleServer类将调用此接口的方法; processMessage() ; processMessage() ; in order to perform actions based on message content, you write a class that implements this interface, and pass instances of it to the server class. 为了基于消息内容执行操作,您编写一个实现此接口的类,并将其实例传递给服务器类。 In the processMessage() method, you perform all the required actions. processMessage()方法中,您执行所有必需的操作。

Since you can register multiple listeners, you can implement a number of actions, eg you could have two listeners for ADT A01 messages (admit patient) ; 由于您可以注册多个侦听器,因此可以执行许多操作,例如,您可以有两个ADT A01消息侦听器(允许患者); one that booked them in, and one that assigned them a bed. 一个预定了他们的房间,另一个给了他们一张床。

I would suggest looking at Mirth Connect http://www.mirthcorp.com/community/mirth-connect as your HL7 message integration engine. 我建议您将Mirth Connect http://www.mirthcorp.com/community/mirth-connect用作HL7消息集成引擎。 Internally it makes use of HAPI. 在内部,它使用HAPI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM