Skip to content

Commit 3be6d09

Browse files
fix: now allows for dummy postcode ZZZSECUR in transform (#1477)
* fix: now allows the bypassing of checking outcodes when postcode is a dummy code * fix: fixing unit tests * fix: fixing unit tests * fix: making sure that all possible matches of speical dummy codes are covered * fix: now returns to TransformReasonForRemoval so transform rules are not effected and can run properly * chore: addressing comments on PR
1 parent 0331745 commit 3be6d09

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformDataLookupFacade.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ public async Task<HashSet<string>> GetCachedExcludedSMUValues()
6060

6161
return excludedSMUData!;
6262
}
63+
6364
public bool ValidateOutcode(string postcode)
6465
{
65-
string outcode = ValidationHelper.ParseOutcode(postcode)
66-
?? throw new TransformationException("Postcode format invalid");
66+
//if a postcode is a dummy postcode then we want to allow the rules to know that we have a dummy postcode
67+
if (postcode.StartsWith("ZZ"))
68+
{
69+
return false;
70+
}
6771

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

75+
var result = _outcodeClient.GetSingle(parsedOutCode).Result;
7076
return result != null;
77+
7178
}
7279

7380
/// <summary>

application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/TransformReasonForRemoval.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ namespace NHS.CohortManager.CohortDistributionService;
22

33
using Model;
44
using Common;
5-
using Data.Database;
65
using System.Text.Json;
7-
using Apache.Arrow.Types;
6+
87

98
public class TransformReasonForRemoval : ITransformReasonForRemoval
109
{

application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/DataLookupFacadeBreastScreening.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public bool ValidateOutcode(string postcode)
5353
{
5454
var outcode = ValidationHelper.ParseOutcode(postcode);
5555
_logger.LogInformation("Validating Outcode: {Outcode}", outcode);
56-
var result = _outcodeClient.GetSingle(outcode).Result;
56+
var result = _outcodeClient.GetSingle(outcode!).Result;
5757

5858
return result != null;
5959
}

application/CohortManager/src/Functions/Shared/Common/ValidationHelper.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
namespace Common;
22

33
using System.Globalization;
4+
using System.Linq.Expressions;
45
using System.Text.RegularExpressions;
6+
using Hl7.Fhir.Validation;
7+
using Model;
58

69
public static class ValidationHelper
710
{
@@ -109,21 +112,16 @@ public static bool ValidatePostcode(string postcode)
109112
/// </remarks>
110113
public static string? ParseOutcode(string postcode)
111114
{
112-
if (postcode == "ZZZSECUR")
113-
{
114-
return postcode;
115-
}
116-
117115
string pattern = @"^([A-Za-z][A-Za-z]?[0-9][A-Za-z0-9]?) ?[0-9][A-Za-z]{2}$";
118116

119117
Match match = Regex.Match(postcode, pattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(2));
118+
120119
if (!match.Success)
121120
{
122121
return null;
123122
}
124123

125124
string outcode = match.Groups[1].Value;
126-
127125
return outcode;
128126
}
129127

0 commit comments

Comments
 (0)