简体   繁体   English

如何正确解析 HL7 消息字符串?

[英]How to parse a HL7 message string properly?

I'm using the NHAPI package to parse incoming message strings to HL7 IMessage interfaces using the PipeParser .我正在使用 NHAPI 包将传入的消息字符串解析为使用PipeParser HL7 IMessage接口。

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.根据HL7 最小层协议 (MLP)定义,HL7 消息始终由一些字符包装, 0x0b0x0b0x0b0x1c, 0x0d For testing purposes I'm sending this message to my application using the tool 7Edit.出于测试目的,我使用工具 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如果将此消息字符串传递给PipeParser.Parse()方法,它将抛出异常消息

Can't parse message beginning MSH|^~&|KISsystem|ZTM|NIDAklinikserver|HL7Proxy|无法解析以 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?是否有可用的东西,或者我是否必须将所有这些分隔符存储到一个字节数组中,将该字节数组转换为一个字符串并从消息字符串中删除这些分隔符字符串?

never used NHAPI before now but I deal with HL7 messages and interfaces regularly.以前从未使用过 NHAPI,但我经常处理 HL7 消息和接口。

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.字符算作空格,因此简单的 Trim() 可以工作。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM