I am new to HL7 and while implementing some functionality I ran into trouble.
What I am trying to achieve:
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.)
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.
In the function private void CreateMshSegment(string currentDateTimeString)
, after the line var mshSegment = _qbpMessage.MSH;
I put a breakpoint to check what MSH segment looks like.
Then I got an error as below on expanding the 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:
I receive the message as below:
I am curious about what is that VT before MSH!
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 ).
VT is the header of the MLLP, that wraps your HL7-Message. From healthstandards.com
These headers and trailers are usually non-printable characters that would not typically be in the content of HL7 messages.
The header is a vertical tab character VT its hex value is 0x0b. The trailer is a file separator character FS (hex 0x1c) immediately followed by a carriage return CR (hex 0x0d)
So it seems that your message misses the trailer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.