Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › OBX First Segment
- This topic has 14 replies, 4 voices, and was last updated 14 years, 7 months ago by
Femina Jaffer.
-
CreatorTopic
-
May 4, 2009 at 5:35 pm #50843
Femina Jaffer
ParticipantHello Everyone, I am in need of assistance, please help me.
I need to find an abnormal flag in any of the OBX segments (the flag is ‘*P”). Once I find this in the message, I need to append ONLY the first OBX segment with an “ABN” at the end.
E.g OBX|1||||abasddkfdjkfjdkf|||ABN
What is the best way to handle this.
Femina
-
CreatorTopic
-
AuthorReplies
-
-
May 4, 2009 at 5:55 pm #67727
Jim Kosloskey
ParticipantFemina,
I am not sure there is sufficient information but I will give a start.
If using an Xlate:
1. Iterate over the OBX (probably a group dpending on Message structure).
2. Inside the ITERATE use an IF Action to check the field in question for the ‘P’.
3. Inside the above IF Action COPY the first OBX (zero in the group position – if this is a group repetition).
4. COPY =ABN to the appropriate field in the first OBX.
Now what is unclear –
– Do you want all of the inbound OBX segments to be repeated to the outpbound andONLY append ABN as a field to the first OBX?
– Do you want only one OBX segment if any of the OBX segments have a ‘P’ in tha appropriate field?
– What do you want if none of the segments has a ‘P’?
email: jim.kosloskey@jim-kosloskey.com
-
May 4, 2009 at 6:01 pm #67728
Femina Jaffer
ParticipantJim,
Here are the answers to your questions:
– Do you want all of the inbound OBX segments to be repeated to the outpbound andONLY append ABN as a field to the first OBX?
YES, this is correct.– Do you want only one OBX segment if any of the OBX segments have a ‘P’ in tha appropriate field?
– What do you want if none of the segments has a ‘P’?
Leave the message or segment alone.fj
-
May 4, 2009 at 7:56 pm #67729
Jim Kosloskey
ParticipantFemina,
New logic…
If using an Xlate:
1. Iterate over the OBX (probably a group depending on Message structure).
2. Outside of the IF Action, but inside the ITERATE – COPY all of the OBX fields for each repetition.
3. Inside the ITERATE use an IF Action to check the field in question for the ‘P’.
4. Inside the above IF Action COPY =ABN to the first OBX (zero in the group position – if this is a group repetition) in the appropriate field.
email: jim.kosloskey@jim-kosloskey.com
-
May 4, 2009 at 9:19 pm #67730
Femina Jaffer
ParticipantJim,
Thanks Jim. However, I will need to do this in TCL as the message coming in is in a UDM format. We alread have code that converts to the ORU format.
-
May 4, 2009 at 10:03 pm #67731
Max Drown (Infor)
ModeratorHere’s a script that I recently wrote to handle a slightly similar situation. I had to reorder the NTE segments. I used a counter and a flag. There is probably a better way to do it, but maybe this will get you started.
Code:proc tps_reorderNTE { args } {
package require extexpfilter
keylget args MODE modeswitch -exact — $mode {
start {
# Do nothing.
}run {
set debug 0
keylget args MSGID mh
set msg [msgget $mh]
set dispList “{CONTINUE $mh}”# Put the segments into a list
set segList [split $msg r]# Initialize the counter
set i 0# Get the OBR-NTE segments
foreach segment $segList {
set segName [string range $segment 0 2]
if {$segName == “OBX”} {
break
}
if {$segName == “NTE”} {
lappend obrNte $segment
lappend nteLoc $i
}
set i [expr $i + 1]
}# Insert the OBR-NTE segments into the segment list
set newMsg [linsert $segList [expr $i + 1] [join $obrNte r]]# Remove the OBR-NTE segments
set newMsg [lreplace $newMsg [lindex $nteLoc 0] [lindex $nteLoc end]]# Return the new, re-ordered message
msgset $mh [join $newMsg r]return $dispList
}shutdown {
# Do nothing.
}default {
# Do nothing.
}
}
}-- Max Drown (Infor)
-
May 4, 2009 at 10:18 pm #67732
Charlie Bursell
ParticipantI still don’t think you have completely stated your problem.
In an OBX segment, field 8 is the Abnormal Flags field. Are you saying if there is a P in there anywhere or are you saying literaly “*P”?
You say append ABN to end of first segment. Are you sure you do not want this in field 8 of first OBX segment? What if there are only 6 fileds? If you append to the end it will be in field 7.
Making some *REAL* broad assumptions
set msg [msgget $mh]
set fldSep [string index $msg 3]
set segments [split $msg r]
# Location of first OBX
set loc1 [lsearch -regexp $segments {^OBX}]
# Loop through all OBX or until P is found
foreach obx [lsearch -all -inline -regexp {^OBX}] {
# Get Abnormal flags
set flags [lindex [split $obx $fldSep] 8]
if {[regexp — {P} $flags]} {
set OBX1 [split [lindex $segments $loc1] $fldSep]
# In case of less than 8 fields
while {[llength $OBX1] <= 9} {lappend OBX1 {}}
set OBX1 [lreplace $OBX1 8 8 ABN]
set segments [lreplace $segments $loc1 $loc1
[join $OBX1 $fldSep]]
break
}
}
# Assume change was made
msgset $mh [join $segments r]
return “{CONTINUE $mh}”
If I made wrong assumptions, logic should still be the same, just change it
-
May 5, 2009 at 3:17 pm #67733
Femina Jaffer
ParticipantThanks Charlie and Max, for your response.
Charlie, per your questions:
The ‘*P” is contained in the OBX 5 if the test is positive for a culture. Literally, I am looking for the “
*P“. It doesn’t matter where I append the “ABN” too, as long as it is in the end of the 1st OBX.Another alternative if you can help me which might be easier: Instead of looking for the “*P”, I could look for an “ABN” in any OBX segment. If found, I need to take too append it to the 1st OBX at the end.
Thanks Femina
-
May 5, 2009 at 3:45 pm #67734
Femina Jaffer
ParticipantOne more thing. the ‘ABN’ or ‘*P’ will NEVER be in the first occurance of the OBX segment (eg. OBX|1|||| ).
-
May 5, 2009 at 3:54 pm #67735
Charlie Bursell
ParticipantSimply modify the code
set msg [msgget $mh]
set fldSep [string index $msg 3]
set segments [split $msg r]
# Location of first OBX
set loc1 [lsearch -regexp $segments {^OBX}]
# Loop through all OBX or until P is found
foreach obx [lsearch -all -inline -regexp {^OBX}] {
# Get Abnormal flags
set flags [lindex [split $obx $fldSep] 5]
if {[regexp -nocase — {*P} $flags]} {
set OBX1 [split [lindex $segments $loc1] $fldSep]
lappend OBX1 ABN
set segments [lreplace $segments $loc1 $loc1
[join $OBX1 $fldSep]]
break
}
}
# Assume change was made
msgset $mh [join $segments r]
return “{CONTINUE $mh}”
-
May 5, 2009 at 4:14 pm #67736
Femina Jaffer
ParticipantCharlie,
when I test this code…
foreach obx [lsearch -all -inline -regexp {^OBX}] {
echo obx $obx
I do not get anything returned using the echo. ??
-
May 5, 2009 at 4:22 pm #67737
Femina Jaffer
ParticipantNever mind. I figured it out. I modified the line too..
foreach obx [lsearch -all -inline -regexp
$segments {^OBX}] {Thanks for all your help!!
-
May 5, 2009 at 5:41 pm #67738
Charlie Bursell
ParticipantCan’t think of everything 🙄
-
May 5, 2009 at 5:53 pm #67739
Max Drown (Infor)
ModeratorCharlie, that is real useful code. I’m going to be re-using the basic concept lots and lots in the future. Thanks for posting it.
Specifically, the “[lsearch -all -inline -regexp $segments {^OBX}]” bit.
-- Max Drown (Infor)
-
May 5, 2009 at 8:12 pm #67740
Femina Jaffer
ParticipantThis code worked! Thank you so much Charlie, like Max said earlier – “very useful”. I’ll definitely be using this again and again.
Femina
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.