Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class TransformDataService
private readonly ITransformReasonForRemoval _transformReasonForRemoval;
private readonly ITransformDataLookupFacade _dataLookup;
private readonly IReasonForRemovalLookup _reasonForRemovalLookup;

public TransformDataService(
ICreateResponse createResponse,
IExceptionHandler exceptionHandler,
Expand Down Expand Up @@ -92,7 +91,6 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
if (participant.NhsNumber == null)
{
return _createResponse.CreateHttpResponse(HttpStatusCode.Accepted, req, "");

}

var response = JsonSerializer.Serialize(participant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,28 @@
}
}
]
},
{
"WorkflowName":"ManualAdd",
"GlobalParams": [
{
"Name": "ValidPrimaryCareProvider",
"Expression": "string.IsNullOrEmpty(newParticipant.PrimaryCareProvider) || dbLookup.CheckIfPrimaryCareProviderExists(newParticipant.PrimaryCareProvider)"
}
],
"Rules":[
{
"RuleName": "3601.ValidatePrimaryCareProvider.NBO.NonFatal",
"Expression": "ValidPrimaryCareProvider",
"Actions": {
"OnFailure": {
"Name": "OutputExpression",
"Context": {
"Expression": "\"Invalid primary care provider GP practice code\""
}
}
}
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
{
newParticipant = requestBody.NewParticipant;

var isManualAdd = ValidationHelper.CheckManualAddFileName(requestBody.FileName);

var ruleFileName = $"{newParticipant.ScreeningName}_lookupRules.json".Replace(" ", "_");
_logger.LogInformation("ruleFileName {RuleFileName}", ruleFileName);

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



var ruleParameters = new[] {
new RuleParameter("existingParticipant", requestBody.ExistingParticipant),
new RuleParameter("newParticipant", newParticipant),
Expand All @@ -86,13 +86,17 @@ public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Ano
{
resultList = await re.ExecuteAllRulesAsync("Common", ruleParameters);
}

if (re.GetAllRegisteredWorkflowNames().Contains(newParticipant.RecordType))
{
_logger.LogInformation("Executing workflow {RecordType}", newParticipant.RecordType);
var ActionResults = await re.ExecuteAllRulesAsync(newParticipant.RecordType, ruleParameters);
resultList.AddRange(ActionResults);
}
if (isManualAdd)
{
var ActionResults = await re.ExecuteAllRulesAsync("ManualAdd", ruleParameters);
resultList.AddRange(ActionResults);
}

// Validation rules are logically reversed
var validationErrors = resultList.Where(x => !x.IsSuccess).Select(x => new ValidationRuleResult(x));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void IntialiseTests()
ReferralFlag = "false"
};

_requestBody = new LookupValidationRequestBody(existingParticipant, newParticipant, "caas.csv");
_requestBody = new LookupValidationRequestBody(existingParticipant, newParticipant, "caas.parquet");
_request.Setup(r => r.CreateResponse()).Returns(() =>
{
var response = new Mock<HttpResponseData>(_context.Object);
Expand Down Expand Up @@ -446,6 +446,56 @@ public async Task Run_ParticipantLocationRemainingOutsideOfCohort_ReturnNoConten
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
public async Task Run_ManualAddValidPCP_ReturnsNoContent()
{
// arrange

_requestBody.FileName = "CS0848402";
_requestBody.NewParticipant.RecordType = Actions.New;
_requestBody.NewParticipant.PrimaryCareProvider = "ZZZAGA";
_requestBody.NewParticipant.AddressLine1 = "123 Test Street";
_requestBody.NewParticipant.Postcode = "TE57 1NG";
_requestBody.ExistingParticipant = null;

var json = JsonSerializer.Serialize(_requestBody);
SetUpRequestBody(json);

_lookupValidation.Setup(x => x.CheckIfPrimaryCareProviderExists("ZZZAGA")).Returns(true);


// Act
var response = await _sut.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);

// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
public async Task Run_ManualAddInvalidPCP_ReturnsValidationException()
{
// arrange

_requestBody.FileName = "CS0848402";
_requestBody.NewParticipant.RecordType = Actions.New;
_requestBody.NewParticipant.PrimaryCareProvider = "ZZZAGA";
_requestBody.NewParticipant.AddressLine1 = "123 Test Street";
_requestBody.NewParticipant.Postcode = "TE57 1NG";
_requestBody.ExistingParticipant = null;

var json = JsonSerializer.Serialize(_requestBody);
SetUpRequestBody(json);

_lookupValidation.Setup(x => x.CheckIfPrimaryCareProviderExists("ZZZAGA")).Returns(false);


// Act
var response = await _sut.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);

// Assert
StringAssert.Contains(body, "3601.ValidatePrimaryCareProvider.NBO.NonFatal");
}

private void SetUpRequestBody(string json)
{
Expand Down
Loading