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 @@ -60,14 +60,21 @@ public async Task<HashSet<string>> GetCachedExcludedSMUValues()

return excludedSMUData!;
}

public bool ValidateOutcode(string postcode)
{
string outcode = ValidationHelper.ParseOutcode(postcode)
?? throw new TransformationException("Postcode format invalid");
//if a postcode is a dummy postcode then we want to allow the rules to know that we have a dummy postcode
if (postcode.StartsWith("ZZ"))
{
return false;
}

var result = _outcodeClient.GetSingle(outcode).Result;
string parsedOutCode = ValidationHelper.ParseOutcode(postcode)
?? throw new TransformationException("Postcode format invalid");

var result = _outcodeClient.GetSingle(parsedOutCode).Result;
return result != null;

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ namespace NHS.CohortManager.CohortDistributionService;

using Model;
using Common;
using Data.Database;
using System.Text.Json;
using Apache.Arrow.Types;


public class TransformReasonForRemoval : ITransformReasonForRemoval
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public bool ValidateOutcode(string postcode)
{
var outcode = ValidationHelper.ParseOutcode(postcode);
_logger.LogInformation("Validating Outcode: {Outcode}", outcode);
var result = _outcodeClient.GetSingle(outcode).Result;
var result = _outcodeClient.GetSingle(outcode!).Result;

return result != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace Common;

using System.Globalization;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using Hl7.Fhir.Validation;
using Model;

public static class ValidationHelper
{
Expand Down Expand Up @@ -109,21 +112,16 @@ public static bool ValidatePostcode(string postcode)
/// </remarks>
public static string? ParseOutcode(string postcode)
{
if (postcode == "ZZZSECUR")
{
return postcode;
}

string pattern = @"^([A-Za-z][A-Za-z]?[0-9][A-Za-z0-9]?) ?[0-9][A-Za-z]{2}$";

Match match = Regex.Match(postcode, pattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));

if (!match.Success)
{
return null;
}

string outcode = match.Groups[1].Value;

return outcode;
}

Expand Down
Loading