Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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,16 @@ public async Task<HashSet<string>> GetCachedExcludedSMUValues()

return excludedSMUData!;
}

public bool ValidateOutcode(string postcode)
{
string outcode = ValidationHelper.ParseOutcode(postcode)
var parsedOutCode = ValidationHelper.ParseOutcode(postcode);
Comment thread
SamRobinson75684 marked this conversation as resolved.
Outdated
_ = parsedOutCode
Comment thread
SamRobinson75684 marked this conversation as resolved.
Outdated
?? throw new TransformationException("Postcode format invalid");

var result = _outcodeClient.GetSingle(outcode).Result;

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 @@ -100,7 +103,7 @@ public static bool ValidatePostcode(string postcode)
}

/// <summary>
/// Gets the outcode (1st part of postcode) from the postcode.
/// Gets the outcode (1st part of postcode) from the postcode and if the postcode is a dummy code
Comment thread
SamRobinson75684 marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="postcode">a non-null string representing the postcode</param>
/// <remarks>
Expand All @@ -109,21 +112,23 @@ 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}$";
string specialDummyOutCodePattern = "^ZZ99|^ZZZSECUR$";

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

if (dummyOutCodePattern.Success)
{
return dummyOutCodePattern.Groups[1].Value;
}

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

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

return outcode;
}

Expand Down
Loading