Parsing an HL7 without a priori messageType knowledge

╄→尐↘猪︶ㄣ 提交于 2019-12-06 05:13:44

问题


In NHapi, how can we parse a message if we don't know what messageType (MSH#9) it is?

var parser = new NHapi.Base.Parser.PipeParser();

IMessage parsedMessage = parser.Parse(SampleMessage);

parsedMessage is a NHapi.Base.Model.GenericMessage.V25 at runtime and I can't seem to read in the MSH header to read the MessageType field and then re-parse(?) the message as that message type.

I'm frustrated by the lack of documentation and examples. Perhaps I'm very far off base. I am very new to HL7, but I thought I was doing well understanding the HL7 spec until I tried using NHapi.


回答1:


parsedMessage.GetStructureName() will give you the message type and trigger event. parser.Encode(parsedMessage) will give you the message back in pipe-delimited format.

The following code shows how to get the message type and also how to get the original message in pipe format.

public static String ParseMessage(String message)
{
    var parser = new NHapi.Base.Parser.PipeParser();
    var parsedMessage = parser.Parse(message);

    //Get the message type and trigger event
    var msgType = parsedMessage.GetStructureName();

    //Get the message in raw, pipe-delimited format
    var pipeDelimitedMessage = parser.Encode(parsedMessage);

    return pipeDelimitedMessage;
}

Some good starter code can be found at the hapi examples site.



来源:https://stackoverflow.com/questions/8567345/parsing-an-hl7-without-a-priori-messagetype-knowledge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!