ORU to MDM

  • Creator
    Topic
  • #53163
    Jared Miller
    Participant

      We have upgraded from 3.8 to 5.8 recently and are in process of migrating interfaces to the new server. Had some tcl code on a couple raw routes that were working before that don’t on the newer version that changed the value in MSH-9 from ORU^R01 to MDM^T02 so I am trying to rework them. Below is my code and it is working right except for the fact that it is creating an extra segment out of field in the OBR that has a space in it…here’s the before and after:

      Before:

      MSH|^~&|SENDAPP|SENDFAC|RECVAPP|RECVFAC|201206201235||ORU^R01|2012062012353738|P|2.2|2012062012353738|

      PID|||0456132||XXXX||19520407|FEMALE||White|^^^^64052|||||||1217200126|266086459|

      OBR||SX12001454|||||20120620082759|20120620120727||||||||||||Archive Copy||||||||||||^Mahmood^Amber^CVT|

      OBX|1||||\10.1.110.68PACSreportsXperReportsHA398_DOC_000.pdf|

      After:

      MSH|^~&|SENDAPP|SENDFAC|RECVAPP|RECVFAC|201206201235||MDM^T02|2012062012353738|P|2.2|2012062012353738|

      PID|||0456132||XXXX||19520407|FEMALE||White|^^^^64052|||||||1217200126|266086459|

      OBR||SX12001454|||||20120620082759|20120620120727||||||||||||Archive

      Copy||||||||||||^Mahmood^Amber^CVT|

      OBX|1||||10.1.110.68PACSreportsXperReportsHA398_DOC_000.pdf|

      So I guess an extra carriage return is getting in there somehow and I can’t seem to figure out how. Any improvement to this issue and other things you find in my code are welcome.  Thanks!

      Code:


      # Now we iterate over each segment in our list.
         foreach segment $segmentList {
      if {[cequal [crange $segment 0 2] MSH]} {
      set fieldList [split $segment $field_sep]
      set msh_9 [lindex $fieldList 8]

      set mtlist [split $msh_9 $sub_sep]
      set msg_9_1 [lindex $mtlist 0]

      if {[cequal $msg_9_1 “ORM”] || [cequal $msg_9_1 “ORU”] } {
           set mtlist [lreplace $mtlist 0 0 “MDM”]
           set mtlist [lreplace $mtlist 1 1 “T02″]
           set msh_9 [join $mtlist $sub_sep]
           set fieldList [lreplace $fieldList 8 8 $msh_9]
           set fieldList [join $fieldList $field_sep]
           set msg [lreplace $msg 0 0 $fieldList]
           set msg [join $msg r]
      echo $msg

          msgset $mh $msg
                      lappend dispList “CONTINUE $mh”
      } else {
          lappend dispList “CONTINUE $mh”
          return $dispList
       }
              }
         }
      }

    Viewing 1 reply thread
    • Author
      Replies
      • #76761
        Levy Lazarre
        Participant

          Hi Jared,

          The issue with the carriage return is probably related to the looping in the code.

          Since the MSH segment is always the first segment in the segments list, I see no reason to loop through the other segments.

          I think you can avoid the issue by limiting your manipulation strictly to the MSH segment. You can use a regular expression to modify the MSH segment in place.

          Please try the following code. From your post, I am guessing that you are changing ORU^R01 and ORM^O01 messages to MDM^T02. If you don’t need the ORM transformation, you can simply comment out the second regsub command.

          Code:



          ######################################################################
          # Name: tps_changeORU_to_MDM
          #
          # Purpose: Change ORU^R01 message to MDM^T02
          #          
          #
          # Notes:             Uses a simple regular expression to make the change in MSH-9
          #                    (modifies the message in place)
          #
          # UPoC type: tps
          #            To be used in TPS, pre Xlate
          #
          # Returns: tps disposition list:
          #          CONTINUE -We always continue the message.
          #
          # Date:    06/25/2012
          #
          #          
          #
          proc tps_changeORU_to_MDM { args } {
             global HciConnName
             
             if ![info exists HciConnName] { set HciConnName UNKNOWN }
             
             # Get the name of the proc for error reporting.
             set module “$HciConnName/[lindex [info level 1] 0]”
             
             keylget args MODE mode        ;# What mode (xlt_pre is run only)
             keylget args CONTEXT context       ;# What context (should be xlt_pre)
             
             switch -exact — $mode {
                 start {
                     return “”         ;# Nothing specific
                 }
                 
                 run {
                     keylget args MSGID mh ;# Get message handle
                     set msg [msgget $mh] ;# Get message
                     
                     # The returned disposition list, should always be “CONTINUE”

                     set dispList [list “CONTINUE $mh”]
                                                         
                     # Get the field and sub-field separators

                     set field_sep [string index $msg 3] ;# HL7 field separator
                     set sub_sep [string index $msg 4] ;# HL7 subfield separator
                     
                     # Get a list of HL7 segments, by splitting the message on carriage return

                     set segmentList [split $msg r] ;
                     
                     # We need to check the event code in the message. If it is
                     # an ORU or ORM, then replace it by MDM.

                     # The MSH segment is always the first in the list of segments:

                     set MSH [lindex $segmentList 0]
                     
                     # Split the MSH segment into fields and retrieve the message type
                     
                     set MSHflds [split $MSH $field_sep]
                     set msgType [lindex $MSHflds 8]
                     # echo >>>Message Type: $msgType<<<

                     # If the message is an ORU or ORM, change the event in the MSH
                     # segment (ORU^R01 becomes MDM^T02, ORM^O01 becomes MDM^T02).

                     if {[regexp ORU|ORM $msgType]} {
                         regsub -all ORU\${sub_sep}R01 $msg MDM${sub_sep}T02 msg
                         regsub -all ORM\${sub_sep}O01 $msg MDM${sub_sep}T02 msg
                     }
               
                     
                     # Put modified message in message handle

                     msgset $mh $msg

                     # Send the modified message on its way
                     
                     
                     return $dispList
                 }
                 
                 shutdown {
                     # Doing some clean-up work
                 }
                 default {
                     error "Unknown mode '$mode' in $module"
                 }
             }
          }

          I hope this helps.

        • #76762
          Jared Miller
          Participant

            Thanks Levy. That makes sense and this code is working for me. I appreciate the assistance!

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