Skip to content

Commit 702639c

Browse files
feat: RFR transform rules (#1788)
* Adding New Rules * fix rule to nullify rfr effective from date * transform unit tests * Update category and comment for rfr static rules * Update Rules to include RDR check * Correcting Logic * Address Comments * remove unused code and sonarqube * Add pds mock data for e2e tests
1 parent 05923c6 commit 702639c

File tree

19 files changed

+2178
-20
lines changed

19 files changed

+2178
-20
lines changed

application/CohortManager/compose.wiremock.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
build:
88
context: ./src/Functions/
99
dockerfile: Shared/Wiremock/Dockerfile
10+
user: "0"
1011
ports:
1112
- "8080:8080"
1213
volumes:

application/CohortManager/src/Functions/CohortDistributionServices/DistributeParticipant/ValidateParticipant.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public ValidateParticipant(IDataServiceClient<CohortDistribution> cohortDistribu
6565
await removeValidationRecordTask;
6666

6767
validationRecord.PreviousParticipantRecord = previousRecord;
68-
68+
6969
// Lookup & Static Validation
7070
var lookupTaskOptions = TaskOptions.FromRetryPolicy(new RetryPolicy(
7171
maxNumberOfAttempts: _config.MaxLookupValidationRetries,
@@ -215,6 +215,7 @@ public async Task<List<ValidationRuleResult>> LookupValidation([ActivityTrigger]
215215
var transformDataRequestBody = new TransformDataRequestBody()
216216
{
217217
Participant = validationRecord.Participant,
218+
FileName = validationRecord.FileName,
218219
// TODO: is this used?
219220
ServiceProvider = validationRecord.ServiceProvider,
220221
ExistingParticipant = validationRecord.PreviousParticipantRecord.ToCohortDistribution()
@@ -258,4 +259,4 @@ public async Task HandleValidationExceptions([ActivityTrigger] ValidationExcepti
258259
}
259260
_logger.LogInformation("Created validation exception and set exception flag to 1 for participant {ParticipantId}", participantRecord.Participant.ParticipantId);
260261
}
261-
}
262+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
services.AddSingleton<ICreateResponse, CreateResponse>();
2525
services.AddSingleton<ITransformDataLookupFacade, TransformDataLookupFacade>();
2626
services.AddSingleton<ITransformReasonForRemoval, TransformReasonForRemoval>();
27+
services.AddSingleton<IReasonForRemovalLookup,ReasonForRemovalLookup>();
2728
services.AddMemoryCache();
2829

2930
// Register health checks

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ public class TransformDataService
2828
private readonly IExceptionHandler _exceptionHandler;
2929
private readonly ITransformReasonForRemoval _transformReasonForRemoval;
3030
private readonly ITransformDataLookupFacade _dataLookup;
31+
private readonly IReasonForRemovalLookup _reasonForRemovalLookup;
3132

3233
public TransformDataService(
3334
ICreateResponse createResponse,
3435
IExceptionHandler exceptionHandler,
3536
ILogger<TransformDataService> logger,
3637
ITransformReasonForRemoval transformReasonForRemoval,
37-
ITransformDataLookupFacade dataLookup
38+
ITransformDataLookupFacade dataLookup,
39+
IReasonForRemovalLookup reasonForRemovalLookup
3840
)
3941
{
4042
_createResponse = createResponse;
4143
_exceptionHandler = exceptionHandler;
4244
_logger = logger;
4345
_transformReasonForRemoval = transformReasonForRemoval;
4446
_dataLookup = dataLookup;
47+
_reasonForRemovalLookup = reasonForRemovalLookup;
4548
}
4649

4750
[Function("TransformDataService")]
@@ -77,25 +80,29 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
7780
participant = await transformString.TransformStringFields(participant);
7881

7982
// Other transformation rules
80-
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant);
83+
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant,ValidationHelper.CheckManualAddFileName(requestBody.FileName));
8184

8285
// Name prefix transformation
8386
if (participant.NamePrefix != null)
8487
participant.NamePrefix = await TransformNamePrefixAsync(participant.NamePrefix, participant);
8588

8689

8790
participant = await _transformReasonForRemoval.ReasonForRemovalTransformations(participant, requestBody.ExistingParticipant);
88-
if (participant.NhsNumber != null)
91+
92+
if (participant.NhsNumber == null)
8993
{
90-
var response = JsonSerializer.Serialize(participant);
91-
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);
94+
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
95+
9296
}
93-
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
97+
98+
var response = JsonSerializer.Serialize(participant);
99+
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);
100+
94101
}
95102
catch (ArgumentException ex)
96103
{
97104
_logger.LogWarning(ex, "An error occurred during transformation");
98-
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
105+
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
99106
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req);
100107
}
101108
catch (TransformationException ex)
@@ -105,14 +112,14 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
105112
}
106113
catch (Exception ex)
107114
{
108-
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
115+
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
109116
_logger.LogWarning(ex, "exception occurred while running transform data service");
110117
return _createResponse.CreateHttpResponse(HttpStatusCode.InternalServerError, req);
111118
}
112119
}
113120

114121
public async Task<CohortDistributionParticipant> TransformParticipantAsync(CohortDistributionParticipant participant,
115-
CohortDistribution databaseParticipant)
122+
CohortDistribution databaseParticipant, bool isManualAdd = false)
116123
{
117124
var excludedSMUList = await _dataLookup.GetCachedExcludedSMUValues();
118125

@@ -133,7 +140,8 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
133140
new RuleParameter("participant", participant),
134141
new RuleParameter("dbLookup", _dataLookup),
135142
new RuleParameter("excludedSMUList", excludedSMUList),
136-
new RuleParameter("existingParticipant", existingParticipant)
143+
new RuleParameter("existingParticipant", existingParticipant),
144+
new RuleParameter("reasonForRemovalLkp",_reasonForRemovalLookup)
137145
};
138146

139147
var resultList = await re.ExecuteAllRulesAsync("Common", ruleParameters);
@@ -142,6 +150,10 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
142150
{
143151
resultList.AddRange(await re.ExecuteAllRulesAsync("Referred", ruleParameters));
144152
}
153+
if (isManualAdd)
154+
{
155+
resultList.AddRange(await re.ExecuteAllRulesAsync("ManualAdd", ruleParameters));
156+
}
145157

146158
await HandleExceptions(resultList, participant);
147159
await CreateTransformExecutedExceptions(resultList, participant);
@@ -216,5 +228,4 @@ private async Task CreateTransformExecutedExceptions(List<RuleResultTree> except
216228
await _exceptionHandler.CreateTransformExecutedExceptions(participant, ruleName, ruleId);
217229
}
218230
}
219-
220231
}

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/transformRules.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,5 +751,43 @@
751751
}
752752
}
753753
]
754+
},
755+
{
756+
"WorkflowName": "ManualAdd",
757+
"Rules": [
758+
{
759+
"RuleName": "96.UpdateRFR.ManualAdd",
760+
"LocalParams": [
761+
{
762+
"Name": "CanTransformRfr",
763+
"Expression": "reasonForRemovalLkp.CanRemovalReasonBeOverridden(participant.ReasonForRemoval)"
764+
},
765+
{
766+
"Name": "HasPrimaryCareProvider",
767+
"Expression": "!string.IsNullOrEmpty(participant.PrimaryCareProvider)"
768+
}
769+
],
770+
"Expression": "!string.IsNullOrEmpty(participant.ReasonForRemoval) && CanTransformRfr && HasPrimaryCareProvider",
771+
"Actions": {
772+
"OnSuccess": {
773+
"Name": "TransformAction",
774+
"Context": {
775+
"transformFields": [
776+
{
777+
"field": "ReasonForRemoval",
778+
"value": null,
779+
"isExpression": false
780+
},
781+
{
782+
"field": "ReasonForRemovalEffectiveFromDate",
783+
"value": null,
784+
"isExpression": false
785+
}
786+
]
787+
}
788+
}
789+
}
790+
}
791+
]
754792
}
755793
]

0 commit comments

Comments
 (0)