Skip to content

Commit 4a2c633

Browse files
committed
[NDR-322] Remove PDMDocumentMetadata table
1 parent 4682e0f commit 4a2c633

File tree

5 files changed

+27
-75
lines changed

5 files changed

+27
-75
lines changed

lambdas/enums/infrastructure.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ def __getattr__(cls, name):
1818

1919
class DynamoTables(StrEnum, metaclass=DynamoMeta):
2020
LLOYD_GEORGE = "LloydGeorgeReferenceMetadata"
21-
PDM = "PDMDocumentMetadata"
2221
CORE = "COREDocumentMetadata"
2322

2423
def __str__(self) -> str:
2524
workspace = os.getenv("WORKSPACE")
2625
if not workspace:
27-
logger.error(
28-
"No workspace environment variable found during table definition."
29-
)
26+
logger.error("No workspace environment variable found during table definition.")
3027
raise DocumentRefException(500, LambdaError.EnvMissing)
3128
return f"{workspace}_{self.value}"
3229

lambdas/handlers/document_reference_virus_scan_handler.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
@ensure_environment_variables(
1717
names=[
1818
"LLOYD_GEORGE_DYNAMODB_NAME",
19-
"PDM_DYNAMODB_NAME",
2019
"STAGING_STORE_BUCKET_NAME",
2120
"LLOYD_GEORGE_BUCKET_NAME",
2221
"PDM_BUCKET_NAME",
2322
"VIRUS_SCAN_STUB",
2423
"DOCUMENT_REVIEW_DYNAMODB_NAME",
25-
"PENDING_REVIEW_BUCKET_NAME"
24+
"PENDING_REVIEW_BUCKET_NAME",
2625
]
2726
)
2827
def lambda_handler(event, context):
@@ -42,6 +41,4 @@ def lambda_handler(event, context):
4241

4342
service.handle_upload_document_reference_request(object_key, object_size)
4443

45-
return ApiGatewayResponse(
46-
200, "Virus Scan was successful", "POST"
47-
).create_api_gateway_response()
44+
return ApiGatewayResponse(200, "Virus Scan was successful", "POST").create_api_gateway_response()

lambdas/handlers/get_fhir_document_reference_handler.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"APPCONFIG_APPLICATION",
2828
"APPCONFIG_CONFIGURATION",
2929
"APPCONFIG_ENVIRONMENT",
30-
"LLOYD_GEORGE_DYNAMODB_NAME",
31-
"PDM_DYNAMODB_NAME",
3230
"PRESIGNED_ASSUME_ROLE",
3331
"CLOUDFRONT_URL",
3432
]
@@ -41,35 +39,21 @@ def lambda_handler(event, context):
4139
document_id, snomed_code = extract_document_parameters(event)
4240

4341
get_document_service = GetFhirDocumentReferenceService()
44-
document_reference = get_document_service.handle_get_document_reference_request(
45-
snomed_code, document_id
46-
)
42+
document_reference = get_document_service.handle_get_document_reference_request(snomed_code, document_id)
4743

4844
if selected_role_id and bearer_token:
49-
verify_user_authorisation(
50-
bearer_token, selected_role_id, document_reference.nhs_number
51-
)
45+
verify_user_authorisation(bearer_token, selected_role_id, document_reference.nhs_number)
5246

53-
document_reference_response = (
54-
get_document_service.create_document_reference_fhir_response(
55-
document_reference
56-
)
57-
)
47+
document_reference_response = get_document_service.create_document_reference_fhir_response(document_reference)
5848

59-
logger.info(
60-
f"Successfully retrieved document reference for document_id: {document_id}, snomed_code: {snomed_code}"
61-
)
49+
logger.info(f"Successfully retrieved document reference for document_id: {document_id}, snomed_code: {snomed_code}")
6250

63-
return ApiGatewayResponse(
64-
status_code=200, body=document_reference_response, methods="GET"
65-
).create_api_gateway_response()
51+
return ApiGatewayResponse(status_code=200, body=document_reference_response, methods="GET").create_api_gateway_response()
6652

6753
except GetFhirDocumentReferenceException as exception:
6854
return ApiGatewayResponse(
6955
status_code=exception.status_code,
70-
body=exception.error.create_error_response().create_error_fhir_response(
71-
exception.error.value.get("fhir_coding")
72-
),
56+
body=exception.error.create_error_response().create_error_fhir_response(exception.error.value.get("fhir_coding")),
7357
methods="GET",
7458
).create_api_gateway_response()
7559

@@ -81,9 +65,7 @@ def extract_document_parameters(event):
8165

8266
if not document_id or not snomed_code:
8367
logger.error("Missing document id or snomed code in request path parameters.")
84-
raise GetFhirDocumentReferenceException(
85-
400, LambdaError.DocumentReferenceMissingParameters
86-
)
68+
raise GetFhirDocumentReferenceException(400, LambdaError.DocumentReferenceMissingParameters)
8769

8870
return document_id, snomed_code
8971

@@ -101,19 +83,13 @@ def verify_user_authorisation(bearer_token, selected_role_id, nhs_number):
10183
userinfo = oidc_service.fetch_userinfo(bearer_token)
10284

10385
org_ods_code = oidc_service.fetch_user_org_code(userinfo, selected_role_id)
104-
smartcard_role_code, _ = oidc_service.fetch_user_role_code(
105-
userinfo, selected_role_id, "R"
106-
)
86+
smartcard_role_code, _ = oidc_service.fetch_user_role_code(userinfo, selected_role_id, "R")
10787
except (OidcApiException, AuthorisationException) as e:
10888
logger.error(f"Authorization error: {str(e)}")
109-
raise GetFhirDocumentReferenceException(
110-
403, LambdaError.DocumentReferenceUnauthorised
111-
)
89+
raise GetFhirDocumentReferenceException(403, LambdaError.DocumentReferenceUnauthorised)
11290

11391
try:
114-
search_patient_service = SearchPatientDetailsService(
115-
smartcard_role_code, org_ods_code
116-
)
92+
search_patient_service = SearchPatientDetailsService(smartcard_role_code, org_ods_code)
11793
search_patient_service.handle_search_patient_request(nhs_number, False)
11894
except SearchPatientException as e:
11995
raise GetFhirDocumentReferenceException(e.status_code, e.error)

lambdas/tests/unit/enums/test_infrastructure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
["enum_value", "expected"],
1010
[
1111
(DynamoTables.LLOYD_GEORGE, "LloydGeorgeReferenceMetadata"),
12-
(DynamoTables.PDM, "PDMDocumentMetadata"),
1312
(DynamoTables.CORE, "COREDocumentMetadata"),
1413
],
1514
)
@@ -29,7 +28,7 @@ def test_dynamo_tables_no_workspace(monkeypatch):
2928
monkeypatch.delenv("WORKSPACE", raising=False)
3029

3130
with pytest.raises(DocumentRefException) as exc:
32-
str(DynamoTables.PDM)
31+
str(DynamoTables.CORE)
3332

3433
assert exc.value.status_code == 500
3534
assert exc.value.error == LambdaError.EnvMissing

lambdas/utils/dynamo_utils.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ def create_expression_attribute_values(attribute_field_values: dict) -> dict:
8787
"""
8888
expression_attribute_values = {}
8989
for field_name, field_value in attribute_field_values.items():
90-
expression_attribute_values[
91-
f"{create_expression_value_placeholder(field_name)}"
92-
] = field_value
90+
expression_attribute_values[f"{create_expression_value_placeholder(field_name)}"] = field_value
9391

9492
return expression_attribute_values
9593

@@ -133,14 +131,12 @@ def filter_uploaded_docs_and_recently_uploading_docs():
133131
filter_builder.add_condition("Uploaded", AttributeOperator.EQUAL, True)
134132
uploaded_filter_expression = filter_builder.build()
135133

136-
filter_builder.add_condition(
137-
"Uploading", AttributeOperator.EQUAL, True
138-
).add_condition("LastUpdated", AttributeOperator.GREATER_OR_EQUAL, time_limit)
134+
filter_builder.add_condition("Uploading", AttributeOperator.EQUAL, True).add_condition(
135+
"LastUpdated", AttributeOperator.GREATER_OR_EQUAL, time_limit
136+
)
139137
uploading_filter_expression = filter_builder.build()
140138

141-
return delete_filter_expression & (
142-
uploaded_filter_expression | uploading_filter_expression
143-
)
139+
return delete_filter_expression & (uploaded_filter_expression | uploading_filter_expression)
144140

145141

146142
def parse_dynamo_record(dynamodb_record: Dict[str, Any]) -> Dict[str, Any]:
@@ -196,12 +192,8 @@ def build_mixed_condition_expression(
196192
if operator in ["attribute_exists", "attribute_not_exists"]:
197193
condition_expressions.append(f"{operator}({condition_placeholder})")
198194
else:
199-
condition_value_placeholder = create_expression_value_placeholder(
200-
field_name, suffix
201-
)
202-
condition_expressions.append(
203-
f"{condition_placeholder} {operator} {condition_value_placeholder}"
204-
)
195+
condition_value_placeholder = create_expression_value_placeholder(field_name, suffix)
196+
condition_expressions.append(f"{condition_placeholder} {operator} {condition_value_placeholder}")
205197
condition_attribute_values[condition_value_placeholder] = field_value
206198

207199
condition_expression = f" {join_operator} ".join(condition_expressions)
@@ -242,9 +234,7 @@ def build_general_transaction_item(
242234
action = action.capitalize()
243235

244236
if action not in ["Put", "Update", "Delete", "Conditioncheck"]:
245-
raise ValueError(
246-
f"Invalid action: {action}. Must be one of: Put, Update, Delete, ConditionCheck"
247-
)
237+
raise ValueError(f"Invalid action: {action}. Must be one of: Put, Update, Delete, ConditionCheck")
248238

249239
transaction_item: dict[str, dict[str, Any]] = {action: {"TableName": table_name}}
250240

@@ -269,14 +259,10 @@ def build_general_transaction_item(
269259
transaction_item[action]["ConditionExpression"] = condition_expression
270260

271261
if expression_attribute_names:
272-
transaction_item[action][
273-
"ExpressionAttributeNames"
274-
] = expression_attribute_names
262+
transaction_item[action]["ExpressionAttributeNames"] = expression_attribute_names
275263

276264
if expression_attribute_values:
277-
transaction_item[action][
278-
"ExpressionAttributeValues"
279-
] = expression_attribute_values
265+
transaction_item[action]["ExpressionAttributeValues"] = expression_attribute_values
280266

281267
return transaction_item
282268

@@ -305,8 +291,8 @@ def build_transaction_item(
305291
expression_attribute_values.update(update_attr_values)
306292

307293
if conditions:
308-
condition_expr, condition_attr_names, condition_attr_values = (
309-
build_mixed_condition_expression(conditions, condition_join_operator)
294+
condition_expr, condition_attr_names, condition_attr_values = build_mixed_condition_expression(
295+
conditions, condition_join_operator
310296
)
311297
condition_expression = condition_expr
312298
expression_attribute_names.update(condition_attr_names)
@@ -336,15 +322,12 @@ def __init__(self):
336322

337323
def _define_tables(self):
338324
self.lg_dynamo_table = DynamoTables.LLOYD_GEORGE
339-
self.pdm_dynamo_table = DynamoTables.PDM
340325
self.core_dynamo_table = DynamoTables.CORE
341326

342327
def resolve(self, doc_type: SnomedCode) -> str:
343328
try:
344329
table = self.mapping[doc_type.code]
345330
return str(table)
346331
except KeyError:
347-
logger.error(
348-
f"SNOMED code {doc_type.code} - {doc_type.display_name} is not supported"
349-
)
332+
logger.error(f"SNOMED code {doc_type.code} - {doc_type.display_name} is not supported")
350333
raise InvalidDocTypeException(400, LambdaError.DocTypeDB)

0 commit comments

Comments
 (0)