Keep optional pipe in HL7 after parsing

388 views Asked by At

Original HL7

MSH|^~\&|RadImage^124|xxx|EI-ARTEFACT|xxx|123456789||ORM^O01|1234||2.3|||AL
PID|1|xxxxxx|xxxx||xxxxx^xxxxx xxxxx|xxx xxx|19391007|F|||104-430, xxx^^xxx^xx^xx^xx||(999)999-999|"||V|||||"||||||||"|N
PV1|1|A|11^11-1^^^^^2|||||123^xxx, xxx|||||||||123^xxx, xxx|||01|||||||||||||||||||NA|||||20191211082900|||||||
ORC|XO|"^"|xxx||CM||^^^xxx^^R||123456789|INTERF^INTERFACE||123^xxx, xxx|HOSPI^Hospitalisé|||KDICTE|3A^3A||"^"
OBR|1|"^"|xxx|82561^SCAN SINUS C+^^82561^SCAN SINUS C+|VU|xxx|"|"|||||"|||1234^xxx, xxx||xx|xxx|xxx|IMAGES^|xxxx||CT|"||^^^xxx^^VU||||AAAA~BBB~CCC|"^"||","~"|"|xxx|A|B|||
ZDS|1.11.11.11.1.11.1.1.11^RadImage^Application^DICOM

End result HL7

MSH|^~\&|RadImage^124|xxx|EI-ARTEFACT|xxx|123456789||ORM^O01|1234||2.3|||AL
PID|1|xxxxxx|xxxx||xxxxx^xxxxx xxxxx|xxx xxx|19391007|F|||104-430, xxx^^xxx^xx^xx^xx||(999)999-999|"||V|||||"||||||||"|N
PV1|1|A|11^11-1^^^^^2|||||123^xxx, xxx|||||||||123^xxx, xxx|||01|||||||||||||||||||NA|||||20191211082900
ORC|XO|"^"|xxx||CM||^^^xxx^^R||123456789|INTERF^INTERFACE||123^xxx, xxx|HOSPI^Hospitalisé|||KDICTE|3A^3A||"^"
OBR|1|"^"|xxx|82561^SCAN SINUS C+^^82561^SCAN SINUS C+|VU|xxx|"|"|||||"|||1234^xxx, xxx||xx|xxx|xxx|IMAGES^|xxxx||CT|"||^^^xxx^^VU||||AAAA~BBB~CCC|"^"||","~"|"|xxx|A|B|||
ZDS|1.11.11.11.1.11.1.1.11^RadImage^Application^DICOM

Hi,

I'm making a DLL in C# for parsing and modyfing a HL7 message using the nhapi Hl7 DLL. The only thing I'm struggling to is to keep the empty pipe at the end of the PV1 segment. It'S removing the pipe in the "End result HL7" vs "Orginal HL7".

I would like to keep those pipe

This is my actual code

...
    using NHapi.Base.Model;
    using NHapi.Base.Parser;
    using NHapi.Base.Util;
    using System.Diagnostics;
    using NHapi.Model.V23.Segment;
    using NHapi.Model.V22.Segment;
    using NHapi.Model.V21.Segment;
    using NHapi.Model.V231.Segment;
...
...
    public void PreAnalysis(ITratmContext ctx, MemBuf mb)
        {
            var parser = new PipeParser();
            Debug.WriteLine(mb.ToString());
            var parsedMessage = parser.Parse(mb.ToString());
            var pipeDelimitedMessage = parser.Encode(parsedMessage);
            Debug.WriteLine(pipeDelimitedMessage);  //Message lose the empty pipe HERE
            var genericMethod = parsedMessage as AbstractMessage;

            // create a terser object instance by wrapping it around the message object
            Terser terser = new Terser(parsedMessage);

            OurTerserHelper terserHelper = new OurTerserHelper(terser);
            String terserExpression = "MSH-12";
            String HL7Version = terserHelper.GetData(terserExpression);

            if (HL7Version == "2.3")
            {
                var obr = genericMethod.GetStructure("OBR") as NHapi.Model.V23.Segment.OBR;
                if (obr != null)
                {
                    for (int i = 0; i < obr.ReasonForStudyRepetitionsUsed; i++)
                    {
                        obr.GetReasonForStudy(i).Identifier.Value = StringExtention.Clean(obr.GetReasonForStudy(i).Identifier.ToString());
                    }
                }
                //var obrRep = obr.ReasonForStudyRepetitionsUsed;
                Debug.WriteLine(parser.Encode(genericMethod.Message));
                mb.Init(parser.Encode(genericMethod.Message));
            }
        }

Thank you very much !!!!

2

There are 2 answers

1
Nick Radov On

There is no need to keep any field separators after the last populated field in a segment. They are superfluous and a waste of space.

1
Chamodh On

I don`t see a point in having a field separator after the last populated field. But if you insist on doing this you could you could append a custom separator at the end.