NHapi:为QBP ^ Q21消息创建MSH段时出现System.TypeInitializationException

问题描述 投票:0回答:1

我是HL7的新手,在实现某些功能时遇到了麻烦。

我想要达到的目标:

  • 我想用段MSH,QPD,RCP创建QBP ^ Q21消息,其中QPD保存查询参数,例如患者ID,姓氏,名字等。
  • 然后我想发送此创建的消息以从HIS(可能是医院的数据库)中获取患者的详细信息。
  • 现在,我在医院中使用Postgresql中的一些表来模拟一个虚拟数据库,并使用HL7汤来接收我创建的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时出现如下错误。

enter image description here

完成执行后,我收到如下错误:

'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汤中看到什么:

我收到如下消息:

enter image description here

我对MSH之前的VT是什么感到好奇!

并且,响应显示为:

enter image description here

如果我的问题太傻了,请原谅我,我很困惑,不胜感激可能导致此错误的任何指针。

c# .net hl7 hl7-v2 nhapi
1个回答
0
投票

VT是MLLP的一部分,它包装了HL7消息。来自healthstandards.com

这些标题和结尾通常是不可打印的字符,它们通常不会出现在HL7消息的内容中。标头是一个垂直制表符,其十六进制值为0x0b。预告片是文件分隔符(十六进制0x1c),后跟回车符(十六进制0x0d)

所以您的信息似乎错过了预告片。

© www.soinside.com 2019 - 2024. All rights reserved.