-
Notifications
You must be signed in to change notification settings - Fork 1
[PRMP-589] Create SearchDocumentReview lambda logic #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
89fccdc
[PRMP-643] Add document review models and status enumeration
NogaNHS 397eb0a
[PRMP-643] Refactor document review models and update document handli…
NogaNHS 1b6ff81
[PRMP-643] update MNS service tests for document reviews
NogaNHS 43975a1
Merge branch 'main' into PRMP-643
NogaNHS 81727f4
set default model class to DocumentReference in fetch_documents method
NogaNHS e403c16
Merge branch 'main' into PRMP-643
NogaNHS 65f132e
Update document review model and status enumeration
NogaNHS d713065
Refactor update_patient_ods_code to remove unnecessary table parameter
NogaNHS 88b2f1e
Merge branch 'main' into PRMP-643
NogaNHS 03309bb
Refactor type hints to use union operator for document return types
NogaNHS d0a9d61
Merge branch 'main' into PRMP-643
NogaNHS 88a3a6c
[PRMP-643] PR comments
NogaNHS 7af8e60
[PRMP-643] Implement DocumentReferenceService and DocumentUploadRevie…
NogaNHS 6cc2a43
[PRMP-643] Fix parameter names in document service fetch calls for co…
NogaNHS ef5149a
[PRMP-643] Add unit tests for DocumentUploadReviewService and update …
NogaNHS 8b97a84
[PRMP-643] Add unit tests for DocumentReferenceService and update Doc…
NogaNHS fb1a8be
[PRMP-643] format
NogaNHS 4af40b3
[PRMP-643] Add mock environment variables for DocumentUploadReviewSer…
NogaNHS 887b193
[PRMP-643]Update mock environment variable for DocumentReviewService …
NogaNHS 4e8d6fd
[PRMP-589] start implementation of querying table with ods code
steph-torres-nhs 3b81cdd
[PRMP-589] search document service calls dynamo with correct table an…
steph-torres-nhs 1b5be45
[PRMP-589] format
steph-torres-nhs 29817d4
[PRMP-589] merge in PRMP-643
steph-torres-nhs 5f6c7c6
[PRMP-589] dynamo service can take limit a query param
steph-torres-nhs c3e2d4f
[PRMP-589] dynamo queried with both limit and ods code
steph-torres-nhs 739c551
[PRMP-589] service returns doc review references and last evaluated key
steph-torres-nhs a01b0b7
[PRMP-589] service returns empty list no documents found, none if not…
steph-torres-nhs 91a1a51
[PRMP-589] error raised on validation error
steph-torres-nhs fc5bc6c
[PRMP-589] handler returns 400 response no ods in request context
steph-torres-nhs 3a0fd2a
[PRMP-589] implement 200 and 500 handler response
steph-torres-nhs 3515c56
[PRMP-589] format
steph-torres-nhs f6de5a5
[PRMP-589] add lambda to deploy lambdas workflow
steph-torres-nhs dbbcb55
[PRMP-589] introduce set logging context
steph-torres-nhs 33aff20
[PRMP-589] refactor model not to use optional types
steph-torres-nhs f2f89eb
[PRMP-589] return subsection of doc review refs
steph-torres-nhs 25621bf
[PRMP-589] add count to resposne
steph-torres-nhs 4ca6572
[PRMP-589] add exclusive start key to to search doc review journey
steph-torres-nhs 86dc76a
[PRMP-589] format
steph-torres-nhs 6ba6cd4
[PRMP-589] add start_key to handler service call
steph-torres-nhs f77fb06
[PRMP-589] merge in main
steph-torres-nhs b9752ca
[PRMP-589] fix broken tests from merging main
steph-torres-nhs f86609e
[PRMP-589] refactor
steph-torres-nhs ca9655b
[PRMP-589] refactor
steph-torres-nhs 9e4e801
[PRMP-589] address sonarcloud
steph-torres-nhs 54c14b5
[PRMP-589] amend test
steph-torres-nhs cdf2770
Merge branch 'main' into PRMP-589
steph-torres-nhs da26c6a
[PRMP-589] add error handling get ods code from request context no co…
steph-torres-nhs b5c63f3
[PRMP-589] change process request output
steph-torres-nhs 58ee6e3
[PRMP-589] add feature flag
steph-torres-nhs 81ef459
[PRMP-589] add feature flag
steph-torres-nhs 6c32fb9
[PRMP-589] refactor encoding and decoding start key to handle dict
steph-torres-nhs c5863cf
Implement query and validation methods for DocumentUploadReviewServic…
NogaNHS 8d441cd
[PRMP-589] fix broken test
steph-torres-nhs e929874
[PRMP-589] refactor errors thrown by doc upload review service
steph-torres-nhs de6f8e8
[PRMP-589] refactor doc review lambda errors
steph-torres-nhs 66de70d
[PRMP-589] refactor format of process request output
steph-torres-nhs 107118b
[PRMP-589] add filter expression to querying review doc refs by custo…
steph-torres-nhs 69528bc
[PRMP-589] ensure new arguements for filtering passed down
steph-torres-nhs 1051fa0
[PRMP-589] address pr comments
steph-torres-nhs 92e53a0
[PRMP-589] PR comments
steph-torres-nhs bd5dc8d
[PRMP-589] conditional return of nextPageToken, include snomed code i…
steph-torres-nhs 7ca3d9f
[PRMP-589] address PR comment
steph-torres-nhs 1ba4197
[PRMP-589] merge in main
steph-torres-nhs a70e52b
[PRMP-589] return more fields in response
steph-torres-nhs c5bdcec
[PRMP-589] format
steph-torres-nhs 775fbba
[PRMP-589] catch non integar limit querystrings
steph-torres-nhs fd63b21
[PRMP-589] update return types
steph-torres-nhs f804cfd
[PRMP-589] refactor how default query limit is handled
steph-torres-nhs a72205c
[PRMP-589] ruff issue
steph-torres-nhs d89eabd
odd format
NogaNHS 08454c6
[PRMP-589] pull in remote
steph-torres-nhs b5351a7
Merge branch 'main' into PRMP-589
steph-torres-nhs b08a33c
Merge branch 'PRMP-589' of https://github.com/nhsconnect/national-doc…
steph-torres-nhs fca9ea5
[PRMP-589] merge in main
steph-torres-nhs e31bc92
Merge branch 'main' into PRMP-589
steph-torres-nhs aa8c8ba
[PRMP-589] fix bugs
steph-torres-nhs 00d83bc
[PRMP-589] add route to authoriser
steph-torres-nhs 631a853
[PRMP-589] Refactor DocumentUploadReviewService tests to use 'query_f…
NogaNHS 1349442
Merge branch 'main' into PRMP-589
NogaNHS 92a7fc1
Merge branch 'main' into PRMP-589
steph-torres-nhs e9967b0
[PRMP-589] handle Decimal type in start key
steph-torres-nhs e1fc8ab
[PRMP-589] address PR comments
steph-torres-nhs 0f87b41
Merge branch 'main' into PRMP-589
steph-torres-nhs c3c992f
Merge branch 'main' into PRMP-589
steph-torres-nhs 7cb6535
Merge branch 'main' into PRMP-589
steph-torres-nhs 365ff0e
Merge branch 'main' into PRMP-589
steph-torres-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
lambdas/enums/document_review_accepted_querystring_parameters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from enum import StrEnum | ||
|
|
||
|
|
||
| class DocumentReviewQuerystringParameters(StrEnum): | ||
| LIMIT = "limit" | ||
| NEXT_PAGE_TOKEN = "nextPageToken" | ||
| UPLOADER = "uploader" | ||
| NHS_NUMBER = "nhsNumber" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import json | ||
|
|
||
| from enums.document_review_accepted_querystring_parameters import ( | ||
| DocumentReviewQuerystringParameters, | ||
| ) | ||
| from enums.feature_flags import FeatureFlags | ||
| from enums.lambda_error import LambdaError | ||
| from services.feature_flags_service import FeatureFlagService | ||
| from services.search_document_review_service import SearchDocumentReviewService | ||
| 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.exceptions import OdsErrorException | ||
| from utils.lambda_exceptions import DocumentReviewException | ||
| from utils.lambda_response import ApiGatewayResponse | ||
| from utils.request_context import request_context | ||
|
|
||
| logger = LoggingService(__name__) | ||
|
|
||
|
|
||
| @set_request_context_for_logging | ||
| @ensure_environment_variables(names=["DOCUMENT_REVIEW_DYNAMODB_NAME"]) | ||
| @override_error_check | ||
| @handle_lambda_exceptions | ||
| def lambda_handler(event, context): | ||
| """ | ||
| Lambda handler for searching documents pending review by custodian. | ||
| Triggered by GET request to /SearchDocumentReview endpoint. | ||
| Args: | ||
| event: API Gateway event containing query optional query string parameters | ||
| QueryStringParameters: limit - Limit for DynamoDB query, defaulted to 50 if not provided, | ||
| nhsNumber - Patient NHS number, used for filtering DynamoDB results, | ||
| uploader - Author ODS code, used for filtering DynamoDB results, | ||
| nextPageToken - Encoded exclusive start key used to query DynamoDB for next page of results. | ||
| context: Lambda context | ||
|
|
||
| Returns: | ||
| API Gateway response containing Document Review references, number of reference returned, and next page token if present. | ||
| 401 - No ODS code or auth token provided in request. | ||
| 500 - Document Review Error, Internal Server Error. | ||
|
|
||
| """ | ||
| try: | ||
| 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 DocumentReviewException(403, LambdaError.FeatureFlagDisabled) | ||
|
|
||
| ods_code = get_ods_code_from_request_context() | ||
|
|
||
NogaNHS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| params = parse_querystring_parameters(event) | ||
|
|
||
| search_document_reference_service = SearchDocumentReviewService() | ||
|
|
||
| references, next_page_token = search_document_reference_service.process_request( | ||
| params=params, ods_code=ods_code | ||
| ) | ||
|
|
||
| response = {"documentReviewReferences": references, "count": len(references)} | ||
|
|
||
| if next_page_token: | ||
| response["nextPageToken"] = next_page_token | ||
|
|
||
| return ApiGatewayResponse( | ||
| status_code=200, | ||
| body=json.dumps(response), | ||
| methods="GET", | ||
| ).create_api_gateway_response() | ||
|
|
||
| except OdsErrorException as e: | ||
| logger.error(e) | ||
| return ApiGatewayResponse( | ||
| status_code=401, | ||
| body=LambdaError.SearchDocumentReviewMissingODS.create_error_body(), | ||
| methods="GET", | ||
| ).create_api_gateway_response() | ||
|
|
||
|
|
||
| def get_ods_code_from_request_context(): | ||
| logger.info("Getting ODS code from request context") | ||
| try: | ||
| ods_code = request_context.authorization.get("selected_organisation", {}).get( | ||
| "org_ods_code" | ||
| ) | ||
| if not ods_code: | ||
| raise OdsErrorException() | ||
|
|
||
| return ods_code | ||
|
|
||
| except AttributeError as e: | ||
| logger.error(e) | ||
| raise DocumentReviewException(401, LambdaError.SearchDocumentReviewMissingODS) | ||
|
|
||
|
|
||
| def parse_querystring_parameters(event): | ||
| logger.info("Parsing query string parameters.") | ||
| params = event.get("queryStringParameters", {}) | ||
|
|
||
| extracted_params = {} | ||
|
|
||
| if not params: | ||
| return extracted_params | ||
|
|
||
| for param in DocumentReviewQuerystringParameters: | ||
| if param in params: | ||
| extracted_params[param.value] = params.get(param) | ||
|
|
||
| return extracted_params | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.