ruby-hl7 0.2.50 released

October 23rd, 2007

This is a maintenance release of the 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. There is a rubyforge project to store the releases. This release is mainly a bug-fix release, here's the list of changes:
  • Modified the requires due to refactoring in facets 2.x

ruby-hl7 0.2.44 released

August 5th, 2007

This is the second 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. There is a rubyforge project to store the releases. This release is mainly a bug-fix release, here's the list of changes:
  • Various segment access related bugs handled (null segments, empty segments)
  • Speed fix when parsing messages where there are a large number of unimplemented segments
  • Associated/Child segment access
Here's an example of the new child segment access api:
1
2
3
4
5
6
7
8
9
10
11
12

require 'rubygems'
require 'ruby-hl7'

msg = HL7::Message.new "my_msg.hl7"

#this will go through each observation and print the observed values
msg["OBR"].each |obr|
  obr.children.each do |obx|
    puts obx.observation_value
  end
end
My thanks to Jeff for bringing the performance issue to my attention. I'm always happy to get feedback, patches and thanks. Cheers!
Ok, so you want to do something more than muck with some fields in passing segments. Ruby-hl7 provides a nice way to encapsulate specific segments as objects, dealing with field aliases instead of field id numbers. After all isn't my_obj.last_checkup_date a little clearer than my_obj.e11. I certainly think so, which is why you can define a class for a segment type. Let's create a class describing a BLG (Billing) segment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# When a message is parsed, the parser checks for a class matching this format
class HL7::Message::Segment::BLG < HL7::Message::Segment
  weight 600  # we want this to go after every other segment (they are sorted ascendingly)

  # we're adding a field alias to BLG.1, which happens to be "when to charge" in the docs
  add_field :name=>:when_to_charge 
  
  # we'll include some value checking logic in the next field we add
  VALID_CHARGES = %w[ CH CO DR DP GR NC NP RS ]
  add_field :name=>:charge_type do |c|
     raise HL7::Exception.new("Invalid charge type") unless c
     raise HL7::Exception.new("Invalid charge type") unless VALID_CHARGES.index(c)
     c # we need to return the final value of c as this is called on read/write
  end

  # we can explicitly set the field id, this would point to BLG.4
  add_field :name=>:charge_type_reason, :idx=>4
end


Now let's use it:
1
2
3
4
5
6
7
8
9
10
11
# create the empty hl7 message
msg = HL7::Message.new

# create our segments and fill in some data
msh = HL7::Message::Segment::MSH.new 
blg = HL7::Message::Segment::BLG.new
blg.when_to_charge = Date.new.to_s
blg.charge_type = "CH"

msg << msh
msg << blg

There you go, the suggested method for dealing with known segments.

ruby-hl7 in the wild

April 1st, 2007

Ron Sweeney put together a cool little HL7 Sniffer that uses libpcap to pull messages from the wire. To my knowledge this is the first use of ruby-hl7 outside of my own personal usage. So props to Ron for creating a cool app. I'll be playing with it when I get back into the States.

ruby-hl7 0.1.23 released

March 18th, 2007

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'rubygems'
require 'ruby-hl7'
require 'socket'

# create the empty hl7 message
msg = HL7::Message.new

# create an empty MSH segment
msh = HL7::Message::Segment::MSH.new 

# 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

# 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"

# 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