Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-added mof updates to previous GP #186

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ private WireMockServer initializeWebServer() {
return wireMockServer;
}

// @Test
// void shouldUpdateMofToPreviousGpAndSendMessageToMofUpdatedSNSTopicWhenOdsCodeNotInSafeList() {
// var nhsNumber = Long.toString(System.currentTimeMillis());
// stubForPdsAdaptor(nhsNumber, getSuspendedResponseWith(nhsNumber));

// var mofUpdatedQueueUrl = sqs.getQueueUrl(mofUpdatedQueueName).getQueueUrl();
// sqs.sendMessage(suspensionQueueUrl, getSuspensionEventWith(nhsNumber, "B85612"));

// await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
// List<Message> receivedMessageHolder = checkMessageInRelatedQueue(mofUpdatedQueueUrl);

// assertTrue(receivedMessageHolder.get(0).getBody().contains("ACTION:UPDATED_MANAGING_ORGANISATION"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("TEST-NEMS-ID"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
// assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
// });
// }
@Test
void shouldUpdateMofToPreviousGpAndSendMessageToMofUpdatedSNSTopicWhenOdsCodeNotInSafeList() {
var nhsNumber = Long.toString(System.currentTimeMillis());
stubForPdsAdaptor(nhsNumber, getSuspendedResponseWith(nhsNumber));

var mofUpdatedQueueUrl = sqs.getQueueUrl(mofUpdatedQueueName).getQueueUrl();
sqs.sendMessage(suspensionQueueUrl, getSuspensionEventWith(nhsNumber, "B85612"));

await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
List<Message> receivedMessageHolder = checkMessageInRelatedQueue(mofUpdatedQueueUrl);

assertTrue(receivedMessageHolder.get(0).getBody().contains("ACTION:UPDATED_MANAGING_ORGANISATION"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("TEST-NEMS-ID"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
});
}

@Test
void shouldSetMOFAsRepoOdsCodeWhenOdsCodeIsInSafeList(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,46 @@ void shouldSendSuspensionMessageToNotSuspendedSNSTopicIfNoLongerSuspendedInPDS()
purgeQueue(notSuspendedQueueUrl);
}

// @Test
// void shouldUpdateManagingOrganisationAndSendMessageToMofUpdatedSNSTopicForSuspendedPatient() {
// var nhsNumber = Long.toString(System.currentTimeMillis());
// stubFor(get(urlMatching("/suspended-patient-status/" + nhsNumber))
// .withHeader("Authorization", matching("Basic c3VzcGVuc2lvbi1zZXJ2aWNlOiJ0ZXN0Ig=="))
// .willReturn(aResponse()
// .withHeader("Content-Type", "application/json")
// .withBody(getSuspendedResponseWith(nhsNumber))));
// stubFor(put(urlMatching("/suspended-patient-status/" + nhsNumber))
// .withHeader("Authorization", matching("Basic c3VzcGVuc2lvbi1zZXJ2aWNlOiJ0ZXN0Ig=="))
// .willReturn(aResponse()
// .withHeader("Content-Type", "application/json")
// .withBody(getSuspendedResponseWith(nhsNumber))));

// var queueUrl = sqs.getQueueUrl(suspensionsQueueName).getQueueUrl();
// var mofUpdatedQueueUrl = sqs.getQueueUrl(mofUpdatedQueueName).getQueueUrl();
// var activeSuspensionsQueueUrl = sqs.getQueueUrl(activeSuspensionsQueueName).getQueueUrl();
// sqs.sendMessage(queueUrl, getSuspensionEventWith(nhsNumber));

// await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
// List<Message> receivedMessageHolder = checkMessageInRelatedQueue(mofUpdatedQueueUrl);

// assertTrue(receivedMessageHolder.get(0).getBody().contains("ACTION:UPDATED_MANAGING_ORGANISATION"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("TEST-NEMS-ID"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
// assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
// });

// await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
// List<Message> receivedMessageHolder = checkMessageInRelatedQueue(activeSuspensionsQueueUrl);

// assertTrue(receivedMessageHolder.get(0).getBody().contains("nhsNumber"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
// assertTrue(receivedMessageHolder.get(0).getBody().contains("2017-11-01T15:00:33+00:00"));
// assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
// });

// purgeQueue(mofUpdatedQueueUrl);
// purgeQueue(activeSuspensionsQueueUrl);
// }
@Test
void shouldUpdateManagingOrganisationAndSendMessageToMofUpdatedSNSTopicForSuspendedPatient() {
var nhsNumber = Long.toString(System.currentTimeMillis());
stubFor(get(urlMatching("/suspended-patient-status/" + nhsNumber))
.withHeader("Authorization", matching("Basic c3VzcGVuc2lvbi1zZXJ2aWNlOiJ0ZXN0Ig=="))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(getSuspendedResponseWith(nhsNumber))));
stubFor(put(urlMatching("/suspended-patient-status/" + nhsNumber))
.withHeader("Authorization", matching("Basic c3VzcGVuc2lvbi1zZXJ2aWNlOiJ0ZXN0Ig=="))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(getSuspendedResponseWith(nhsNumber))));

var queueUrl = sqs.getQueueUrl(suspensionsQueueName).getQueueUrl();
var mofUpdatedQueueUrl = sqs.getQueueUrl(mofUpdatedQueueName).getQueueUrl();
var activeSuspensionsQueueUrl = sqs.getQueueUrl(activeSuspensionsQueueName).getQueueUrl();
sqs.sendMessage(queueUrl, getSuspensionEventWith(nhsNumber));

await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
List<Message> receivedMessageHolder = checkMessageInRelatedQueue(mofUpdatedQueueUrl);

assertTrue(receivedMessageHolder.get(0).getBody().contains("ACTION:UPDATED_MANAGING_ORGANISATION"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("TEST-NEMS-ID"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
});

await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
List<Message> receivedMessageHolder = checkMessageInRelatedQueue(activeSuspensionsQueueUrl);

assertTrue(receivedMessageHolder.get(0).getBody().contains("nhsNumber"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("B85612"));
assertTrue(receivedMessageHolder.get(0).getBody().contains("2017-11-01T15:00:33+00:00"));
assertTrue(receivedMessageHolder.get(0).getMessageAttributes().containsKey("traceId"));
});

purgeQueue(mofUpdatedQueueUrl);
purgeQueue(activeSuspensionsQueueUrl);
}

@Test
void shouldPutEventOutOfOrderInRelevantQueues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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) {
Expand All @@ -51,24 +51,20 @@ private boolean isSafeToProcess(SuspensionEvent suspensionEvent) {
return true;
}

// 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 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
Loading
Loading