diff --git a/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/transformRules.json b/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/transformRules.json index d98b271d7..05b6a328f 100644 --- a/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/transformRules.json +++ b/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/transformRules.json @@ -2,9 +2,13 @@ { "WorkflowName": "Common", "Rules": [ + { + "RuleName": "61.Other.SupersededNhsNumber.NoTransformation", + "Expression": "participant.RecordType == Actions.Amended && !string.IsNullOrEmpty(participant.SupersededByNhsNumber) && !string.IsNullOrEmpty(participant.ReasonForRemoval)" + }, { "RuleName": "60.Other.SupersededNhsNumber", - "Expression": "participant.RecordType == Actions.Amended && !string.IsNullOrEmpty(participant.SupersededByNhsNumber)", + "Expression": "participant.RecordType == Actions.Amended && !string.IsNullOrEmpty(participant.SupersededByNhsNumber) && string.IsNullOrEmpty(participant.ReasonForRemoval)", "Actions": { "OnSuccess": { "Name": "TransformAction", diff --git a/application/CohortManager/src/Functions/Shared/Common/ExceptionHandler.cs b/application/CohortManager/src/Functions/Shared/Common/ExceptionHandler.cs index b303efb21..4e1fe6a12 100644 --- a/application/CohortManager/src/Functions/Shared/Common/ExceptionHandler.cs +++ b/application/CohortManager/src/Functions/Shared/Common/ExceptionHandler.cs @@ -386,6 +386,7 @@ public async Task CreateTransformExecutedExceptions(CohortDistributionParticipan { 35 => ExceptionCategory.Confusion, 60 => ExceptionCategory.Superseded, + 61 => ExceptionCategory.Superseded, _ => ExceptionCategory.TransformExecuted }; } diff --git a/tests/UnitTests/TransformDataServiceTests/TransformDataServiceTests/TransformDataServiceTests.cs b/tests/UnitTests/TransformDataServiceTests/TransformDataServiceTests/TransformDataServiceTests.cs index 029de8b68..f43afaed4 100644 --- a/tests/UnitTests/TransformDataServiceTests/TransformDataServiceTests/TransformDataServiceTests.cs +++ b/tests/UnitTests/TransformDataServiceTests/TransformDataServiceTests/TransformDataServiceTests.cs @@ -630,7 +630,7 @@ public async Task Run_DateOfDeathSuppliedAndReasonForRemovalIsDea_ShouldNotChang } [TestMethod] - public async Task Run_SupersededNhsNumberNotNull_TransformAndRaiseException() + public async Task Run_SupersededNhsNumberNotNullAndRfRIsNull_TransformAndRaiseException() { // Arrange _requestBody.Participant.SupersededByNhsNumber = "1234567890"; @@ -664,6 +664,48 @@ public async Task Run_SupersededNhsNumberNotNull_TransformAndRaiseException() times: Times.Once); } + [TestMethod] + public async Task Run_SupersededNhsNumberNotNullAndRfRNotNull_NoTransformAndRaiseException() + { + // Arrange + _requestBody.Participant.SupersededByNhsNumber = "1234567890"; + _requestBody.Participant.RecordType = Actions.Amended; + _requestBody.Participant.ReasonForRemoval = "SCT"; + _requestBody.Participant.ReasonForRemovalEffectiveFromDate = DateTime.UtcNow.Date.ToString("yyyyMMdd"); + + var json = JsonSerializer.Serialize(_requestBody); + SetUpRequestBody(json); + var expectedResponse = new CohortDistributionParticipant + { + RecordType = Actions.Amended, + NhsNumber = "1", + SupersededByNhsNumber = "1234567890", + FirstName = "John", + FamilyName = "Smith", + NamePrefix = "MR", + Gender = Gender.Male, + ReferralFlag = false, + PrimaryCareProvider = null, + ReasonForRemoval = "SCT", + ReasonForRemovalEffectiveFromDate = DateTime.UtcNow.Date.ToString("yyyyMMdd") + }; + + // Act + var result = await _function.RunAsync(_request.Object); + + // Assert + string responseBody = await AssertionHelper.ReadResponseBodyAsync(result); + + Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); + Assert.AreEqual(JsonSerializer.Serialize(expectedResponse), responseBody); + _handleException + .Verify(i => i.CreateTransformExecutedExceptions(It.IsAny(), "OtherSupersededNhsNumberNoTransformation", 61, null), + times: Times.Once); + _handleException + .Verify(i => i.CreateTransformExecutedExceptions(It.IsAny(), "OtherSupersededNhsNumber", 60, null), + times: Times.Never); + } + [TestMethod] public async Task Run_DelRecord_TransformRfrAndRaiseException() {