Search code examples
c#.net-corehl7hl7-dotnetcore

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


I am using HL7-dotnetcore package which seems to be really nice. Unfortunately I'm struggling while creating new HL7 message.

I am trying to create new MDM_T02 message as explained in the guide (docs) with following code:

Message mdmMessage = new Message();

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

But, I get following exception message:

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

The AddSegmentMSH method expects the messageType as a parameter. But I don't know about the trigger event. I think the exception comes from here. Does someone know how to fix it?


Solution

  • The problem is because you are sending messageType as MDM_T02. This is invalid value. The MDM is message and T02 is an event. Those should be separated by component separator; default CAPS (^) symbol. Observe that you are separating those with underscore (_) symbol.

    Due to this, toolkit is not able to validate your message type. You should change "MDM_T02" to "MDM^T02".

    Refer to following code on 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);
    }
    

    Observe that the exception being thrown in above code is same that you mentioned in question. Also observe the first line; the SplitString is done on ComponentDelimiter.