#
######################################################################
# replaceHL7Field – generic routine to replace the data in an HL7 field
# Args: msg the entire HL7 message
# segmentID the name of the segment containing the field to replace
# fieldID the index of the field to replace
# data the data that will replace the current contents of the field
#
# Returns: the an entire HL7 message
#
proc replacehl7 {msg segmentID fieldID data {fieldSeparator “|”}} {
set segmentList [split $msg r]
set newSegmentList “”
set data “5555”
foreach segment $segmentList {
if {[crange $segment 0 2] == OBX} {
set fieldList [split $segment $fieldSeparator]
set fieldList [lreplace $fieldList 5 5 $data]
set segment [join $fieldList $fieldSeparator]
}
set newSegmentList [lappend newSegmentList $segment]
}
return [join $newSegmentList r]