-
Notifications
You must be signed in to change notification settings - Fork 2
chore: adding unit tests for PDS functionality #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SamRobinson75684
merged 13 commits into
main
from
fix/DTOSS-10515-Handling-not-found-in-pds-func
Aug 11, 2025
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b902893
fix: pds function now maganges all responses from the 3rd party pds API
SamRobinson75684 932be90
chore: creating a new class that contains all the pds constraints
SamRobinson75684 7d9a210
Merge branch 'main' into Fix/DTOSS-10515-Handling-not-found-in-pds-func
SamRobinson75684 efe831b
Merge branch 'Fix/DTOSS-10515-Handling-not-found-in-pds-func' of http…
SamRobinson75684 d74c0bc
chore: removing unneeded codes
SamRobinson75684 35d65c7
Merge branch 'main' into Fix/DTOSS-10515-Handling-not-found-in-pds-func
SamRobinson75684 3a5e801
chore: renaming ProcessPdsResponse to ProcessPdsNotFoundResponse
SamRobinson75684 a101923
fix: making sure to add service buss to pds
SamRobinson75684 a75af90
Merge branch 'main' into fix/DTOSS-10515-Handling-not-found-in-pds-func
SamRobinson75684 b677c11
chor: adding unit tests for pds functions features
SamRobinson75684 dbe57dc
Merge branch 'main' into fix/DTOSS-10515-Handling-not-found-in-pds-func
SamRobinson75684 6e12730
chore: addressing comments on pr
SamRobinson75684 58647a2
Merge branch 'main' into fix/DTOSS-10515-Handling-not-found-in-pds-func
SamRobinson75684 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...n/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/IPdsProcessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace NHS.CohortManager.DemographicServices; | ||
|
|
||
| using Model; | ||
|
|
||
| public interface IPdsProcessor | ||
| { | ||
| Task ProcessPdsNotFoundResponse(HttpResponseMessage pdsResponse, string nhsNumber); | ||
| Task ProcessRecord(Participant participant); | ||
| Task<bool> UpsertDemographicRecordFromPDS(ParticipantDemographic participantDemographic); | ||
| } | ||
110 changes: 110 additions & 0 deletions
110
...on/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/PdsProcessor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| namespace NHS.CohortManager.DemographicServices; | ||
|
|
||
| using System.Collections.Concurrent; | ||
| using System.Net.Http.Json; | ||
| using Common; | ||
| using DataServices.Client; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Options; | ||
| using Model; | ||
|
|
||
| public class PdsProcessor : IPdsProcessor | ||
| { | ||
| private readonly ILogger<PdsProcessor> _logger; | ||
|
|
||
| private readonly IDataServiceClient<ParticipantDemographic> _participantDemographicClient; | ||
| private readonly ICreateBasicParticipantData _createBasicParticipantData; | ||
| private readonly RetrievePDSDemographicConfig _config; | ||
| private readonly IAddBatchToQueue _addBatchToQueue; | ||
|
|
||
|
|
||
| public PdsProcessor( | ||
| ILogger<PdsProcessor> logger, | ||
| ICreateBasicParticipantData createBasicParticipantData, | ||
| IDataServiceClient<ParticipantDemographic> participantDemographicClient, | ||
| IAddBatchToQueue addBatchToQueue, | ||
| IOptions<RetrievePDSDemographicConfig> retrievePDSDemographicConfig) | ||
| { | ||
| _logger = logger; | ||
| _participantDemographicClient = participantDemographicClient; | ||
| _createBasicParticipantData = createBasicParticipantData; | ||
| _addBatchToQueue = addBatchToQueue; | ||
| _config = retrievePDSDemographicConfig.Value; | ||
| } | ||
|
|
||
| public async Task ProcessPdsNotFoundResponse(HttpResponseMessage pdsResponse, string nhsNumber) | ||
| { | ||
| var errorResponse = await pdsResponse!.Content.ReadFromJsonAsync<PdsErrorResponse>(); | ||
| // we now create a record as an update record and send to the manage participant function. Reason for removal for date should be today and the reason for remove of ORR | ||
| if (errorResponse!.issue!.FirstOrDefault()!.details!.coding!.FirstOrDefault()!.code == PdsConstants.InvalidatedResourceCode) | ||
| { | ||
| var pdsDemographic = new PdsDemographic() | ||
| { | ||
| NhsNumber = nhsNumber, | ||
| PrimaryCareProvider = null, | ||
| ReasonForRemoval = PdsConstants.OrrRemovalReason, | ||
| RemovalEffectiveFromDate = DateTime.UtcNow.Date.ToString("yyyyMMdd") | ||
| }; | ||
| var participant = new Participant(pdsDemographic); | ||
| participant.RecordType = Actions.Removed; | ||
| //sends record for an update | ||
| await ProcessRecord(participant); | ||
| return; | ||
| } | ||
| _logger.LogError("the PDS function has returned a 404 error. function now stopping processing"); | ||
| } | ||
|
|
||
|
|
||
| public async Task ProcessRecord(Participant participant) | ||
| { | ||
| var updateRecord = new ConcurrentQueue<BasicParticipantCsvRecord>(); | ||
| participant.RecordType = participant.RecordType = Actions.Removed; | ||
|
SamRobinson75684 marked this conversation as resolved.
Outdated
|
||
|
|
||
| var basicParticipantCsvRecord = new BasicParticipantCsvRecord | ||
| { | ||
| BasicParticipantData = _createBasicParticipantData.BasicParticipantData(participant), | ||
| FileName = PdsConstants.DefaultFileName, | ||
| Participant = participant | ||
| }; | ||
|
|
||
| updateRecord.Enqueue(basicParticipantCsvRecord); | ||
|
|
||
| _logger.LogInformation("Sending record to the update queue."); | ||
| await _addBatchToQueue.ProcessBatch(updateRecord, _config.ParticipantManagementTopic); | ||
| } | ||
|
|
||
|
|
||
| public async Task<bool> UpsertDemographicRecordFromPDS(ParticipantDemographic participantDemographic) | ||
| { | ||
| ParticipantDemographic oldParticipantDemographic = await _participantDemographicClient.GetSingleByFilter(i => i.NhsNumber == participantDemographic.NhsNumber); | ||
|
|
||
| if (oldParticipantDemographic == null) | ||
| { | ||
| _logger.LogInformation("Participant Demographic record not found, attemping to add Participant Demographic."); | ||
| bool addSuccess = await _participantDemographicClient.Add(participantDemographic); | ||
|
|
||
| if (addSuccess) | ||
| { | ||
| _logger.LogInformation("Successfully added Participant Demographic."); | ||
| return true; | ||
| } | ||
|
|
||
| _logger.LogError("Failed to add Participant Demographic."); | ||
| return false; | ||
| } | ||
|
|
||
| _logger.LogInformation("Participant Demographic record found, attempting to update Participant Demographic."); | ||
| participantDemographic.ParticipantId = oldParticipantDemographic.ParticipantId; | ||
| bool updateSuccess = await _participantDemographicClient.Update(participantDemographic); | ||
|
|
||
| if (updateSuccess) | ||
| { | ||
| _logger.LogInformation("Successfully updated Participant Demographic."); | ||
| return true; | ||
| } | ||
|
|
||
| _logger.LogError("Failed to update Participant Demographic."); | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.