This project is read-only.

Incorrect parsing

Feb 2, 2015 at 1:23 PM
Edited Feb 2, 2015 at 1:43 PM
We have decided to use NHapi.Base library for parsing HL7 messages.
I created unitTest and receive strange result:

expected: TST|C1Data&subC1Data&subC1Data2^C2Data
actual: TST|C1Data^C2Data^subC1Data2
[TestMethod]
        public void PutField()
        {
            //arrange
            string expectedMessage = @"MSH|^~\&|||||||ADT^A31|||2.3||||
TST|C1Data&subC1Data&subC1Data2^C2Data";
            var parser = new PipeParser();
            
            //act
            var message = parser.Parse(expectedMessage);
            var actualMessage = PipeParser.Encode(message,  new EncodingCharacters('|', @"^~\&"));

            //assert
            Assert.AreEqual(expectedMessage, actualMessage);
        }
Is it bug or I use library incorrectly? Could you give some advise?
Feb 3, 2015 at 12:19 AM
Edited Feb 3, 2015 at 12:20 AM
In the HL7 2.3 standard, the Country code field is actually a non-repeating ID type of length 2.

It looks like you are trying to put more than what that field is specified as, and as such are getting strange results. (i.e. this field doesn't support sub components '&' or repetitions '&')

Can you first try to conform your test data against the HL7 specification, to which this parser is generated from?

Then if there are oddities with the parsing of data we can look into what problem/s there may be.
Feb 3, 2015 at 10:18 AM
Thank you for reply.

Does the lib allow validating input message against the standard? Instead of getting strange results after parsing/building message it would be more convenient to get some kind of validation exception.