use of uk.nhs.adaptors.pss.translator.exception.AttachmentLogException in project nia-patient-switching-standard-adaptor by NHSDigital.
the class COPCMessageHandler method checkAndMergeFileParts.
public void checkAndMergeFileParts(InboundMessage inboundMessage, String conversationId) throws SAXException, AttachmentLogException, ValidationException, InlineAttachmentProcessingException {
Document ebXmlDocument = xPathService.parseDocumentFromXml(inboundMessage.getEbXML());
var inboundMessageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH);
var currentAttachmentLog = patientAttachmentLogService.findAttachmentLog(inboundMessageId, conversationId);
if (currentAttachmentLog == null) {
throw new AttachmentLogException("Given COPC message is missing an attachment log");
}
// if a message has arrived early, it will not have a parent ID so we can cancel early.
if (currentAttachmentLog.getParentMid() == null) {
return;
}
var conversationAttachmentLogs = patientAttachmentLogService.findAttachmentLogs(conversationId);
var attachmentLogFragments = conversationAttachmentLogs.stream().sorted(Comparator.comparingInt(PatientAttachmentLog::getOrderNum)).filter(log -> !(log.getParentMid() == null) && log.getParentMid().equals(currentAttachmentLog.getParentMid())).toList();
var parentLogMessageId = attachmentLogFragments.size() == 1 ? currentAttachmentLog.getMid() : currentAttachmentLog.getParentMid();
attachmentLogFragments = conversationAttachmentLogs.stream().sorted(Comparator.comparingInt(PatientAttachmentLog::getOrderNum)).filter(log -> !(log.getParentMid() == null) && log.getParentMid().equals(parentLogMessageId)).toList();
var allFragmentsHaveUploaded = attachmentLogFragments.stream().allMatch(PatientAttachmentLog::getUploaded);
if (allFragmentsHaveUploaded) {
String payload = attachmentHandlerService.buildSingleFileStringFromPatientAttachmentLogs(attachmentLogFragments, conversationId);
var parentLogFile = conversationAttachmentLogs.stream().filter(log -> log.getMid().equals(parentLogMessageId)).findAny().orElse(null);
var mergedLargeAttachment = createNewLargeAttachmentInList(parentLogFile, payload);
attachmentHandlerService.storeAttachments(mergedLargeAttachment, conversationId);
var updatedLog = PatientAttachmentLog.builder().mid(parentLogFile.getMid()).uploaded(true).build();
patientAttachmentLogService.updateAttachmentLog(updatedLog, conversationId);
attachmentLogFragments.forEach((PatientAttachmentLog log) -> {
attachmentHandlerService.removeAttachment(log.getFilename(), conversationId);
patientAttachmentLogService.deleteAttachmentLog(log.getMid(), conversationId);
});
}
}
use of uk.nhs.adaptors.pss.translator.exception.AttachmentLogException in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MhsQueueMessageHandler method handleMessage.
public boolean handleMessage(Message message) {
try {
InboundMessage inboundMessage = readMessage(message);
Document ebXmlDocument = xPathService.parseDocumentFromXml(inboundMessage.getEbXML());
String conversationId = xPathService.getNodeValue(ebXmlDocument, CONVERSATION_ID_PATH);
applyConversationId(conversationId);
String interactionId = xPathService.getNodeValue(ebXmlDocument, INTERACTION_ID_PATH);
if (ACKNOWLEDGEMENT_INTERACTION_ID.equals(interactionId)) {
acknowledgmentMessageHandler.handleMessage(inboundMessage, conversationId);
} else if (EHR_EXTRACT_INTERACTION_ID.equals(interactionId)) {
ehrExtractMessageHandler.handleMessage(inboundMessage, conversationId);
} else if (CONTINUE_ATTACHMENT_INTERACTION_ID.equals(interactionId)) {
continueMessageHandler.handleMessage(inboundMessage, conversationId);
} else {
LOGGER.info("Handling message with [{}] interaction id not implemented", interactionId);
}
return true;
} catch (JMSException | JAXBException | SAXException e) {
LOGGER.error("Unable to read the content of the inbound MHS message", e);
return false;
} catch (JsonProcessingException | DataFormatException e) {
LOGGER.error("Unable to parse messages", e);
return false;
} catch (InlineAttachmentProcessingException | AttachmentLogException e) {
LOGGER.error("Unable to process inline attachments", e);
return false;
} catch (AttachmentNotFoundException e) {
LOGGER.error("Unable to find attachment reference inbound message", e);
return false;
} catch (BundleMappingException e) {
LOGGER.error("Unable to map EHR Extract to FHIR bundle", e);
return false;
} catch (ParseException e) {
LOGGER.error("Unable to parse Ebxml References", e);
return false;
}
// catch (SkeletonEhrProcessingException e) {
// LOGGER.error("Unable to process EhrExtract", e);
// return false;
// }
}
Aggregations