Skip to content

Commit c055a09

Browse files
NRL-497 Count endpoint using dynamoDB count, remove producer count, add performance tests
1 parent 4a9a5d3 commit c055a09

File tree

14 files changed

+120
-158
lines changed

14 files changed

+120
-158
lines changed

api/consumer/searchDocumentReference/search_document_reference.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,13 @@ def handler(
113113
"total": 0,
114114
}
115115
logger.log(LogReference.CONSEARCH006)
116-
total = sum(
117-
1
118-
for _ in repository.search(
119-
nhs_number=params.nhs_number,
120-
custodian=custodian_id,
121-
pointer_types=pointer_types,
122-
categories=categories,
123-
)
116+
117+
total = repository.count_by_nhs_number(
118+
nhs_number=params.nhs_number,
119+
pointer_types=pointer_types,
124120
)
125121
bundle["total"] = total
122+
logger.log(LogReference.CONSEARCH007, total=total)
126123
response = Response.from_resource(Bundle.model_validate(bundle))
127124
logger.log(LogReference.CONSEARCH999)
128125
return response

api/consumer/searchPostDocumentReference/search_post_document_reference.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,16 @@ def handler(
112112
"link": [{"relation": "self", "url": self_link}],
113113
"total": 0,
114114
}
115-
logger.log(LogReference.CONSEARCH006)
116-
total = sum(
117-
1
118-
for _ in repository.search(
119-
nhs_number=body.nhs_number,
120-
custodian=custodian_id,
121-
pointer_types=pointer_types,
122-
categories=categories,
123-
)
115+
logger.log(LogReference.CONPOSTSEARCH006)
116+
117+
total = repository.count_by_nhs_number(
118+
nhs_number=body.nhs_number,
119+
pointer_types=pointer_types,
124120
)
125121
bundle["total"] = total
122+
logger.log(LogReference.CONPOSTSEARCH007, total=total)
126123
response = Response.from_resource(Bundle.model_validate(bundle))
127-
logger.log(LogReference.CONSEARCH999)
124+
logger.log(LogReference.CONPOSTSEARCH999)
128125
return response
129126

130127
for result in repository.search(

api/producer/searchDocumentReference/search_document_reference.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,6 @@ def handler(
8686
categories=params.category.root.split(",") if params.category else [],
8787
)
8888

89-
if params.field_summary and params.field_summary.root == "count":
90-
logger.log(LogReference.PROSEARCH006)
91-
bundle = {"resourceType": "Bundle", "type": "searchset", "total": 0}
92-
total = sum(
93-
1
94-
for _ in repository.search(
95-
custodian=metadata.ods_code,
96-
custodian_suffix=metadata.ods_code_extension,
97-
nhs_number=params.nhs_number,
98-
pointer_types=pointer_types,
99-
categories=categories,
100-
)
101-
)
102-
bundle["total"] = total
103-
response = Response.from_resource(Bundle.model_validate(bundle))
104-
logger.log(LogReference.PROSEARCH999)
105-
return response
106-
10789
for result in repository.search(
10890
custodian=metadata.ods_code,
10991
custodian_suffix=metadata.ods_code_extension,

api/producer/searchDocumentReference/tests/test_search_document_reference_producer.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -455,40 +455,6 @@ def test_search_document_reference_filters_by_pointer_types(
455455
}
456456

457457

458-
@mock_aws
459-
@mock_repository
460-
def test_search_document_reference_filters_by_summary_count(
461-
repository: DocumentPointerRepository,
462-
):
463-
doc_ref = load_document_reference("Y05868-736253002-Valid")
464-
doc_pointer = DocumentPointer.from_document_reference(doc_ref)
465-
repository.create(doc_pointer)
466-
467-
event = create_test_api_gateway_event(
468-
headers=create_headers(),
469-
query_string_parameters={
470-
"subject:identifier": "https://fhir.nhs.uk/Id/nhs-number|6700028191",
471-
"_summary": "count",
472-
},
473-
)
474-
475-
result = handler(event, create_mock_context())
476-
body = result.pop("body")
477-
478-
assert result == {
479-
"statusCode": "200",
480-
"headers": default_response_headers(),
481-
"isBase64Encoded": False,
482-
}
483-
484-
parsed_body = json.loads(body)
485-
assert parsed_body == {
486-
"resourceType": "Bundle",
487-
"type": "searchset",
488-
"total": 1,
489-
}
490-
491-
492458
@mock_aws
493459
@mock_repository
494460
def test_search_document_reference_invalid_json(repository: DocumentPointerRepository):

api/producer/searchPostDocumentReference/search_post_document_reference.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ def handler(
7979
pointer_types=pointer_types,
8080
categories=categories,
8181
)
82-
if body.field_summary and body.field_summary.root == "count":
83-
logger.log(LogReference.PROPOSTSEARCH006)
84-
total = sum(
85-
1
86-
for _ in repository.search(
87-
custodian=metadata.ods_code,
88-
custodian_suffix=metadata.ods_code_extension,
89-
nhs_number=body.nhs_number,
90-
pointer_types=pointer_types,
91-
categories=categories,
92-
)
93-
)
94-
bundle["total"] = total
95-
response = Response.from_resource(Bundle.model_validate(bundle))
96-
logger.log(LogReference.PROPOSTSEARCH999)
97-
return response
9882

9983
for result in repository.search(
10084
custodian=metadata.ods_code,

api/producer/swagger.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,8 +2091,6 @@ components:
20912091
$ref: "#/components/schemas/RequestQueryType"
20922092
category:
20932093
$ref: "#/components/schemas/RequestQueryCategory"
2094-
_summary:
2095-
$ref: "#/components/schemas/RequestQuerySummary"
20962094
next-page-token:
20972095
$ref: "#/components/schemas/NextPageToken"
20982096
RequestQuerySubject:
@@ -2105,9 +2103,6 @@ components:
21052103
RequestQueryCategory:
21062104
type: string
21072105
example: "http://snomed.info/sct|103693007"
2108-
RequestQuerySummary:
2109-
type: string
2110-
example: "count"
21112106
NextPageToken:
21122107
type: string
21132108
RequestHeaderOdsCode:
@@ -2229,18 +2224,6 @@ components:
22292224
invalid:
22302225
summary: Unknown
22312226
value: http://snomed.info/sct|410970009
2232-
_summary:
2233-
name: summary
2234-
in: query
2235-
schema:
2236-
$ref: "#/components/schemas/RequestQuerySummary"
2237-
examples:
2238-
none:
2239-
summary: None
2240-
value: ""
2241-
SNOMED_CODES_CARE_PLAN:
2242-
summary: Search only, just returns a count of the matching resources, without returning the actual matches
2243-
value: count
22442227
nextPageToken:
22452228
name: next-page-token
22462229
in: query

layer/nrlf/core/log_references.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ class LogReference(Enum):
184184
CONSEARCH004 = _Reference(
185185
"DEBUG", "Parsed DocumentReference and added to search results"
186186
)
187-
CONSEARCH006 = _Reference("DEBUG", "Search with summary count parameter enabled")
188187
CONSEARCH005 = _Reference(
189188
"EXCEPTION", "The DocumentReference resource could not be parsed"
190189
)
190+
CONSEARCH006 = _Reference("DEBUG", "Search with summary count parameter enabled")
191+
CONSEARCH007 = _Reference(
192+
"INFO", "Search with summary count parameter returned total results"
193+
)
191194
CONSEARCH999 = _Reference(
192195
"INFO", "Successfully completed consumer searchDocumentReference"
193196
)
@@ -209,11 +212,14 @@ class LogReference(Enum):
209212
CONPOSTSEARCH004 = _Reference(
210213
"DEBUG", "Parsed DocumentReference and added to search results"
211214
)
215+
CONPOSTSEARCH005 = _Reference(
216+
"EXCEPTION", "The DocumentReference resource could not be parsed"
217+
)
212218
CONPOSTSEARCH006 = _Reference(
213219
"DEBUG", "Search with summary count parameter enabled"
214220
)
215-
CONPOSTSEARCH005 = _Reference(
216-
"EXCEPTION", "The DocumentReference resource could not be parsed"
221+
CONPOSTSEARCH007 = _Reference(
222+
"INFO", "Search with summary count parameter returned total results"
217223
)
218224
CONPOSTSEARCH999 = _Reference(
219225
"INFO", "Successfully completed consumer searchPostDocumentReference"

layer/nrlf/producer/fhir/r4/model.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: swagger.yaml
3-
# timestamp: 2025-06-13T14:34:21+00:00
3+
# timestamp: 2025-05-22T18:53:21+00:00
44

55
from __future__ import annotations
66

@@ -468,10 +468,6 @@ class RequestQueryCategory(RootModel[str]):
468468
root: Annotated[str, Field(examples=["http://snomed.info/sct|103693007"])]
469469

470470

471-
class RequestQuerySummary(RootModel[str]):
472-
root: Annotated[str, Field(examples=["count"])]
473-
474-
475471
class NextPageToken(RootModel[str]):
476472
root: str
477473

@@ -563,9 +559,6 @@ class RequestParams(Parent):
563559
] = None
564560
type: Optional[RequestQueryType] = None
565561
category: Optional[RequestQueryCategory] = None
566-
field_summary: Annotated[Optional[RequestQuerySummary], Field(alias="_summary")] = (
567-
None
568-
)
569562
next_page_token: Annotated[
570563
Optional[NextPageToken], Field(alias="next-page-token")
571564
] = None

layer/nrlf/producer/fhir/r4/strict_model.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: swagger.yaml
3-
# timestamp: 2025-06-13T14:34:21+00:00
3+
# timestamp: 2025-05-22T18:53:21+00:00
44

55
from __future__ import annotations
66

@@ -416,10 +416,6 @@ class RequestQueryCategory(RootModel[StrictStr]):
416416
root: Annotated[StrictStr, Field(examples=["http://snomed.info/sct|103693007"])]
417417

418418

419-
class RequestQuerySummary(RootModel[StrictStr]):
420-
root: Annotated[StrictStr, Field(examples=["count"])]
421-
422-
423419
class NextPageToken(RootModel[StrictStr]):
424420
root: StrictStr
425421

@@ -500,9 +496,6 @@ class RequestParams(Parent):
500496
] = None
501497
type: Optional[RequestQueryType] = None
502498
category: Optional[RequestQueryCategory] = None
503-
field_summary: Annotated[Optional[RequestQuerySummary], Field(alias="_summary")] = (
504-
None
505-
)
506499
next_page_token: Annotated[
507500
Optional[NextPageToken], Field(alias="next-page-token")
508501
] = None

tests/features/producer/searchDocumentReference-success.feature

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,39 +107,3 @@ Feature: Producer - searchDocumentReference - Success Scenarios
107107
| author | X26 |
108108
And the Bundle does not contain a DocumentReference with ID 'RX898-1111111111-SearchNHSDocRefTest1'
109109
And the Bundle does not contain a DocumentReference with ID 'RX898-1111111111-SearchNHSDocRefTest3'
110-
111-
Scenario: Search for DocumentReference by NHS number and Summary
112-
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
113-
And the organisation 'RX898' is authorised to access pointer types:
114-
| system | value |
115-
| http://snomed.info/sct | 736253002 |
116-
| http://snomed.info/sct | 1363501000000100 |
117-
And a DocumentReference resource exists with values:
118-
| property | value |
119-
| id | RX898-1111111111-SearchMultipleRefTest1 |
120-
| subject | 9278693472 |
121-
| status | current |
122-
| type | 736253002 |
123-
| category | 734163000 |
124-
| contentType | application/pdf |
125-
| url | https://example.org/my-doc-1.pdf |
126-
| custodian | RX898 |
127-
| author | X26 |
128-
And a DocumentReference resource exists with values:
129-
| property | value |
130-
| id | RX898-1111111111-SearchMultipleRefTest3 |
131-
| subject | 9278693472 |
132-
| status | current |
133-
| type | 1363501000000100 |
134-
| category | 1102421000000108 |
135-
| contentType | application/pdf |
136-
| url | https://example.org/my-doc-3.pdf |
137-
| custodian | RX898 |
138-
| author | X26 |
139-
When producer 'RX898' searches for DocumentReferences with parameters:
140-
| parameter | value |
141-
| subject | 9278693472 |
142-
| _summary | count |
143-
Then the response status code is 200
144-
And the response is a searchset Bundle
145-
And the Bundle has a total of 2

0 commit comments

Comments
 (0)