Tcl iterate issue

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tcl iterate issue

  • Creator
    Topic
  • #50942
    Shaun Beckman
    Participant

    Below is a portion of a script provide by Goutham some time ago to filter on data in PV1 – 7.1,8.1,9.1 & 17.1. The issue we have encountered with a new system is PV1_9 repeats an indeterminate amount of times. We have tried using a counter with the foreach command, but are unable to make it work.

    Can someone provide direction for iterating through PV1_9.1?

    Any help would be greatly appreciated.

      set fldcnt 0

      # init – variables

      set pv1_7_1 “”;set pv1_8_1 “”;set pv1_9_1 “”;set pv1_17_1 “”

      set obr_16_1 “”

              # get message

      set msg [split [msgget $mh] r]

      # PV1 Seg – extract Dr codes from pv1 – 7.1,8.1,9.1 & 17.1

      set pv1_loc [lsearch -regexp $msg {^PV1}]

      set pv1_seg [lindex $msg $pv1_loc]

      echo $pv1_seg

      set pv1_7_1 [lindex [split [lindex [split $pv1_seg |] 7] ^] 0]

      set pv1_8_1 [lindex [split [lindex [split $pv1_seg |] 8] ^] 0]

      set pv1_9_1 [lindex [split [lindex [split $pv1_seg |] 9] ^] 0]

      set pv1_17_1 [lindex [split [lindex [split $pv1_seg |] 17] ^] 0]

      set dr_cd_in_msg “${pv1_7_1} ${pv1_8_1} ${pv1_9_1} ${pv1_17_1} “

Viewing 11 reply threads
  • Author
    Replies
    • #68127

      Here is some basic tcl demonstrating the foreach statement.

      set pv1_09 “one~two~three~four~five~six”
      foreach myVar [split $pv1_09 ~] {

      [code]set pv1_09 “one~two~three~four~five~six”
      foreach myVar [split $pv1_09 ~] {

      -- Max Drown (Infor)

    • #68128
      Tom Rioux
      Participant

      Are you wanting the variable PV1_9_1 to contain a list of all of the doctor codes from each iteration of PV1.9?

      Tom

    • #68129
      Shaun Beckman
      Participant

      Tom,

      Yes, that is what I am looking for.

    • #68130
      Charlie Bursell
      Participant

      I would change it thusly

      set fldcnt 0

       # init – variables

       set pv1_7_1 “”;set pv1_8_1 “”;set pv1_9_1 “”;set pv1_17_1 “”

       set obr_16_1 “”

               # get message

       set msg [split [msgget $mh] r]

       set fldSep [string index $msg 3]

       set subSep [string index $msg 4]

       set iterSep [string index $msg 5]

       set segments [split $msg r]

       set pv1Flds [split [lsearch -inline -regexp $segments {^PV1} $flldSep]

       lassign $pv1Flds {} {} {} {} {} {} pv1_7 pv1_8 pv1_9

       set pv1_17 [lindex $pv1Flds 17]

        set dr_cd_in_msg  {}

       

        # Get PV1.7 and 8

        foreach fld

        {

                 lappend dr_cd_in_msg  [lindex [split $fld $subSep] 0]

          }

         

          # Do PV1.9

          foreach fld [split $pv1_9 $iterSep] {

                lappend dr_cd_in_msg  [lindex [split $fld $subSep] 0]

          }

           # Now PV1.17

            lappend dr_cd_in_msg   [lindex [split $pv1_17 $subSep] 0]

        I didn’t test it so watch out for fat-finger errors  ðŸ˜‰

    • #68131
      Shaun Beckman
      Participant

      Charlie,

      I made a few minor changes, but the value of $dr_cd_in_msg returns the following: {} {} {}

      Can you tell what I’m missing in the code?

      $proc filter_nonphys_hpf_hpp { args } {

    • #68132
      Charlie Bursell
      Participant

      Shawn:

      You might try changing append dr_cd_in_msg $obr_16_1

      to lappend dr_cd_in_msg $obr_16_1

      To do much more I would need an example message

    • #68133
      Shaun Beckman
      Participant

      Charlie,

      File attached.

      Thanks for your help.

    • #68134
      Michael Hertel
      Participant

      Quote:

          # get message

      set msg [split [msgget $mh] r]

      set fldSep [string index $msg 3]

      set subSep [string index $msg 4]

      set iterSep [string index $msg 5]

      set segments [split $msg r]

      You are double splitting the message.

      set msg [split [msgget $mh] r]

      followed by

      set segments [split $msg r]

      is not what you want.

    • #68135
      Shaun Beckman
      Participant

      Thanks, Michael.

      I made the change, but echoing $dr_cd_in_msg still returns {} {} {}

    • #68136
      Charlie Bursell
      Participant

      Shawn;

      Send me an e-mail:  cbursell@healthvision.com

    • #68137
      Tom Rioux
      Participant

      Shaun,

      Here is your code.  I made a couple of changes and have it working as you want it to…I can only guess without knowing more.

      proc filter_nonphys_hpf_hpp { args } {

       keylget args MODE mode

       keylget args ARGS uargs

       switch -exact — $mode {

           start {

               return “”

           }

           run {

               set drcodes UNKNOWN  ;# default value

               keylget args MSGID mh

               keylget uargs DRCODES drcodes

               set drcodes “\m($drcodes)\M”

      # init – variables

      set pv1_7_1 “”;set pv1_8_1 “”;set pv1_9_1 “”;set pv1_17_1 “”

      set obr_16_1 “”

             # get message

      set msg [msgget $mh]

      set fldSep [string index $msg 3]

      set subSep [string index $msg 4]

      set iterSep [string index $msg 5]

      set segments [split $msg r]

      set pv1Flds [split [lsearch -regexp -inline $segments ^PV1] $fldSep]

      lassign $pv1Flds {} {} {} {} {} {} pv1_7_1 pv1_8_1 pv1_9_1

      set pv1_17_1 [lindex $pv1Flds 17]

      set dr_cd_in_msg  {}

      # Get PV1.7 and 8

      foreach fld

        {

                  lappend dr_cd_in_msg  [lindex [split $fld $subSep] 0]

        }

        # Do PV1.9

        foreach fld [split $pv1_9_1 $iterSep] {

                lappend dr_cd_in_msg  [lindex [split $fld $subSep] 0]

        }

          # Now PV1.17

          lappend dr_cd_in_msg  [lindex [split $pv1_17_1 $subSep] 0]

                 # OBR seg – extract Dr codes from obr – 16.1

          set obr_seg [lsearch -regexp -inline $segments {^OBR}]

          set obr_16 [lindex [split $obr_seg |] 16]

                 set obr_16_1 [lindex [split $obr_16 ^] 0]

          lappend dr_cd_in_msg $obr_16_1

                 # Check if the physician codes are in pv1 7.1,8.1,9.1,17.1 or obr16.1

        # If found continue message else kill message

                 if {[regexp $drcodes $dr_cd_in_msg]} {

               echo “Found a Match … continue message”

               echo DR_CD_IN_MSG: $dr_cd_in_msg

               return “{CONTINUE $mh}”

          } else {

               echo “Dr code not in message .. message killed”

               echo “Dr codes in Message: $dr_cd_in_msg”

               echo “Wanted Dr codes : $drcodes”

               return “{KILL $mh}”

          }

             }

          }

        }

    • #68138
      Shaun Beckman
      Participant

      I wanted to thank everyone for their input. I appreciate all the help. Charlie was nice enough to send me a proc yesterday that worked like a champ.

      Thanks again everyone!!!

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

Forum Statistics

Registered Users
5,116
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10