0

I have an issue about the NACK message generated by HAPI,

I'm generating the NACK message as follows;

 Message msg= hl7Msg.generateACK(HL7Constants.HL7_MSA_ERROR_FIELD_VALUE, 
                    new HL7Exception(errorMsg));

This returns; following message;

MSH|^~\&|||||20130604165513.576+0100||ACK|108|P|2.5 
MSA|AE|HL7Gtw01361605B49500 
ERR|^^^207&ERROR&hl70357&&errmsg

If you notice the ERR segment, it doesn't have required info;

Is the above message valid?

I suspect it has to be like this;

MSH|^~\&|||||20130604165513.576+0100||ACK|108|P|2.5 
MSA|AE|HL7Gtw01361605B49500 
ERR|||207|E|^errmsg

Why do i get such invalid message? Am i doing anything wrong here?

Ratha
  • 9,434
  • 17
  • 85
  • 163
  • Can you give me the complete code you have written? – Sid Jun 06 '13 at 12:45
  • Sid, This is the line i did to generate NACK message; hl7Msg.generateACK('AE',new HL7Exception(errorMsg)); this is the API link, i used to generate ack http://hl7api.sourceforge.net/apidocs/src-html/ca/uhn/hl7v2/model/Message.html#line.170 – Ratha Jun 06 '13 at 12:54
  • @Sid please refer this question also http://stackoverflow.com/questions/16957792/why-nack-message-misses-to-create-the-fields-3-4-and-5-in-hapi – Ratha Jun 06 '13 at 12:54
  • @Sid any idea, why this happens? – Ratha Jun 07 '13 at 04:49
  • At present i cant say anything, until I reproduce the error on my system. – Sid Jun 07 '13 at 14:35
  • @Sid i got help from hapi mailing list..the issue is the version i used.. – Ratha Jun 07 '13 at 14:51

1 Answers1

0

Ans from hapi mailing list;

If possible, you should upgrade to most recent version (2.1). This version makes the distinction between ERR segments as of version 2.5 (where ERR-2 and ERR-3 is populated) and before version 2.5 (where ERR-1 is used) when generateACK is called with an Exception.

Anyway, you can use util classes like Terser to modify fields of the ERR segment in the ACK message as you wish. In your case you would probably have to copy values from ERR-1 to ERR-3

    Segment err = (Segment)msg.get("ERR");
    Terser.set(err, 3, 0, 1, 1, Terser.get(err, 1, 0, 4, 1));
    Terser.set(err, 3, 0, 2, 1, Terser.get(err, 1, 0, 4, 2));
    Terser.set(err, 3, 0, 3, 1, Terser.get(err, 1, 0, 4, 3));
    Terser.set(err, 3, 0, 9, 1, Terser.get(err, 1, 0, 4, 5));
    Terser.set(err, 4, 0, 1, 1, "E");

and optionally remove the values in ERR-1 afterwards:

Terser.set(err, 1, 0, 4, 1, "");

Ratha
  • 9,434
  • 17
  • 85
  • 163