Forum Replies Created
-
AuthorReplies
-
Thank you both 😀 I will work on the code snip-it you supplied and let you know if it works.
May 16, 2014 at 5:15 pm in reply to: Replace field back into a segment while using a foreach loop #80609Thank you both! I did finally get it to work. When doing the lreplace, I had to put the new segment back into the original $msg variable then set newmsg to $msg since I am working with two lists within a loop. And, I had to close the loop before the final join. I hope this all make sense. I am posting the last part of my code where I made the changes.
#rebuild msg (put new segment back into the message)
set msg [lreplace $msg $loc $loc $newobxseg]
set newmsg $msg
};# close loop
set newmsg [join $newmsg “r”]
msgset $mh $newmsg
return “{CONTINUE $mh}”
May 15, 2014 at 3:06 pm in reply to: Replace field back into a segment while using a foreach loop #80606Thank you! I was able to figure that out but I now have another problem. I am able to convert all 5 iterations of OBX.3 to upper case but when the message ‘CONTINUES’ only the last iteration is in the output.
This is my code:
#loop through the message and convert OBX.3 to UPPERCASE
foreach loc [lsearch -all -regexp $msg “^OBX”] {
# get the obx segment and obx 3 field from the message
set obxseg [lindex $msg $loc]
set obxfield [split $obxseg $fsep]
set obx_3 [lindex $obxfield 3]
#make all data in obx.3 UPPERCASE
regsub -all — {.*} $obx_3 {[string toupper {&}]} obx_3
set obx_3 [subst -nobackslashes -novariables $obx_3]
# rebuild segment (put new obx3 back into the segment)
set newobxseg [lreplace $obxfield 3 3 $obx_3]
set newobxseg [join $newobxseg $fsep]
#rebuild msg (put new segment back into the message)
set newmsg [lreplace $msg $loc $loc $newobxseg]
set newmsg [join $newmsg “r”]
msgset $mh $newmsg
};# close loop
return “{CONTINUE $mh}”
This is what the new segment looks like when I echo $newobxseg:
OBX|1|NM|CONVERT TO UPPER||75|bpm|||||R|||20140505143841-0500
OBX|2|NM|CONVERT TO UPPER||76|bpm|||||R|||20140505143841-0848
OBX|3|NM|CONVERT TO UPPER||77|bpm|||||R|||20140505143841-0650
OBX|4|NM|CONVERT TO UPPER||78|bpm|||||R|||20140505143841-4785
OBX|5|NM|CONVERT TO UPPER||79|bpm|||||R|||20140505143841-3256
BUT, this is the output with ‘CONTINUE’:
CONTINUE: ‘MSH|^~&|||||20140505143841-0500||ORU^R01|10|P|2.3
PID|||7000128^^^^EPIC~7000128^^^^PHHS||ONE^OBIX^||19840425|||||||||||340604813
PV1|||^^LW04^1^^PHHS^^^^^^||||||||||||||||613600366|||||||||||||||||||||||||20140505143841
ORC||||||
OBR|||||||20140505143841
OBX|1|NM|convert to upper||75|bpm|||||R|||20140505143841-0500
OBX|2|NM|convert to upper||76|bpm|||||R|||20140505143841-0848
OBX|3|NM|convert to upper||77|bpm|||||R|||20140505143841-0650
OBX|4|NM|convert to upper||78|bpm|||||R|||20140505143841-4785
OBX|5|NM|CONVERT TO UPPER||79|bpm|||||R|||20140505143841-3256
I must be missing something in my code but I don’t know what.
-
AuthorReplies