简体   繁体   English

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

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

I am new to HL7 and while implementing some functionality I ran into trouble.我是 HL7 的新手,在实现某些功能时遇到了麻烦。

What I am trying to achieve:我正在努力实现的目标:

  • I want to create a QBP^Q21 message with the segments MSH, QPD, RCP where QPD holds the query parameters like Patient ID, Lastname, Firstname, etc.我想用 MSH、QPD、RCP 段创建QBP^Q21消息,其中 QPD 保存查询参数,如患者 ID、姓氏、名字等。
  • I then want to send this created message to fetch the details of the patient from the HIS (a database in hospital possibly).然后我想发送这个创建的消息以从 HIS(可能是医院的数据库)中获取患者的详细信息。
  • For now, I am mocking a dummy database at the hospital using some tables in Postgresql, and using HL7 Soup to receive my created QBP^Q21 message and query the psql database and return the response.现在,我正在使用 Postgresql 中的一些表在医院模拟一个虚拟数据库,并使用 HL7 Soup 接收我创建的 QBP^Q21 消息并查询 psql 数据库并返回响应。

The code looks like this:代码如下所示:

(Please note: This code segment only includes query message creation. I have not included the code to send the created messages using MLLP.) (请注意:此代码段仅包含查询消息创建。我没有包含使用 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();
        }
    }
}

The error I received while debugging:我在调试时收到的错误:

I am using MS Visual Studio 2019 community edition for coding and debugging.我正在使用 MS Visual Studio 2019 社区版进行编码和调试。

In the function private void CreateMshSegment(string currentDateTimeString) , after the line var mshSegment = _qbpMessage.MSH;在函数private void CreateMshSegment(string currentDateTimeString) ,在var mshSegment = _qbpMessage.MSH;行之后I put a breakpoint to check what MSH segment looks like.我放了一个断点来检查 MSH 段的样子。

Then I got an error as below on expanding the mshSegment .然后我在扩展mshSegment如下错误。

在此处输入图片说明

After completing the execution I am getting an error as below:完成执行后,我收到如下错误:

'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).

What do I see in HL7 Soup:我在 HL7 汤中看到了什么:

I receive the message as below:我收到如下消息:

在此处输入图片说明

I am curious about what is that VT before MSH!我很好奇MSH之前那个VT是什么!

And, the response is shown as:并且,响应显示为:

在此处输入图片说明

Forgive me if my question is too silly, I am stuck and would appreciate any pointers on what could possibly be causing this error.如果我的问题太愚蠢,请原谅我,我被卡住了,希望能提供有关可能导致此错误的任何提示。

HL7 messages are enframed by the so called M inimal L ower L ayer P rotocol ( MLLP ). HL7消息由所以称为M inimal大号奥尔大号艾尔P rotocol(MLLP)enframed。

VT is the header of the MLLP, that wraps your HL7-Message. VT是 MLLP 的标头,用于包装您的 HL7 消息。 From healthstandards.com来自healthstandards.com

These headers and trailers are usually non-printable characters that would not typically be in the content of HL7 messages.这些头和尾通常是不可打印的字符,通常不会出现在 HL7 消息的内容中。

The header is a vertical tab character VT its hex value is 0x0b.标题是一个垂直制表符VT,其十六进制值为 0x0b。 The trailer is a file separator character FS (hex 0x1c) immediately followed by a carriage return CR (hex 0x0d)尾部是一个文件分隔符FS (十六进制 0x1c),后面紧跟一个回车CR (十六进制 0x0d)

So it seems that your message misses the trailer.因此,您的消息似乎错过了预告片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM