HL7 parsing without a priori message.

In NHapi, how can we parse a message if we do not know what messageType is (MSH # 9)?

var parser = new NHapi.Base.Parser.PipeParser(); IMessage parsedMessage = parser.Parse(SampleMessage); 

parsedMessage is NHapi.Base.Model.GenericMessage.V25 at runtime, and I cannot read the MSH header to read the MessageType field, and then re-parse (?) the message as this message type.

I am disappointed by the lack of documentation and examples. Perhaps I am very far from the base. I am very new to HL7, but I thought I had a good understanding of the HL7 specification until I tried using NHapi.

+4
source share
1 answer

parsedMessage.GetStructureName() will provide you with the message type and trigger event. parser.Encode(parsedMessage) will provide you with a message in a delimited channel format.

The following code shows how to get the message type, as well as how to get the original message in a 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 on the hapi website.

+8
source

Source: https://habr.com/ru/post/1387095/


All Articles