HL7: Illegal embedded chars

Introduction

This example use the hl7.delimiter.fix module to pre-process HL7 messages to fix unescaped “&” (ampersand) characters by escaping them as “\T\”, so that they a not misinterpreted as HL7 separators.

The “&” (ampersand) character in HL7 is a sub sub field separator. A validly produced HL7 message that contains “&” characters should escape them as \T\ so that  an HL7 parser doesn’t interpret these as sub sub field separators. Unfortunately it’s not uncommon to get some home grown HL7 implementation which doesn’t correctly escape the “&” characters in things like OBX segments containing textual data.

This example was refactored from code kindly given by Jeff Drum of HICG. See this forum entry: http://help.interfaceware.com/forums/topic/how-to-handle-special-characters-in-message-field.

If you have any questions please contact us at support@interfaceware.com.

Using the Code [top]

  • Import the HL7: Illegal embedded chars channel from the Builtin: Iguana Protocols repository
  • Experiment with the code to find out how it works
  • Then add the module(s) to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module uses require to return a single function
  • Adapt the code to your own requirements
  • Use the hl7.fix{} function to fix unescaped “&” characters
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

The channel is simple enough, it just uses the hl7.fix{} function to fix (escape) the unescaped “&” characters.

There are are two trace() statements in the code, so you can view the message before and after it is fixed.

This is the message before it is fixed, with and unescaped “&” in the first OBX segment:

And this is the fixed message, with the “&” replaced by “\T\”:

More information [top]

Leave a Reply