-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_document_review_handler.py
More file actions
95 lines (81 loc) · 3.48 KB
/
get_document_review_handler.py
File metadata and controls
95 lines (81 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import json
from enums.feature_flags import FeatureFlags
from enums.lambda_error import LambdaError
from enums.logging_app_interaction import LoggingAppInteraction
from services.feature_flags_service import FeatureFlagService
from services.get_document_review_service import GetDocumentReviewService
from utils.audit_logging_setup import LoggingService
from utils.decorators.ensure_env_var import ensure_environment_variables
from utils.decorators.handle_lambda_exceptions import handle_lambda_exceptions
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 validate_patient_id
from utils.lambda_exceptions import GetDocumentReviewException
from utils.lambda_response import ApiGatewayResponse
from utils.request_context import request_context
logger = LoggingService(__name__)
@set_request_context_for_logging
@validate_patient_id
@ensure_environment_variables(
names=[
"DOCUMENT_REVIEW_DYNAMODB_NAME",
"PRESIGNED_ASSUME_ROLE",
"EDGE_REFERENCE_TABLE",
"CLOUDFRONT_URL",
]
)
@override_error_check
@handle_lambda_exceptions
def lambda_handler(event, context):
request_context.app_interaction = LoggingAppInteraction.GET_REVIEW_DOCUMENTS.value
logger.info("Get Document Review handler has been triggered")
feature_flag_service = FeatureFlagService()
upload_lambda_enabled_flag_object = feature_flag_service.get_feature_flags_by_flag(
FeatureFlags.UPLOAD_DOCUMENT_ITERATION_3_ENABLED
)
if not upload_lambda_enabled_flag_object[FeatureFlags.UPLOAD_DOCUMENT_ITERATION_3_ENABLED]:
logger.info("Feature flag not enabled, event will not be processed")
raise GetDocumentReviewException(404, LambdaError.FeatureFlagDisabled)
# Extract patient_id from query string parameters
query_params = event.get("queryStringParameters", {})
patient_id = query_params.get("patientId", "")
if not patient_id:
logger.error("Missing patient_id in query string parameters")
raise GetDocumentReviewException(
400, LambdaError.DocumentReferenceMissingParameters
)
# Extract id from path parameters
path_params = event.get("pathParameters", {})
document_id = path_params.get("id")
if not document_id:
logger.error("Missing id in path parameters")
raise GetDocumentReviewException(
400, LambdaError.DocumentReferenceMissingParameters
)
request_context.patient_nhs_no = patient_id
logger.info(
f"Retrieving document review for patient_id: {patient_id}, document_id: {document_id}"
)
# Get document review service
document_review_service = GetDocumentReviewService()
document_review = document_review_service.get_document_review(
patient_id=patient_id, document_id=document_id
)
if document_review:
logger.info(
"Document review retrieved successfully",
{"Result": "Successful document review retrieval"},
)
return ApiGatewayResponse(
200, json.dumps(document_review), "GET"
).create_api_gateway_response()
else:
logger.error(
"Document review not found",
{"Result": "No document review available"},
)
return ApiGatewayResponse(
404,
LambdaError.DocumentReferenceNotFound.create_error_body(),
"GET",
).create_api_gateway_response()