Repeating field issue in tcl

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Repeating field issue in tcl

  • Creator
    Topic
  • #51671
    Eric Sligh
    Participant

      I am trying to concat doctor numbers in the PV1-9. I get the first concat to work but not the repeating doctor numbers in the same field.

      The $hmsId is an argument. For this facility it is 018. I also pad the original 3 digit number with zeros up to 5 by calling the x_prepenZeros proc.

      My output in PV1-9 looks like this:

      01800229^TEST^CHAD^J~400^BALASUBRAMANIAN^LAKSHMI~727^BABBAR^HARSH

      Here is my current code:

       # Consulting Doc

                         set pv1_9 [lindex $fields 9]

                         set pv1_9_list [split [lindex $fields 9] $sub_sep]

                         set DocNumber_9_0 [lindex $pv1_9_list 0]

                         if {$DocNumber_9_0 != “”} {

                            set nDocNum [x_prepenZeros 5 $DocNumber_9_0]

                            set replaceDocNum “”

                            append replaceDocNum $hmsId $nDocNum

                            set pv1_9 [join [lreplace $pv1_9_list 0 0 $replaceDocNum] $sub_sep]

                            set fields [lreplace $fields 9 9 $pv1_9]

                         }

      What am I missing that would continue the same code into the repeating portion of the field.

      Any help is greatly appreciated.

    Viewing 10 reply threads
    • Author
      Replies
      • #71188
        David Barr
        Participant

          Here’s where your problem starts:

          Code:

          set pv1_9 [lindex $fields 9]
          set pv1_9_list [split [lindex $fields 9] $sub_sep]

          pv1_9 contains the correct data, but before you can split on the subfield separator, you need to split on the repeating field character.  That will give you a list of fields, and you can iterate over that list and split each of those fields on the subfield separator.

        • #71189
          Eric Sligh
          Participant

            So something like this first then the code I below before?

            set pv1_9_list [split [lindex $fields 9] $rep_sep]

          • #71190
            David Barr
            Participant

              That would work.  You also have to iterate over that list (foreach pv1_9_rep $pv1_9_list …).

            • #71191
              Eric Sligh
              Participant

                Thanks David.

              • #71192
                Eric Sligh
                Participant

                  Here is what I have so far:

                  # Consulting Doc

                                      set pv1_9 [lindex $fields 9]

                                      set pv1_9_list [split [lindex $fields 9] $ssub_sep]

                                      for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {

                                       set DocNumber_9_0 [lindex $pv1_9_list $i]

                                       echo $DocNumber_9_0

                                       if {$DocNumber_9_0 != “”} {

                                         set nDocNum [x_prepenZeros 5 $DocNumber_9_0]

                                         echo $nDocNum

                                         set replaceDocNum “”

                                         append replaceDocNum $hmsId $nDocNum

                                         echo $replaceDocNum

                                         set pv1_9_list [lreplace $pv1_9_list $i $i $replaceDocNum]

                                       }

                                      }

                  I have tried iterating over the subfields the same way as the repeating field above and still cannot quite get it to work. For some reason it is not allowing the x_prepenZeros proc to be called correctly.

                  Here is the output for the PV1-9 field:

                  |018727^BABBAR^ELEPHANT~018400^BUDDY^TEST~018727^BABBAR^ELEPHANT|

                  Here is what the output should be:

                  |01800727^BABBAR^ELEPHANT~01800400^BUDDY^TEST~01800727^BABBAR^ELEPHANT|

                  The doctor numbers have to be at least 8 characters in length.

                  What am I missing here? Any help is appreciated.

                • #71193
                  Tom Rioux
                  Participant

                    Forget the callout and simply change your code to the following:

                    set pv1_9 [lindex $fields 9]

                    set pv1_9_list [split [lindex $fields 9] $ssub_sep]

                    for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {

                         set DocNumber_9_0 [lindex $pv1_9_list $i]

                         if {$DocNumber_9_0 != “”} {

                             set nDocNum [format %05d $DocNumber_9_0]

                             set replaceDocNum “”

                             append replaceDocNum $hmsId $nDocNum

                             set pv1_9_list [lreplace $pv1_9_list $i $i $replaceDocNum]

                         }

                    }

                    Hope this helps…

                    Tom Rioux

                  • #71194
                    Eric Sligh
                    Participant

                      Tom,

                      When I inserted that code I got the following error:

                      Please Wait ……

                      Command Issued: hcitpstest -r run -f len10 -c sms_ib_data -e “hcitpstestshowbydisp ” /quovadx/qdx5.6/integrator/pod_prod_01/HCIDOCNUMISSUE “z_fixHmsToMcKesson.1.1 {HMSID 018} {MCKID A} {TOSYS HCI}”

                      Command output:

                      229^LONG^CHAD^J

                      [0:TEST] Tcl error:

                      msgId = message0

                      proc = ‘z_fixHmsToMcKesson.1.1’

                      args = ‘{HMSID 018} {MCKID A} {TOSYS HCI}’

                      result = ‘expected integer but got “229^LONG^CHAD^J”‘

                      errorInfo: ‘

                      expected integer but got “229^LONG^CHAD^J”

                         while executing

                      “format %05d $DocNumber_9_0”

                         (“PV1” arm line 50)

                         invoked from within

                      “switch -exact — $type {

                                      MSH {

                                         set msg_type_1 [lindex [split [lindex $fields 8] $sub_sep] 0]

                                         …”

                         (“foreach” body line 4)

                         invoked from within

                      “foreach seg $msg {

                               set fields [split $seg |]

                                   set type [csubstr $seg 0 3]

                                   switch -exact — $type {

                                 …”

                         (“run” arm line 33)

                         invoked from within

                      “switch -exact — $mode {

                             start {

                                 # Perform special init functions

                               # N.B.: there may or may not be a MSGID key in args

                      …”

                         (procedure “z_fixHmsToMcKesson.1.1” line 5)

                         invoked from within

                      “z_fixHmsToMcKesson.1.1 {MSGID message0} {CONTEXT sms_ib_data} {ARGS {{HMSID 018} {MCKID A} {TOSYS HCI}}} {MODE run} {VERSION 3.0}”‘

                    • #71195
                      Tom Rioux
                      Participant

                        Sorry….deleted a line by mistake.   Add this line:

                        set pv1_9 [lindex $fields 9]

                        set pv1_9_list [split [lindex $fields 9] $ssub_sep]

                        for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {

                            set DocNumber_9_0 [lindex $pv1_9_list $i]

                            if {$DocNumber_9_0 != “”} {

                                set DocNumber_9_0 [lindex $pv1_9_list 0]

                                set nDocNum [format %05d $DocNumber_9_0]

                                set replaceDocNum “”

                                append replaceDocNum $hmsId $nDocNum

                                set pv1_9_list [lreplace $pv1_9_list $i $i $replaceDocNum]

                            }

                        }

                      • #71196
                        Eric Sligh
                        Participant

                          Since the split isn’t working correctly it still doesn’t add the zeros. It is interpreting the entire string.

                          result = ‘expected integer but got “229^LONG^CHAD^J”‘

                          So the %d will not work unless I get the second split of the sub_sep to work.

                          My output now looks like this after I changed the %d to %s:

                          018018229^TEST^CHAD^J

                          So it is closer but instead of the 018018229 it should be 01800229.

                        • #71197
                          Chris Williams
                          Participant

                            Could your split problem be that in the early example you are splitting on $sub_sep, and later you are using $ssub_sep?

                          • #71198
                            David Barr
                            Participant

                              Does this work?

                              set pv1_9 [lindex $fields 9]
                              set pv1_9_list [split [lindex $fields 9] $ssub_sep]
                              for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {

                              [code]set pv1_9 [lindex $fields 9]
                              set pv1_9_list [split [lindex $fields 9] $ssub_sep]
                              for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {

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