C# NHapi:System.TypeInitializationException为QBP^Q21消息创建MSH段时发生异常
我是HL7新手,在实现某些功能时遇到了麻烦 我正在努力实现的目标: 我想创建一个QBP^Q21消息,其中包含MSH、QPD、RCP段,其中QPD包含患者ID、姓氏、姓氏等查询参数。 然后我想发送这个创建的消息,以便从医院的HIS a数据库中获取患者的详细信息。 现在,我正在医院使用Postgresql中的一些表模拟一个虚拟数据库,并使用HL7 Soup接收我创建的QBP^Q21消息,查询psql数据库并返回响应。 代码如下所示: 请注意:此代码段仅包括查询消息创建。我没有包含使用MLLP发送创建的消息的代码C# NHapi:System.TypeInitializationException为QBP^Q21消息创建MSH段时发生异常,c#,.net,hl7,hl7-v2,nhapi,C#,.net,Hl7,Hl7 V2,Nhapi,我是HL7新手,在实现某些功能时遇到了麻烦 我正在努力实现的目标: 我想创建一个QBP^Q21消息,其中包含MSH、QPD、RCP段,其中QPD包含患者ID、姓氏、姓氏等查询参数。 然后我想发送这个创建的消息,以便从医院的HIS a数据库中获取患者的详细信息。 现在,我正在医院使用Postgresql中的一些表模拟一个虚拟数据库,并使用HL7 Soup接收我创建的QBP^Q21消息,查询psql数据库并返回响应。 代码如下所示: 请注意:此代码段仅包括查询消息创建。我没有包含使用MLLP发送创建
using System;
using System.Globalization;
using NHapi.Model.V281.Message;
using NHapi.Base.Util;
namespace HealthLevel7
{
class QryMessageBuilder
{
private QBP_Q21 _qbpMessage;
public QBP_Q21 Build()
{
var currentDateTimeString = GetCurrentTimeStamp();
_qbpMessage = new QBP_Q21();
Terser terser = new Terser(_qbpMessage);
// Query by parameters: message segments here
CreateMshSegment(currentDateTimeString);
CreateQpdSegment(currentDateTimeString, terser);
CreateRcpSegment();
return _qbpMessage;
}
// Create MSH Segment
private void CreateMshSegment(string currentDateTimeString)
{
var mshSegment = _qbpMessage.MSH;
mshSegment.FieldSeparator.Value = "|";
mshSegment.EncodingCharacters.Value = "^~\\&";
mshSegment.SendingApplication.NamespaceID.Value = "my_sender";
mshSegment.SendingFacility.NamespaceID.Value = "my_app";
mshSegment.ReceivingApplication.NamespaceID.Value = "Dummy_HIS";
mshSegment.ReceivingFacility.NamespaceID.Value = "Dummy_Hospital";
mshSegment.DateTimeOfMessage.Value = currentDateTimeString;
mshSegment.MessageType.MessageCode.Value = "QBP";
mshSegment.MessageType.TriggerEvent.Value = "Q21";
mshSegment.MessageType.MessageStructure.Value = "QBP_Q21";
mshSegment.MessageControlID.Value = GetSequenceNumber();
mshSegment.ProcessingID.ProcessingID.Value = "P";
mshSegment.VersionID.VersionID.Value = "2.8.1";
}
// Create QPD Segment
private void CreateQpdSegment(string currentDateTimeString, Terser t)
{
// var patient = CreatePidSegment();
var qpdSegment = _qbpMessage.QPD;
t.Set("QPD-1-1", GetSequenceNumber());
t.Set("QPD-1-2", "Patient Query");
qpdSegment.QueryTag.Value = "Q001";
t.Set("QPD-3-1", "100000001");
t.Set("QPD-4-1", "Smith");
t.Set("QPD-4-2", "John");
t.Set("QPD-6", "19890419");
t.Set("QPD-7", "M");
}
// Create RCP Segment
private void CreateRcpSegment()
{
var rcpSegment = _qbpMessage.RCP;
rcpSegment.QueryPriority.Value = "I";
rcpSegment.QuantityLimitedRequest.Quantity.Value = "999";
rcpSegment.ResponseModality.Text.Value = "";
rcpSegment.ExecutionAndDeliveryTime.Value = "";
rcpSegment.ModifyIndicator.Value = "";
}
private static string GetCurrentTimeStamp()
{
// Return current timestamp
return DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
}
private static string GetSequenceNumber()
{
// Arbitrary facility number
const string facilityNumberPrefix = "1234";
return facilityNumberPrefix + GetCurrentTimeStamp();
}
}
}
调试时收到的错误:
我正在使用MS Visual Studio 2019社区版进行编码和调试
在函数private void CreateMshSegmentstring currentDateTimeString中,在var mshSegment=_qbpMessage.MSH;我放置了一个断点来检查MSH段的外观
然后,我在扩展MSH段时遇到如下错误
完成执行后,我得到一个错误,如下所示:
我在HL7汤中看到了什么:
我收到的信息如下:
我很好奇MSH之前的VT是什么
并且,响应如下所示:
如果我的问题太傻,请原谅,我被卡住了,如果有人能指点一下可能导致此错误的原因,我将不胜感激。HL7消息由所谓的最小下层协议MLLP构成框架 VT是MLLP的标头,用于包装HL7消息。 从 这些头和尾通常是不可打印的字符,通常不会出现在HL7消息的内容中 标题是垂直制表符VT,其十六进制值为0x0b。 尾部是一个文件分隔符FS hex 0x1c,后跟回车CR hex 0x0d
因此,您的消息似乎错过了预告片。Hi@sqlab,谢谢您的建议。我将尝试此操作并在此处更新。如果您遵循建议,或者如果您的程序在没有任何调试选项的情况下运行,会发生什么情况?
'HealthLevel7.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.0.0\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.TypeInitializationException' in NHapi.Base.dll
Error occured while creating HL7 message The type initializer for 'NHapi.Base.PackageManager' threw an exception.
The program '[16976] HealthLevel7.exe: Program Trace' has exited with code 0 (0x0).
The program '[16976] HealthLevel7.exe' has exited with code 0 (0x0).