This is the first public release of my Ruby HL7 library. HL7 is a standard for information exchange in hospitals, it’s used for everything from lab work to billing and scheduling. The library can parse or generate HL7 messages. Currently the library only support HL7 2.x, but I’d like to add support for the xml based HL7 3.0 in a future version.

You can install the library by typing gem install ruby-hl7. The bugtracker is hosted locally. I’ve created a rubyforge project to store the releases.

Here’s an example of ruby-hl7 usage:

require ‘rubygems’
require ‘ruby-hl7’
require ‘socket’

  1. create the empty hl7 message
    msg = HL7::Message.new
  1. create an empty MSH segment
    msh = HL7::Message::Segment::MSH.new
  1. create an empty NTE segment
    nte = HL7::Message::Segment::NTE.new
    msg << msh # add the MSH segment to our message
    msg << nte # add the NTE segment to our message
  1. let’s fill in some fields using pre-defined aliases
    msh.sending_app = “my test app”
    msh.sending_facility = “my apartment”
    nte.comment = “my message rocks, ruby-hl7 is great”
  1. let’s create our own on-the-fly segment (NK1 is not implemented in code)
    seg = HL7::Message::Segment::Default.new
    seg.e0 = “NK1” # define the segment’s name
    seg.e1 = “MORE INFO” # define it’s first field
    seg.e2 = “OTHER INFO” # define it’s second field
    msg << seg # add the new segment to the message

soc = TCPSocket.open( “192.168.1.234”, 5700 )
soc.write msg.to_mllp
soc.close



posted on March 18, 2007