Removing ~

  • Creator
    Topic
  • #52223
    Steven Lindsey
    Participant

      In the OBR 28 filed is a repeating filed; in the 0 6 12 18 spot and I need to pull out the Dr. number.  The only problem that I have is that there is ~ in front of those numbers.  How can I can I get around that.

      Example

      0839^JUDY^JANE^^^^~6061^JONES^BOB^^^^~6061^KEVIN^COOL^^^^

      Here is my Tclproc:

      set OBRList [split [lindex $segList $OBRpos] $fldSep]

      set OBRDrList [split [lindex $OBRList $OBRDrCC] $subSep]

      set OBRDrCC [split [lindex $OBRDrList 0] $subSep]

      Thanks,

      Steven

    Viewing 7 reply threads
    • Author
      Replies
      • #73463
        Levy Lazarre
        Participant

          Steven,

          The second ‘split’ in your code should be on the repetition separator (~), not the subfield separator:

          set repSep ~

          set OBRDrList [split [lindex $OBRList $OBRDrCC] $repSep]

          # This will leave you with the following list items in the OBRDrList

          # 0839^JUDY^JANE^^^^     6061^JONES^BOB^^^^     6061^KEVIN^COOL^^^^

          # You can now split each item on the subfield separator (^) and pull the first

          # list element, which is the Dr number you desire

          foreach Dr $OBRDrList {

             set DrNumber [lindex [split $Dr $subSep] 0]

             # puts $DrNumber

          }

        • #73464
          Steven Lindsey
          Participant

            That worked!

            Thanks

          • #73465
            Steven Lindsey
            Participant

              That wroks and shows the values that I need but if i echo the DrNumber out side the brackets it only gives me the last Dr.  I was it that.

              set OBRList [split [lindex $segList $OBRpos] $fldSep]

              set OBRDrList [split [lindex $OBRList $OBRDrCC] $repSep]

              echo $OBRDrList

               

              foreach Dr $OBRDrList {

               

              set DrNumber [lindex [split $Dr $subSep] 0]

              echo $DrNumber

              }

              echo $DrNumber

              msgset $mh [join $segList r]

              Here is what it echo’s

              0839^JUDY^JANE^^^^     6061^JONES^BOB^^^^     6061^KEVIN^COOL^^^^

              0839

              6061

              6061

              6061

            • #73466
              Steven Lindsey
              Participant

                Why is that.

                sorry

              • #73467
                Tom Rioux
                Participant

                  Steven,

                  In your foreach, you are doing a “set” command on the DrNumber variable.  With the “set” , each time through the foreach loop, it will overwrite what was previously there.  That is why you are only seeing the last ID.

                  If you want the DrNumber to contain all of the ID’s, then use the “lappend” command instead.

                  Hope this helps…

                  Tom

                • #73468
                  Levy Lazarre
                  Participant

                    Steven,

                    Tom is correct. I just assumed that you were doing something with the Doctor number within the foreach loop every time you collect it with the ‘set’ command. I didn’t know your logic, so I just used a ‘puts’ statement as an example for display.

                    As Tom said, if you want to collect all the numbers in a list, then you have to issue a ‘lappend’ command after the ‘set’ command.

                    lappend myList $DrNumber  

                    After exiting the loop, myList would then contain all the doctor numbers.

                    I hope this helps.

                  • #73469
                    Steven Lindsey
                    Participant

                      Ok that does get them all to come out.  What Im trying to do is run those numbers against a table.  The current way seems to group the numbers together.  Here is the full tclproc: I want to run each of those number against the table.  Thanks for your help.

                      proc tpsKillAlls_ORC_OBR { args } {

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

                      # Get the Connection/Proc Name for Error/Debug Messages

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

                      global HciConnName

                      set myname “$HciConnName/[lindex [info level 1] 0]”

                      set nowis [clock format [clock scan now] -format “%D – %T”]

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

                      # Initialize Variables Used

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

                      set dispList {} ;# Disposition List Returned to Engine

                      set fldSep “” ;# Field Seperator – get from MSH

                      set subSep “” ;# SubField Seperator – get from MSH

                      set repSep “” ;# Repeating Field Seperator – get from MSH

                      set ORCpos -1 ;# Position of ORC Segment in msg

                      set OBRpos -1 ;# Position of OBR Segment in msg

                      set ORCList

                    • ;# ORC Segment Fields in List Form

                      set OBRList

                    • ;# OBR Segment Fields in List Form

                      set ORCDrList

                    • ;# ORC subfields in List Form            

                      set OBRDrList

                    • ;# OBR subfields in List Form

                      set defaultvalue {} ;# Value in table when no his is found

                      set ORCDrLocation 12 ;# Dr name

                      set OBRDrLocation 16 ;# Dr name

                      et OBRDrCC 28 ;# Dr name that is cc for result

                      set table “Alls_EHR_Dr”  ;# Table with Dr. number in it.

                       

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

                      # Switch based on what mode the engine was in when it called the procedure

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

                      keylget args MODE mode   ;# The mode the engine called from

                      switch -exact — $mode {

                       start { }

                        run {

                          set mh [keylget args MSGID] ;# Get message handle from args

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

                           set fldSep [string index $msg 3] ;# Field Seperator

                           set subSep [string index $msg 4] ;# Sub-Field Seperator

                           set repSep [string index $msg 5] ;# Repeating Field Seperator

                           set segList [split $msg r] ;# Split message into segList

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

                      # Find Position of Segments – If missing -> Error out Message and Return

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

                      set ORCpos [lsearch -regexp $segList {^ORC}]

                      set OBRpos [lsearch -regexp $segList {^OBR}]

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

                      # Pull out the dr fields and get the Affinity Dr. code

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

                      set ORCList [split [lindex $segList $ORCpos] $fldSep]

                      set ORCDrList [split [lindex $ORCList $ORCDrLocation] $subSep]

                      set ORCDr [split [lindex $ORCDrList 0] $subSep]

                       

                      set OBRList [split [lindex $segList $OBRpos] $fldSep]

                      set OBRDrList [split [lindex $OBRList $OBRDrLocation] $subSep]

                      set OBRDr [split [lindex $OBRDrList 0] $subSep]

                      set OBRList [split [lindex $segList $OBRpos] $fldSep]

                      set OBRDrList [split [lindex $OBRList $OBRDrCC] $repSep]

                        echo $OBRDrList

                       

                      foreach Dr $OBRDrList {

                      set DrNumber [lindex [split $Dr $subSep] 0]

                      lappend DrCCList $DrNumber

                        }

                      echo $DrCCList

                         msgset $mh [join $segList r]

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

                      # Check the Dr. Code with the Alls_Dr.tbl and see if it is a match. If there is a match

                      # then the message would pass, else kill it.

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

                       

                        set value [tbllookup $table $ORCDr]

                       

                        set value2 [tbllookup $table $OBRDr]

                       

                        set value3 [tbllookup $table $DrCCList]

                        if {

                        [string equal $value “YES”]

                          || [string equal $value2 “YES”]

                          || [string equal $value3 “YES”]

                          } then {

                            lappend dispList “CONTINUE $mh”

                         } else {

                           lappend dispList “KILL $mh”

                           }  

                           

                      }

                         time { }

                         shutdown { }

                      } ;# End Switch

                      return $dispList

                      } ;# End Proc

                      Now it just groups the numbers:

                      0839 6061 6061

                • #73470
                  Jim Levy
                  Participant

                    Hi Steven,

                    First, I am assuming the each provider code in your table is associated with a “YES” in the right had column (Note that I commented out some of your code and added a bit with explanatory comments as to what I was doing).  If that’s the case you can do this:

                    Near the top of your code:  set disp “KILL”

                    Make these changes:

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

                               # Check the Dr. Code with the Alls_Dr.tbl and see if it is a match. If there is a match

                               # then the message would pass, else kill it.

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

                               #set value [tbllookup $table $ORCDr]

                               #set value2 [tbllookup $table $OBRDr]

                               #set value3 [tbllookup $table $DrCCList]

                               # This will loop through each value in the DrCCList

                               foreach Dr $DrCCList {

                                   # Gets the value in the right hand column for the Dr code in the left hand column

                                   set IsItThere [tbllookup $table $Dr]

                                   # If “IsItThere” is “YES”, set “disp” to “CONTINUE”

                                   if { $IsItThere eq “YES” } {

                                       set disp “CONTINUE”

                                       # Break out of the foreach loop and continue execution of the proc

                                       break

                                   }

                                   lappend dispList “$disp $mh”

                               }

                                   #if {

                                   #[string equal $value “YES”]

                                   #|| [string equal $value2 “YES”]

                                   #|| [string equal $value3 “YES”]

                                   #} then {

                                   #lappend dispList “CONTINUE $mh”

                               #} else {

                                   #lappend dispList “KILL $mh”

                               

                    Also, you should add a default value in your table of “NO”.

                    Note that I didn’t test this code so you should.

                    I hope this helps,

                    Jim

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