Splitting the MSH

Clovertech Forums Read Only Archives Cloverleaf Tcl Library Splitting the MSH

  • Creator
    Topic
  • #51497
    Kevin Crist
    Participant

      I am trying to split the MSH to get the value for field 5. I cant seem to get it working, i am splitting the ORC and OBR just fine and am trying to do the MSH the same way but i get nothing. Is there a certain way to split the MSH?

      Here is how i am splitting them:

      set MSHList [split [lindex $segList $MSHpos] $fldSep]

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

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

    Viewing 4 reply threads
    • Author
      Replies
      • #70514
        Steve Carter
        Participant

          Are you sure you’re getting the MSH segment?  I’d need to see more of the code to know if something else isn’t right.  Based on what you have, that should work.

          Steve

        • #70515
          Kevin Crist
          Participant

            below is my proc. It works like i want it to, but then i wanted to find something in the msh-5 field but am not getting anything. Attached is a sample message.

            proc tpsOrderNumber { 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 MSHpos -1 ;# Position of MSH Segment in msg

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

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

            set MSHList

          • ;# MSH Segment Fields in List Form

            set OBRList

          • ;# OBR Segment Fields in List Form

            set ORCList

          • ;# ORC Segment Fields in List Form          

            set MSHorderDept 5 ;# Dept test was ordered from

            set orderingDept 18 ;# Segment in ordering where

             set OBRorderNum 2 ;# OBR Order Number

             set ORCorderNum 2 ;# ORC Order Number

               

             set orderDept “” ;# Department that the order was from

             

             

            set table “OrderNumber_Letter” ;# Table to use for the Order Letter

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

            # 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 dispList

              ;# Initialize to good message

                   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

            • ;# Message Segments in List Form

                 set fldList

            • ;# Fields of a segment in List Form

                 set repList

            • ;# The Repitions of the Field in List Form

                 set subfldList

            • ;# Sub-Fields of a Field in List Form

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

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

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

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

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

              if { $OBRpos < 0 } {

                 

               msgmetaset $mh USERDATA “Required Segment OBR Missing!”

               echo n n n

                echo “:WARN – OBR Segment Missing !”

               echo “:WARN – Sending Message to error db.”

               echo “:WARN – Here Is: $myname”

               echo “:WARN – Now Is: $nowis”

               echo $msg

               echo n n n    

                     set dispList

                     return $dispList

              }

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

              if { $ORCpos < 0 } {

                 

               msgmetaset $mh USERDATA “Required Segment ORC Missing!”

               echo n n n

                echo “:WARN – ORC Segment Missing !”

               echo “:WARN – Sending Message to error db.”

               echo “:WARN – Here Is: $myname”

               echo “:WARN – Now Is: $nowis”

               echo $msg

               echo n n n    

                     set dispList

                     return $dispList

              }

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

              # Getting the MSH, OBR, ORC segment as a list. This part is working.

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

              set MSHList [split [lindex $segList $MSHpos] $fldSep]

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

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

                 

              echo MSHList: $MSHList    

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

              # Getting the Ordering Dept and corresponding letter from the table. This part is working.

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

               set orderCode [lindex $MSHList $MSHorderDept]

               set orderDept [lindex $OBRList $orderingDept]

               set orderLetter [tbllookup $table $orderDept]

              echo orderCode: $orderCode

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

              # Getting the Order Number from the OBR Segment. This part is working.

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

              set cmOrderNum  [lindex $OBRList $OBRorderNum]

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

              # Join the order letter to the order number. This part is working.

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

              set newcmOrderNum [join “$orderLetter$cmOrderNum”]

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

              # Put the new order number back into the OBR segment. This part is working.

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

                 lset ORCList $ORCorderNum $newcmOrderNum

                 lset OBRList $OBRorderNum $newcmOrderNum

                   

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

              # Put the new segment back into the HL& message. This part is working.

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

                 

                 lset segList $ORCpos [join $ORCList $fldSep]

                 lset segList $OBRpos [join $OBRList $fldSep]

                 

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

              # Rebuild msg and store at mh for engine. This part is working.

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

              msgset $mh [join $segList r]

              }

                 time { }

                 shutdown { }

              } ;# End Switch

              return $dispList

              } ;# End Proc

      • #70516
        Keith McLeod
        Participant

          Remember that MSH:1 is the field separator so when you split MSH

          MSH|^&~|||||… so if you are splitting the same as the other segments, then the value in MSH:5 is index 4 since the first pipe is MSH:1.

          Index 0 –> MSH

          Index 1 –> ^&~ which is really MSH:2

          Index 2 –> MSH:3

          Hope this helps….

        • #70517
          Michael Lacriola
          Participant

            To add on what Keith stated, the MSH segment is handled a bit differently when using field numbers. Fields related to indices in the MSH are off by 1.

            Example, in the MSH segment, HL7 field 1 is not synonymous with the index after the split. MSH.#1 is the pipe, index 1 after the split is the ^&~.

            All the other fields using .# notation regarding HL7 segments match directly to the index value after the split. PID.#18, considered the account number is really the 18 index after the split of the PID segment. So if $pid contains the string of the PID segment only; [lindex [split $pid |] 18] would give you the value of PID.#18.

            MSH.#5 is really [lindex [split $msh |] 4] if msh contains just the string of the MSH data.

          • #70518
            Kevin Crist
            Participant

              Thank you all for your replies, learned a few things. When i got to looking at my code:

              set MSHList [split [lindex $segList $MSHpos] $fldSep]

              i didnt have the MSHpos set for it to find it. After doing that it all seemed to work.

              Thanks for your time.

            • Viewing 4 reply threads
              • The forum ‘Tcl Library’ is closed to new topics and replies.