簡體   English   中英

NHapi:為 QBP^Q21 消息創建 MSH 段時出現 System.TypeInitializationException

[英]NHapi: System.TypeInitializationException while creating MSH segment for QBP^Q21 message

我是 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是什么!

並且,響應顯示為:

在此處輸入圖片說明

如果我的問題太愚蠢,請原諒我,我被卡住了,希望能提供有關可能導致此錯誤的任何提示。

HL7消息由所以稱為M inimal大號奧爾大號艾爾P rotocol(MLLP)enframed。

VT是 MLLP 的標頭,用於包裝您的 HL7 消息。 來自healthstandards.com

這些頭和尾通常是不可打印的字符,通常不會出現在 HL7 消息的內容中。

標題是一個垂直制表符VT,其十六進制值為 0x0b。 尾部是一個文件分隔符FS (十六進制 0x1c),后面緊跟一個回車CR (十六進制 0x0d)

因此,您的消息似乎錯過了預告片。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM