Sidebar

My HL7 message has carriage returns in the fields.

+1 vote
615 views
asked Mar 9, 2020 by mike-r-7535 (13,830 points)
What preprocessor script can I use to correct malformed HL7 that has /r characters in some fields.

1 Answer

0 votes

In Source node, check the box for Run preprocessing script... Select "only messages that fail to parse."


var rawMessage = new java.lang.String(bytesIn, 'UTF-8');

var lines = rawMessage.split("\\r\\n?"); // HL7 - CR plus LF if it is present
var newMessage = "";

for (var i = 0; i < lines.length; i++) {
   var currentLine = lines[i];
   var lineEnding = "\r";
   if (i === 0) {
      // if first line, don't include a line ending.
      lineEnding = "";
   }
   try {
      var parsedHl7Line = qie.parseHL7String(currentLine);
   } catch (err) {
      // if failed to parse, don't include a line ending.
      lineEnding = "";
   }
   newMessage += lineEnding + currentLine;
}

bytesOut = new java.lang.String(newMessage).getBytes("UTF-8");

Here is a link to a sample channel for testing the above. The channel contains two sample HL7 messages: one is valid and the other is invalid.

answered Mar 9, 2020 by mike-r-7535 (13,830 points)
edited Mar 12, 2020 by mike-r-7535
commented Mar 12, 2020 by mohammed-j-4610 (140 points)
I have tried the above. I have saved and restarted the Channel.

How should I retest?

Resolving / resubmitting the offending message still results in an error.

Does it need to be resent from the source system?
commented Mar 12, 2020 by mike-r-7535 (13,830 points)
I have added a sample channel for testing to my answer.  Note: The preprocessing script executes before the source message is originally written to the database.  This means that resubmitting a message will not execute the preprocess script.  Only new messages picked up by the channel will execute the preprocess script.  You can manually edit the source of the failed message, and then resubmit the message.
...