Skip to content

Commit

Permalink
Removed logic that updates mof to previous GP for suspension events (#…
Browse files Browse the repository at this point in the history
…178)

Co-authored-by: Andy Flint <[email protected]>
  • Loading branch information
AndyFlintNHS and AndyFlintAnswerDigital authored Mar 14, 2024
1 parent 55d386f commit 02d7189
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void processMofUpdate(String suspensionMessage, SuspensionEvent suspensionEvent,
if (toggleConfig.isCanUpdateManagingOrganisationToRepo() && isSafeToProcess(suspensionEvent)) {
transferToRepository(patientStatus, suspensionEvent);
} else {
updateMofToPreviousGp(patientStatus, suspensionEvent);
// updateMofToPreviousGp(patientStatus, suspensionEvent);
log.info("Suspension event found from non-safe listed ODS code. Ignoring as this is not intended for ORC.");
}
} catch (InvalidPdsRequestException invalidPdsRequestException) {
messagePublisherBroker.invalidMessage(suspensionMessage, suspensionEvent.getNemsMessageId());
Expand All @@ -50,20 +51,24 @@ private boolean isSafeToProcess(SuspensionEvent suspensionEvent) {
return true;
}

private void updateMofToPreviousGp(PdsAdaptorSuspensionStatusResponse patientStatus, SuspensionEvent suspensionEvent) {
if (mofIsCurrentlySetAsIntended(patientStatus.getManagingOrganisation(), suspensionEvent.previousOdsCode())) {
log.info("Managing Organisation field is already set to previous GP");
messagePublisherBroker.mofNotUpdatedMessage(suspensionEvent.nemsMessageId(), false);
messagePublisherBroker.activeSuspensionMessage(suspensionEvent);
}
else {
var updateMofResponse = pdsService.updateMof(patientStatus.getNhsNumber(), suspensionEvent.previousOdsCode(), patientStatus.getRecordETag());
log.info("Managing Organisation field Updated to " + updateMofResponse.getManagingOrganisation());
var isSuperseded = nhsNumberIsSuperseded(suspensionEvent.nhsNumber(), patientStatus.getNhsNumber());
messagePublisherBroker.mofUpdatedMessage(suspensionEvent.nemsMessageId(), suspensionEvent.previousOdsCode(), isSuperseded);
messagePublisherBroker.activeSuspensionMessage(suspensionEvent);
}
}
// TODO
// Commented out while testing as it is causing race conditions between dev & pre-prod
// We need to establish if we are keeping this logic or removing it at a later date
// If removing, remember to remove the commented out tests on ManagingOrganisationServiceTest.java
// private void updateMofToPreviousGp(PdsAdaptorSuspensionStatusResponse patientStatus, SuspensionEvent suspensionEvent) {
// if (mofIsCurrentlySetAsIntended(patientStatus.getManagingOrganisation(), suspensionEvent.previousOdsCode())) {
// log.info("Managing Organisation field is already set to previous GP");
// messagePublisherBroker.mofNotUpdatedMessage(suspensionEvent.nemsMessageId(), false);
// messagePublisherBroker.activeSuspensionMessage(suspensionEvent);
// }
// else {
// var updateMofResponse = pdsService.updateMof(patientStatus.getNhsNumber(), suspensionEvent.previousOdsCode(), patientStatus.getRecordETag());
// log.info("Managing Organisation field Updated to " + updateMofResponse.getManagingOrganisation());
// var isSuperseded = nhsNumberIsSuperseded(suspensionEvent.nhsNumber(), patientStatus.getNhsNumber());
// messagePublisherBroker.mofUpdatedMessage(suspensionEvent.nemsMessageId(), suspensionEvent.previousOdsCode(), isSuperseded);
// messagePublisherBroker.activeSuspensionMessage(suspensionEvent);
// }
// }

private void transferToRepository(PdsAdaptorSuspensionStatusResponse pdsResponse, SuspensionEvent suspensionEvent) {
if (mofIsCurrentlySetAsIntended(pdsResponse.getManagingOrganisation(), repoOdsCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,85 +44,86 @@ void setUp() {
mofService = new ManagingOrganisationService(pdsService, messagePublisherBroker, REPO_ODS_CODE, toggleConfig, ALLOWED_ODS_CODES);
}

@Test
void shouldSendMofUpdateAndActiveSuspensionMessageForSuspendedPatient() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
null, RECORD_E_TAG, false);

var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
PREVIOUS_ODS_CODE, "E2", false);

when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);

mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
//verify(messagePublisherBroker).activeSuspensionMessage(NHS_NUMBER, PREVIOUS_ODS_CODE, LAST_UPDATED_DATE);
}

@Test
void shouldSendMofUpdateForSuspendedPatientWhenCurrentOdsCodeIsDifferentValue() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, "A1000",
null, RECORD_E_TAG, false);

var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
PREVIOUS_ODS_CODE, "E2", false);

when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);

mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
}

@Test
void shouldSendMofUpdateForSuspendedPatientWhenSuperseded() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var supersededNhsNumber = "different-nhs-number";
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(supersededNhsNumber, true, null,
null, RECORD_E_TAG, false);

var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(supersededNhsNumber, true, null,
PREVIOUS_ODS_CODE, "E2", false);

when(pdsService.updateMof(supersededNhsNumber, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);

mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(pdsService).updateMof(supersededNhsNumber, PREVIOUS_ODS_CODE, RECORD_E_TAG);
verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, true);
}

@Test
void shouldSendMofNotUpdateWhenMofTheSameAsPreviousGp() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
PREVIOUS_ODS_CODE, RECORD_E_TAG, false);


mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(messagePublisherBroker).mofNotUpdatedMessage(NEMS_MESSAGE_ID, false);
verifyNoInteractions(pdsService);
}

@Test
void shouldThrowInvalidRequestExceptionIfPdsFails() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
null, RECORD_E_TAG, false);

when(pdsService.updateMof(any(), any(), any())).thenThrow(InvalidPdsRequestException.class);

Assertions.assertThrows(InvalidPdsRequestException.class, () ->
mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse));

verify(messagePublisherBroker).invalidMessage(STRING_SUSPENSION_MESSAGE, NEMS_MESSAGE_ID);
}
// TODO We need to establish if we are keeping this logic or removing it at a later date
// @Test
// void shouldSendMofUpdateAndActiveSuspensionMessageForSuspendedPatient() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// null, RECORD_E_TAG, false);
//
// var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// PREVIOUS_ODS_CODE, "E2", false);
//
// when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);
//
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
// verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
// //verify(messagePublisherBroker).activeSuspensionMessage(NHS_NUMBER, PREVIOUS_ODS_CODE, LAST_UPDATED_DATE);
// }
//
// @Test
// void shouldSendMofUpdateForSuspendedPatientWhenCurrentOdsCodeIsDifferentValue() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, "A1000",
// null, RECORD_E_TAG, false);
//
// var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// PREVIOUS_ODS_CODE, "E2", false);
//
// when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);
//
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
// verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
// }
//
// @Test
// void shouldSendMofUpdateForSuspendedPatientWhenSuperseded() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var supersededNhsNumber = "different-nhs-number";
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(supersededNhsNumber, true, null,
// null, RECORD_E_TAG, false);
//
// var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(supersededNhsNumber, true, null,
// PREVIOUS_ODS_CODE, "E2", false);
//
// when(pdsService.updateMof(supersededNhsNumber, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);
//
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(pdsService).updateMof(supersededNhsNumber, PREVIOUS_ODS_CODE, RECORD_E_TAG);
// verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, true);
// }
//
// @Test
// void shouldSendMofNotUpdateWhenMofTheSameAsPreviousGp() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// PREVIOUS_ODS_CODE, RECORD_E_TAG, false);
//
//
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(messagePublisherBroker).mofNotUpdatedMessage(NEMS_MESSAGE_ID, false);
// verifyNoInteractions(pdsService);
// }
//
// @Test
// void shouldThrowInvalidRequestExceptionIfPdsFails() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// null, RECORD_E_TAG, false);
//
// when(pdsService.updateMof(any(), any(), any())).thenThrow(InvalidPdsRequestException.class);
//
// Assertions.assertThrows(InvalidPdsRequestException.class, () ->
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse));
//
// verify(messagePublisherBroker).invalidMessage(STRING_SUSPENSION_MESSAGE, NEMS_MESSAGE_ID);
// }

@Test
void shouldSendMofUpdateToRepoWhenToggleIsTrue() {
Expand Down Expand Up @@ -164,25 +165,26 @@ void shouldSendMofUpdateToRepoWhenBothTogglesAreTrueAndOdsCodeIsSafeListed() {
verify(messagePublisherBroker).repoIncomingMessage(afterUpdateResponse, suspensionEvent);
}

@Test
void shouldSendMofUpdateToPreviousGpWhenBothTogglesAreTrueAndOdsCodeIsNotInTheSafeList() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
null, RECORD_E_TAG, false);

var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
PREVIOUS_ODS_CODE, "E2", false);


when(toggleConfig.isCanUpdateManagingOrganisationToRepo()).thenReturn(true);
when(toggleConfig.isRepoProcessOnlySafeListedOdsCodes()).thenReturn(true);
when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);

mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
}
// TODO We need to establish if we are keeping this logic or removing it at a later date
// @Test
// void shouldSendMofUpdateToPreviousGpWhenBothTogglesAreTrueAndOdsCodeIsNotInTheSafeList() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, PREVIOUS_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// null, RECORD_E_TAG, false);
//
// var afterUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// PREVIOUS_ODS_CODE, "E2", false);
//
//
// when(toggleConfig.isCanUpdateManagingOrganisationToRepo()).thenReturn(true);
// when(toggleConfig.isRepoProcessOnlySafeListedOdsCodes()).thenReturn(true);
// when(pdsService.updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG)).thenReturn(afterUpdateResponse);
//
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(pdsService).updateMof(NHS_NUMBER, PREVIOUS_ODS_CODE, RECORD_E_TAG);
// verify(messagePublisherBroker).mofUpdatedMessage(NEMS_MESSAGE_ID, PREVIOUS_ODS_CODE, false);
// }

@Test
void shouldSendMofNotUpdateWhenMofTheSameAsRepo() {
Expand All @@ -198,18 +200,18 @@ void shouldSendMofNotUpdateWhenMofTheSameAsRepo() {
verifyNoInteractions(pdsService);
}

@Test
void shouldSendMofNotUpdateWhenMofTheSameAsRepoAndCanUpdateMofToRepoIsFalse() {
var suspensionEvent = new SuspensionEvent(NHS_NUMBER, REPO_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
REPO_ODS_CODE, RECORD_E_TAG, false);

when(toggleConfig.isCanUpdateManagingOrganisationToRepo()).thenReturn(false);
mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);

verify(messagePublisherBroker).mofNotUpdatedMessage(NEMS_MESSAGE_ID, false);
verify(messagePublisherBroker).activeSuspensionMessage(suspensionEvent);
verifyNoInteractions(pdsService);
}

// TODO We need to establish if we are keeping this logic or removing it at a later date
// @Test
// void shouldSendMofNotUpdateWhenMofTheSameAsRepoAndCanUpdateMofToRepoIsFalse() {
// var suspensionEvent = new SuspensionEvent(NHS_NUMBER, REPO_ODS_CODE, NEMS_MESSAGE_ID, LAST_UPDATED_DATE);
// var beforeUpdateResponse = new PdsAdaptorSuspensionStatusResponse(NHS_NUMBER, true, null,
// REPO_ODS_CODE, RECORD_E_TAG, false);
//
// when(toggleConfig.isCanUpdateManagingOrganisationToRepo()).thenReturn(false);
// mofService.processMofUpdate(STRING_SUSPENSION_MESSAGE, suspensionEvent, beforeUpdateResponse);
//
// verify(messagePublisherBroker).mofNotUpdatedMessage(NEMS_MESSAGE_ID, false);
// verify(messagePublisherBroker).activeSuspensionMessage(suspensionEvent);
// verifyNoInteractions(pdsService);
// }
}

0 comments on commit 02d7189

Please sign in to comment.