use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode.
@Test
public void When_SendNackMessageRCMR_WithGeneralFailure_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID);
verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
assertEquals("30", ackMessageDataCaptor.getValue().getNackCode());
}
use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode.
@Test
public void When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_ShouldHaveCorrectNackCode() throws JAXBException {
RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
nackAckPreparationService.sendNackMessage(NACKReason.EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, CONVERSATION_ID);
verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture());
assertEquals("21", ackMessageDataCaptor.getValue().getNackCode());
}
use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class NackAckPreparationServiceTest method When_SendNackMessageRCMR_WithNoErrors_Expect_ShouldUpdateLog.
@Test
public void When_SendNackMessageRCMR_WithNoErrors_Expect_ShouldUpdateLog() throws JAXBException {
RCMRIN030000UK06Message payload = unmarshallString(readInboundMessagePayloadFromFile(), RCMRIN030000UK06Message.class);
when(sendNACKMessageHandler.prepareAndSendMessage(any(NACKMessageData.class))).thenReturn(true);
assertTrue(nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID));
verify(migrationStatusLogService).addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID);
}
use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class EhrExtractMessageHandler method handleMessage.
public void handleMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException, JsonProcessingException, InlineAttachmentProcessingException, BundleMappingException, AttachmentNotFoundException, ParseException, SAXException {
RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId);
MigrationStatusLog migrationStatusLog = migrationStatusLogService.getLatestMigrationStatusLog(conversationId);
migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_RECEIVED, conversationId);
try {
Document ebXmlDocument = getEbXmlDocument(inboundMessage);
String messageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH);
boolean hasExternalAttachment = !(inboundMessage.getExternalAttachments() == null || inboundMessage.getExternalAttachments().isEmpty());
// Manage attachments against the EHR message
var attachments = inboundMessage.getAttachments();
if (attachments != null) {
attachmentHandlerService.storeAttachments(attachments, conversationId);
for (var i = 0; i < attachments.size(); i++) {
var attachment = attachments.get(i);
PatientAttachmentLog newAttachmentLog = buildPatientAttachmentLogFromAttachment(messageId, migrationRequest, attachment);
patientAttachmentLogService.addAttachmentLog(newAttachmentLog);
}
}
if (!hasExternalAttachment) {
var fileUpdatedPayload = attachmentReferenceUpdaterService.updateReferenceToAttachment(inboundMessage.getAttachments(), conversationId, inboundMessage.getPayload());
inboundMessage.setPayload(fileUpdatedPayload);
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);
nackAckPreparationService.sendAckMessage(payload, conversationId);
}
// sending continue message
if (hasExternalAttachment) {
String patientNhsNumber = XmlParseUtilService.parseNhsNumber(payload);
for (InboundMessage.ExternalAttachment externalAttachment : inboundMessage.getExternalAttachments()) {
PatientAttachmentLog patientAttachmentLog;
// save COPC_UK01 messages
patientAttachmentLog = buildPatientAttachmentLogFromExternalAttachment(migrationRequest, externalAttachment);
patientAttachmentLogService.addAttachmentLog(patientAttachmentLog);
}
migrationStatusLogService.updatePatientMigrationRequestAndAddMigrationStatusLog(conversationId, null, objectMapper.writeValueAsString(inboundMessage), EHR_EXTRACT_TRANSLATED);
sendContinueRequest(payload, conversationId, patientNhsNumber, migrationRequest.getWinningPracticeOdsCode(), migrationStatusLog.getDate().toInstant());
}
} catch (BundleMappingException | DataFormatException | JsonProcessingException | InlineAttachmentProcessingException | AttachmentNotFoundException | SAXException | StorageException ex) {
nackAckPreparationService.sendNackMessage(EHR_EXTRACT_CANNOT_BE_PROCESSED, payload, conversationId);
throw ex;
} catch (ParseException ex) {
throw ex;
}
}
use of org.hl7.v3.RCMRIN030000UK06Message in project nia-patient-switching-standard-adaptor by NHSDigital.
the class EHRTimeoutHandler method sendNackMessage.
private void sendNackMessage(InboundMessage inboundMessage, String conversationId) throws JAXBException {
RCMRIN030000UK06Message payload = unmarshallString(inboundMessage.getPayload(), RCMRIN030000UK06Message.class);
NACKMessageData messageData = NACKMessageData.builder().nackCode(LARGE_MESSAGE_TIMEOUT.getCode()).fromAsid(outboundMessageUtil.parseFromAsid(payload)).toAsid(outboundMessageUtil.parseToAsid(payload)).toOdsCode(outboundMessageUtil.parseToOdsCode(payload)).messageRef(outboundMessageUtil.parseMessageRef(payload)).conversationId(conversationId).build();
LOGGER.debug("EHR Extract message timed out: sending NACK message");
migrationStatusLogService.addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId);
sendNACKMessageHandler.prepareAndSendMessage(messageData);
}
Aggregations