Help TCL Proc – Repeating field PV18

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Help TCL Proc – Repeating field PV18

  • Creator
    Topic
  • #53932
    Femina Jaffer
    Participant

      Hi,

      I am having trouble over something that I shouldn’t be struggling with…Not sure what I am missing here.

      I am trying to replace the repeating field in PV1 8 after trimming the U off. I am not able to do the replace.  I cannot understand why my append in PV1 switch does work.  Please advise.

                   foreach segment $splitMsg {

                     set segID [string range $segment 0 2]

                        switch -exact $segID {

                             MSH {

                                   if {$MSHcount > 0} {

                                       append outMsg “n$segment[format %c 13]”

                                   } else { append outMsg “n$segment[format %c 13]”}

                                  incr MSHcount +1

                             }

         PV1 {

                                         set splitSeg [split $segment |]

                                         set PV1_8 [lindex $splitSeg 8]

                                         

                                         set PV18_1seg [lindex [split $PV1_8  ~] 0]

                                         set PV18_2seg [lindex [split $PV1_8  ~] 1]

                                         set PV2_1fld “”

                                         set PV1_1fld [string trimright [lindex [split [lindex $PV18_1seg] ^] 0] U]

                                         set PV1_2fld [string trimright [lindex [split [lindex $PV18_2seg] ^] 0] U]

                                                 

                                    if {$PV1_1fld != “”} {

                                       set PV18_1seg [split $PV18_1seg ^]  

                                       set PV18_2seg [lindex [split $PV18_1seg ~] 1]                                

                                       set newpv18 [join [lreplace $PV18_1seg 0 0 $PV1_1fld] ^]

                                      # set newpv18 [join $newpv18 |]

                                       set segment [lreplace $splitSeg 8 8 [lindex $newpv18 8]]

                                       set segment [join $segment |]

                                       append outMsg $splitSeg[format %c 13]                              }

                                }

                             default {append outMsg “n$segment[format %c 13]”}

                        }

                   }

                 incr currentCount +1

                 set counterOut [open /tst/cis6.0/integrator/testdev/FTP/TAMTRON/UPA/tamtronCounter w+]

                 puts $counterOut $currentCount

                 flush $counterOut

         set outMsg [string trimleft $outMsg]

                 puts $outFile $outMsg

                 flush $outFile

                 lappend dispList “KILL $mh”

             }

      Thanks,

      FJ

    Viewing 5 reply threads
    • Author
      Replies
      • #79586
        Femina Jaffer
        Participant

          I forgot to include what the PV1 8 looks like..

          PV1|1|I|4-S^0404^01||||36657^Worsham^Anthony^James^MD|126193U^Haaland^Christina^M^~33290U^Rollstin^Amber^Daun^MD|

          and I need it to look like this:

          PV1|1|I|4-S^0404^01||||36657^Worsham^Anthony^James^MD|126193^Haaland^Christina^M^~33290^Rollstin^Amber^Daun^MD|

        • #79587

          Sprinkle (liberally) echo statements throughout out your code to see what the code is doing. Remove these statements once you have your code working.

          Ex. echo outMsg: $outMsg

          -- Max Drown (Infor)

        • #79588

          This would be better done in an xlate probably using a COPY statement on the subfield and a tcl fragment.

          set xlateOutVals

            0 end-1]]

            or

            set xlateOutVals

              U]]

              -- Max Drown (Infor)

            1. #79589

              In your script, your code should probably be …

              append outMsg $segment[format %c 13]

              -- Max Drown (Infor)

            2. #79590
              Femina Jaffer
              Participant

                Thank you.  These are valid points and I will give them a try.

                Also, Max I had realized I had append outmsg $spltSeg instead of $segments, and did change this – but no luck.

                Thank you so much, I really do appreciate all your tips and wisdom

                Femina

              • #79591
                David Barr
                Participant

                  Try this:

                  Code:

                                     PV1 {
                                         set splitSeg [split $segment |]
                                         set PV1_8 [lindex $splitSeg 8]
                                         set new_PV1_8 {}
                                         foreach fld [split $PV1_8 ~] {
                                             set cmps [split $fld ^]
                                             set cmp1 [string trimright [lindex $cmps 0] U]
                                             set cmps [lreplace $cmps 0 0 $cmp1]
                                             lappend new_PV1_8 [join $cmps ^]
                                         }
                                         set splitSeg [lreplace $splitSeg 8 8 [join $new_PV1_8 ~]]
                                         append outMsg “n[join $splitSeg |]r”
                                     }

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