Skip to content

Fix: [AEA-6446] - Bug fix single patient return not loading prescription findings#1975

Open
connoravo-nhs wants to merge 4 commits intomainfrom
AEA-6327-fix-single-patient-return
Open

Fix: [AEA-6446] - Bug fix single patient return not loading prescription findings#1975
connoravo-nhs wants to merge 4 commits intomainfrom
AEA-6327-fix-single-patient-return

Conversation

@connoravo-nhs
Copy link
Copy Markdown
Contributor

Summary

  • Routine Change

Details

Fix the bug where a single patient returned on basic details search was being incorrectly redirected to search by prescription ID page, because it didn't have the searchType handled correctly.

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 27, 2026 16:49
@github-actions
Copy link
Copy Markdown
Contributor

This PR is linked to a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket:

AEA-6327

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a navigation bug in the CPT UI where a single patient result from a basic-details search could lead to an incorrect redirect (preventing prescription findings from loading) by ensuring the subsequent prescription list lookup uses the correct searchType.

Changes:

  • Ensure searchType is set to "nhs" when basic-details search returns exactly one patient and the flow pivots to an NHS-number-based prescription lookup.
  • Add additional logging when NavigationProvider.getRelevantSearchParameters can’t return parameters for the requested search type.
  • Update the unit test expectation for the single-result basic-details search flow.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/cpt-ui/src/pages/PrescriptionListPage.tsx Minor condition formatting for the basic-details redirect guard.
packages/cpt-ui/src/pages/BasicDetailsSearchResultsPage.tsx Sets searchType: "nhs" when exactly one patient is returned.
packages/cpt-ui/src/context/NavigationProvider.tsx Adds an info log when relevant search parameters aren’t available.
packages/cpt-ui/__tests__/BasicDetailsSearchResultsPage.test.tsx Updates expectation to include searchType: "nhs" for the single-result flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 152 to 161
if (payload.length === 1) {
const relevantParams =
navigationContext.getRelevantSearchParameters("basicDetails")
// Set the search type before attempting search again
// As we'll now be using the nhs number search
searchContext.setAllSearchParameters({
...relevantParams,
nhsNumber: payload[0].nhsNumber
nhsNumber: payload[0].nhsNumber,
searchType: "nhs"
})
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setAllSearchParameters overwrites searchType; this block correctly sets searchType: "nhs" for the single-result path, but the row-click path in the same page still calls setAllSearchParameters without searchType, which will clear it and can cause PrescriptionListPage to hit the default case and redirect to prescription-ID search. Consider also setting the appropriate searchType (and updating the related row-click/link/key navigation tests accordingly) so navigation is consistent for both single and multi-result flows.

Copilot uses AI. Check for mistakes.
Comment on lines +163 to +166
logger.info("Navigation: No relevant search parameters found", {
searchType,
originalSearchParameters
})
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log line includes originalSearchParameters, which can contain patient identifiers (e.g. NHS number, name, postcode). Logging these at info level risks leaking PII into browser logs and creates noisy telemetry since getRelevantSearchParameters is called frequently. Consider removing the parameters from the log (or redacting sensitive fields) and/or downgrading to debug/trace.

Copilot uses AI. Check for mistakes.
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
@connoravo-nhs connoravo-nhs changed the title Fix: [AEA-6327] - Bug fix single patient return not loading prescription findings Fix: [AEA-6446] - Bug fix single patient return not loading prescription findings Mar 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants