Skip to content

Commit 4e90968

Browse files
committed
Merge branch 'main' into feat/update-ui-rule-descriptions
2 parents 2ad2b1b + f9cb436 commit 4e90968

File tree

30 files changed

+2411
-133
lines changed

30 files changed

+2411
-133
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: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ public class TransformDataService
2828
private readonly IExceptionHandler _exceptionHandler;
2929
private readonly ITransformReasonForRemoval _transformReasonForRemoval;
3030
private readonly ITransformDataLookupFacade _dataLookup;
31-
31+
private readonly IReasonForRemovalLookup _reasonForRemovalLookup;
3232
public TransformDataService(
3333
ICreateResponse createResponse,
3434
IExceptionHandler exceptionHandler,
3535
ILogger<TransformDataService> logger,
3636
ITransformReasonForRemoval transformReasonForRemoval,
37-
ITransformDataLookupFacade dataLookup
37+
ITransformDataLookupFacade dataLookup,
38+
IReasonForRemovalLookup reasonForRemovalLookup
3839
)
3940
{
4041
_createResponse = createResponse;
4142
_exceptionHandler = exceptionHandler;
4243
_logger = logger;
4344
_transformReasonForRemoval = transformReasonForRemoval;
4445
_dataLookup = dataLookup;
46+
_reasonForRemovalLookup = reasonForRemovalLookup;
4547
}
4648

4749
[Function("TransformDataService")]
@@ -77,25 +79,28 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
7779
participant = await transformString.TransformStringFields(participant);
7880

7981
// Other transformation rules
80-
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant);
82+
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant,ValidationHelper.CheckManualAddFileName(requestBody.FileName));
8183

8284
// Name prefix transformation
8385
if (participant.NamePrefix != null)
8486
participant.NamePrefix = await TransformNamePrefixAsync(participant.NamePrefix, participant);
8587

8688

8789
participant = await _transformReasonForRemoval.ReasonForRemovalTransformations(participant, requestBody.ExistingParticipant);
88-
if (participant.NhsNumber != null)
90+
91+
if (participant.NhsNumber == null)
8992
{
90-
var response = JsonSerializer.Serialize(participant);
91-
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);
93+
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
9294
}
93-
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");
95+
96+
var response = JsonSerializer.Serialize(participant);
97+
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);
98+
9499
}
95100
catch (ArgumentException ex)
96101
{
97102
_logger.LogWarning(ex, "An error occurred during transformation");
98-
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
103+
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
99104
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req);
100105
}
101106
catch (TransformationException ex)
@@ -105,14 +110,14 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
105110
}
106111
catch (Exception ex)
107112
{
108-
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
113+
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
109114
_logger.LogWarning(ex, "exception occurred while running transform data service");
110115
return _createResponse.CreateHttpResponse(HttpStatusCode.InternalServerError, req);
111116
}
112117
}
113118

114119
public async Task<CohortDistributionParticipant> TransformParticipantAsync(CohortDistributionParticipant participant,
115-
CohortDistribution databaseParticipant)
120+
CohortDistribution databaseParticipant, bool isManualAdd = false)
116121
{
117122
var excludedSMUList = await _dataLookup.GetCachedExcludedSMUValues();
118123

@@ -133,7 +138,8 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
133138
new RuleParameter("participant", participant),
134139
new RuleParameter("dbLookup", _dataLookup),
135140
new RuleParameter("excludedSMUList", excludedSMUList),
136-
new RuleParameter("existingParticipant", existingParticipant)
141+
new RuleParameter("existingParticipant", existingParticipant),
142+
new RuleParameter("reasonForRemovalLkp",_reasonForRemovalLookup)
137143
};
138144

139145
var resultList = await re.ExecuteAllRulesAsync("Common", ruleParameters);
@@ -142,6 +148,10 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
142148
{
143149
resultList.AddRange(await re.ExecuteAllRulesAsync("Referred", ruleParameters));
144150
}
151+
if (isManualAdd)
152+
{
153+
resultList.AddRange(await re.ExecuteAllRulesAsync("ManualAdd", ruleParameters));
154+
}
145155

146156
await HandleExceptions(resultList, participant);
147157
await CreateTransformExecutedExceptions(resultList, participant);
@@ -216,5 +226,4 @@ private async Task CreateTransformExecutedExceptions(List<RuleResultTree> except
216226
await _exceptionHandler.CreateTransformExecutedExceptions(participant, ruleName, ruleId);
217227
}
218228
}
219-
220229
}

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)