Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0904a5b
[PRMP-975] add util to extract relevant querystring params
steph-torres-nhs Jan 6, 2026
d6a88c5
[PRMP-975] remove functionality of searching multiple tables
steph-torres-nhs Jan 6, 2026
e7d8076
Merge branch 'main' into PRMP-975
steph-torres-nhs Jan 9, 2026
0aae733
[PRMP-975] extract limit from querystring
steph-torres-nhs Jan 12, 2026
65e3deb
[PRMP-975] add pagination to doc ref search service
steph-torres-nhs Jan 12, 2026
50a322b
[PRMP-975] add query with pagination to doc ref search
steph-torres-nhs Jan 12, 2026
44d0f47
[PRMP-975] amend how filter is handled
steph-torres-nhs Jan 13, 2026
ed30447
[PRMP-975] update lg dynamo mock response
steph-torres-nhs Jan 13, 2026
7ff97f9
[PRMP-975] update lg dynamo mock response
steph-torres-nhs Jan 13, 2026
45ce75d
[PRMP-975] add filter build helper
steph-torres-nhs Jan 13, 2026
21135cd
[PRMP-975] camelize response
steph-torres-nhs Jan 13, 2026
47520bb
[PRMP-975] add test
steph-torres-nhs Jan 13, 2026
a360b9e
Merge branch 'main' into PRMP-975
steph-torres-nhs Jan 13, 2026
0968a90
[PRMP-975] address PR comments
steph-torres-nhs Jan 14, 2026
402ac05
[PRMP-975] format
steph-torres-nhs Jan 14, 2026
f86d414
[PRMP-975] adjust filter expression
steph-torres-nhs Jan 14, 2026
887bebb
[PRMP-975] change getDocSearchResults response object
steph-torres-nhs Jan 15, 2026
e3f19ed
[PRMP-975] check 204 response, upload complete filter
steph-torres-nhs Jan 16, 2026
1bbf5ad
Merge branch 'main' into PRMP-975
steph-torres-nhs Jan 16, 2026
c2f10ff
Merge branch 'main' into PRMP-975
steph-torres-nhs Jan 19, 2026
176fb90
[PRMP-975] amend stubbed response e2e tests
steph-torres-nhs Jan 19, 2026
bbd75fd
[PRMP-975] update branch, resolve conflicts
steph-torres-nhs Feb 4, 2026
42f5a3a
[PRMP-975] refactor test
steph-torres-nhs Feb 4, 2026
67a41f8
[PRMP-975] format
steph-torres-nhs Feb 4, 2026
d8dd9ee
[PRMP-975] only return upload compelete document references
steph-torres-nhs Feb 4, 2026
bc727ca
[PRMP-975] remove redundant response
steph-torres-nhs Feb 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ describe('GP Workflow: View Lloyd George record', () => {

cy.intercept('GET', '/SearchDocumentReferences*', {
statusCode: 200,
body: testFiles,
body: {
references: testFiles,
nextPageToken: 'abc',
},
}).as('searchDocumentReferences');

cy.get('#verify-submit').click();
Expand All @@ -142,7 +145,10 @@ describe('GP Workflow: View Lloyd George record', () => {

cy.intercept('GET', '/SearchDocumentReferences*', {
statusCode: 200,
body: testFiles,
body: {
references: testFiles,
nextPageToken: 'abc',
},
}).as('searchDocumentReferences');

setUpDownloadManifestIntercepts();
Expand Down Expand Up @@ -259,7 +265,10 @@ describe('GP Workflow: View Lloyd George record', () => {

cy.intercept('GET', '/SearchDocumentReferences*', {
statusCode: 200,
body: singleTestFile,
body: {
references: singleTestFile,
nextPageToken: 'abc'
},
}).as('searchDocumentReferences');

setUpDownloadManifestIntercepts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ describe('PCSE Workflow: Access and download found files', () => {

cy.intercept('GET', '/SearchDocumentReferences*', {
statusCode: 200,
body: searchDocumentReferencesResponse,
body: {
references: searchDocumentReferencesResponse,
nextPageToken: 'abc',
},
}).as('documentSearch');

cy.get('#verify-submit').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ const mockUseConfig = useConfig as Mock;

const testFileName1 = 'John_1';
const testFileName2 = 'John_2';
const searchResults = [
buildSearchResult({ fileName: testFileName1 }),
buildSearchResult({ fileName: testFileName2 }),
];
const searchResults = {
references: [
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need references property here

buildSearchResult({ fileName: testFileName1 }),
buildSearchResult({ fileName: testFileName2 }),
],
};

let history = createMemoryHistory({
initialEntries: ['/'],
Expand Down Expand Up @@ -124,8 +126,8 @@ describe('RemoveRecordStage', () => {
).toBeInTheDocument();
});

expect(screen.getByText(searchResults[0].fileName)).toBeInTheDocument();
expect(screen.getByText(searchResults[1].fileName)).toBeInTheDocument();
expect(screen.getByText(searchResults.references[0].fileName)).toBeInTheDocument();
expect(screen.getByText(searchResults.references[1].fileName)).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('[GET] getDocumentSearchResults', () => {

test('Document search results handles a 2XX response', async () => {
const searchResult = buildSearchResult();
const mockResults = [searchResult];
const mockResults = { references: [searchResult] };
mockedAxios.get.mockImplementation(() =>
Promise.resolve({ status: 200, data: mockResults }),
);
Expand Down
7 changes: 4 additions & 3 deletions app/src/helpers/requests/getDocumentSearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type DocumentSearchResultsArgs = {
};

export type GetDocumentSearchResultsResponse = {
data: Array<SearchResult>;
references: Array<SearchResult>;
Copy link
Contributor

Choose a reason for hiding this comment

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

arn't you missing nextPageToken here?

};

const getDocumentSearchResults = async ({
Expand All @@ -26,16 +26,17 @@ const getDocumentSearchResults = async ({
const gatewayUrl = baseUrl + endpoints.DOCUMENT_SEARCH;

try {
const response: GetDocumentSearchResultsResponse = await axios.get(gatewayUrl, {
const { data } = await axios.get<GetDocumentSearchResultsResponse>(gatewayUrl, {
headers: {
...baseHeaders,
},
params: {
patientId: nhsNumber?.replaceAll(/\s/g, ''), // replace whitespace
docType: docType == DOCUMENT_TYPE.ALL ? undefined : docType,
limit: 9999,
},
});
return response?.data;
return data.references;
} catch (e) {
if (isLocal) {
return [
Expand Down
2 changes: 2 additions & 0 deletions lambdas/enums/dynamo_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ class AttributeOperator(Enum):
class ConditionOperator(Enum):
OR = "|"
AND = "&"
EQUAL = "="
NOT_EQUAL = "<>"
46 changes: 28 additions & 18 deletions lambdas/handlers/document_reference_search_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@
from utils.decorators.override_error_check import override_error_check
from utils.decorators.set_audit_arg import set_request_context_for_logging
from utils.decorators.validate_patient_id import (
extract_nhs_number_from_event,
validate_patient_id,
)
from utils.document_type_utils import extract_document_type_to_enum
from utils.lambda_exceptions import DocumentRefSearchException
from utils.lambda_response import ApiGatewayResponse
from utils.request_context import request_context
from utils.utilities import camelize_dict

logger = LoggingService(__name__)


@set_request_context_for_logging
@validate_patient_id
@ensure_environment_variables(names=["DYNAMODB_TABLE_LIST"])
@ensure_environment_variables(names=["LLOYD_GEORGE_DYNAMODB_NAME"])
@override_error_check
@handle_lambda_exceptions
def lambda_handler(event, context):
request_context.app_interaction = LoggingAppInteraction.VIEW_PATIENT.value
logger.info("Starting document reference search process")

nhs_number = extract_nhs_number_from_event(event)
nhs_number, next_page_token, limit = extract_querystring_params(event)

doc_type = event.get("queryStringParameters", {}).get("docType", None)
try:
document_snomed_code = extract_document_type_to_enum(doc_type) if doc_type else None
document_snomed_code = (
extract_document_type_to_enum(doc_type) if doc_type else None
)
except ValueError:
raise DocumentRefSearchException(400, LambdaError.DocTypeInvalid)

Expand All @@ -48,25 +50,33 @@ def lambda_handler(event, context):
doc_upload_iteration2_enabled = upload_lambda_enabled_flag_object[
FeatureFlags.UPLOAD_DOCUMENT_ITERATION_2_ENABLED
]

additional_filters = {}
if doc_upload_iteration2_enabled:
additional_filters["doc_status"] = "final"
if document_snomed_code:
additional_filters["document_snomed_code"] = document_snomed_code[0].value

response = document_reference_search_service.get_document_references(
nhs_number,
check_upload_completed=True,
additional_filters=additional_filters
logger.info("Searching for patient references with pagination.")

response_dict = (
document_reference_search_service.get_paginated_references_by_nhs_number(
nhs_number=nhs_number,
limit=limit,
next_page_token=next_page_token,
filter=additional_filters,
)
)
response = camelize_dict(response_dict)
logger.info("User is able to view docs", {"Result": "Successful viewing docs"})

if response:
return ApiGatewayResponse(
200, json.dumps(response), "GET"
).create_api_gateway_response()
else:
return ApiGatewayResponse(
204, json.dumps([]), "GET"
).create_api_gateway_response()
return ApiGatewayResponse(
200, json.dumps(response), "GET"
).create_api_gateway_response()


def extract_querystring_params(event):
nhs_number = event["queryStringParameters"]["patientId"]
next_page_token = event["queryStringParameters"].get("nextPageToken")
limit = event["queryStringParameters"].get("limit")

return nhs_number, next_page_token, limit
Loading
Loading