HL7-dotnetcore:为什么 HL7 消息验证失败并出现错误 "Message Type & Trigger Event value not found in message"?

HL7-dotnetcore: Why the HL7 message validation fail with error "Message Type & Trigger Event value not found in message"?

我正在使用 HL7-dotnetcore package,这似乎非常好。不幸的是,我在创建新的 HL7 消息时遇到了困难。

我正在尝试使用以下代码创建新的 MDM_T02 消息,如 guide (docs) 中所述:

Message mdmMessage = new Message();

mdmMessage.AddSegmentMSH(
    "sendingApplication",
    "sendingFacility",
    "receivingApplication",
    "receivingFacility",
    string.Empty,
    "MDM_T02",
    $"Id{DateTime.Now.Ticks}",
    "P",
    "2.6");

但是,我收到以下异常消息:

Failed to validate the message with error - Message Type & Trigger Event value not found in message

AddSegmentMSH method expects the messageType as a parameter. But I don't know about the trigger event. I think the exception comes from here。有人知道如何解决吗?

问题是因为您将 messageType 作为 MDM_T02 发送。这是无效值。 MDM 是消息,T02 是事件。那些应该由组件分隔符分隔;默认大写 (^) 符号。请注意,您使用下划线 (_) 符号分隔它们。

因此,Toolkit 无法验证您的消息类型。您应该将 "MDM_T02" 更改为 "MDM^T02".

参考github上的以下代码:

var MSH_9_comps = MessageHelper.SplitString(MSH_9, this.Encoding.ComponentDelimiter);

if (MSH_9_comps.Count >= 3)
{
    this.MessageStructure = MSH_9_comps[2];
}
else if (MSH_9_comps.Count > 0 && MSH_9_comps[0] != null && MSH_9_comps[0].Equals("ACK"))
{
    this.MessageStructure = "ACK";
}
else if (MSH_9_comps.Count == 2)
{
    this.MessageStructure = MSH_9_comps[0] + "_" + MSH_9_comps[1];
}
else
{
    throw new HL7Exception("Message Type & Trigger Event value not found in message", HL7Exception.UNSUPPORTED_MESSAGE_TYPE);
}

观察到上面代码中抛出的异常与您提到的问题相同。还要观察第一行; SplitStringComponentDelimiter 上完成。