1

我有一个问题,nHapi PipeParser 似乎没有解析 REF_I12(患者转诊)消息的 PID 段。如果我在不同的消息 (ADT_A01) 中使用完全相同的 PID 段,则解析 PID 段。我正在使用 HL7 2.5 版

以下工作代码说明了该问题:

using NHapi.Base.Parser;
using NHapi.Model.V25.Message;
using System;

public class MessageTester
{
    public static void Test()
    {
        var parser = new PipeParser();

        var adtMsg = new NHapi.Model.V25.Message.ADT_A01();

        adtMsg.MSH.MessageType.MessageCode.Value = "ADT";
        adtMsg.MSH.MessageType.TriggerEvent.Value = "A01";
        adtMsg.MSH.MessageType.MessageStructure.Value = "ADT_A01";
        adtMsg.MSH.FieldSeparator.Value = "|";
        adtMsg.MSH.EncodingCharacters.Value = @"^~\&";
        adtMsg.MSH.VersionID.VersionID.Value = "2.5";

        adtMsg.PID.SetIDPID.Value = "1";
        adtMsg.PID.CountyCode.Value = "ZAR";

        var name = adtMsg.PID.GetPatientName(0);
        name.PrefixEgDR.Value = "Mr";
        name.FamilyName.Surname.Value = "LastName";
        name.GivenName.Value = "FirstName";
        name.NameTypeCode.Value = "L";
        adtMsg.PID.AdministrativeSex.Value = "M";

        // The following returns a value of "ZAR", as expected.
        Console.WriteLine("Pre-Encoded ADT_A01 CountryCode: {0}", adtMsg.PID.CountyCode.Value);
        // The following returns a value of 1, as expected.
        Console.WriteLine("Pre-Encoded ADT_A01 PatientNameRepititionsUsed: {0}", adtMsg.PID.PatientNameRepetitionsUsed);

        var encodedADT_A01 = parser.Encode(adtMsg);

        var parsedADT_A01 = parser.Parse(encodedADT_A01) as ADT_A01;

        // After parsing the encoded message the following returns a value of "ZAR", as expected.
        Console.WriteLine("Parsed ADT_A01 CountryCode: {0}", parsedADT_A01.PID.CountyCode.Value);
        // After parsing the encoded message the following returns a value of 1, as expected.
        Console.WriteLine("Parsed ADT_A01 PatientNameRepititionsUsed: {0}", parsedADT_A01.PID.PatientNameRepetitionsUsed);

        Console.WriteLine("----------------------------------------------------------------");

        var refMsg = new NHapi.Model.V25.Message.REF_I12();

        refMsg.MSH.MessageType.MessageCode.Value = "REF";
        refMsg.MSH.MessageType.TriggerEvent.Value = "I12";
        refMsg.MSH.MessageType.MessageStructure.Value = "REF_I12";
        refMsg.MSH.FieldSeparator.Value = "|";
        refMsg.MSH.EncodingCharacters.Value = @"^~\&";
        refMsg.MSH.VersionID.VersionID.Value = "2.5";

        refMsg.PID.SetIDPID.Value = "1";
        refMsg.PID.CountyCode.Value = "ZAR";

        name = refMsg.PID.GetPatientName(0);
        name.PrefixEgDR.Value = "Mr";
        name.FamilyName.Surname.Value = "LastName";
        name.GivenName.Value = "FirstName";
        name.NameTypeCode.Value = "L";
        refMsg.PID.AdministrativeSex.Value = "M";

        // The following returns a value of "ZAR", as expected.
        Console.WriteLine("Pre-Encoded REF_I12 CountryCode: {0}", refMsg.PID.CountyCode.Value);
        // The following returns a value of 1, as expected.
        Console.WriteLine("Pre-Encoded REF_I12 PatientNameRepititionsUsed: {0}", refMsg.PID.PatientNameRepetitionsUsed);

        var encodedREF_I12 = parser.Encode(refMsg);

        var parsedREF_I12 = parser.Parse(encodedREF_I12) as REF_I12;

        // After parsing the encoded message the following returns nothing, where "ZAR" is expected.
        Console.WriteLine("Parsed REF_I12 CountryCode: {0}", parsedREF_I12.PID.CountyCode.Value);
        // After parsing the encoded message the following returns a value of 0, where 1 is expected.
        Console.WriteLine("Parsed REF_I12 PatientNameRepititionsUsed: {0}", parsedREF_I12.PID.PatientNameRepetitionsUsed);
    }

}

任何帮助将不胜感激。谢谢

4

1 回答 1

1

我找到了问题的根源。

检查HAPI API Docs后,我意识到我没有填充 REF_I12 消息的必需段,即 REF_I12_PROVIDER_CONTACT 段。使用以下代码行在构建消息时将此段添加到消息中,从而成功解析消息:

refMsg.GetPROVIDER_CONTACT(0).PRD.GetProviderName(0).FamilyName.Surname.Value = "DummyProviderLastName";

这是已修复问题的完整原始源代码:

    using NHapi.Base.Parser;
    using NHapi.Model.V25.Message;
    using System;

    public class MessageTester
    {
        public static void Test()
        {
            var parser = new PipeParser();

            var adtMsg = new NHapi.Model.V25.Message.ADT_A01();

            adtMsg.MSH.MessageType.MessageCode.Value = "ADT";
            adtMsg.MSH.MessageType.TriggerEvent.Value = "A01";
            adtMsg.MSH.MessageType.MessageStructure.Value = "ADT_A01";
            adtMsg.MSH.FieldSeparator.Value = "|";
            adtMsg.MSH.EncodingCharacters.Value = @"^~\&";
            adtMsg.MSH.VersionID.VersionID.Value = "2.5";

            adtMsg.PID.SetIDPID.Value = "1";
            adtMsg.PID.CountyCode.Value = "ZAR";

            var name = adtMsg.PID.GetPatientName(0);
            name.PrefixEgDR.Value = "Mr";
            name.FamilyName.Surname.Value = "LastName";
            name.GivenName.Value = "FirstName";
            name.NameTypeCode.Value = "L";
            adtMsg.PID.AdministrativeSex.Value = "M";

            // The following returns a value of "ZAR", as expected.
            Console.WriteLine("Pre-Encoded ADT_A01 CountryCode: {0}", adtMsg.PID.CountyCode.Value);
            // The following returns a value of 1, as expected.
            Console.WriteLine("Pre-Encoded ADT_A01 PatientNameRepititionsUsed: {0}", adtMsg.PID.PatientNameRepetitionsUsed);

            var encodedADT_A01 = parser.Encode(adtMsg);

            var parsedADT_A01 = parser.Parse(encodedADT_A01) as ADT_A01;

            // After parsing the encoded message the following returns a value of "ZAR", as expected.
            Console.WriteLine("Parsed ADT_A01 CountryCode: {0}", parsedADT_A01.PID.CountyCode.Value);
            // After parsing the encoded message the following returns a value of 1, as expected.
            Console.WriteLine("Parsed ADT_A01 PatientNameRepititionsUsed: {0}", parsedADT_A01.PID.PatientNameRepetitionsUsed);

            Console.WriteLine("----------------------------------------------------------------");

            var refMsg = new NHapi.Model.V25.Message.REF_I12();

            refMsg.MSH.MessageType.MessageCode.Value = "REF";
            refMsg.MSH.MessageType.TriggerEvent.Value = "I12";
            refMsg.MSH.MessageType.MessageStructure.Value = "REF_I12";
            refMsg.MSH.FieldSeparator.Value = "|";
            refMsg.MSH.EncodingCharacters.Value = @"^~\&";
            refMsg.MSH.VersionID.VersionID.Value = "2.5";

            // THIS LINE OF CODE FIXED THE ISSUE
            refMsg.GetPROVIDER_CONTACT(0).PRD.GetProviderName(0).FamilyName.Surname.Value = "DummyProviderLastName";

            refMsg.PID.SetIDPID.Value = "1";
            refMsg.PID.CountyCode.Value = "ZAR";

            name = refMsg.PID.GetPatientName(0);
            name.PrefixEgDR.Value = "Mr";
            name.FamilyName.Surname.Value = "LastName";
            name.GivenName.Value = "FirstName";
            name.NameTypeCode.Value = "L";
            refMsg.PID.AdministrativeSex.Value = "M";

            // The following returns a value of "ZAR", as expected.
            Console.WriteLine("Pre-Encoded REF_I12 CountryCode: {0}", refMsg.PID.CountyCode.Value);
            // The following returns a value of 1, as expected.
            Console.WriteLine("Pre-Encoded REF_I12 PatientNameRepititionsUsed: {0}", refMsg.PID.PatientNameRepetitionsUsed);

            var encodedREF_I12 = parser.Encode(refMsg);

            var parsedREF_I12 = parser.Parse(encodedREF_I12) as REF_I12;

            // FIXED: After parsing the encoded message the following returns "ZAR" as expected.
            Console.WriteLine("Parsed REF_I12 CountryCode: {0}", parsedREF_I12.PID.CountyCode.Value);
            // FIXED: After parsing the encoded message the following returns a value of 1 as expected.
            Console.WriteLine("Parsed REF_I12 PatientNameRepititionsUsed: {0}", parsedREF_I12.PID.PatientNameRepetitionsUsed);
        }

    }

经验教训:如果您的消息未按预期解析,请检查 Hapi API 文档以获取所需的段。

谢谢

于 2015-04-09T19:14:01.393 回答