Trying to replace a & in PV2-3

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Trying to replace a & in PV2-3

  • Creator
    Topic
  • #53587
    gricelda lopez
    Participant

      Hi there

      My goal is to replace the “&” for the word “and” in PV2-3.  In my pre proc I was able to see it work in test but when i attached it to my thread config it didn’t work. This is my first proc and I am thinking it didn’t work becuase it isn’t writing out the updated field into the segment. Please help..below is my code

      ######################################################################

      # Name:   replaceAmpersand

      # Purpose:   Filters all transactions with no mrn

      #

      proc replaceAmpersand { args } {

              global HciConnName

      #Get mode start or run

      set mode [keylget args MODE]      

               switch -exact — $mode {

                start { return “”

      }      

      run {

      #get message handle

               set mh [keylget args MSGID]

      #The returned disposition list, assumes good message

      set dispList

        set msg [msgget $mh]   ;#Get a copy of the message

        echo The Message content follows….

        echo $msg

        set fldSep [string index $msg 3]   ;#Normally|

                 set subSep [string index $msg 4]   ;#Normally^

        set outbuf {}

        #Variable to set where the bad character might appear

        set segList [split $msg r]

        set PV2 [lindex [lregexp $segList {^PV2}] 0]

        set PV2flds [split $PV2 $fldSep]

        set PV2_3 [lindex $PV2flds 3]

        echo Segment List =$segList

        echo PV2 = $PV2

        echo PV2flds = $PV2flds

        echo complaint = $PV2_3

             

                       set newPV2_3 [regsub -all — {s*&s*} $PV2_3 { AND }]

                       echo new PV2_3= $newPV2_3

             

                                   

          msgset $mh $outbuf

        }

        return $dispList  

                   

          }  

        }

    Viewing 1 reply thread
    • Author
      Replies
      • #78207
        Levy Lazarre
        Participant

          Hi Gricelda,

          You are going in the right direction but you are missing some steps. You need to save your field change to the PV2 segment, then save the edited PV2 segment to the segments list. You also need to fill your outbuf.

          Something like this:

          Code:



          # Rebuild the PV2 segment with the change
          set PV2flds [lreplace $PV2flds 3 3 $newPV2_3]

          # Put the PV2 segment back into a string
          set PV2 [join $PV2flds $fldSep]
          # echo “Modified PV2 segment: $PV2”

          # Find the location of the PV2 segment in the segments list:

          set PV2loc [lsearch -regexp $segList {^PV2}]
          # echo >>>PV2 Location: $PV2loc<<<

          # Replace the original PV2 segment in the message with the modified one
          set segList [lreplace $segList $PV2loc $PV2loc $PV2]

          # Join the segments back into a message with segments
          # separated by a carriage return
          set outbuf [join $segList r]

          # Put modified message in message handle
          msgset $mh $outbuf

        • #78208
          gricelda lopez
          Participant

            thanks Levy!

            I appreciate your help and the comments to help me understand each line.

            Gricelda

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