You can do it with a string map command without looping through and finding each occurrence. I do question why they need to be removed – those are valid escape sequences in HL7 that should be replaced in the destination system when the message is filed. For example, “\R\” would be replaced by “~” (assuming “|^~\&” on the MSH segment). I do remember having to do this for a vendor’s embedded and encoded PDF one time because they went through and replaced all the delimiter characters in the encoded PDF – made for a magnificent crash when decoding the PDF.
To do it properly, you should pull out the delimiter characters from the MSH field first and use those rather than hard-coding values. Assuming this is done in a UPOC tcl:
keylget args MSGID mh
set msg [msgget $mh]
#separator
set fldSep [string index $msg 3]
set subSep [string index $msg 4]
set repSep [string index $msg 5]
set escSep [string index $msg 6]
set sb2Sep [string index $msg 7]
set map_list
# pull out the field from the message you want to change, for example an OBX-5 value, then use the string map command
set obx_5 [string map $map_list $obx_5]
# then replace the OBX-5 value in the message with the one you just fixed above.
If you need more detail on the pulling out and replacing of fields, I can provide that information as well.
Doing this within a translate is also possible, although I’ve never done it that way. Same concept, just a TCL fragment on the OBX-5 copy.
Paul Bishop
Carle Foundation Hospital
Urbana, IL