Skip to content
1 change: 1 addition & 0 deletions application/CohortManager/compose.wiremock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
build:
context: ./src/Functions/
dockerfile: Shared/Wiremock/Dockerfile
user: "0"
ports:
- "8080:8080"
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ValidateParticipant(IDataServiceClient<CohortDistribution> cohortDistribu
await removeValidationRecordTask;

validationRecord.PreviousParticipantRecord = previousRecord;

// Lookup & Static Validation
var lookupTaskOptions = TaskOptions.FromRetryPolicy(new RetryPolicy(
maxNumberOfAttempts: _config.MaxLookupValidationRetries,
Expand Down Expand Up @@ -215,6 +215,7 @@ public async Task<List<ValidationRuleResult>> LookupValidation([ActivityTrigger]
var transformDataRequestBody = new TransformDataRequestBody()
{
Participant = validationRecord.Participant,
FileName = validationRecord.FileName,
// TODO: is this used?
ServiceProvider = validationRecord.ServiceProvider,
ExistingParticipant = validationRecord.PreviousParticipantRecord.ToCohortDistribution()
Expand Down Expand Up @@ -258,4 +259,4 @@ public async Task HandleValidationExceptions([ActivityTrigger] ValidationExcepti
}
_logger.LogInformation("Created validation exception and set exception flag to 1 for participant {ParticipantId}", participantRecord.Participant.ParticipantId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
services.AddSingleton<ICreateResponse, CreateResponse>();
services.AddSingleton<ITransformDataLookupFacade, TransformDataLookupFacade>();
services.AddSingleton<ITransformReasonForRemoval, TransformReasonForRemoval>();
services.AddSingleton<IReasonForRemovalLookup,ReasonForRemovalLookup>();
services.AddMemoryCache();

// Register health checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ public class TransformDataService
private readonly IExceptionHandler _exceptionHandler;
private readonly ITransformReasonForRemoval _transformReasonForRemoval;
private readonly ITransformDataLookupFacade _dataLookup;
private readonly IReasonForRemovalLookup _reasonForRemovalLookup;

public TransformDataService(
ICreateResponse createResponse,
IExceptionHandler exceptionHandler,
ILogger<TransformDataService> logger,
ITransformReasonForRemoval transformReasonForRemoval,
ITransformDataLookupFacade dataLookup
ITransformDataLookupFacade dataLookup,
IReasonForRemovalLookup reasonForRemovalLookup
)
{
_createResponse = createResponse;
_exceptionHandler = exceptionHandler;
_logger = logger;
_transformReasonForRemoval = transformReasonForRemoval;
_dataLookup = dataLookup;
_reasonForRemovalLookup = reasonForRemovalLookup;
}

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

// Other transformation rules
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant);
participant = await TransformParticipantAsync(participant, requestBody.ExistingParticipant,ValidationHelper.CheckManualAddFileName(requestBody.FileName));

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


participant = await _transformReasonForRemoval.ReasonForRemovalTransformations(participant, requestBody.ExistingParticipant);
if (participant.NhsNumber != null)

if (participant.NhsNumber == null)
{
var response = JsonSerializer.Serialize(participant);
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");

}
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");

var response = JsonSerializer.Serialize(participant);
return _createResponse.CreateHttpResponse(HttpStatusCode.OK, req, response);

}
catch (ArgumentException ex)
{
_logger.LogWarning(ex, "An error occurred during transformation");
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req);
}
catch (TransformationException ex)
Expand All @@ -105,14 +112,14 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
}
catch (Exception ex)
{
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, "", participant.ScreeningName, JsonSerializer.Serialize(participant));
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, participant.NhsNumber, requestBody.FileName!, participant.ScreeningName!, JsonSerializer.Serialize(participant));
_logger.LogWarning(ex, "exception occurred while running transform data service");
return _createResponse.CreateHttpResponse(HttpStatusCode.InternalServerError, req);
}
}

public async Task<CohortDistributionParticipant> TransformParticipantAsync(CohortDistributionParticipant participant,
CohortDistribution databaseParticipant)
CohortDistribution databaseParticipant, bool isManualAdd = false)
{
var excludedSMUList = await _dataLookup.GetCachedExcludedSMUValues();

Expand All @@ -133,7 +140,8 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
new RuleParameter("participant", participant),
new RuleParameter("dbLookup", _dataLookup),
new RuleParameter("excludedSMUList", excludedSMUList),
new RuleParameter("existingParticipant", existingParticipant)
new RuleParameter("existingParticipant", existingParticipant),
new RuleParameter("reasonForRemovalLkp",_reasonForRemovalLookup)
};

var resultList = await re.ExecuteAllRulesAsync("Common", ruleParameters);
Expand All @@ -142,6 +150,10 @@ public async Task<CohortDistributionParticipant> TransformParticipantAsync(Cohor
{
resultList.AddRange(await re.ExecuteAllRulesAsync("Referred", ruleParameters));
}
if (isManualAdd)
{
resultList.AddRange(await re.ExecuteAllRulesAsync("ManualAdd", ruleParameters));
}

await HandleExceptions(resultList, participant);
await CreateTransformExecutedExceptions(resultList, participant);
Expand Down Expand Up @@ -216,5 +228,4 @@ private async Task CreateTransformExecutedExceptions(List<RuleResultTree> except
await _exceptionHandler.CreateTransformExecutedExceptions(participant, ruleName, ruleId);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,43 @@
}
}
]
},
{
"WorkflowName": "ManualAdd",
"Rules": [
{
"RuleName": "96.UpdateRFR.ManualAdd",
"LocalParams": [
{
"Name": "CanTransformRfr",
"Expression": "reasonForRemovalLkp.CanRemovalReasonBeOverridden(participant.ReasonForRemoval)"
},
{
"Name": "HasPrimaryCareProvider",
"Expression": "!string.IsNullOrEmpty(participant.PrimaryCareProvider)"
}
],
"Expression": "!string.IsNullOrEmpty(participant.ReasonForRemoval) && CanTransformRfr && HasPrimaryCareProvider",
"Actions": {
"OnSuccess": {
"Name": "TransformAction",
"Context": {
"transformFields": [
{
"field": "ReasonForRemoval",
"value": null,
"isExpression": false
},
{
"field": "ReasonForRemovalEffectiveFromDate",
"value": null,
"isExpression": false
}
]
}
}
}
}
]
}
]
Loading
Loading