From: Tripp, B. <Bry...@uh...> - 2002-04-09 00:56:44
|
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/ |