Moving a string from OBX.5 to OBR.8

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Moving a string from OBX.5 to OBR.8

  • Creator
    Topic
  • #51106
    Jan Tooke
    Participant

      I have been out of the interface world for a couple of years now due to a re-org.  I am now back working with interfaces (as of a couple of weeks ago) and am on the rusty side right now.  🙁

      I am trying to search through my OBX segments on an ORU message to find “Release Date Time: 08/04/2009 13:11” (date and time will vary).  Then I need to move it to the OBR.8 field to populate in the receiving system for reporting.  Once it’s moved to OBR.8, I will drop the words “Release Date Time” and reformat the date to what the vendor is expecting (yyyymmddhhss).

      Has anyone done something like this before?  Any suggestions/examples of the best way to accomplish this?

      Thanks!

      Jan Tooke

    Viewing 4 reply threads
    • Author
      Replies
      • #68822
        Levy Lazarre
        Participant

          Jan,

          This can be accomplished by a Tcl script on the inbound TPS or pre-Xlate.

          Since you don’t know which OBX segment will contain the procedure date, you could run a regular expression against the message and search for the string “Release Date Time:”. I would not move the whole string to OBR-8 then drop the prefix. Instead I would use the regular expression to capture the date that comes after the prefix, reformat the date as needed, and copy it to OBR-8. Next you rebuild the OBR segment and the message.

          Something like this should work for you:

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

          # Name: tps_move_obs_datetime

          #

          # Purpose: Copy the Observation End Date/Time from a variable OBX

          #          segment to OBR-8.

          #          The receiver expects this date in OBR.8 in the format

          #          yyyymmddHHMM.

          #

          #          The purpose of this script is to extract the procedure date

          #          from one of the OBX segments and copy it to OBR-8.

          #          

          #  

          # UPoC type: tps

          #            To be used in inbound TPS or in Route Details, pre-Xlate.

          #

          # Args: tps keyedlist containing the following keys:

          #       MODE    run mode (“start”, “run” or “time”)

          #       MSGID   message handle

          #       ARGS    user-supplied arguments: None for this script

          #

          #

          # Returns: tps disposition list:

          #          CONTINUE -We always continue the message, modified or not.

          #

          # Date:    08/12/2009

          #

          #

          # Example of OBX segment with the procedure date:

          # OBX||TX||17|Release Date Time: 08/04/2009 13:11||||||F|

          proc tps_move_obs_datetime { args } {

             keylget args MODE mode               ;# Fetch mode

             

             set dispList {}

             set signed_flag “”

             

             switch -exact — $mode {

                 start {

                     # Perform special init functions

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

                 }

                 

                 run {

                     # ‘run’ mode always has a MSGID; fetch and process it

                     keylget args MSGID mh

                     set msg [msgget $mh]

                     set fieldSep [string index $msg 3]

                     set segmentList [split $msg r]

                                 

                     # We can use a regular expression to search the message for

                     # the string “Release Date Time:” and capture the date that

                     # comes after it.

                     set all “”            ;# for the complete match

                     set dt “”             ;# to capture the date/time only

                     # The expression within parentheses captures the date/time in

                     # the variable “dt”. Format dd/dd/dddd dd:dd

                     regexp “Release Date Time:\s+(\d+/\d+/\d+\s+\d+:\d+)” $msg all dt

                     echo “Total match: $all”

                     echo “Matched Date: $dt”

                     # If we weren’t able to pull the date from the report text,

                     # just continue the message.

                     if {[string equal $dt “”]} {

                         # No extracted date. Bail out.

                         echo “No extracted date. Just continuing message unmodified”

                         lappend dispList “CONTINUE $mh”

                         return $dispList

                     } ;# end if statement            

                     

                     # Change the date format from mm/dd/yyyy HH:MM to HL7 format yyyymmddhhmm

                     set dt [clock format [clock scan $dt] -format %Y%m%d%H%M]

                     echo “Transformed Date: $dt”

                     # Now that we have the procedure date, it’s just a matter of copying this

                     # value to OBR-8, rebuilding the message, and continuing the modified message.

                     

                     set newSegmentList “”

                     foreach segment $segmentList {

                         # Change field 8 in the OBR segment only

                         if {[string equal [string range $segment 0 2] OBR]} {

                             # Break the segment in a list of fields

                             set fieldList [split $segment $fieldSep]

                             # Make the substitution

                             set fieldList [lreplace $fieldList 8 8 $dt]

                             # Put the segment back together as a string

                             set segment [join $fieldList $fieldSep]

                         } ;# end if statement

                         # Add each segment to the new list

                         set newSegmentList [lappend newSegmentList $segment]

                     } ;# end foreach statement

                     

                     # Put the message back together as a string

                     set msg [join $newSegmentList r]

                     

                     # Change the message stored in the message handle to our modified message!

                     msgset $mh $msg

                     

                     # Now continue the modified message

                     lappend dispList “CONTINUE $mh”

                     return $dispList

                     

                 } ;# end run mode

                 

                 time {

                     # Timer-based processing

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

                 }

                 

                 shutdown {

                     # Doing some clean-up work

                 }

             }

             

             return $dispList

          }

        • #68823
          Jim Kosloskey
          Participant

            Jan,

            Of course if you are using an Xlate, the same principal (or others) can be used with an xltp type proc.

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #68824
            Jan Tooke
            Participant

              Thanks!  I have been working with a TPS proc, but could not get the regexp syntax down.  This helps!  Thanks!

            • #68825
              Michael Bowman
              Participant

                Levy, Thanks so much for the code! I just bummed it as well and modified for a project I was doing… very nice! Thanks again.

              • #68826
                Robert Milfajt
                Participant

                  Quote:

                  I just bummed it as well and modified for a project I was doing…

                  Buddy could you spare some code fragments to get me by…    8)

                  Robert Milfajt
                  Northwestern Medicine
                  Chicago, IL

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