Here's a new HL7 parser I've been working on. It's not quite done yet, but I think it works pretty well. I'm planning on adding features to delete and insert segments soon. I've used TCLDOC formatted comments, so you can generate nicely formatted documentation if you'd like. Any suggestions are appreciated.
Description:
This library contains routines for manipulating HL7 messages. This
involves splitting messages into segments, fields, components and
subcomponents. It saves processing time by only splitting apart the
parts of the message that are required to get or set the specified
field. As each part of the message is split, it is stored for future
requests, so if you make multiple requests for fields in a single
segment, only one segment split is required.
Example code:
package require hl7
keylget ARGS MSGID mh
set hl7 [hl7::parse_msg [msgget $mh]]
set msgType [hl7::get_field hl7 MSH.9.2]
hl7::set_field hl7 MSH.10 12345
for { set i 1 } { $i <= [hl7::count hl7 DG1] } { incr i } {
set diag_text [hl7::get_field hl7 DG1($i).4]
}
for { set i 1 } { $i <= [hl7::count hl7 PID.3] } { incr i } {
if { [hl7::get_field hl7 PID.3($i).5] eq "MR" } {
set mrn [hl7::get_field hl7 PID.3($i).1]
}
}
msgset $mh [hl7::join_msg hl7]
A field specifier has this format:
segment_name [ (repeating_segment_number) ] [ .field_number [
(repeating_field_number) ] [ .component_number [ .subcomponent_number ] ] ]
Examples:
PID.3
PID field 3
MRG(2).2
field 2 of MRG segment #2.
PID.3.5.1
PID segment, field 3, component 5, subcomponent 1.
DG1
the entire DG1 segment.