log.error("Attempting to send error message to remote system.", e);
// create error message ...
String errorMessage = null;
try {
Message out = DefaultApplication.makeACK(inHeader);
Terser t = new Terser(out);
// copy required data from incoming message ...
try {
t.set("/MSH-10", MessageIDGenerator.getInstance().getNewID());
} catch (IOException ioe) {
throw new HL7Exception("Problem creating error message ID: "
+ ioe.getMessage());
}
// populate MSA ...
t.set("/MSA-1", "AE"); // should this come from HL7Exception
// constructor?
t.set("/MSA-2", Terser.get(inHeader, 10, 0, 1, 1));
String excepMessage = e.getMessage();
if (excepMessage != null)
t.set("/MSA-3",
excepMessage.substring(0,
Math.min(80, excepMessage.length())));
/*
* Some earlier ACKs don't have ERRs, but I think we'll change this
* within HAPI so that there is a single ACK for each version (with
* an ERR).
*/
// see if it's an HL7Exception (so we can get specific information)
// ...
if (e.getClass().equals(HL7Exception.class)) {
Segment err = (Segment) out.get("ERR");
// ((HL7Exception) e).populate(err); // FIXME: this is broken,
// it relies on the database in a place where it's not available
} else {
t.set("/ERR-1-4-1", "207");
t.set("/ERR-1-4-2", "Application Internal Error");