我遇到了一个问题,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);
}
}任何帮助都将不胜感激。谢谢
发布于 2015-04-09 19:14:01
我已经找到了问题的根源。
在检查了HAPI API文档之后,我意识到我没有填充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文档中所需的片段。
谢谢
https://stackoverflow.com/questions/29546140
复制相似问题