public ValidationExceptionHandler<Message> getNewInstance(HapiContext context) { RespondingValidationExceptionHandler handler = new RespondingValidationExceptionHandler(context); handler.setErrorAcknowledgementCode(getErrorAcknowledgementCode()); handler.setSuccessAcknowledgementCode(getSuccessAcknowledgementCode()); handler.setMinimumSeverityToCollect(getMinimumSeverityToCollect()); return handler; }
/** * Returns the generated response message. * * @return the generated response * @throws HL7Exception if no response could be generated * @see {@link #generateResponseMessage(Object)} * @see {@link #populateResponseMessage(ca.uhn.hl7v2.model.Message)} * */ public final Message result() throws HL7Exception { Object validationSubject = getValidationSubject(); if (validationSubject == null) { throw new HL7Exception("Need non-null validation subject"); } Message response = generateResponseMessage(validationSubject); populateResponseMessage(response); return response; }
/** * Populates the generated response based on the collected * {@link ValidationException}s. In case of exceptions, each exception will * cause an entry in one or more ERR segments. * * @param response response message to be populated * @throws HL7Exception */ protected void populateResponseMessage(Message response) throws HL7Exception { if (response == null) return; List<ValidationException> exceptions = getExceptions(); for (int i = 0; i < exceptions.size(); i++) { ValidationException ve = exceptions.get(i); // TODO respect minimumSeverity here? if (ve.getSeverity() == Severity.ERROR) { ve.populateResponse(response, getErrorAcknowledgementCode(), i); } } }
/** * Generates an empty response message. This class generates an * ACKnowledgement using the code returned by {@link #getSuccessAcknowledgementCode()}. * * @param request request message, either a {@link String} or a * {@link Message} * @return acknowledgment to the request * @throws HL7Exception */ protected Message generateResponseMessage(Object request) throws HL7Exception { try { Message in; if (request instanceof String) { Segment s = getHapiContext().getGenericParser().getCriticalResponseData( (String)request); in = s.getMessage(); DeepCopy.copy(s, (Segment) in.get("MSH")); } else if (request instanceof Message) { in = (Message) request; } else { throw new HL7Exception("Validated message must be either Message or String"); } return in.generateACK(getSuccessAcknowledgementCode(), null); } catch (IOException e) { throw new HL7Exception(e); } }
/** * Populates the generated response based on the collected * {@link ValidationException}s. In case of exceptions, each exception will * cause an entry in one or more ERR segments. * * @param response response message to be populated * @throws HL7Exception */ protected void populateResponseMessage(Message response) throws HL7Exception { if (response == null) return; List<ValidationException> exceptions = getExceptions(); for (int i = 0; i < exceptions.size(); i++) { ValidationException ve = exceptions.get(i); // TODO respect minimumSeverity here? if (ve.getSeverity() == Severity.ERROR) { ve.populateResponse(response, getErrorAcknowledgementCode(), i); } } }
/** * Generates an empty response message. This class generates an * ACKnowledgement using the code returned by {@link #getSuccessAcknowledgementCode()}. * * @param request request message, either a {@link String} or a * {@link Message} * @return acknowledgment to the request * @throws HL7Exception */ protected Message generateResponseMessage(Object request) throws HL7Exception { try { Message in; if (request instanceof String) { Segment s = getHapiContext().getGenericParser().getCriticalResponseData( (String)request); in = s.getMessage(); DeepCopy.copy(s, (Segment) in.get("MSH")); } else if (request instanceof Message) { in = (Message) request; } else { throw new HL7Exception("Validated message must be either Message or String"); } return in.generateACK(getSuccessAcknowledgementCode(), null); } catch (IOException e) { throw new HL7Exception(e); } }
public ValidationExceptionHandler<Message> getNewInstance(HapiContext context) { RespondingValidationExceptionHandler handler = new RespondingValidationExceptionHandler(context); handler.setErrorAcknowledgementCode(getErrorAcknowledgementCode()); handler.setSuccessAcknowledgementCode(getSuccessAcknowledgementCode()); handler.setMinimumSeverityToCollect(getMinimumSeverityToCollect()); return handler; }
/** * Returns the generated response message. * * @return the generated response * @throws HL7Exception if no response could be generated * @see {@link #generateResponseMessage(Object)} * @see {@link #populateResponseMessage(ca.uhn.hl7v2.model.Message)} * */ public final Message result() throws HL7Exception { Object validationSubject = getValidationSubject(); if (validationSubject == null) { throw new HL7Exception("Need non-null validation subject"); } Message response = generateResponseMessage(validationSubject); populateResponseMessage(response); return response; }