diff --git a/db-connector/changelog/migration/14-add-error-code-column-to-migration_status_log-table.xml b/db-connector/changelog/migration/14-add-error-code-column-to-migration_status_log-table.xml new file mode 100644 index 000000000..7985e1e2f --- /dev/null +++ b/db-connector/changelog/migration/14-add-error-code-column-to-migration_status_log-table.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/db-connector/src/main/java/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao.java b/db-connector/src/main/java/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao.java index befc9df6d..6ba134139 100644 --- a/db-connector/src/main/java/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao.java +++ b/db-connector/src/main/java/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao.java @@ -16,7 +16,8 @@ public interface MigrationStatusLogDao { @SqlUpdate("insert_migration_status_log") @UseClasspathSqlLocator void addMigrationStatusLog(@Bind("status") MigrationStatus status, - @Bind("date") OffsetDateTime date, @Bind("migrationRequestId") int migrationRequestId, @Bind("messageId") String messageId + @Bind("date") OffsetDateTime date, @Bind("migrationRequestId") int migrationRequestId, + @Bind("messageId") String messageId, @Bind("gp2gpErrorCode") String gp2gpErrorCode ); @SqlQuery("select_migration_status_log") diff --git a/db-connector/src/main/java/uk/nhs/adaptors/connector/model/MigrationStatusLog.java b/db-connector/src/main/java/uk/nhs/adaptors/connector/model/MigrationStatusLog.java index 53a4f2d87..8d30864b4 100644 --- a/db-connector/src/main/java/uk/nhs/adaptors/connector/model/MigrationStatusLog.java +++ b/db-connector/src/main/java/uk/nhs/adaptors/connector/model/MigrationStatusLog.java @@ -13,10 +13,12 @@ @Setter @Builder public class MigrationStatusLog { + private int id; @EnumByName private MigrationStatus migrationStatus; private OffsetDateTime date; private int migrationRequestId; private String messageId; + private String gp2gpErrorCode; } diff --git a/db-connector/src/main/java/uk/nhs/adaptors/connector/service/MigrationStatusLogService.java b/db-connector/src/main/java/uk/nhs/adaptors/connector/service/MigrationStatusLogService.java index 000ef6700..d2b51182a 100644 --- a/db-connector/src/main/java/uk/nhs/adaptors/connector/service/MigrationStatusLogService.java +++ b/db-connector/src/main/java/uk/nhs/adaptors/connector/service/MigrationStatusLogService.java @@ -17,18 +17,22 @@ @Service @AllArgsConstructor(onConstructor = @__(@Autowired)) public class MigrationStatusLogService { + private final PatientMigrationRequestDao patientMigrationRequestDao; private final MigrationStatusLogDao migrationStatusLogDao; private final DateUtils dateUtils; - public void addMigrationStatusLog(MigrationStatus migrationStatus, String conversationId, String messageId) { + public void addMigrationStatusLog(MigrationStatus migrationStatus, String conversationId, String messageId, String gp2gpErrorCode) { + int migrationRequestId = patientMigrationRequestDao.getMigrationRequestId(conversationId); migrationStatusLogDao.addMigrationStatusLog( migrationStatus, dateUtils.getCurrentOffsetDateTime(), migrationRequestId, - messageId + messageId, + gp2gpErrorCode ); + LOGGER.debug("Changed MigrationStatus of PatientMigrationRequest with id=[{}] to [{}]", migrationRequestId, migrationStatus.name()); } @@ -45,6 +49,6 @@ public List getMigrationStatusLogs(String conversationId) { public void updatePatientMigrationRequestAndAddMigrationStatusLog(String conversationId, String bundle, String inboundMessage, MigrationStatus migrationStatus, String messageId) { patientMigrationRequestDao.saveBundleAndInboundMessageData(conversationId, bundle, inboundMessage); - addMigrationStatusLog(migrationStatus, conversationId, messageId); + addMigrationStatusLog(migrationStatus, conversationId, messageId, null); } } diff --git a/db-connector/src/main/resources/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao/insert_migration_status_log.sql b/db-connector/src/main/resources/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao/insert_migration_status_log.sql index 8b5684494..20a236b55 100644 --- a/db-connector/src/main/resources/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao/insert_migration_status_log.sql +++ b/db-connector/src/main/resources/uk/nhs/adaptors/connector/dao/MigrationStatusLogDao/insert_migration_status_log.sql @@ -1,2 +1,2 @@ -INSERT INTO migration_status_log(status, date, migration_request_id, message_id) -VALUES (:status, :date, :migrationRequestId, :messageId); \ No newline at end of file +INSERT INTO migration_status_log(status, date, migration_request_id, message_id, gp2gp_error_code) +VALUES (:status, :date, :migrationRequestId, :messageId, :gp2gpErrorCode); \ No newline at end of file diff --git a/db-connector/src/test/java/uk/nhs/adaptors/connector/service/MigrationStatusLogServiceTest.java b/db-connector/src/test/java/uk/nhs/adaptors/connector/service/MigrationStatusLogServiceTest.java index 0827cf9cc..fd359ce56 100644 --- a/db-connector/src/test/java/uk/nhs/adaptors/connector/service/MigrationStatusLogServiceTest.java +++ b/db-connector/src/test/java/uk/nhs/adaptors/connector/service/MigrationStatusLogServiceTest.java @@ -40,8 +40,8 @@ public void testAddMigrationStatusLog() { when(patientMigrationRequestDao.getMigrationRequestId(nhsNumber)).thenReturn(MIGRATION_REQUEST_ID); when(dateUtils.getCurrentOffsetDateTime()).thenReturn(now); - migrationStatusLogService.addMigrationStatusLog(MigrationStatus.MIGRATION_COMPLETED, nhsNumber, null); + migrationStatusLogService.addMigrationStatusLog(MigrationStatus.MIGRATION_COMPLETED, nhsNumber, null, null); - verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.MIGRATION_COMPLETED, now, MIGRATION_REQUEST_ID, null); + verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.MIGRATION_COMPLETED, now, MIGRATION_REQUEST_ID, null, null); } } diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/AcknowledgeMessageHandlingIT.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/AcknowledgeMessageHandlingIT.java index 79be903d1..762175392 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/AcknowledgeMessageHandlingIT.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/AcknowledgeMessageHandlingIT.java @@ -52,6 +52,7 @@ public class AcknowledgeMessageHandlingIT { private static final String ERROR_REASON_MESSAGE_PLACEHOLDER = "{{reasonMessage}}"; private static final String LOSING_ODS_CODE = "K547"; private static final String WINNING_ODS_CODE = "ABC"; + public static final String TEST_ERROR_MESSAGE = "Test Error Message"; @Autowired private PatientMigrationRequestDao patientMigrationRequestDao; @@ -72,7 +73,7 @@ public class AcknowledgeMessageHandlingIT { public void setUp() { conversationId = generateConversationId().toUpperCase(Locale.ROOT); patientMigrationRequestDao.addNewRequest(generatePatientNhsNumber(), conversationId, LOSING_ODS_CODE, WINNING_ODS_CODE); - migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null, null); } @Test @@ -93,7 +94,7 @@ public void handleNegativeAcknowledgeMessageFromQueue() { @Test public void handleNegativeAcknowledgeMessageWithUndeclairedErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "101", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "101", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN)); @@ -101,7 +102,7 @@ public void handleNegativeAcknowledgeMessageWithUndeclairedErrorReasonFromQueue( @Test public void handleNegativeAcknowledgeMessageWithUnknownErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "99", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "99", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN)); @@ -109,7 +110,7 @@ public void handleNegativeAcknowledgeMessageWithUnknownErrorReasonFromQueue() { @Test public void handleNegativeAcknowledgeMessageWithPatientNotRegisteredErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "06", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "06", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED)); @@ -117,7 +118,7 @@ public void handleNegativeAcknowledgeMessageWithPatientNotRegisteredErrorReasonF @Test public void handleNegativeAcknowledgeMessageWithSENDERNOTCONFIGUREDErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "07", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "07", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_SENDER_NOT_CONFIGURED)); @@ -125,7 +126,7 @@ public void handleNegativeAcknowledgeMessageWithSENDERNOTCONFIGUREDErrorReasonFr @Test public void handleNegativeAcknowledgeMessageWithEHRGENERATIONErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "10", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "10", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_EHR_GENERATION_ERROR)); @@ -133,7 +134,7 @@ public void handleNegativeAcknowledgeMessageWithEHRGENERATIONErrorReasonFromQueu @Test public void handleNegativeAcknowledgeMessageWithMISFORMEDREQUESTErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "18", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "18", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_MISFORMED_REQUEST)); @@ -141,7 +142,7 @@ public void handleNegativeAcknowledgeMessageWithMISFORMEDREQUESTErrorReasonFromQ @Test public void handleNegativeAcknowledgeMessageWithNOTPRIMARYHEALTHCAREPROVIDERErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "19", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "19", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_NOT_PRIMARY_HEALTHCARE_PROVIDER)); @@ -149,7 +150,7 @@ public void handleNegativeAcknowledgeMessageWithNOTPRIMARYHEALTHCAREPROVIDERErro @Test public void handleNegativeAcknowledgeMessageWithMULTIORNORESPONSESErrorReasonFromQueue() { - sendAcknowledgementMessageToQueue("AE", "24", "Test Error Message"); + sendAcknowledgementMessageToQueue("AE", "24", TEST_ERROR_MESSAGE); // verify if correct status is set in the DB await().until(() -> isCorrectStatusSet(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_MULTI_OR_NO_RESPONSES)); diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/E2EMappingIT.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/E2EMappingIT.java index 371fb8977..5e9276448 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/E2EMappingIT.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/E2EMappingIT.java @@ -1,14 +1,11 @@ package uk.nhs.adaptors.pss.translator; -import static org.assertj.core.api.Assertions.fail; import static org.awaitility.Awaitility.await; import static uk.nhs.adaptors.common.util.FileUtil.readResourceAsString; import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString; import static uk.nhs.adaptors.pss.util.JsonPathIgnoreGeneratorUtil.generateJsonPathIgnores; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Locale; import java.util.stream.Stream; @@ -21,10 +18,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.skyscreamer.jsonassert.Customization; -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; -import org.skyscreamer.jsonassert.comparator.CustomComparator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -47,7 +40,6 @@ public class E2EMappingIT extends BaseEhrHandler { private static final boolean OVERWRITE_EXPECTED_JSON = false; - private static final int NHS_NUMBER_MIN_MAX_LENGTH = 10; private static final String PSS_ADAPTOR_URL = "https://PSSAdaptor/"; private static final String EBXML_PART_PATH = "/xml/RCMR_IN030000UK06/ebxml_part.xml"; //these are programming language special characters, not to be confused with line endings @@ -348,28 +340,4 @@ private String getOdsToBeReplaced(String expectedBundle) { return expectedBundle.substring(startIndex, endIndex); } - private String getLocationToBeReplaced(String expectedBundle) { - var startIndex = expectedBundle.toLowerCase().indexOf(PSS_ADAPTOR_URL.toLowerCase()) + PSS_ADAPTOR_URL.length(); - var endIndex = expectedBundle.toLowerCase().indexOf("\"", startIndex); - - return expectedBundle.substring(startIndex, endIndex); - } - - @SneakyThrows - private void overwriteExpectJson(String newExpected) { - try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/json/expectedBundle.json", StandardCharsets.UTF_8)) { - printWriter.print(newExpected); - } - fail("Re-run the tests with OVERWRITE_EXPECTED_JSON=false"); - } - - private void assertBundleContent(String actual, String expected, List ignoredPaths) throws JSONException { - // when comparing json objects, this will ignore various json paths that contain random values like ids or timestamps - var customizations = ignoredPaths.stream() - .map(jsonPath -> new Customization(jsonPath, (o1, o2) -> true)) - .toArray(Customization[]::new); - - JSONAssert.assertEquals(expected, actual, - new CustomComparator(JSONCompareMode.STRICT, customizations)); - } } \ No newline at end of file diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/EhrExtractHandlingIT.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/EhrExtractHandlingIT.java index 10befc4b8..97f595fda 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/EhrExtractHandlingIT.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/EhrExtractHandlingIT.java @@ -138,7 +138,7 @@ public void handleEhrExtractWithConfidentialityCodeFromQueue() throws JSONExcept private void startPatientMigrationJourney() { patientMigrationRequestDao.addNewRequest(patientNhsNumber, conversationId, LOSING_ODS_CODE, WINNING_ODS_CODE); - migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null, null); } private String generatePatientNhsNumber() { diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/FailedProcessHandingIT.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/FailedProcessHandingIT.java index e4dbaa2d2..65427baa2 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/FailedProcessHandingIT.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/FailedProcessHandingIT.java @@ -107,7 +107,7 @@ public void When_ProcessFailedByIncumbent_With_CopcMessage_Expect_NotProcessed() @Test public void When_ProcessFailedByNME_With_EhrExtract_Expect_NotProcessed() { - migrationStatusLogService.addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, getConversationId(), null); + migrationStatusLogService.addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, getConversationId(), null, "99"); sendEhrExtractToQueue(); @@ -133,7 +133,7 @@ private void whenCopcSentExpectNackCode(MigrationStatus preCopcMigrationStatus, await().until(this::isContinueRequestAccepted); - migrationStatusLogService.addMigrationStatusLog(preCopcMigrationStatus, getConversationId(), null); + migrationStatusLogService.addMigrationStatusLog(preCopcMigrationStatus, getConversationId(), null, null); sendCopcToQueue(); diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/amqp/ServiceFailureIT.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/amqp/ServiceFailureIT.java index ef4eb6ab4..e456f82e6 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/amqp/ServiceFailureIT.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/translator/amqp/ServiceFailureIT.java @@ -319,7 +319,7 @@ private void sendRequestToPssQueue(String conversationId, String patientNhsNumbe getPatientMigrationRequestDao() .addNewRequest(patientNhsNumber, conversationId, getLosingODSCode(), getWiningODSCode()); getMigrationStatusLogService() - .addMigrationStatusLog(REQUEST_RECEIVED, conversationId, null); + .addMigrationStatusLog(REQUEST_RECEIVED, conversationId, null, null); var transferRequestMessage = TransferRequestMessage.builder() .patientNhsNumber(patientNhsNumber) diff --git a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/util/BaseEhrHandler.java b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/util/BaseEhrHandler.java index 633c2330b..e69043d12 100644 --- a/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/util/BaseEhrHandler.java +++ b/gp2gp-translator/src/integrationTest/java/uk/nhs/adaptors/pss/util/BaseEhrHandler.java @@ -83,7 +83,7 @@ public void setUp() { protected void startPatientMigrationJourney() { patientMigrationRequestDao.addNewRequest(patientNhsNumber, conversationId, losingODSCode, winingODSCode); - migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null, null); } protected boolean isEhrExtractTranslated() { @@ -118,14 +118,14 @@ protected void verifyBundle(String path) throws JSONException { } @SneakyThrows - private void overwriteExpectJson(String newExpected) { + protected void overwriteExpectJson(String newExpected) { try (PrintWriter printWriter = new PrintWriter("src/integrationTest/resources/json/expectedBundle.json", StandardCharsets.UTF_8)) { printWriter.print(newExpected); } fail("Re-run the tests with OVERWRITE_EXPECTED_JSON=false"); } - private void assertBundleContent(String actual, String expected, List ignoredPaths) throws JSONException { + protected void assertBundleContent(String actual, String expected, List ignoredPaths) throws JSONException { // when comparing json objects, this will ignore various json paths that contain random values like ids or timestamps var customizations = ignoredPaths.stream() .map(jsonPath -> new Customization(jsonPath, (o1, o2) -> true)) diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/model/NACKReason.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/model/NACKReason.java index 24bd11366..130822828 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/model/NACKReason.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/model/NACKReason.java @@ -4,6 +4,7 @@ import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_NEGATIVE_ACK_FAILED_TO_INTEGRATE; import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_NEGATIVE_ACK_NON_ABA_INCORRECT_PATIENT; import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_NEGATIVE_ACK_SUPPRESSED; +import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED; import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_GENERAL_PROCESSING_ERROR; import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_EXTRACT_CANNOT_BE_PROCESSED; import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_LRG_MSG_ATTACHMENTS_NOT_RECEIVED; @@ -17,6 +18,7 @@ @RequiredArgsConstructor public enum NACKReason { + LARGE_MESSAGE_REASSEMBLY_FAILURE("29"), LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED("31"), LARGE_MESSAGE_GENERAL_FAILURE("30"), @@ -26,6 +28,7 @@ public enum NACKReason { UNEXPECTED_CONDITION("99"), ABA_EHR_EXTRACT_REJECTED_WRONG_PATIENT("17"), ABA_EHR_EXTRACT_SUPPRESSED("15"), + PATIENT_NOT_AT_SURGERY("06"), NON_ABA_EHR_EXTRACT_REJECTED_WRONG_PATIENT("28"); @Getter @@ -43,6 +46,7 @@ public MigrationStatus getMigrationStatus() { case ABA_EHR_EXTRACT_SUPPRESSED -> EHR_EXTRACT_NEGATIVE_ACK_SUPPRESSED; case ABA_EHR_EXTRACT_REJECTED_WRONG_PATIENT -> EHR_EXTRACT_NEGATIVE_ACK_ABA_INCORRECT_PATIENT; case NON_ABA_EHR_EXTRACT_REJECTED_WRONG_PATIENT -> EHR_EXTRACT_NEGATIVE_ACK_NON_ABA_INCORRECT_PATIENT; + case PATIENT_NOT_AT_SURGERY -> EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED; }; } } diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingService.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingService.java index 5f3a986fe..dec85e43e 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingService.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingService.java @@ -114,7 +114,7 @@ public void mergeAndBundleMessage(String conversationId) throws JAXBException, J EHR_EXTRACT_TRANSLATED, null ); - migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null, null); } catch (InlineAttachmentProcessingException | SAXException | TransformerException | JAXBException | AttachmentNotFoundException | JsonProcessingException e) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationService.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationService.java index 44cf09326..0e67f5221 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationService.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationService.java @@ -33,7 +33,7 @@ public boolean sendAckMessage(RCMRIN030000UK06Message payload, String conversati LOGGER.debug("Sending Final ACK message for Conversation ID: [{}]", conversationId); migrationStatusLogService. - addMigrationStatusLog(FINAL_ACK_SENT, conversationId, null); + addMigrationStatusLog(FINAL_ACK_SENT, conversationId, null, null); return sendACKMessageHandler.prepareAndSendMessage(prepareAckMessageData( payload, @@ -46,7 +46,7 @@ public boolean sendAckMessage(COPCIN000001UK01Message payload, String conversati LOGGER.debug("Sending ACK message for COPC message with Conversation ID: [{}]", conversationId); migrationStatusLogService. - addMigrationStatusLog(COPC_ACKNOWLEDGED, conversationId, null); + addMigrationStatusLog(COPC_ACKNOWLEDGED, conversationId, null, null); return sendACKMessageHandler.prepareAndSendMessage(prepareAckMessageData( payload, @@ -132,7 +132,7 @@ public boolean sendNackMessage(NACKReason reason, RCMRIN030000UKMessage payload, LOGGER.debug("Sending NACK message with acknowledgement code [{}] for message EHR Extract message [{}]", reason.getCode(), payload.getId().getRoot()); - migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null); + migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null, reason.getCode()); return sendNACKMessageHandler.prepareAndSendMessage(prepareNackMessageData( reason, @@ -146,7 +146,7 @@ public boolean sendNackMessage(NACKReason reason, COPCIN000001UK01Message payloa LOGGER.debug("Sending NACK message with acknowledgement code [{}] for message COPC message [{}]", reason.getCode(), payload.getId().getRoot()); - migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null); + migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null, reason.getCode()); return sendNACKMessageHandler.prepareAndSendMessage(prepareNackMessageData( reason, diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandler.java index 400aab447..3de07b430 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandler.java @@ -41,6 +41,7 @@ public class AcknowledgmentMessageHandler { private final FailedProcessHandlingService failedProcessHandlingService; public void handleMessage(InboundMessage inboundMessage, String conversationId) throws SAXException { + Document document = xPathService.parseDocumentFromXml(inboundMessage.getPayload()); String ackTypeCode = xPathService.getNodeValue(document, ACK_TYPE_CODE_XPATH); String nackReasonCode = null; @@ -50,7 +51,8 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId) return; } - if (ackTypeCode.equals(NACK_ERROR_TYPE_CODE) || ackTypeCode.equals(NACK_REJECT_TYPE_CODE)) { + var negativeAckError = isNegativeAckError(ackTypeCode); + if (negativeAckError) { nackReasonCode = xPathService.getNodeValue(document, NACK_REASON_CODE_PATH); if (nackReasonCode == null) { nackReasonCode = ""; @@ -65,10 +67,10 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId) return; } - if (currentMigrationStatus.equals(FINAL_ACK_SENT) || currentMigrationStatus.equals(MIGRATION_COMPLETED)) { + if (FINAL_ACK_SENT.equals(currentMigrationStatus) || MIGRATION_COMPLETED.equals(currentMigrationStatus)) { var loggerMessage = "Received an ack with type code {}, but the migration is complete"; - if (currentMigrationStatus.equals(FINAL_ACK_SENT)) { + if (FINAL_ACK_SENT.equals(currentMigrationStatus)) { loggerMessage = loggerMessage + " and the EHR has been accepted"; } @@ -76,7 +78,15 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId) return; } - migrationStatusLogService.addMigrationStatusLog(newMigrationStatus, conversationId, null); + if (negativeAckError) { + migrationStatusLogService.addMigrationStatusLog(newMigrationStatus, conversationId, null, nackReasonCode); + } else { + migrationStatusLogService.addMigrationStatusLog(newMigrationStatus, conversationId, null, null); + } + } + + private static boolean isNegativeAckError(String ackTypeCode) { + return NACK_ERROR_TYPE_CODE.equals(ackTypeCode) || NACK_REJECT_TYPE_CODE.equals(ackTypeCode); } private MigrationStatus getMigrationStatus(String ackTypeCode, String reasonCode) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandler.java index 0a115d240..0cc4d1035 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandler.java @@ -90,13 +90,13 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId) } PatientMigrationRequest migrationRequest = migrationRequestDao.getMigrationRequest(conversationId); - migrationStatusLogService.addMigrationStatusLog(COPC_MESSAGE_RECEIVED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(COPC_MESSAGE_RECEIVED, conversationId, null, null); try { Document ebXmlDocument = getEbXmlDocument(inboundMessage); String messageId = xPathService.getNodeValue(ebXmlDocument, MESSAGE_ID_PATH); PatientAttachmentLog patientAttachmentLog = patientAttachmentLogService.findAttachmentLog(messageId, conversationId); - migrationStatusLogService.addMigrationStatusLog(COPC_MESSAGE_PROCESSING, conversationId, messageId); + migrationStatusLogService.addMigrationStatusLog(COPC_MESSAGE_PROCESSING, conversationId, messageId, null); // If there is no PatientAttachmentLog for this message then we have received a message out of order if (patientAttachmentLog == null) { @@ -149,8 +149,10 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId) failMigration(conversationId, UNEXPECTED_CONDITION); } else { failMigration(conversationId, LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED); - migrationStatusLogService.addMigrationStatusLog( - LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getMigrationStatus(), conversationId, null); + migrationStatusLogService.addMigrationStatusLog(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } } catch (ExternalAttachmentProcessingException e) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandler.java index 6bbf0f5fc..8637f9ad9 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandler.java @@ -95,7 +95,7 @@ public void handleMessage(InboundMessage inboundMessage, String conversationId, return; } - migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_RECEIVED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(EHR_EXTRACT_RECEIVED, conversationId, null, null); try { Document ebXmlDocument = getEbXmlDocument(inboundMessage); @@ -211,7 +211,7 @@ private void processAndCompleteEHRMessage(InboundMessage inboundMessage, messageId ); - migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null, null); } private void processExternalAttachmentsAndSendContinueMessage(InboundMessage inboundMessage, diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandler.java index 031e9a2e4..de480bb18 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandler.java @@ -33,6 +33,7 @@ import uk.nhs.adaptors.pss.translator.mhs.model.InboundMessage; import uk.nhs.adaptors.pss.translator.service.XPathService; import uk.nhs.adaptors.connector.service.MigrationStatusLogService; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import java.text.ParseException; import java.util.Locale; @@ -94,7 +95,10 @@ public boolean handleMessage(Message message) { // Current child try catch blocks do not detect this condition so no failed migration log is added... // We are however unlikely to have a payload at this point so cannot send a NACK if (conversationId != null && !conversationId.isEmpty()) { - migrationStatusLogService.addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, + conversationId, + null, + UNEXPECTED_CONDITION.getCode()); } return false; } catch (JsonProcessingException | DataFormatException e) { diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandler.java index 9d651c7e2..b33aca64a 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandler.java @@ -16,6 +16,7 @@ import uk.nhs.adaptors.pss.translator.service.ContinueRequestService; import uk.nhs.adaptors.pss.translator.service.IdGeneratorService; import uk.nhs.adaptors.pss.translator.service.MhsClientService; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; @Slf4j @Component @@ -41,7 +42,10 @@ public void prepareAndSendRequest(ContinueRequestData data) { mhsClientService.send(request); } catch (WebClientResponseException webClientResponseException) { LOGGER.error("Received an ERROR response from MHS: [{}]", webClientResponseException.getMessage()); - migrationStatusLogService.addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ERROR, data.getConversationId(), null); + migrationStatusLogService.addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ERROR, + data.getConversationId(), + null, + UNEXPECTED_CONDITION.getCode()); if (webClientResponseException.getStatusCode().is5xxServerError()) { throw new MhsServerErrorException("Unable to sent continue message"); @@ -51,6 +55,10 @@ public void prepareAndSendRequest(ContinueRequestData data) { } LOGGER.info("Got response from MHS - 202 Accepted"); - migrationStatusLogService.addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ACCEPTED, data.getConversationId(), null); + migrationStatusLogService.addMigrationStatusLog( + MigrationStatus.CONTINUE_REQUEST_ACCEPTED, + data.getConversationId(), + null, + null); } } diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandler.java index 3899485d5..e612d198b 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandler.java @@ -15,6 +15,7 @@ import uk.nhs.adaptors.pss.translator.service.EhrExtractRequestService; import uk.nhs.adaptors.pss.translator.service.IdGeneratorService; import uk.nhs.adaptors.pss.translator.service.MhsClientService; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; @Slf4j @Component @@ -43,12 +44,15 @@ public boolean prepareAndSendRequest(TransferRequestMessage message) { LOGGER.debug(response); } catch (WebClientResponseException wcre) { LOGGER.error("Received an ERROR response from MHS: [{}]", wcre.getMessage()); - migrationStatusLogService.addMigrationStatusLog(MigrationStatus.EHR_EXTRACT_REQUEST_ERROR, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(MigrationStatus.EHR_EXTRACT_REQUEST_ERROR, + conversationId, + null, + UNEXPECTED_CONDITION.getCode()); return false; } LOGGER.info("Got response from MHS - 202 Accepted"); - migrationStatusLogService.addMigrationStatusLog(MigrationStatus.EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(MigrationStatus.EHR_EXTRACT_REQUEST_ACCEPTED, conversationId, null, null); return true; } } diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandler.java index 613a752b5..61295d392 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandler.java @@ -124,7 +124,7 @@ private void handleRequestTimeout(PatientMigrationRequest migrationRequest) { if (timeoutDateTime.isBefore(currentTime)) { LOGGER.info("Migration Request timed out at [{}]", timeoutDateTime); - migrationStatusLogService.addMigrationStatusLog(ERROR_REQUEST_TIMEOUT, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(ERROR_REQUEST_TIMEOUT, conversationId, null, null); } } catch (SdsRetrievalException e) { @@ -171,7 +171,8 @@ private void handleMigrationTimeout(PatientMigrationRequest migrationRequest, NA LOGGER.error("Error retrieving persist duration: [{}]", e.getMessage()); } catch (JsonProcessingException | SAXException | DateTimeParseException | JAXBException e) { LOGGER.error("Error parsing inbound message from database"); - migrationStatusLogService.addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null); + migrationStatusLogService + .addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null, UNEXPECTED_CONDITION.getCode()); } finally { mdcService.applyConversationId(""); } @@ -196,9 +197,9 @@ private void sendNackMessage(InboundMessage inboundMessage, String conversationI if (reason == LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED) { migrationStatusLogService - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null, reason.getCode()); } else { - migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null); + migrationStatusLogService.addMigrationStatusLog(reason.getMigrationStatus(), conversationId, null, reason.getCode()); } } } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationServiceTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationServiceTest.java index 4b43e7537..ae1a13bd7 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationServiceTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/service/NackAckPreparationServiceTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -13,7 +14,14 @@ import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_EXTRACT_CANNOT_BE_PROCESSED; import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_LRG_MSG_GENERAL_FAILURE; import static uk.nhs.adaptors.common.util.FileUtil.readResourceAsString; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallString; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_GENERAL_FAILURE; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_TIMEOUT; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.CLINICAL_SYSTEM_INTEGRATION_FAILURE; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.EHR_EXTRACT_CANNOT_BE_PROCESSED; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_REASSEMBLY_FAILURE; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED; import javax.xml.bind.JAXBException; @@ -36,6 +44,7 @@ @ExtendWith(MockitoExtension.class) class NackAckPreparationServiceTest { + private static final String NHS_NUMBER = "123456"; private static final String CONVERSATION_ID = randomUUID().toString(); private static final String TEST_TO_ODS = "M85019"; @@ -66,8 +75,9 @@ public void When_SendNackMessageRCMR_WithNoErrors_Expect_ShouldUpdateLog() throw 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, null); + assertTrue(nackAckPreparationService.sendNackMessage(LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID)); + verify(migrationStatusLogService) + .addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null, LARGE_MESSAGE_GENERAL_FAILURE.getCode()); } @Test @@ -78,7 +88,8 @@ public void When_SendNackMessageRCMR_WithErrors_Expect_ShouldUpdateLog() throws when(sendNACKMessageHandler.prepareAndSendMessage(any(NACKMessageData.class))).thenReturn(false); assertFalse(nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID)); - verify(migrationStatusLogService).addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null); + verify(migrationStatusLogService) + .addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null, LARGE_MESSAGE_GENERAL_FAILURE.getCode()); } @Test @@ -144,7 +155,7 @@ public void When_SendNackMessageRCMR_WithGeneralFailure_Expect_ShouldHaveCorrect CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("30", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_GENERAL_FAILURE.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -158,7 +169,7 @@ public void When_SendNackMessageRCMR_WithTimeoutFailure_Expect_ShouldHaveCorrect CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("25", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_TIMEOUT.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -172,7 +183,7 @@ public void When_SendNackMessageRCMR_WithClinicalSysIntegrationFailure_Expect_Sh CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("11", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(CLINICAL_SYSTEM_INTEGRATION_FAILURE.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -186,7 +197,7 @@ public void When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_Shou CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("21", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(EHR_EXTRACT_CANNOT_BE_PROCESSED.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -200,7 +211,7 @@ public void When_SendNackMessageRCMR_WithUnexpectedCondition_Expect_ShouldHaveCo CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("99", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(UNEXPECTED_CONDITION.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -214,7 +225,7 @@ public void When_SendNackMessageRCMR_WithEHRExtractCannotBeProcessed_Expect_AddM payload, CONVERSATION_ID); - verify(migrationStatusLogService).addMigrationStatusLog(migrationStatusCaptor.capture(), any(), isNull()); + verify(migrationStatusLogService).addMigrationStatusLog(migrationStatusCaptor.capture(), any(), isNull(), anyString()); assertEquals(MigrationStatus.ERROR_EXTRACT_CANNOT_BE_PROCESSED, migrationStatusCaptor.getValue()); } @@ -227,7 +238,8 @@ public void When_SendNackMessageCOPC_WithNoErrors_Expect_ShouldUpdateLog() throw 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, null); + verify(migrationStatusLogService) + .addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null, LARGE_MESSAGE_GENERAL_FAILURE.getCode()); } @Test @@ -238,7 +250,8 @@ public void When_SendNackMessageCOPC_WithErrors_Expect_ShouldUpdateLog() throws when(sendNACKMessageHandler.prepareAndSendMessage(any(NACKMessageData.class))).thenReturn(false); assertFalse(nackAckPreparationService.sendNackMessage(NACKReason.LARGE_MESSAGE_GENERAL_FAILURE, payload, CONVERSATION_ID)); - verify(migrationStatusLogService).addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null); + verify(migrationStatusLogService) + .addMigrationStatusLog(ERROR_LRG_MSG_GENERAL_FAILURE, CONVERSATION_ID, null, LARGE_MESSAGE_GENERAL_FAILURE.getCode()); } @Test @@ -276,7 +289,7 @@ public void When_SendNackMessageCOPC_WithReAssemblyFailure_Expect_ShouldHaveCorr CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("29", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_REASSEMBLY_FAILURE.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -290,7 +303,7 @@ public void When_SendNackMessageCOPC_WithAttachmentsNotReceived_Expect_ShouldHav CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("31", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -304,7 +317,7 @@ public void When_SendNackMessageCOPC_WithGeneralFailure_Expect_ShouldHaveCorrect CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("30", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_GENERAL_FAILURE.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -318,7 +331,7 @@ public void When_SendNackMessageCOPC_WithTimeoutFailure_Expect_ShouldHaveCorrect CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("25", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(LARGE_MESSAGE_TIMEOUT.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -332,7 +345,7 @@ public void When_SendNackMessageCOPC_WithClinicalSysIntegrationFailure_Expect_Sh CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("11", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(CLINICAL_SYSTEM_INTEGRATION_FAILURE.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -346,7 +359,7 @@ public void When_SendNackMessageCOPC_WithEHRExtractCannotBeProcessed_Expect_Shou CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("21", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(EHR_EXTRACT_CANNOT_BE_PROCESSED.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -360,7 +373,7 @@ public void When_SendNackMessageCOPC_WithUnexpectedCondition_Expect_ShouldHaveCo CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(ackMessageDataCaptor.capture()); - assertEquals("99", ackMessageDataCaptor.getValue().getNackCode()); + assertEquals(UNEXPECTED_CONDITION.getCode(), ackMessageDataCaptor.getValue().getNackCode()); } @Test @@ -374,7 +387,7 @@ public void When_SendNackMessageCOPC_WithEHRExtractCannotBeProcessed_Expect_AddM payload, CONVERSATION_ID); - verify(migrationStatusLogService).addMigrationStatusLog(migrationStatusCaptor.capture(), any(), isNull()); + verify(migrationStatusLogService).addMigrationStatusLog(migrationStatusCaptor.capture(), any(), isNull(), anyString()); assertEquals(ERROR_EXTRACT_CANNOT_BE_PROCESSED, migrationStatusCaptor.getValue()); } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandlerTest.java index 4baca1740..b55f3d177 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/AcknowledgmentMessageHandlerTest.java @@ -3,6 +3,7 @@ import static java.util.UUID.randomUUID; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -12,6 +13,7 @@ import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED; import static uk.nhs.adaptors.common.enums.MigrationStatus.EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN; import static uk.nhs.adaptors.common.enums.MigrationStatus.FINAL_ACK_SENT; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.PATIENT_NOT_AT_SURGERY; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,7 +70,7 @@ public void handleMessageWithAckTypeCode() throws SAXException { acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); verify(migrationStatusLogService) - .addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACKNOWLEDGED, CONVERSATION_ID, null); + .addMigrationStatusLog(EHR_EXTRACT_REQUEST_ACKNOWLEDGED, CONVERSATION_ID, null, null); } @Test @@ -79,19 +81,23 @@ public void handleMessageWithNackErrorTypeCode() throws SAXException { acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN, CONVERSATION_ID, null); + verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN, CONVERSATION_ID, null, ""); } @Test public void handleMessageWithNackErrorTypeCodeAndErrorCode() throws SAXException { + inboundMessage = new InboundMessage(); - prepareXPathServiceMocks(NACK_ERROR_TYPE_CODE, "06"); + prepareXPathServiceMocks(NACK_ERROR_TYPE_CODE, PATIENT_NOT_AT_SURGERY.getCode()); prepareMigrationStatusMocks(EHR_EXTRACT_REQUEST_ACCEPTED); acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); verify(migrationStatusLogService) - .addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED, CONVERSATION_ID, null); + .addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED, + CONVERSATION_ID, + null, + PATIENT_NOT_AT_SURGERY.getCode()); } @Test @@ -102,19 +108,22 @@ public void handleMessageWithNackRejectTypeCode() throws SAXException { acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN, CONVERSATION_ID, null); + verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN, CONVERSATION_ID, null, ""); } @Test public void handleMessageWithNackRejectTypeCodeAndErrorCode() throws SAXException { inboundMessage = new InboundMessage(); - prepareXPathServiceMocks(NACK_REJECT_TYPE_CODE, "06"); + prepareXPathServiceMocks(NACK_REJECT_TYPE_CODE, PATIENT_NOT_AT_SURGERY.getCode()); prepareMigrationStatusMocks(EHR_EXTRACT_REQUEST_ACCEPTED); acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); verify(migrationStatusLogService) - .addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED, CONVERSATION_ID, null); + .addMigrationStatusLog(EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_PATIENT_NOT_REGISTERED, + CONVERSATION_ID, + null, + PATIENT_NOT_AT_SURGERY.getCode()); } @Test @@ -125,7 +134,7 @@ public void handleMessageWithUnknownTypeCode() throws SAXException { acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @Test @@ -136,7 +145,7 @@ public void When_HandleMessage_With_NackErrorTypeCodeAndFinalAckSent_Expect_Migr acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @Test @@ -147,7 +156,7 @@ public void When_HandleMessage_With_NackRejectTypeCodeAndFinalAckSent_Expect_Mig acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @Test @@ -158,7 +167,7 @@ public void When_HandleMessage_With_AckTypeCodeAndFinalAckSent_Expect_MigrationS acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @Test @@ -167,7 +176,7 @@ public void When_HandleMessage_With_AckTypeCodeAndFailedStatus_Expect_MigrationS acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @Test @@ -176,7 +185,7 @@ public void When_HandleMessage_With_NackTypeCodeAndFailedStatus_Expect_Migration acknowledgmentMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), any(), anyString()); } @SneakyThrows diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandlerTest.java index c75399040..11dd43bf3 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/COPCMessageHandlerTest.java @@ -1095,7 +1095,7 @@ public void When_HandleMessage_With_ProcessHasFailed_Expect_FailureHandled() { .handleFailedProcess(any(COPCIN000001UK01Message.class), eq(CONVERSATION_ID)); verify(migrationStatusLogService, times(0)) - .addMigrationStatusLog(COPC_MESSAGE_RECEIVED, CONVERSATION_ID, null); + .addMigrationStatusLog(COPC_MESSAGE_RECEIVED, CONVERSATION_ID, null, null); } @Test @@ -1277,11 +1277,13 @@ public void When_HandleMessage_With_AttachmentProcessingErrorNotStorageCause_Exp .sendNackMessage(LARGE_MESSAGE_GENERAL_FAILURE, mockCOPCMessage, CONVERSATION_ID); verify(sendNACKMessageHandler).prepareAndSendMessage(nackMessageDataCaptor.capture()); - assertThat(nackMessageDataCaptor.getValue().getNackCode()).isEqualTo(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); + assertEquals(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode(), nackMessageDataCaptor.getValue().getNackCode()); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getMigrationStatus(), CONVERSATION_ID, null); - + .addMigrationStatusLog(LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getMigrationStatus(), + CONVERSATION_ID, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } finally { mockedXmlUnmarshall.close(); } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandlerTest.java index 72c985434..93af884c9 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/EhrExtractMessageHandlerTest.java @@ -157,7 +157,7 @@ public void When_HandleMessageWithValidDataIsCalled_Expect_CallsMigrationStatus ehrExtractMessageHandler.handleMessage(inboundMessage, CONVERSATION_ID, RCMRIN030000UK06Message.class); - verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_RECEIVED, CONVERSATION_ID, null); + verify(migrationStatusLogService).addMigrationStatusLog(EHR_EXTRACT_RECEIVED, CONVERSATION_ID, null, null); verify(migrationStatusLogService).updatePatientMigrationRequestAndAddMigrationStatusLog( CONVERSATION_ID, @@ -782,7 +782,7 @@ public void When_HandleMessage_With_ProcessHasFailed_Expect_FailureHandled() .handleFailedProcess(any(RCMRIN030000UK06Message.class), eq(CONVERSATION_ID)); verify(migrationStatusLogService, times(0)) - .addMigrationStatusLog(EHR_EXTRACT_RECEIVED, CONVERSATION_ID, null); + .addMigrationStatusLog(EHR_EXTRACT_RECEIVED, CONVERSATION_ID, null, null); } @SneakyThrows diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandlerTest.java index 21b2e6fea..6170dc5bb 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/MhsQueueMessageHandlerTest.java @@ -12,6 +12,7 @@ import static org.mockito.Mockito.when; import static uk.nhs.adaptors.common.util.FileUtil.readResourceAsString; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import java.text.ParseException; import java.util.Locale; @@ -50,6 +51,7 @@ @ExtendWith(MockitoExtension.class) public class MhsQueueMessageHandlerTest { + private static final String NHS_NUMBER = "123456"; private static final String INBOUND_MESSAGE_STRING = "{hi i'm inbound message}"; private static final String EHR_EXTRACT_INTERACTION_ID = "RCMR_IN030000UK06"; @@ -164,7 +166,11 @@ public void handleEhrExtractMessageWhenEhrExtractMessageHandlerThrowsErrorShould boolean result = mhsQueueMessageHandler.handleMessage(message); assertFalse(result); - verify(migrationStatusLogService).addMigrationStatusLog(MigrationStatus.EHR_GENERAL_PROCESSING_ERROR, CONVERSATION_ID_UPPER, null); + verify(migrationStatusLogService) + .addMigrationStatusLog(MigrationStatus.EHR_GENERAL_PROCESSING_ERROR, + CONVERSATION_ID_UPPER, + null, + UNEXPECTED_CONDITION.getCode()); } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandlerTest.java index 5a4529239..33b9dcdab 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendContinueRequestHandlerTest.java @@ -25,12 +25,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import java.io.IOException; import java.nio.charset.Charset; @@ -38,6 +38,7 @@ @Slf4j @ExtendWith(MockitoExtension.class) public class SendContinueRequestHandlerTest { + private static final String NHS_NUMBER = "9446363101"; private static final String CONVERSATION_ID = "6E242658-3D8E-11E3-A7DC-172BDA00FA67"; private static final String LOSING_ODS_CODE = "B83002"; //to odds code @@ -118,7 +119,11 @@ public void When_MHSClientService_SendThrowsErrors_Expect_MigrationStatusLogAddS } catch (Exception e) { } - verify(migrationStatusLogService).addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ERROR, CONVERSATION_ID, null); + verify(migrationStatusLogService) + .addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ERROR, + CONVERSATION_ID, + null, + UNEXPECTED_CONDITION.getCode()); } @Test @@ -171,7 +176,7 @@ public void When_ParametersCorrect_Expect_MigrationStatusLogServiceAddMigrationS .build(); sendContinueRequestHandler.prepareAndSendRequest(continueRequestData); - verify(migrationStatusLogService).addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ACCEPTED, CONVERSATION_ID, null); + verify(migrationStatusLogService).addMigrationStatusLog(MigrationStatus.CONTINUE_REQUEST_ACCEPTED, CONVERSATION_ID, null, null); } @Test @@ -219,8 +224,7 @@ public void When_SendRequest_Expect_BuildRequestCalledWithCorrectParams() throws when(continueRequestService.buildContinueRequest(any(), any())).thenReturn(testPayload); sendContinueRequestHandler.prepareAndSendRequest(continueRequestData); - verify(continueRequestService).buildContinueRequest(eq(continueRequestData), eq(MESSAGE_ID.toUpperCase())); - verify(requestBuilder).buildSendContinueRequest(eq(CONVERSATION_ID), eq(LOSING_ODS_CODE), eq(outboundMessage), - eq(MESSAGE_ID.toUpperCase())); + verify(continueRequestService).buildContinueRequest(continueRequestData, MESSAGE_ID.toUpperCase()); + verify(requestBuilder).buildSendContinueRequest(CONVERSATION_ID, LOSING_ODS_CODE, outboundMessage, MESSAGE_ID.toUpperCase()); } } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandlerTest.java index 54b4c390d..7a5e5be98 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/SendEhrExtractRequestHandlerTest.java @@ -19,6 +19,7 @@ import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientResponseException; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import lombok.SneakyThrows; import uk.nhs.adaptors.common.enums.MigrationStatus; @@ -86,6 +87,7 @@ public void whenSendMessageThenTrueIsReturned() { verify(migrationStatusLogService).addMigrationStatusLog( MigrationStatus.EHR_EXTRACT_REQUEST_ACCEPTED, CONVERSATION_ID, + null, null ); } @@ -107,7 +109,8 @@ public void whenSendMessageThenErrorFalseIsReturned() { verify(migrationStatusLogService).addMigrationStatusLog( MigrationStatus.EHR_EXTRACT_REQUEST_ERROR, CONVERSATION_ID, - null + null, + UNEXPECTED_CONDITION.getCode() ); } } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandlerTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandlerTest.java index 3c10de179..745539437 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandlerTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/task/scheduled/EHRTimeoutHandlerTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; @@ -25,6 +26,8 @@ import static uk.nhs.adaptors.common.enums.MigrationStatus.ERROR_REQUEST_TIMEOUT; import static uk.nhs.adaptors.common.enums.MigrationStatus.REQUEST_RECEIVED; import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_TIMEOUT; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED; +import static uk.nhs.adaptors.pss.translator.model.NACKReason.UNEXPECTED_CONDITION; import java.time.Duration; import java.time.LocalDateTime; @@ -216,7 +219,7 @@ void When_CheckForTimeouts_With_PreEhrParsedRequests_Expect_EhrRequestTimeout(Mi verify(sendNACKMessageHandler, times(0)).prepareAndSendMessage(any()); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(eq(ERROR_REQUEST_TIMEOUT), eq(conversationId), eq(null)); + .addMigrationStatusLog(ERROR_REQUEST_TIMEOUT, conversationId, null, null); } @Test @@ -227,7 +230,10 @@ public void When_CheckForTimeouts_WithNackFailsToSend_Expect_MigrationLogNotUpda callCheckForTimeoutsWithOneRequest(EHR_EXTRACT_PROCESSING, TEN_DAYS_AGO, 0, conversationId); verify(migrationStatusLogService, times(0)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_TIMEOUT.getCode()); } @Test @@ -241,7 +247,10 @@ public void When_CheckForTimeouts_WithSendNackThrows_Expect_MigrationLogNotUpdat .isInstanceOf(MhsServerErrorException.class); verify(migrationStatusLogService, times(0)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_TIMEOUT.getCode()); } @Test @@ -252,7 +261,10 @@ public void When_CheckForTimeouts_WithTimeout_Expect_MigrationLogUpdated() { callCheckForTimeoutsWithOneRequest(EHR_EXTRACT_PROCESSING, TEN_DAYS_AGO, 0, conversationId); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } @Test @@ -263,7 +275,10 @@ public void When_CheckForTimeouts_WithTimeoutAndCOPCReceived_Expect_MigrationLog callCheckForTimeoutsWithOneRequest(COPC_MESSAGE_RECEIVED, TEN_DAYS_AGO, 2, conversationId); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } @Test @@ -274,7 +289,10 @@ public void When_CheckForTimeouts_WithTimeoutAndCOPCProcessing_Expect_MigrationL callCheckForTimeoutsWithOneRequest(COPC_MESSAGE_PROCESSING, TEN_DAYS_AGO, 2, conversationId); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } @Test @@ -285,7 +303,10 @@ public void When_CheckForTimeouts_WithTimeoutAndCOPCAcknowledged_Expect_Migratio callCheckForTimeoutsWithOneRequest(COPC_ACKNOWLEDGED, TEN_DAYS_AGO, 2, conversationId); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } @Test @@ -296,7 +317,10 @@ public void When_CheckForTimeouts_WithTimeoutAndEhrExtractProcessing_Expect_Migr callCheckForTimeoutsWithOneRequest(EHR_EXTRACT_PROCESSING, TEN_DAYS_AGO, 2, conversationId); verify(migrationStatusLogService, times(1)) - .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), conversationId, null); + .addMigrationStatusLog(LARGE_MESSAGE_TIMEOUT.getMigrationStatus(), + conversationId, + null, + LARGE_MESSAGE_ATTACHMENTS_NOT_RECEIVED.getCode()); } @Test @@ -341,7 +365,7 @@ public void When_CheckForTimeouts_WithSdsRetrievalException_Expect_MigrationLogN ehrTimeoutHandler.checkForTimeouts(); - verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), isNull()); + verify(migrationStatusLogService, times(0)).addMigrationStatusLog(any(), any(), isNull(), anyString()); } @Test @@ -356,7 +380,11 @@ public void When_CheckForTimeouts_WithJsonProcessingException_Expect_MigrationLo ehrTimeoutHandler.checkForTimeouts(); - verify(migrationStatusLogService, times(1)).addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null); + verify(migrationStatusLogService, times(1)) + .addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, + conversationId, + null, + UNEXPECTED_CONDITION.getCode()); } @Test @@ -372,7 +400,11 @@ public void When_CheckForTimeouts_WithSAXException_Expect_MigrationLogUpdated() ehrTimeoutHandler.checkForTimeouts(); - verify(migrationStatusLogService, times(1)).addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null); + verify(migrationStatusLogService, times(1)) + .addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, + conversationId, + null, + UNEXPECTED_CONDITION_CODE); } @Test @@ -388,7 +420,11 @@ public void When_CheckForTimeouts_WithDateTimeParseException_Expect_MigrationLog ehrTimeoutHandler.checkForTimeouts(); - verify(migrationStatusLogService, times(1)).addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, conversationId, null); + verify(migrationStatusLogService, times(1)) + .addMigrationStatusLog(EHR_GENERAL_PROCESSING_ERROR, + conversationId, + null, + UNEXPECTED_CONDITION_CODE); } private void callCheckForTimeoutsWithOneRequest(MigrationStatus migrationStatus, ZonedDateTime requestTimestamp, diff --git a/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/AcknowledgeRecordControllerIT.java b/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/AcknowledgeRecordControllerIT.java index 5ea31fa67..3b10a35bf 100644 --- a/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/AcknowledgeRecordControllerIT.java +++ b/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/AcknowledgeRecordControllerIT.java @@ -141,6 +141,6 @@ public void sendAcknowledgeRequestWithMissingConfirmationResponseHeader() throws private void addMigrationRequestAndLogWithStatus(String conversationId, MigrationStatus status) { patientMigrationRequestDao.addNewRequest(PATIENT_NUMBER, conversationId, LOSING_PRACTICE_ODS, WINNING_PRACTICE_ODS); patientMigrationRequestDao.saveBundleAndInboundMessageData(conversationId, BUNDLE_VALUE, INBOUND_MESSAGE_VALUE); - migrationStatusLogService.addMigrationStatusLog(status, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(status, conversationId, null, null); } } \ No newline at end of file diff --git a/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerIT.java b/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerIT.java index 6359f1e32..e4f28e1e0 100644 --- a/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerIT.java +++ b/gpc-api-facade/src/integrationTest/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerIT.java @@ -338,6 +338,6 @@ private void completePatientMigrationJourney(String conversationId) { patientMigrationRequestDao.addNewRequest(MOCK_PATIENT_NUMBER, conversationId, LOSING_PRACTICE_ODS, WINNING_PRACTICE_ODS); patientMigrationRequestDao.saveBundleAndInboundMessageData(conversationId, readResourceAsString(EXAMPLE_JSON_BUNDLE), StringUtils.EMPTY); - migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null); + migrationStatusLogService.addMigrationStatusLog(MIGRATION_COMPLETED, conversationId, null, null); } } diff --git a/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferController.java b/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferController.java index f4d6b10d1..1ba6fe263 100644 --- a/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferController.java +++ b/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferController.java @@ -54,6 +54,7 @@ @Validated public class PatientTransferController { + public static final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; private static final String ISSUE_SYSTEM = "https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1"; private final PatientTransferService patientTransferService; private final FhirParser fhirParser; @@ -124,14 +125,14 @@ public ResponseEntity migratePatientStructuredRecord( } private OperationOutcome createErrorBodyForInProgressRequest(String conversationId) { - var operationErrorCode = "INTERNAL_SERVER_ERROR"; + var operationErrorCode = INTERNAL_SERVER_ERROR; var operationErrorMessage = "PS - The Given NHS number is already being processed against Conversation ID: " + conversationId + ", you cannot start a new request until the current request has completed or failed."; - CodeableConcept details = CodeableConceptUtils. - createCodeableConcept(operationErrorCode, ISSUE_SYSTEM, operationErrorMessage, null); + var details = CodeableConceptUtils.createCodeableConcept(operationErrorCode, ISSUE_SYSTEM, operationErrorMessage, null); return createOperationOutcome(EXCEPTION, ERROR, details, ""); } + private OperationOutcome createErrorBodyFromMigrationStatus(MigrationStatus migrationStatus) { String operationErrorCode; @@ -152,15 +153,16 @@ private OperationOutcome createErrorBodyFromMigrationStatus(MigrationStatus migr + "not the patient’s current primary healthcare provider"; break; case EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_EHR_GENERATION_ERROR: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; + operationErrorMessage = "GP2GP - Failed to successfully generate the EHR"; break; case EHR_EXTRACT_REQUEST_NEGATIVE_ACK_GP2GP_MULTI_OR_NO_RESPONSES: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "GP2GP - SDS lookup provided zero or more than one result to the query for each interaction."; break; case EHR_EXTRACT_REQUEST_NEGATIVE_ACK_UNKNOWN: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "GP2GP - This is a code that should only be used in circumstances where no other codes can" + " be used to accurately describe the condition."; break; @@ -169,47 +171,47 @@ private OperationOutcome createErrorBodyFromMigrationStatus(MigrationStatus migr operationErrorMessage = "GP2GP - End Point setup but GP2GP configuration switched OFF"; break; case ERROR_LRG_MSG_REASSEMBLY_FAILURE: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - The Adaptor was unable to recombine the parts of a received attachment"; break; case ERROR_LRG_MSG_ATTACHMENTS_NOT_RECEIVED: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - At least one attachment has not been received or could not be processed"; break; case ERROR_LRG_MSG_GENERAL_FAILURE: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - A general processing error has occurred"; break; case ERROR_LRG_MSG_TIMEOUT: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - An attachment was not received before a timeout condition occurred"; break; case ERROR_REQUEST_TIMEOUT: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - The EHR record was not received within the given timeout timeframe"; break; case EHR_EXTRACT_NEGATIVE_ACK_ABA_INCORRECT_PATIENT: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - A-B-A EHR Extract Received and rejected due to wrong record or wrong patient"; break; case EHR_EXTRACT_NEGATIVE_ACK_NON_ABA_INCORRECT_PATIENT: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - Non A-B-A EHR Extract Received and rejected due to wrong record or wrong patient"; break; case EHR_EXTRACT_NEGATIVE_ACK_FAILED_TO_INTEGRATE: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - Failed to successfully integrate EHR Extract"; break; case EHR_EXTRACT_NEGATIVE_ACK_SUPPRESSED: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - A-B-A EHR Extract Received and Stored As Suppressed Record"; break; case ERROR_EXTRACT_CANNOT_BE_PROCESSED: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - EHR Extract message not well-formed or not able to be processed"; break; default: - operationErrorCode = "INTERNAL_SERVER_ERROR"; + operationErrorCode = INTERNAL_SERVER_ERROR; operationErrorMessage = "PS - A general error has occurred"; break; } diff --git a/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferService.java b/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferService.java index 2d8acd72c..e15c2f91c 100644 --- a/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferService.java +++ b/gpc-api-facade/src/main/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferService.java @@ -46,7 +46,7 @@ public MigrationStatusLog handlePatientMigrationRequest(Parameters parameters, M patientMigrationRequestDao.addNewRequest(patientNhsNumber, conversationId, headers.get(TO_ODS), headers.get(FROM_ODS)); int addedId = patientMigrationRequestDao.getMigrationRequestId(conversationId); - migrationStatusLogDao.addMigrationStatusLog(REQUEST_RECEIVED, dateUtils.getCurrentOffsetDateTime(), addedId, null); + migrationStatusLogDao.addMigrationStatusLog(REQUEST_RECEIVED, dateUtils.getCurrentOffsetDateTime(), addedId, null, null); var pssMessage = createTransferRequestMessage(patientNhsNumber, headers, conversationId); pssQueuePublisher.sendToPssQueue(pssMessage); diff --git a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerTest.java b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerTest.java index 0a06865e1..77c0a39a6 100644 --- a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerTest.java +++ b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/controller/PatientTransferControllerTest.java @@ -1,6 +1,7 @@ package uk.nhs.adaptors.pss.gpc.controller; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -39,6 +40,7 @@ @ExtendWith(MockitoExtension.class) public class PatientTransferControllerTest { + private static final String RESPONSE_BODY = "{responseBody}"; private static final Parameters PARAMETERS = new Parameters(); private static final String TO_ASID_VALUE = "123"; @@ -68,7 +70,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsNew() { ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertThat(response.getBody()).isNull(); } @@ -79,7 +82,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsReceived() { ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); assertThat(response.getBody()).isNull(); } @@ -90,7 +94,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsInProgress() { ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); assertThat(response.getBody()).isNull(); } @@ -102,7 +107,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsCompleted() { ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + assertEquals(HttpStatus.OK, response.getStatusCode()); assertThat(response.getBody()).isEqualTo(RESPONSE_BODY); } @@ -113,7 +119,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsUnsupported() { Exception exception = assertThrows(IllegalStateException.class, () -> controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE)); - assertThat(exception.getMessage()).isEqualTo("Unsupported transfer status: EHR_EXTRACT_REQUEST_ERROR"); + + assertEquals("Unsupported transfer status: EHR_EXTRACT_REQUEST_ERROR", exception.getMessage()); } @Test @@ -126,7 +133,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsEhrExtractNegative ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } @Test @@ -139,7 +147,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsEhrExtractNegative ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_IMPLEMENTED); + + assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode()); } @Test @@ -152,7 +161,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsEhrExtractNegative ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + + assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode()); } @Test @@ -165,7 +175,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsEhrExtractNegative ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + + assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); } @Test @@ -178,7 +189,8 @@ public void migratePatientStructuredRecordWhenTransferStatusIsErrorRequestTimeou ResponseEntity response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } @Test @@ -189,7 +201,7 @@ public void migratePatientStructureRecordWhenExistingPatientMigrationRequestInPr var response = controller.migratePatientStructuredRecord( PARAMETERS, TO_ASID_VALUE, FROM_ASID_VALUE, TO_ODS_VALUE, FROM_ODS_VALUE); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } diff --git a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferServiceTest.java b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferServiceTest.java index 73619fbf3..64f515821 100644 --- a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferServiceTest.java +++ b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/service/PatientTransferServiceTest.java @@ -1,6 +1,7 @@ package uk.nhs.adaptors.pss.gpc.service; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -99,10 +100,10 @@ public void handlePatientMigrationRequestWhenRequestIsNew() { MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS); - assertThat(patientMigrationRequest).isEqualTo(null); + assertThat(patientMigrationRequest).isNull(); verify(pssQueuePublisher).sendToPssQueue(expectedPssQueueMessage); verify(patientMigrationRequestDao).addNewRequest(PATIENT_NHS_NUMBER, CONVERSATION_ID, LOSING_ODS_CODE, WINNING_ODS_CODE); - verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.REQUEST_RECEIVED, now, migrationRequestId, null); + verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.REQUEST_RECEIVED, now, migrationRequestId, null, null); } @Test @@ -125,10 +126,10 @@ public void handlePatientMigrationRequestWhenRequestIsNewAndConversationIdIsLowe MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS); - assertThat(patientMigrationRequest).isEqualTo(null); + assertThat(patientMigrationRequest).isNull(); verify(pssQueuePublisher).sendToPssQueue(expectedPssQueueMessage); verify(patientMigrationRequestDao).addNewRequest(PATIENT_NHS_NUMBER, CONVERSATION_ID, LOSING_ODS_CODE, WINNING_ODS_CODE); - verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.REQUEST_RECEIVED, now, migrationRequestId, null); + verify(migrationStatusLogDao).addMigrationStatusLog(MigrationStatus.REQUEST_RECEIVED, now, migrationRequestId, null, null); } @Test @@ -143,7 +144,7 @@ public void handlePatientMigrationRequestWhenRequestIsInProgress() { MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS); - assertThat(patientMigrationRequest).isEqualTo(expectedMigrationStatusLog); + assertEquals(expectedMigrationStatusLog, patientMigrationRequest); verifyNoInteractions(pssQueuePublisher); verify(patientMigrationRequestDao).getMigrationRequest(CONVERSATION_ID); verifyNoMoreInteractions(patientMigrationRequestDao); @@ -162,7 +163,7 @@ public void handlePatientMigrationRequestWhenRequestIsInProgressAndCalledWithALo MigrationStatusLog patientMigrationRequest = service.handlePatientMigrationRequest(parameters, HEADERS); - assertThat(patientMigrationRequest).isEqualTo(expectedMigrationStatusLog); + assertEquals(expectedMigrationStatusLog, patientMigrationRequest); verifyNoInteractions(pssQueuePublisher); verify(patientMigrationRequestDao).getMigrationRequest(CONVERSATION_ID); verifyNoMoreInteractions(patientMigrationRequestDao); @@ -212,7 +213,7 @@ public void checkExistingPatientMigrationRequestInProgressWhenExistingMigrationI var existingConversationId = service.checkExistingPatientMigrationRequestInProgress(parameters); assertThat(existingConversationId).isNotNull(); - assertThat(existingConversationId).isEqualTo(CONVERSATION_ID); + assertEquals(CONVERSATION_ID, existingConversationId); } @ParameterizedTest diff --git a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/util/fhir/OperationOutcomeUtilsTest.java b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/util/fhir/OperationOutcomeUtilsTest.java index d6463613e..52dea339b 100644 --- a/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/util/fhir/OperationOutcomeUtilsTest.java +++ b/gpc-api-facade/src/test/java/uk/nhs/adaptors/pss/gpc/util/fhir/OperationOutcomeUtilsTest.java @@ -3,9 +3,8 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity.ERROR; import static org.hl7.fhir.dstu3.model.OperationOutcome.IssueType.NOTSUPPORTED; - +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.OperationOutcome; import org.junit.jupiter.api.Test; import uk.nhs.adaptors.common.util.CodeableConceptUtils; @@ -15,16 +14,17 @@ public class OperationOutcomeUtilsTest { @Test public void testCreateOperationOutcome() { + var details = createCodeableConcept(); var diagnostics = "Dancing not supported"; - OperationOutcome result = OperationOutcomeUtils.createOperationOutcome(NOTSUPPORTED, ERROR, details, diagnostics); + var result = OperationOutcomeUtils.createOperationOutcome(NOTSUPPORTED, ERROR, details, diagnostics); assertThat(result.getMeta().getProfile().get(0).equals(URI_TYPE)).isTrue(); - assertThat(result.getIssueFirstRep().getCode()).isEqualTo(NOTSUPPORTED); - assertThat(result.getIssueFirstRep().getSeverity()).isEqualTo(ERROR); - assertThat(result.getIssueFirstRep().getDetails()).isEqualTo(details); - assertThat(result.getIssueFirstRep().getDiagnostics()).isEqualTo(diagnostics); + assertEquals(NOTSUPPORTED, result.getIssueFirstRep().getCode()); + assertEquals(ERROR, result.getIssueFirstRep().getSeverity()); + assertEquals(details, result.getIssueFirstRep().getDetails()); + assertEquals(diagnostics, result.getIssueFirstRep().getDiagnostics()); } private CodeableConcept createCodeableConcept() {