Efferent-Health/HL7-dotnetcore

\.br\ is not properly serialized leading to ParseMessage failure

Closed this issue · 4 comments

Hi,

Using version 2.26 and running into an issue with message parsing. Using new Message().ParseMessage I'm getting a result of IsParsed=false for the following message


            MSH|^~\&|ABC|ABC|ABCBSOUT||20210927010100||ORU^R01|20210927010100|P|2.3
            PID ||12345^^^EMPI|12345^^^MRN^MR||LAST^FIRST^M||19690101|Male||White|123 Main ST^^SPRINGFIELD^DE^55555^USA^Mailing||||||||
            PV1||Inpatient|ABCICU^ICU1^ICU1A^ABC|||||||Med Surg||||||||Step Down|987654321^^^Encounter^VN|||||||||||||||||||||||||20210927010100
            OBR|1||55555555555^SCM|Vital Signs^Vital Signs^OBS|||20210927010100|||||||||||||||20210927010100|||C|||||||
            NTE|1||Some Text\.br\
            OBX|1|TX|TEST^Test 1^OBS|1|critical lab values|||N|||R|||20210927010100

It appears to be related to the escaped BR tag in the NTE segment because if I look at the serialized message I see the following:

NTE|1||Some Text<BR>

Here's a unit test demonstrating this issue

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HL7.Dotnetcore;

    [TestClass]
    public class HL7Tests
    {

        private string sourceHl7 = @"
            MSH|^~\&|ABC|ABC|ABCBSOUT||20210927010100||ORU^R01|20210927010100|P|2.3
            PID ||12345^^^EMPI|12345^^^MRN^MR||LAST^FIRST^M||19630101|Male||White|123 Main ST^^SPRINGFIELD^DE^55555^USA^Mailing||||||||
            PV1||Inpatient|ABCICU^ICU1^ICU1A^ABC|||||||Med Surg||||||||Step Down|987654321^^^Encounter^VN|||||||||||||||||||||||||20210927010100
            OBR|1||55555555555^SCM|Vital Signs^Vital Signs^OBS|||20210927010100|||||||||||||||20210927010100|||C|||||||
            NTE|1||Some Text\.br\
            OBX|1|TX|TEST^Test 1^OBS|1|critical lab values|||N|||R|||20210927010100
            ";

        [TestMethod]
        public void TestParse()
        {
            var hl7 = new Message(sourceHl7);
            var isParsed = false;

            try
            {
                isParsed = hl7.ParseMessage();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to parse");
            }

            if (!isParsed)
            {
                Console.WriteLine("Source HL7 could not be parsed.");
                Console.WriteLine(sourceHl7);
                Console.WriteLine(hl7.SerializeMessage(false));
            }

            Assert.IsTrue(isParsed);
        }
    }

Edited: Added omitted MSH

hi @justinfalk,
Your sample message doesn't have the required header segment (MSH). That would never parse correctly.

Sorry, that was a result of hastily deidentifying the message. The message still fails due the the serialization problem I referenced above. I went and edited the original issue to add the missing MSH. Thanks.

Here's a much narrower example of the bug in the Encoding function

        [TestMethod]
        public void TestEncode()
        {
            var text = @"Some Text\.br\";
            var decoded = new HL7Encoding().Decode(text);  // <BR>
            var encoded = new HL7Encoding().Encode(decoded); // Still <BR>

            Assert.AreEqual(text, encoded);
        }

Actually, this appears to be resolved in 2.26. I was using an older version.

Looks like this fix corrects the issue: #82