Skip to content

Commit f9cb436

Browse files
feat: rule 40 enhancement (#1789)
* Adding New Rules * fix rule to nullify rfr effective from date * transform unit tests * update rules * Complete Unit Tests * Update Rule 40 Category * Update category and comment for rfr static rules * fix unit tests * Update Rules to include RDR check * Correcting Logic * Address Comments * fix merge issue * more merge issues * remove duplicate code
1 parent 702639c commit f9cb436

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformDataService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class TransformDataService
2929
private readonly ITransformReasonForRemoval _transformReasonForRemoval;
3030
private readonly ITransformDataLookupFacade _dataLookup;
3131
private readonly IReasonForRemovalLookup _reasonForRemovalLookup;
32-
3332
public TransformDataService(
3433
ICreateResponse createResponse,
3534
IExceptionHandler exceptionHandler,
@@ -92,7 +91,6 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
9291
if (participant.NhsNumber == null)
9392
{
9493
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
95-
9694
}
9795

9896
var response = JsonSerializer.Serialize(participant);

application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/Breast_Screening_lookupRules.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,28 @@
102102
}
103103
}
104104
]
105+
},
106+
{
107+
"WorkflowName":"ManualAdd",
108+
"GlobalParams": [
109+
{
110+
"Name": "ValidPrimaryCareProvider",
111+
"Expression": "string.IsNullOrEmpty(newParticipant.PrimaryCareProvider) || dbLookup.CheckIfPrimaryCareProviderExists(newParticipant.PrimaryCareProvider)"
112+
}
113+
],
114+
"Rules":[
115+
{
116+
"RuleName": "3601.ValidatePrimaryCareProvider.NBO.NonFatal",
117+
"Expression": "ValidPrimaryCareProvider",
118+
"Actions": {
119+
"OnFailure": {
120+
"Name": "OutputExpression",
121+
"Context": {
122+
"Expression": "\"Invalid primary care provider GP practice code\""
123+
}
124+
}
125+
}
126+
}
127+
]
105128
}
106129
]

application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/LookupValidation.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
5959
{
6060
newParticipant = requestBody.NewParticipant;
6161

62+
var isManualAdd = ValidationHelper.CheckManualAddFileName(requestBody.FileName);
63+
6264
var ruleFileName = $"{newParticipant.ScreeningName}_lookupRules.json".Replace(" ", "_");
6365
_logger.LogInformation("ruleFileName {RuleFileName}", ruleFileName);
6466

@@ -72,8 +74,6 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
7274
};
7375
var re = new RulesEngine.RulesEngine(rules, reSettings);
7476

75-
76-
7777
var ruleParameters = new[] {
7878
new RuleParameter("existingParticipant", requestBody.ExistingParticipant),
7979
new RuleParameter("newParticipant", newParticipant),
@@ -86,13 +86,17 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
8686
{
8787
resultList = await re.ExecuteAllRulesAsync("Common", ruleParameters);
8888
}
89-
9089
if (re.GetAllRegisteredWorkflowNames().Contains(newParticipant.RecordType))
9190
{
9291
_logger.LogInformation("Executing workflow {RecordType}", newParticipant.RecordType);
9392
var ActionResults = await re.ExecuteAllRulesAsync(newParticipant.RecordType, ruleParameters);
9493
resultList.AddRange(ActionResults);
9594
}
95+
if (isManualAdd)
96+
{
97+
var ActionResults = await re.ExecuteAllRulesAsync("ManualAdd", ruleParameters);
98+
resultList.AddRange(ActionResults);
99+
}
96100

97101
// Validation rules are logically reversed
98102
var validationErrors = resultList.Where(x => !x.IsSuccess).Select(x => new ValidationRuleResult(x));

tests/UnitTests/ScreeningValidationServiceTests/LookupValidation/LookupValidationTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void IntialiseTests()
6060
ReferralFlag = "false"
6161
};
6262

63-
_requestBody = new LookupValidationRequestBody(existingParticipant, newParticipant, "caas.csv");
63+
_requestBody = new LookupValidationRequestBody(existingParticipant, newParticipant, "caas.parquet");
6464
_request.Setup(r => r.CreateResponse()).Returns(() =>
6565
{
6666
var response = new Mock<HttpResponseData>(_context.Object);
@@ -446,6 +446,56 @@ public async Task Run_ParticipantLocationRemainingOutsideOfCohort_ReturnNoConten
446446
// Assert
447447
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
448448
}
449+
[TestMethod]
450+
public async Task Run_ManualAddValidPCP_ReturnsNoContent()
451+
{
452+
// arrange
453+
454+
_requestBody.FileName = "CS0848402";
455+
_requestBody.NewParticipant.RecordType = Actions.New;
456+
_requestBody.NewParticipant.PrimaryCareProvider = "ZZZAGA";
457+
_requestBody.NewParticipant.AddressLine1 = "123 Test Street";
458+
_requestBody.NewParticipant.Postcode = "TE57 1NG";
459+
_requestBody.ExistingParticipant = null;
460+
461+
var json = JsonSerializer.Serialize(_requestBody);
462+
SetUpRequestBody(json);
463+
464+
_lookupValidation.Setup(x => x.CheckIfPrimaryCareProviderExists("ZZZAGA")).Returns(true);
465+
466+
467+
// Act
468+
var response = await _sut.RunAsync(_request.Object);
469+
string body = await AssertionHelper.ReadResponseBodyAsync(response);
470+
471+
// Assert
472+
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
473+
}
474+
[TestMethod]
475+
public async Task Run_ManualAddInvalidPCP_ReturnsValidationException()
476+
{
477+
// arrange
478+
479+
_requestBody.FileName = "CS0848402";
480+
_requestBody.NewParticipant.RecordType = Actions.New;
481+
_requestBody.NewParticipant.PrimaryCareProvider = "ZZZAGA";
482+
_requestBody.NewParticipant.AddressLine1 = "123 Test Street";
483+
_requestBody.NewParticipant.Postcode = "TE57 1NG";
484+
_requestBody.ExistingParticipant = null;
485+
486+
var json = JsonSerializer.Serialize(_requestBody);
487+
SetUpRequestBody(json);
488+
489+
_lookupValidation.Setup(x => x.CheckIfPrimaryCareProviderExists("ZZZAGA")).Returns(false);
490+
491+
492+
// Act
493+
var response = await _sut.RunAsync(_request.Object);
494+
string body = await AssertionHelper.ReadResponseBodyAsync(response);
495+
496+
// Assert
497+
StringAssert.Contains(body, "3601.ValidatePrimaryCareProvider.NBO.NonFatal");
498+
}
449499

450500
private void SetUpRequestBody(string json)
451501
{

0 commit comments

Comments
 (0)