Skip to content

Commit 93e4813

Browse files
Merge branch 'main' into Fix/DTOSS-0000-accidently-created-tests-in-wrong-place
2 parents ec8c277 + c213c2a commit 93e4813

6 files changed

Lines changed: 121 additions & 48 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/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/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
}

tests/UnitTests/ParticipantManagementServicesTests/ManageServiceNowParticipantTests/ManageServiceNowParticipantFunctionTests.cs

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public async Task Run_WhenNoPdsMatch_SendsServiceNowMessageType1()
113113
public async Task Run_WhenNhsNumberSuperseded_SendsServiceNowMessageType1()
114114
{
115115
// Arrange
116-
var json = JsonSerializer.Serialize(new ParticipantDemographic
116+
var json = JsonSerializer.Serialize(new PdsDemographic
117117
{
118-
NhsNumber = 123
118+
NhsNumber = "123"
119119
});
120120
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={_serviceNowParticipant.NhsNumber}"))
121121
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
@@ -205,10 +205,10 @@ public async Task Run_WhenParticipantDataDoesNotMatchPdsData_SendsServiceNowMess
205205
string firstName, string familyName, string dateOfBirth)
206206
{
207207
// Arrange
208-
var json = JsonSerializer.Serialize(new ParticipantDemographic
208+
var json = JsonSerializer.Serialize(new PdsDemographic
209209
{
210-
NhsNumber = _serviceNowParticipant.NhsNumber,
211-
GivenName = firstName,
210+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
211+
FirstName = firstName,
212212
FamilyName = familyName,
213213
DateOfBirth = dateOfBirth
214214
});
@@ -241,7 +241,14 @@ public async Task Run_WhenParticipantDataDoesNotMatchPdsData_SendsServiceNowMess
241241
public async Task Run_WhenServiceNowParticipantIsValidAndDoesNotExistInTheDataStore_AddsTheNewParticipant()
242242
{
243243
// Arrange
244-
var json = JsonSerializer.Serialize(_demographic);
244+
var json = JsonSerializer.Serialize(new PdsDemographic
245+
{
246+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
247+
FirstName = _serviceNowParticipant.FirstName,
248+
FamilyName = _serviceNowParticipant.FamilyName,
249+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
250+
Postcode = "SW1A 2AA"
251+
});
245252
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={_serviceNowParticipant.NhsNumber}"))
246253
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
247254
{
@@ -292,7 +299,14 @@ public async Task Run_WhenServiceNowParticipantIsValidAndDoesNotExistInTheDataSt
292299
public async Task Run_WhenServiceNowParticipantIsValidAndExistsInTheDataStoreButIsBlocked_DoesNotUpdateTheParticipantAndSendsMessageType1()
293300
{
294301
// Arrange
295-
var json = JsonSerializer.Serialize(_demographic);
302+
var json = JsonSerializer.Serialize(new PdsDemographic
303+
{
304+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
305+
FirstName = _serviceNowParticipant.FirstName,
306+
FamilyName = _serviceNowParticipant.FamilyName,
307+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
308+
Postcode = "SW1A 2AA"
309+
});
296310
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={_serviceNowParticipant.NhsNumber}"))
297311
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
298312
{
@@ -341,7 +355,14 @@ public async Task Run_WhenServiceNowParticipantIsValidAndExistsInTheDataStoreBut
341355
public async Task Run_WhenServiceNowParticipantIsValidAndExistsInTheDataStoreAndIsNotBlocked_UpdatesTheParticipant()
342356
{
343357
// Arrange
344-
var json = JsonSerializer.Serialize(_demographic);
358+
var json = JsonSerializer.Serialize(new PdsDemographic
359+
{
360+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
361+
FirstName = _serviceNowParticipant.FirstName,
362+
FamilyName = _serviceNowParticipant.FamilyName,
363+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
364+
Postcode = "SW1A 2AA"
365+
});
345366
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={_serviceNowParticipant.NhsNumber}"))
346367
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
347368
{
@@ -405,7 +426,14 @@ public async Task Run_WhenServiceNowParticipantIsVhrAndDoesNotExistInDataStore_A
405426
ReasonForAdding = ServiceNowReasonsForAdding.VeryHighRisk
406427
};
407428

408-
var json = JsonSerializer.Serialize(_demographic);
429+
var json = JsonSerializer.Serialize(new PdsDemographic
430+
{
431+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
432+
FirstName = _serviceNowParticipant.FirstName,
433+
FamilyName = _serviceNowParticipant.FamilyName,
434+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
435+
Postcode = "SW1A 2AA"
436+
});
409437

410438
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={vhrParticipant.NhsNumber}"))
411439
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
@@ -461,7 +489,14 @@ public async Task Run_WhenServiceNowParticipantIsVhrAndDoesNotExistInDataStore_A
461489
public async Task Run_WhenServiceNowParticipantIsNotVhrAndDoesNotExistInDataStore_AddsNewParticipantWithoutVhrFlag()
462490
{
463491
// Arrange
464-
var json = JsonSerializer.Serialize(_demographic);
492+
var json = JsonSerializer.Serialize(new PdsDemographic
493+
{
494+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
495+
FirstName = _serviceNowParticipant.FirstName,
496+
FamilyName = _serviceNowParticipant.FamilyName,
497+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
498+
Postcode = "SW1A 2AA"
499+
});
465500

466501
_httpClientFunctionMock.Setup(x => x.SendGetResponse($"{_configMock.Object.Value.RetrievePdsDemographicURL}?nhsNumber={_serviceNowParticipant.NhsNumber}"))
467502
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
@@ -528,7 +563,14 @@ public async Task Run_WhenVhrParticipantExistsWithNullVhrFlag_SetsVhrFlagToTrue(
528563
ReasonForAdding = ServiceNowReasonsForAdding.VeryHighRisk
529564
};
530565

531-
var json = JsonSerializer.Serialize(_demographic);
566+
var json = JsonSerializer.Serialize(new PdsDemographic
567+
{
568+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
569+
FirstName = _serviceNowParticipant.FirstName,
570+
FamilyName = _serviceNowParticipant.FamilyName,
571+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
572+
Postcode = "SW1A 2AA"
573+
});
532574

533575
var existingParticipant = new ParticipantManagement
534576
{
@@ -594,7 +636,14 @@ public async Task Run_WhenVhrParticipantExistsWithNullVhrFlag_SetsVhrFlagToTrue(
594636
public async Task Run_WhenParticipantExistsWithVhrFlagAlreadySet_MaintainsVhrFlag()
595637
{
596638
// Arrange
597-
var json = JsonSerializer.Serialize(_demographic);
639+
var json = JsonSerializer.Serialize(new PdsDemographic
640+
{
641+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
642+
FirstName = _serviceNowParticipant.FirstName,
643+
FamilyName = _serviceNowParticipant.FamilyName,
644+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
645+
Postcode = "SW1A 2AA"
646+
});
598647

599648
var existingParticipant = new ParticipantManagement
600649
{
@@ -659,7 +708,14 @@ public async Task Run_WhenParticipantExistsWithVhrFlagAlreadySet_MaintainsVhrFla
659708
public async Task Run_WhenNonVhrParticipantExistsWithNullVhrFlag_LeavesVhrFlagAsNull()
660709
{
661710
// Arrange
662-
var json = JsonSerializer.Serialize(_demographic);
711+
var json = JsonSerializer.Serialize(new PdsDemographic
712+
{
713+
NhsNumber = _serviceNowParticipant.NhsNumber.ToString(),
714+
FirstName = _serviceNowParticipant.FirstName,
715+
FamilyName = _serviceNowParticipant.FamilyName,
716+
DateOfBirth = _serviceNowParticipant.DateOfBirth.ToString("yyyy-MM-dd"),
717+
Postcode = "SW1A 2AA"
718+
});
663719

664720
var existingParticipant = new ParticipantManagement
665721
{

0 commit comments

Comments
 (0)