2

I'm using the NHAPI package to parse incoming message strings to HL7 IMessage interfaces using the PipeParser.

Based on the HL7 Minimum Layer Protocol (MLP) definition the HL7 message is always wrapped by some characters, 0x0b at start and 0x1c, 0x0d at the end. For testing purposes I'm sending this message to my application using the tool 7Edit.

MSH|^~\&|KISsystem|ZTM|NIDAklinikserver|HL7Proxy|201902271130||ADT^A01|68371142|P|2.3
EVN|A01|201902271130|201902271130
PID|1||677789||Aubertinó^Letizia||19740731|F||
PV1|1|O|||||||||||||||||456456456
IN1|1||999567890|gematik Musterkasse1GKV||||||||||||Prof. Dr.Aubertinó^Letizia||19740731|||||||||||201902271101|||||||X110173919

The debugged message string is

MSH|^~\&|KISsystem|ZTM|NIDAklinikserver|HL7Proxy|201902271130||ADT^A01|68371142|P|2.3
EVN|A01|201902271130|201902271130
PID|1||677789||Aubertin�^Letizia||19740731|F||
PV1|1|O|||||||||||||||||456456456
IN1|1||999567890|gematik Musterkasse1GKV||||||||||||Prof. Dr.Aubertin�^Letizia||19740731|||||||||||201902271101|||||||X110173919

Here you can see the characters wrapping the message. If you pass this message string to the PipeParser.Parse() method it will throw an exception with the message

Can't parse message beginning MSH|^~&|KISsystem|ZTM|NIDAklinikserver|HL7Proxy|

I think I will have to remove all those characters first. Is there something ready to use or do I have to store all those delimiters to a byte array, convert this byte array to a string and remove those delimiter strings from the message string?

  • How are you getting the original HL7 message that you're putting into 7Edit? If you're doing a copy-paste out of a browser window or another app, sometimes there can be characters in there that you don't see that are added to make it display nicely. I've had that happen to me with connection strings where it replaces the space character (0x20) with character (0xC2). – Merkle Groot Sep 10 '20 at 15:20
  • I think you are using the wrong tool. The are a few different format of HL7 data. It looks like your data is from a device like a Blood Analyzer. The NHAPI package supports both piped and xml. Make sure you are using the correct parameters. See : http://nhapi.sourceforge.net/home.php – jdweng Sep 10 '20 at 17:25

1 Answers1

1

never used NHAPI before now but I deal with HL7 messages and interfaces regularly.

You have to sanitize the data you're getting, so your assumption to remove the characters is correct. The characters count as whitespace so a simple Trim() works. We have clients that sometimes precede messages with special characters and double quotes randomly so that's always fun. But in this case the fix is pretty simple.

The below code parses the message on my end.

string message2 = @"MSH|^~\&|KISsystem|ZTM|NIDAklinikserver|HL7Proxy|201902271130||ADT^A01|68371142|P|2.3
                            EVN|A01|201902271130|201902271130
                            PID|1||677789||Aubertin�^Letizia||19740731|F||
                            PV1|1|O|||||||||||||||||456456456
                            IN1|1||999567890|gematik Musterkasse1GKV||||||||||||Prof. Dr.Aubertin�^Letizia||19740731|||||||||||201902271101|||||||X11017391";

var ourPP = new PipeParser();

try
{
    //exception is thrown without the Trim(); No exception with the Trim()
    var hl7Message = ourPP.Parse(message2.Trim());
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
Console.ReadKey();
Mikael
  • 1,002
  • 1
  • 11
  • 22
  • 1
    oh damn, `Trim` really worked ... but does it always? :D –  Sep 11 '20 at 06:12
  • Yeah it should. It just trims the `0x0b` and `0x1c, 0x0d` which will be present in every HL7 messages if you receive them the same way. – Mikael Sep 11 '20 at 13:43