|
From: Alex H. <al...@9p...> - 2002-04-09 20:38:12
|
I'm working on a project that is using HAPI and am doing things highly
similar to what Bryan describes. The difference is that I'm using session
and entity beans to encapsulate the database access rather than use JDBC
directly.
I have a class that acts to do the work of processing HL7 messages and then
create value objects and shipping them off to the session bean.
In working with the A-type messages for demographics, I've found that I've
written some redundant code to pull out the demographics segments from the
contents of the A messages. I have a series of functions that are
type-specific to each message type. These functions extract segments like
PID, NK1, etc. and use generic helper functions to populate my value object.
One strategy I though of was to implement some type of common interface by
which client code could query a generic message class and ask it for a
particular segment. If the segment was not available from the concrete
message, NULL would be returned. Something like this would eliminate the
need to write lots and lots of message type specific code.
Thoughts on putting more in the Message class to support stuff like this?
Its good to see some posts on this list!
-Alex
-----Original Message-----
From: hl7...@li...
[mailto:hl7...@li...]On Behalf Of Tripp, Bryan
Sent: Monday, April 08, 2002 7:56 PM
To: 'Tumkur, Priyadarshan'; 'hl7...@li...'
Subject: RE: [HAPI-devel] Beginners question
Hi Darshan,
The straightforward way to do this is to read data from a message object and
use it to build the necessary SQL statements.
By the way, has anyone else developed a more elegant method yet?
I'll try to walk you through a simple example to get you started. We'll use
a v2.4 ACK message because it's simple and because it comes with the HAPI
distribution. We'll make a class that accepts a JDBC connection in the
constructor, and has a method that writes a few message fields to a table,
like this ...
import java.sql.*;
import ca.uhn.hl7v2.model.v24.ACK;
public class DBWriteDemo {
private static Connection conn;
public DBWriteDemo(Connection c) {
this.conn = c;
}
public void storeData(ACK message) throws SQLException {
// ...
}
}
Within the "storeData" method you would just read data from the incoming
message, build an SQL insert statement, and execute it. To keep things
simple, let's imagine you have a table called "message_times" and you want
to insert two fields into it - the message time stamp ("time") and the
message ID ("ID"). You could do something like this:
public void storeData(ACK message) throws SQLException {
//the HAPI part ...
String messageTime =
message.getMSH().getDateTimeOfMessage().getValue();
String messageID =
message.getMSH().getMessageControlID().getValue();
//the JDBC part ...
StringBuffer sql = new StringBuffer();
sql.append("insert into message_times (time, ID) values ('");
sql.append(messageTime);
sql.append("', '");
sql.append(messageID);
sql.append("')");
Statement s = conn.createStatement();
s.execute(sql.toString());
s.close();
}
For testing purposes, an easy way to get an ACK object would be to put an
ACK message in a file, read it into a String, and parse it. To try it out,
you could make a main() along the following lines:
public static void main(String args[]) {
try {
//PipeParser is HAPI's main HL7 parser for the traditional
HL7 encoding
PipeParser parser = new PipeParser();
//read the file ...
File messageFile = new File(args[0]);
FileReader r = new FileReader(messageFile);
char[] cbuf = new char[(int)messageFile.length()];
r.read(cbuf);
r.close();
String messString = String.valueOf(cbuf);
//parse the message into an ACK message object ...
ACK message = (ACK) parser.parse(messString);
// ... make sure your JDBC driver is loaded
//store the message data
DBWriteDemo demo = new
DBWriteDemo(DriverManager.getConnection(/* ... database URL ... */));
demo.storeData(message);
} catch (Exception e) {
e.printStackTrace();
}
}
To obtain real messages in your production app you could use the
ca.uhn.hl7v2.app.SimpleServer class to listen for messages (assuming you are
receiving messages over a socket). For more detail, please see the JavaDocs
for this class as well as Application, MessageTypeRouter, and Responder in
the same package. In a nutshell, you would configure the server to route
the messages you are interested in to an implementation of the Application
interface that you create. Application has the following method:
public Message processMessage(Message in);
... your implementation of this would be very similar to the "storeData()"
method above. If this isn't clear, let me know and I can explain further.
About the HL7 Access database ... you need this because HAPI needs a
specific Java class for every message structure. For example, to handle
ADT_A01 messages, you need an ADT_A01 class. These classes are generated
automatically using the Access database.
I would rather just give you the necessary message classes than make you buy
the database. The reason I can't do that, yet, is because of HL7's
copyright on the database, which covers derived materials. We are
discussing with HL7 the possibility of releasing the message classes so that
people don't need the database. So far HL7 has been very receptive, but we
won't have a final answer before the Atlanta working group meeting at the
end of the month. I'll post a message to the list as soon as I hear
something definitive. In the mean time, the only thing to do is buy the
database.
Good luck, I hope this helps.
Regards,
Bryan
-----Original Message-----
From: Tumkur, Priyadarshan [mailto:Pri...@Mc...]
Sent: April 8, 2002 5:15 PM
To: 'hl7...@li...'
Subject: [HAPI-devel] Beginners question
Hi ,
I am new to the HL7 structure and has been assigned to write a Parser to
extract the Patient Demographic Data (PID) info from the HL7 messages. I
bumped into your tool and wanted some basic information for using HAPI.
We are interested in extracting Patient information and store in the DB. Can
you tell me how I can start off to do that using your tools. I am really not
getting the point of Access Database which
we are supposed to buy for generation of different modules. Please update
the best way as to how I can implement my requirement using HAPI.
Thanks,
Darshan
___________________________________________________________________________
CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is
for the sole use of the intended recipient(s) and may contain confidential
and privileged information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient, please
contact the sender by reply e-mail and destroy all copies of the original
message.
_______________________________________________
Hl7api-devel mailing list
Hl7...@li...
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
Sponsored by http://www.ThinkGeek.com/
Sponsored by http://www.ThinkGeek.com/
_______________________________________________
Hl7api-devel mailing list
Hl7...@li...
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
|