Looking for a script to parse HL7 escape sequences

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Looking for a script to parse HL7 escape sequences

  • Creator
    Topic
  • #47623
    Jason Alexander
    Participant

      I have been unable to find an existing script to remove HL7 escape sequences.  We’re working on an interface where we will get an inbound HL7 feed and want to convert it to an outbound flat-file feed.  We need to remove the HL7 escape sequences before we build the flatfiles.

      Need the script to process escape sequences in-order from the beginning of the field in a single-pass.  Pattern matching for one pattern per pass through the script will not work (we’ve already seen the string ESSEX0D\X0A in one of our test files).

      I *can* write this, I just don’t want to reinvent the wheel if it has already been done somewhere.

    Viewing 0 reply threads
    • Author
      Replies
      • #56296
        Jason Alexander
        Participant

          David Barr from MedStar Health out in Maryland was kind enough to send me the following proc to do what is needed.  You need to pass in the delimiter list as well as the string to process.

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

          # Name:         unescape_HL7

          # Purpose:      Remove HL7 escape sequences and replace them with

          #               the actual characters represented (including escaped

          #               hexadecimal values)

          # Args:         Two strings required

          #               input – the actual string to be unescaped

          #               delimiters – the delimiters as foudn in MSH-1 and MSH-2

          #

          # Comments:    

          proc unescape_HL7 { input delimiters } {

             set delim_f [string range $delimiters 0 0]

             set delim_s [string range $delimiters 1 1]

             set delim_r [string range $delimiters 2 2]

             set delim_e [string range $delimiters 3 3]

             set delim_t [string range $delimiters 4 4]

             set output “”

             while {[ string length $input ]} {

               set char [string range $input 0 0]

               set input [string range $input 1 end]

               #echo processing $char

               if { [string equal $char $delim_e] } {

                   set esc “”

                   set char [string range $input 0 0]

                   set input [string range $input 1 end]

                   while {![string equal $char $delim_e]} {

                     append esc $char

                     set char [string range $input 0 0]

                     set input [string range $input 1 end]

                   }

                   #echo “escape sequence: $esc”

                   switch -exact [string range $esc 0 0] {

                     “F” {

                         append output $delim_f

                     }

                     “E” {

                         append output $delim_e

                     }

                     “S” {

                         append output $delim_s

                     }

                     “T” {

                         append output $delim_t

                     }

                     “R” {

                         append output $delim_r

                     }

                     “X” {

                         scan [string range $esc 1 end] “%x” x

                         append output [format “%c” $x]

                     }

                     default {

                         #echo unknown escape sequence $esc

                     }

                   }

               } else {

                   append output $char

               }

             }

             return $output

          }

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