use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.
the class PatientTransferService method handlePatientMigrationRequest.
public MigrationStatusLog handlePatientMigrationRequest(Parameters parameters, Map<String, String> headers) {
var conversationId = mdcService.getConversationId();
PatientMigrationRequest patientMigrationRequest = patientMigrationRequestDao.getMigrationRequest(conversationId);
if (patientMigrationRequest == null) {
var patientNhsNumber = getNhsNumberFromParameters(parameters).get().getValue();
patientMigrationRequestDao.addNewRequest(patientNhsNumber, conversationId, headers.get(TO_ODS), headers.get(FROM_ODS));
int addedId = patientMigrationRequestDao.getMigrationRequestId(conversationId);
migrationStatusLogDao.addMigrationStatusLog(REQUEST_RECEIVED, dateUtils.getCurrentOffsetDateTime(), addedId);
var pssMessage = createTransferRequestMessage(patientNhsNumber, headers, conversationId);
pssQueuePublisher.sendToPssQueue(pssMessage);
} else {
return migrationStatusLogDao.getLatestMigrationStatusLog(patientMigrationRequest.getId());
}
return null;
}
use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.
the class InboundMessageMergingService method mergeAndBundleMessage.
public void mergeAndBundleMessage(String conversationId) throws JAXBException, JsonProcessingException {
if (!StringUtils.hasText(conversationId)) {
throw new ValidationException(CONVERSATION_ID_HAS_NOT_BEEN_GIVEN);
}
PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
var inboundMessage = objectMapper.readValue(migrationRequest.getInboundMessage(), InboundMessage.class);
RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
try {
var attachmentLogs = getUndeletedLogsForConversation(conversationId);
var attachmentsContainSkeletonMessage = attachmentLogs.stream().anyMatch(log -> log.getSkeleton().equals(true));
if (attachmentsContainSkeletonMessage) {
findAndReplaceSkeleton(attachmentLogs, inboundMessage, conversationId);
}
// process attachments
var bypassPayloadLoadingArray = new String[attachmentLogs.size()];
Arrays.fill(bypassPayloadLoadingArray, "");
var messageAttachments = attachmentHandlerService.buildInboundAttachmentsFromAttachmentLogs(attachmentLogs, Arrays.asList(bypassPayloadLoadingArray), conversationId);
var newPayloadStr = attachmentReferenceUpdaterService.updateReferenceToAttachment(messageAttachments, conversationId, inboundMessage.getPayload());
// process bundle
inboundMessage.setPayload(newPayloadStr);
payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
var bundle = bundleMapperService.mapToBundle(payload, migrationRequest.getLosingPracticeOdsCode());
migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, fhirParser.encodeToJson(bundle), objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
} catch (InlineAttachmentProcessingException | SAXException | TransformerException | BundleMappingException | JAXBException | AttachmentNotFoundException | JsonProcessingException e) {
LOGGER.error("failed to merge Large Message Parts", e);
nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
}
}
use of uk.nhs.adaptors.connector.model.PatientMigrationRequest in project nia-patient-switching-standard-adaptor by NHSDigital.
the class COPCMessageHandler method extractFragmentsAndLog.
private void extractFragmentsAndLog(PatientMigrationRequest migrationRequest, PatientAttachmentLog parentAttachmentLog, String conversationId, InboundMessage message) throws ParseException, SAXException, ValidationException, InlineAttachmentProcessingException {
List<EbxmlReference> attachmentReferenceDescription = new ArrayList<>();
attachmentReferenceDescription.addAll(xmlParseUtilService.getEbxmlAttachmentsData(message));
// first item is always the message payload reference so skip it
for (var index = 1; index < attachmentReferenceDescription.size(); index++) {
var payloadReference = attachmentReferenceDescription.get(index);
var descriptionString = "";
var messageId = "";
var fileUpload = false;
// in this instance there should only ever be one CID on a fragment index file
if (payloadReference.getHref().contains("cid:")) {
messageId = payloadReference.getHref().substring(payloadReference.getHref().indexOf("cid:") + "cid:".length());
descriptionString = message.getAttachments().get(0).getDescription();
// upload the file
attachmentHandlerService.storeAttachments(message.getAttachments(), conversationId);
fileUpload = true;
} else {
var localMessageId = payloadReference.getHref().substring(payloadReference.getHref().indexOf("mid:") + "mid:".length());
messageId = localMessageId;
var externalAttachmentResult = message.getExternalAttachments().stream().filter(attachment -> attachment.getMessageId().equals(localMessageId)).findFirst();
if (externalAttachmentResult == null || externalAttachmentResult.stream().count() != 1) {
throw new ValidationException("External Attachment in payload header does not match a received External Attachment ID");
}
var externalAttachment = externalAttachmentResult.get();
descriptionString = externalAttachment.getDescription();
}
PatientAttachmentLog fragmentLog = patientAttachmentLogService.findAttachmentLog(messageId, conversationId);
if (fragmentLog != null) {
updateFragmentLog(fragmentLog, parentAttachmentLog, descriptionString, index - 1, parentAttachmentLog.getLargeAttachment());
patientAttachmentLogService.updateAttachmentLog(fragmentLog, conversationId);
} else {
PatientAttachmentLog newFragmentLog = buildPatientAttachmentLog(messageId, descriptionString, parentAttachmentLog.getMid(), migrationRequest.getId(), index - 1, fileUpload, parentAttachmentLog.getLargeAttachment());
patientAttachmentLogService.addAttachmentLog(newFragmentLog);
}
}
}
Aggregations