Skip to content

Commit e60e390

Browse files
MohammadIqbalAD-NHSadamwhitingnhs
authored andcommitted
[PRMP-1495] - Fix stitching for all records not 1of1 (#1116)
1 parent e059017 commit e60e390

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lambdas/services/document_service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,15 @@ def get_nhs_numbers_based_on_ods_code(
172172
) -> list[str]:
173173
"""Get unique NHS numbers for patients with given ODS code."""
174174
table_name = table_name or self.table_name
175-
filter_expression = Attr("Author").eq(ods_code) & Attr("FileName").begins_with(
176-
"2of",
177-
)
178175
projection_expression = "NhsNumber"
176+
if ods_code == "ALL":
177+
filter_expression = Attr("FileName").begins_with(
178+
"2of",
179+
)
180+
else:
181+
filter_expression = Attr("Author").eq(ods_code) & Attr("FileName").begins_with(
182+
"2of",
183+
)
179184

180185
logger.info("Starting scan of table for NHS numbers based on ODS code...")
181186
results = self.dynamo_service.scan_whole_table(

lambdas/services/pdf_stitching_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def retrieve_multipart_references(
5959
)
6060

6161
if doc_type == SupportedDocumentTypes.LG:
62-
if any("1of1" in result.file_name for result in document_references):
62+
if any("1of1_" in result.file_name for result in document_references):
6363
logger.error(
6464
"There is already a stitched LG document reference present in DynamoDb"
6565
)

lambdas/services/virus_scan_result_service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ def get_new_access_token(self):
117117
self.access_token = response.json()["accessToken"]
118118

119119
self.update_ssm_access_token(self.access_token)
120-
except Exception as e:
121-
# ignore TooManyRequests exception as it will be handled by the retry mechanism in request_virus_scan
120+
except ClientError as e:
121+
# ignore TooManyRequests error as it will be handled by the retry mechanism in request_virus_scan
122122
# this is to prevent a scenario where multiple concurrent Lambda executions all attempt to refresh the token at the same time,
123123
# resulting in a flood of requests to the token endpoint and subsequent failures. By ignoring the TooManyRequests exception,
124124
# we allow the retry mechanism to handle the situation gracefully without overwhelming the token service.
125-
if str(e).find("TooManyRequests") != -1:
125+
if "TooManyRequests" in str(e):
126+
logger.info("Failed to store token in SSM, too many requests, starting retry")
126127
return
128+
129+
except Exception as e:
127130
logger.error(
128131
f"{LambdaError.VirusScanNoToken.to_str()}: {str(e)}",
129132
{"Result": FAIL_SCAN},

0 commit comments

Comments
 (0)