Hey Max. I took your HL7get script and modified it slightly to return a list of Segments if only the Segment is specified in the arguments.
This might be usefull if you want to grab all the OBX segments in a message and do something with them.
Troy
proc hl7get {args} {
set MyMsg [lindex $args 0] ;# 1st argument is the message
set MySeg [lindex $args 1] ;# 2nd argument is the segment
set MyFld [lindex $args 2] ;# 3rd argument is the field
set MySubFld [lindex $args 3] ;# 4th argument is the sub-field
set FldSep [string index $MyMsg 3] ;# Get the field seperator
set SubSep [string index $MyMsg 4] ;# Get the sub-field seperator
set RetVal “” ;# Initialize the return value to NULL
set LenSubFld [string length $MySubFld] ;# See if the user spcified a sub-field
set SplitMsg [split $MyMsg r] ;# Split the message into a list of segments
set TheSegment [lindex $SplitMsg [lsearch -regexp $SplitMsg “^$MySeg”] ] ;# Extract the segment we want
if { $TheField != “” } { ;# If user specified a field
set SplitSegment [split $TheSegment $FldSep] ;# Split the segment into a list of fields
set TheField [lindex $SplitSegment $MyFld] ;# Get the field number we’re looking for
if { $LenSubFld > 0 } { ;# If the user specified a sub-field
set SplitField [split $TheField $SubSep] ;# Split the field into sub-fields
set RetVal [lindex $SplitField $MySubFld] ;# Return the sub-field component value
} else {
set RetVal $TheField ;# Otherwise return the whole field
}
} else {
set RetVal $TheSegment ;# If only Segment specified, return Segment(s)
}
return $RetVal ;# Return the value of the field
}