tps filter proc for iterating segments

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library tps filter proc for iterating segments

  • Creator
    Topic
  • #55147
    Gordon Koch
    Participant

    For some time, I have used a rather useful tps filter proc that killed messages based on a value in a defined field/segment, stated per the arguments passed along. However, I just discovered that the proc does not work on repeating segments, only the first iteration is interrogated. My goal is to kill a message based on the value in OBX-3, where the OBX segment of course repeats, and the value is not in the first iterate.

    I am struggling on how to add this functionality to the code shown below. Multiple values work, as per the foreach commands in the operator sections (is, not, prefixIs), but I am getting the syntax wrong on where to add the foreach in order for the tcl proc to cycle through the OBX (or any other defined segments) iterations.

    Any help is appreciated.

    Thank you,

    Gordon

    proc tpsFilterByHL7Field { args } {

       global HciConnName gModule

       set gModule “(tpsFilterByHL7Field/$HciConnName)”

       keylget args MODE mode              ;# What mode are we in

       switch -exact — $mode {

           start {

               return “” ;# Perform special init functions

           }

           run {

               keylget args MSGID mh

               set msg [msgget $mh]

               keylget args ARGS.SEGMENTID segmentId

               keylget args ARGS.FIELDID fieldId

               keylget args ARGS.VALUELIST valueList

               keylget args ARGS.OPERATOR operator

    # get the field separator from MSH segment

    set fieldSep [string index [getHL7Segment $msg MSH] 3]

               # get the field from the hl7 message

               set segment [getHL7Segment $msg $segmentId]

               set fieldValue [getHL7Field $segment $fieldSep $fieldId]

    #echo fieldValue_sam<$fieldValue>

               set valueList [split $valueList |]

               # run the test

               switch $operator {

                   is {

                       # if value is found in list, kill

                       foreach value $valueList {

                           if {[cequal $value null]} {

                               set value “”

                           }

                           if {[cequal $value numeric]} {

                               if {[ctype digit $fieldValue]} {

                                  set returnList “{KILL $mh}”

                                  break

                               } else {

                                  set returnList “{CONTINUE $mh}”

                               }

                           } elseif {[cequal $fieldValue $value]} {

                               set returnList “{KILL $mh}”

                               break

                           } else {

                               set returnList “{CONTINUE $mh}”

                           }

                       }

                   }

                   not {

                       # if value not found in list, kill

                       foreach value $valueList {

                           if { [cequal $value null] } {

                               set value “”

                           }

                           if {[cequal $value numeric]} {

                               if {![ctype digit $fieldValue]} {

                                  set returnList “{KILL $mh}”

                                  break

                               } else {

                                  set returnList “{CONTINUE $mh}”

                               }

                           } elseif { ![cequal $fieldValue $value] } {

                               set returnList “{KILL $mh}”

                           } else {

                               set returnList “{CONTINUE $mh}”

                               break

                           }

                       }

                   }

                   prefixIs {

                       # if value begins with one found in list, kill

                       foreach value $valueList {

                           if { [string match $value* $fieldValue] } {

                               set returnList “{KILL $mh}”

                               break

                           } else {

                               set returnList “{CONTINUE $mh}”

                           }

                       }

                   }

                }

               return $returnList

           }

    shutdown {

       # Doing some clean-up work

    }

           default {

       echo “Unknown mode in tpsFilterByHL7Field: ‘$mode'”

               return “”                   ;# Dont know what to do

           }

       }

    }

Viewing 1 reply thread
  • Author
    Replies
    • #84330
      Harpreet Khakh
      Participant

      Looping through OBX segments will be needed in your case.

      Below is what I think will work, please test with your data.

      This is what I did:

      1) Defined variable for disposition (changed returnList to disp and values accordingly)

      2) introduced loop for OBX segments

      3) moved your code testing the value in field to within the loop

      Let me know if any questions.

      #define variable for disposition

                 set disp “CONTINUE”

                 

                 set segments [split msg r] ; #get list of segments of HL7 message

                 # get text for each OBX segment and loop through

                 foreach obx [lsearch -inline $segments “OBX*”] {

                     set obxFields  [split $obx $fieldSep]       ; #split obx segment into list of fields

                     set fieldValue [lindex $obxFields $fieldId] ; #get field to be searched

                     

                     # run the test

                     switch $operator {

                         is {

                             # if value is found in list, kill

                             foreach value $valueList {

                                 if {[cequal $value null]} {

                                     set value “”

                                 }

                                 if {[cequal $value numeric]} {

                                     if {[ctype digit $fieldValue]} {

                                        set disp “KILL”

                                        break

                                     }  

                                     #else {

                                     #   set returnList “{CONTINUE $mh}”

                                     #}

                                 } elseif {[cequal $fieldValue $value]} {

                                     set disp “KILL”

                                     break

                                 }

                                 #else {

                                 #    set returnList “{CONTINUE $mh}”

                                 #}

                             }

                         }

                         not {

                             # if value not found in list, kill

                             foreach value $valueList {

                                 if { [cequal $value null] } {

                                     set value “”

                                 }

                                 if {[cequal $value numeric]} {

                                     if {![ctype digit $fieldValue]} {

                                        set disp “KILL”

                                        break

                                     }

                                     #else {

                                     #   set returnList “{CONTINUE $mh}”

                                     #}

                                 } elseif { ![cequal $fieldValue $value] } {

                                     set disp “KILL”

                                 } else {

                                     set disp “CONTINUE”

                                     break

                                 }

                             }

                         }

                         prefixIs {

                             # if value begins with one found in list, kill

                             foreach value $valueList {

                                 if { [string match $value* $fieldValue] } {

                                     set returnList “{KILL $mh}”

                                     break

                                 } else {

                                     set returnList “{CONTINUE $mh}”

                                 }

                             }

                         }

                      }

                 }

                 

                 

                 return “{$disp $mh}”

    • #84331
      Gordon Koch
      Participant

      Thank you for the response. My original use case was resolved in a different manor (the messages were interrogated inside the Xlate), but I will make a note of this for the future.

Viewing 1 reply thread
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,074
Forums
28
Topics
9,252
Replies
34,241
Topic Tags
275