Skip to content

Commit 9eb5c3d

Browse files
authored
Merge branch 'main' into DTOSS-10571-Remove-Rule-40
2 parents 56c063a + 76dc878 commit 9eb5c3d

36 files changed

Lines changed: 880 additions & 616 deletions

File tree

application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/RetrievePDSDemographic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymou
8484
var upsertResult = await _pdsProcessor.UpsertDemographicRecordFromPDS(participantDemographic);
8585

8686
return upsertResult ?
87-
_createResponse.CreateHttpResponse(HttpStatusCode.OK, req, JsonSerializer.Serialize(participantDemographic)) :
87+
_createResponse.CreateHttpResponse(HttpStatusCode.OK, req, JsonSerializer.Serialize(pdsDemographic)) :
8888
_createResponse.CreateHttpResponse(HttpStatusCode.InternalServerError, req);
8989
}
9090
catch (Exception ex)

application/CohortManager/src/Functions/Functions.sln

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthClientCredentialsTests"
231231
EndProject
232232
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PdsProcesserTests", "PdsProcesserTests", "{5555D2A1-8C8F-5B64-9F84-08EFE0FC7CD8}"
233233
EndProject
234-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdsProcessorTests", "..\..\..\..\tests\PdsProcessorTests\PdsProcessorTests.csproj", "{FC22C311-57DD-B069-4041-AD2AC8F80B5D}"
234+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdsProcessorTests", "..\..\..\..\tests\UnitTests\PdsProcessorTests\PdsProcessorTests.csproj", "{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}"
235235
EndProject
236236
Global
237237
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -1371,18 +1371,18 @@ Global
13711371
{59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x64.Build.0 = Release|Any CPU
13721372
{59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x86.ActiveCfg = Release|Any CPU
13731373
{59CBDBE5-29BE-F38C-80E6-40843F2F8AF6}.Release|x86.Build.0 = Release|Any CPU
1374-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1375-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
1376-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x64.ActiveCfg = Debug|Any CPU
1377-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x64.Build.0 = Debug|Any CPU
1378-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x86.ActiveCfg = Debug|Any CPU
1379-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Debug|x86.Build.0 = Debug|Any CPU
1380-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1381-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|Any CPU.Build.0 = Release|Any CPU
1382-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x64.ActiveCfg = Release|Any CPU
1383-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x64.Build.0 = Release|Any CPU
1384-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x86.ActiveCfg = Release|Any CPU
1385-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D}.Release|x86.Build.0 = Release|Any CPU
1374+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1375+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
1376+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|x64.ActiveCfg = Debug|Any CPU
1377+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|x64.Build.0 = Debug|Any CPU
1378+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|x86.ActiveCfg = Debug|Any CPU
1379+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Debug|x86.Build.0 = Debug|Any CPU
1380+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
1381+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|Any CPU.Build.0 = Release|Any CPU
1382+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|x64.ActiveCfg = Release|Any CPU
1383+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|x64.Build.0 = Release|Any CPU
1384+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|x86.ActiveCfg = Release|Any CPU
1385+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0}.Release|x86.Build.0 = Release|Any CPU
13861386
EndGlobalSection
13871387
GlobalSection(SolutionProperties) = preSolution
13881388
HideSolutionNode = FALSE
@@ -1444,6 +1444,6 @@ Global
14441444
{52C72C2E-9A76-4ECF-A210-C3F7C584C193} = {19500E0D-AAAB-6F02-E24F-82619ACA2290}
14451445
{4BD680A2-1ACB-7D6B-B2FD-8EBE9AEB5050} = {E8E33C5F-F9FB-3ACA-2B58-298ED48517C1}
14461446
{59CBDBE5-29BE-F38C-80E6-40843F2F8AF6} = {E8E33C5F-F9FB-3ACA-2B58-298ED48517C1}
1447-
{FC22C311-57DD-B069-4041-AD2AC8F80B5D} = {5555D2A1-8C8F-5B64-9F84-08EFE0FC7CD8}
1447+
{392B3D99-C5C5-DB9F-4DCA-F389E679C7C0} = {5555D2A1-8C8F-5B64-9F84-08EFE0FC7CD8}
14481448
EndGlobalSection
14491449
EndGlobal

application/CohortManager/src/Functions/ParticipantManagementServices/ManageServiceNowParticipant/ManageServiceNowParticipantFunction.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public async Task Run([ServiceBusTrigger(topicName: "%ServiceNowParticipantManag
4141
{
4242
try
4343
{
44-
var participantDemographic = await ValidateAndRetrieveParticipantFromPds(serviceNowParticipant);
45-
if (participantDemographic is null)
44+
var pdsDemographic = await ValidateAndRetrieveParticipantFromPds(serviceNowParticipant);
45+
if (pdsDemographic is null)
4646
{
4747
return;
4848
}
@@ -58,7 +58,7 @@ public async Task Run([ServiceBusTrigger(topicName: "%ServiceNowParticipantManag
5858

5959
// TODO: Add call to subscribe to NEMS (DTOSS-3881)
6060

61-
var participantForDistribution = new BasicParticipantCsvRecord(serviceNowParticipant, participantDemographic, participantManagement);
61+
var participantForDistribution = new BasicParticipantCsvRecord(serviceNowParticipant, pdsDemographic, participantManagement);
6262

6363
var sendToQueueSuccess = await _queueClient.AddAsync(participantForDistribution, _config.CohortDistributionTopic);
6464

@@ -73,7 +73,7 @@ public async Task Run([ServiceBusTrigger(topicName: "%ServiceNowParticipantManag
7373
}
7474
}
7575

76-
private async Task<ParticipantDemographic?> ValidateAndRetrieveParticipantFromPds(ServiceNowParticipant serviceNowParticipant)
76+
private async Task<PdsDemographic?> ValidateAndRetrieveParticipantFromPds(ServiceNowParticipant serviceNowParticipant)
7777
{
7878
var pdsResponse = await _httpClientFunction.SendGetResponse($"{_config.RetrievePdsDemographicURL}?nhsNumber={serviceNowParticipant.NhsNumber}");
7979
string responseMessage = await _httpClientFunction.GetResponseText(pdsResponse);
@@ -90,37 +90,37 @@ public async Task Run([ServiceBusTrigger(topicName: "%ServiceNowParticipantManag
9090
return null;
9191
}
9292

93-
var participantDemographic = await DeserializeParticipantDemographic(pdsResponse, serviceNowParticipant);
94-
if (participantDemographic is null) return null;
93+
var pdsDemographic = await DeserializePdsDemographic(pdsResponse, serviceNowParticipant);
94+
if (pdsDemographic is null) return null;
9595

96-
return await ValidateParticipantData(serviceNowParticipant, participantDemographic)
97-
? participantDemographic
96+
return await ValidateParticipantData(serviceNowParticipant, pdsDemographic)
97+
? pdsDemographic
9898
: null;
9999
}
100100

101-
private async Task<ParticipantDemographic?> DeserializeParticipantDemographic(HttpResponseMessage pdsResponse, ServiceNowParticipant serviceNowParticipant)
101+
private async Task<PdsDemographic?> DeserializePdsDemographic(HttpResponseMessage pdsResponse, ServiceNowParticipant serviceNowParticipant)
102102
{
103103
var jsonString = await pdsResponse.Content.ReadAsStringAsync();
104-
var participantDemographic = JsonSerializer.Deserialize<ParticipantDemographic>(jsonString);
104+
var pdsDemographic = JsonSerializer.Deserialize<PdsDemographic>(jsonString);
105105

106-
if (participantDemographic is null)
106+
if (pdsDemographic is null)
107107
{
108-
await HandleException(new Exception($"Deserialisation of PDS for ServiceNow Participant response to {typeof(ParticipantDemographic)} returned null"), serviceNowParticipant, ServiceNowMessageType.AddRequestInProgress);
108+
await HandleException(new Exception($"Deserialisation of PDS for ServiceNow Participant response to {typeof(PdsDemographic)} returned null"), serviceNowParticipant, ServiceNowMessageType.AddRequestInProgress);
109109
return null;
110110
}
111111

112-
return participantDemographic;
112+
return pdsDemographic;
113113
}
114114

115-
private async Task<bool> ValidateParticipantData(ServiceNowParticipant serviceNowParticipant, ParticipantDemographic participantDemographic)
115+
private async Task<bool> ValidateParticipantData(ServiceNowParticipant serviceNowParticipant, PdsDemographic pdsDemographic)
116116
{
117-
if (participantDemographic.NhsNumber != serviceNowParticipant.NhsNumber)
117+
if (pdsDemographic.NhsNumber != serviceNowParticipant.NhsNumber.ToString())
118118
{
119119
await HandleException(new Exception("NHS Numbers don't match for ServiceNow Participant and PDS, NHS Number must have been superseded"), serviceNowParticipant, ServiceNowMessageType.UnableToAddParticipant);
120120
return false;
121121
}
122122

123-
if (!CheckParticipantDataMatches(serviceNowParticipant, participantDemographic))
123+
if (!CheckParticipantDataMatches(serviceNowParticipant, pdsDemographic))
124124
{
125125
await HandleException(new Exception("Participant data from ServiceNow does not match participant data from PDS"), serviceNowParticipant, ServiceNowMessageType.UnableToAddParticipant);
126126
return false;
@@ -219,11 +219,11 @@ private async Task HandleException(Exception exception, ServiceNowParticipant se
219219
await SendServiceNowMessage(serviceNowParticipant.ServiceNowCaseNumber, serviceNowMessageType);
220220
}
221221

222-
private static bool CheckParticipantDataMatches(ServiceNowParticipant serviceNowParticipant, ParticipantDemographic participantDemographic)
222+
private static bool CheckParticipantDataMatches(ServiceNowParticipant serviceNowParticipant, PdsDemographic pdsDemographic)
223223
{
224-
return serviceNowParticipant.FirstName == participantDemographic.GivenName &&
225-
serviceNowParticipant.FamilyName == participantDemographic.FamilyName &&
226-
serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd") == participantDemographic.DateOfBirth;
224+
return serviceNowParticipant.FirstName == pdsDemographic.FirstName &&
225+
serviceNowParticipant.FamilyName == pdsDemographic.FamilyName &&
226+
serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd") == pdsDemographic.DateOfBirth;
227227
}
228228

229229
private async Task SendServiceNowMessage(string serviceNowCaseNumber, ServiceNowMessageType servicenowMessageType)

application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public async Task<BlockParticipantResult> GetParticipant(BlockParticipantDto blo
141141
var pdsRecordsMatch = ValidateRecordsMatch(pdsParticipant, blockParticipantRequest);
142142
var pdsResponseBody = JsonSerializer.Serialize(new BlockParticipantDto
143143
{
144-
NhsNumber = pdsParticipant.NhsNumber,
144+
NhsNumber = long.Parse(pdsParticipant.NhsNumber),
145145
FamilyName = pdsParticipant.FamilyName!,
146146
DateOfBirth = pdsParticipant.DateOfBirth!
147147
});
@@ -161,7 +161,7 @@ private async Task<BlockParticipantResult> BlockNewParticipant(BlockParticipantD
161161

162162
var participantManagementRecord = new ParticipantManagement
163163
{
164-
NHSNumber = pdsParticipant.NhsNumber,
164+
NHSNumber = long.Parse(pdsParticipant.NhsNumber),
165165
BlockedFlag = 1,
166166
EligibilityFlag = 0,
167167
};
@@ -219,7 +219,7 @@ private async Task<bool> SetBlockedFlag(ParticipantManagement participant, bool
219219
return await _participantManagementDataService.Update(participant);
220220
}
221221

222-
private async Task<ParticipantDemographic> GetPDSParticipant(long nhsNumber)
222+
private async Task<PdsDemographic> GetPDSParticipant(long nhsNumber)
223223
{
224224
var pdsResponse = await _httpClient.SendGet(_config.RetrievePdsDemographicURL, CreateNhsNumberQueryParams(nhsNumber));
225225
if (string.IsNullOrEmpty(pdsResponse))
@@ -228,7 +228,7 @@ private async Task<ParticipantDemographic> GetPDSParticipant(long nhsNumber)
228228
return null!;
229229
}
230230

231-
var pdsDemographic = JsonSerializer.Deserialize<ParticipantDemographic>(pdsResponse);
231+
var pdsDemographic = JsonSerializer.Deserialize<PdsDemographic>(pdsResponse);
232232

233233
return pdsDemographic!;
234234
}
@@ -250,6 +250,23 @@ private static bool ValidateRecordsMatch(ParticipantDemographic participant, Blo
250250
&& parsedDob == dtoDateOfBirth;
251251
}
252252

253+
private static bool ValidateRecordsMatch(PdsDemographic participant, BlockParticipantDto dto)
254+
{
255+
256+
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd",new CultureInfo("en-GB"),DateTimeStyles.None, out var dtoDateOfBirth ))
257+
{
258+
throw new FormatException("Date of Birth not in the correct format");
259+
}
260+
261+
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd",new CultureInfo("en-GB"),DateTimeStyles.None, out var parsedDob))
262+
{
263+
return false;
264+
}
265+
return string.Equals(participant.FamilyName, dto.FamilyName, StringComparison.InvariantCultureIgnoreCase)
266+
&& long.Parse(participant.NhsNumber) == dto.NhsNumber
267+
&& parsedDob == dtoDateOfBirth;
268+
}
269+
253270
private static Dictionary<string, string> CreateNhsNumberQueryParams(long nhsNumber) =>
254271
new Dictionary<string, string>
255272
{

application/CohortManager/src/Functions/Shared/Common/Pagination/PaginationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Common;
22

33
public class PaginationService<T> : IPaginationService<T>
44
{
5-
private const int pageSize = 20;
5+
private const int pageSize = 10;
66

77
public PaginationResult<T> GetPaginatedResult(
88
IQueryable<T> source,
@@ -19,7 +19,7 @@ public PaginationResult<T> GetPaginatedResult(
1919
var idList = source.Select(idSelector).OrderBy(id => id).ToList();
2020

2121
// Get the index of the lastId
22-
int lastIdIndex = lastId.HasValue? idList.IndexOf(lastId.Value) : -1;
22+
int lastIdIndex = lastId.HasValue ? idList.IndexOf(lastId.Value) : -1;
2323
int currentPage = lastIdIndex >= 0 ? (lastIdIndex / pageSize) + 2 : 1;
2424
var totalItems = source.Count();
2525
var totalPages = (int)Math.Ceiling((double)totalItems / pageSize);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public static bool ValidatePostcode(string postcode)
109109
/// </remarks>
110110
public static string? ParseOutcode(string postcode)
111111
{
112+
if (postcode == "ZZZSECUR")
113+
{
114+
return postcode;
115+
}
116+
112117
string pattern = @"^([A-Za-z][A-Za-z]?[0-9][A-Za-z0-9]?) ?[0-9][A-Za-z]{2}$";
113118

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

application/CohortManager/src/Functions/Shared/Data/Database/ValidationExceptionData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public async Task<bool> UpdateExceptionServiceNowId(int exceptionId, string serv
125125
ParticipantPostCode = participantDemographic?.PostCode,
126126
TelephoneNumberHome = participantDemographic?.TelephoneNumberHome,
127127
EmailAddressHome = participantDemographic?.EmailAddressHome,
128-
PrimaryCareProvider = participantDemographic?.PrimaryCareProvider
128+
PrimaryCareProvider = participantDemographic?.PrimaryCareProvider,
129+
SupersededByNhsNumber = participantDemographic?.SupersededByNhsNumber,
129130
};
130131

131132
if (participantDemographic == null)

application/CohortManager/src/Functions/Shared/Model/BasicParticipantCsvRecord.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public BasicParticipantCsvRecord()
1717

1818
}
1919

20-
public BasicParticipantCsvRecord(ServiceNowParticipant serviceNowParticipant, ParticipantDemographic participantDemographic, ParticipantManagement? participantManagement)
20+
public BasicParticipantCsvRecord(ServiceNowParticipant serviceNowParticipant, PdsDemographic pdsDemographic, ParticipantManagement? participantManagement)
2121
{
2222
FileName = serviceNowParticipant.ServiceNowCaseNumber;
2323
BasicParticipantData = new BasicParticipantData
@@ -29,7 +29,7 @@ public BasicParticipantCsvRecord(ServiceNowParticipant serviceNowParticipant, Pa
2929
Participant = new Participant
3030
{
3131
ReferralFlag = "1",
32-
Postcode = participantDemographic.PostCode,
32+
Postcode = pdsDemographic.Postcode,
3333
ScreeningAcronym = "BSS" // TODO: Remove hardcoding when adding support for additional screening programs
3434
};
3535
}

application/CohortManager/src/Functions/Shared/Model/EFModels/ExceptionManagement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ public ValidationException ToValidationException()
6565
return new ValidationException
6666
{
6767
ExceptionId = ExceptionId,
68-
FileName = FileName,
6968
NhsNumber = NhsNumber,
7069
DateCreated = DateCreated,
7170
DateResolved = DateResolved,
7271
RuleId = RuleId,
7372
RuleDescription = RuleDescription,
74-
ErrorRecord = ErrorRecord,
7573
Category = Category,
7674
ScreeningName = ScreeningName,
7775
ExceptionDate = ExceptionDate,

application/CohortManager/src/Functions/Shared/Model/ExceptionDetails.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class ExceptionDetails
1717
public string? EmailAddressHome { get; set; }
1818
public string? PrimaryCareProvider { get; set; }
1919
public Gender? Gender { get; set; }
20+
public long? SupersededByNhsNumber { get; set; }
2021
}

0 commit comments

Comments
 (0)