我是 HL7 的新手,在实现一些功能时遇到了麻烦。
我想要达到的目标:
- 我想创建一个带有 MSH、QPD、RCP 段的QBP^Q21消息,其中 QPD 保存查询参数,如患者 ID、姓氏、名字等。
- 然后我想发送这个创建的消息以从 HIS(可能是医院的数据库)中获取患者的详细信息。
- 现在,我正在使用 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 CreateMshSegment(string currentDateTimeString)
中,在行之后var mshSegment = _qbpMessage.MSH;
我放了一个断点来检查 MSH 段的样子。
然后我在扩展mshSegment
.
完成执行后,我收到如下错误:
'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).
我在 HL7 汤中看到了什么:
我收到如下消息:
我很好奇MSH之前的VT是什么!
并且,响应显示为:
如果我的问题太愚蠢,请原谅我,我被卡住了,希望能提供任何可能导致此错误的指示。