-
Notifications
You must be signed in to change notification settings - Fork 3
VED-821 Refactor get by ID journey in line with cleaner design #868
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
7 commits
Select commit
Hold shift + click to select a range
01e8b29
Refactor get by ID journey
dlzhry2nhs 33cb049
Tidy folder structure
dlzhry2nhs b309292
Fix delete endpoint
dlzhry2nhs 8c152ac
A couple of Sonar issues
dlzhry2nhs f3d372b
Merge branch 'master' into feature/VED-821-refactor-get-by-id
dlzhry2nhs 55b5343
Resolve PR comments
dlzhry2nhs 8e3d89f
Merge branch 'master' into feature/VED-821-refactor-get-by-id
dlzhry2nhs 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
Empty file.
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,27 @@ | ||
| """Utility module for interacting with the AWS API Gateway event provided to controllers""" | ||
| from typing import Optional | ||
|
|
||
| from aws_lambda_typing.events import APIGatewayProxyEventV1 | ||
|
|
||
| from controller.constants import SUPPLIER_SYSTEM_HEADER_NAME | ||
| from models.errors import UnauthorizedError | ||
| from utils import dict_utils | ||
|
|
||
|
|
||
| def get_path_parameter(event: APIGatewayProxyEventV1, param_name: str) -> str: | ||
| return dict_utils.get_field( | ||
| event["pathParameters"], | ||
| param_name, | ||
| default="" | ||
| ) | ||
|
|
||
|
|
||
| def get_supplier_system_header(event: APIGatewayProxyEventV1) -> str: | ||
| """Retrieves the supplier system header from the API Gateway event""" | ||
| supplier_system: Optional[str] = dict_utils.get_field(dict(event), "headers", SUPPLIER_SYSTEM_HEADER_NAME) | ||
|
|
||
| if supplier_system is None: | ||
| # SupplierSystem header must be provided for looking up permissions | ||
| raise UnauthorizedError() | ||
|
|
||
| return supplier_system | ||
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,24 @@ | ||
| """Utility module providing helper functions for dealing with response formats for AWS API Gateway""" | ||
| import json | ||
| from typing import Optional | ||
|
|
||
|
|
||
| def create_response( | ||
dlzhry2nhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| status_code: int, | ||
| body: Optional[dict | str] = None, | ||
| headers: Optional[dict] = None | ||
| ): | ||
| """Creates response body as per Lambda -> API Gateway proxy integration""" | ||
| if body is not None: | ||
| if isinstance(body, dict): | ||
| body = json.dumps(body) | ||
| if headers: | ||
| headers["Content-Type"] = "application/fhir+json" | ||
| else: | ||
| headers = {"Content-Type": "application/fhir+json"} | ||
|
|
||
| return { | ||
| "statusCode": status_code, | ||
| "headers": headers if headers else {}, | ||
| **({"body": body} if body else {}), | ||
| } | ||
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,5 @@ | ||
| """FHIR Controller constants""" | ||
|
|
||
|
|
||
| SUPPLIER_SYSTEM_HEADER_NAME = "SupplierSystem" | ||
| E_TAG_HEADER_NAME = "E-Tag" |
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,42 @@ | ||
| """Module for the global FHIR API exception handler""" | ||
| import functools | ||
| import uuid | ||
| from typing import Callable, Type | ||
|
|
||
| from clients import logger | ||
| from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE | ||
| from controller.aws_apig_response_utils import create_response | ||
| from models.errors import UnauthorizedVaxError, UnauthorizedError, ResourceNotFoundError, create_operation_outcome, \ | ||
| Severity, Code | ||
|
|
||
|
|
||
| _CUSTOM_EXCEPTION_TO_STATUS_MAP: dict[Type[Exception], int] = { | ||
| UnauthorizedError: 403, | ||
| UnauthorizedVaxError: 403, | ||
| ResourceNotFoundError: 404 | ||
| } | ||
|
|
||
|
|
||
| def fhir_api_exception_handler(function: Callable) -> Callable: | ||
| """Decorator to handle any expected FHIR API exceptions or unexpected exception and provide a valid response to | ||
| the client""" | ||
|
|
||
| @functools.wraps(function) | ||
| def wrapper(*args, **kwargs): | ||
| try: | ||
| return function(*args, **kwargs) | ||
| except tuple(_CUSTOM_EXCEPTION_TO_STATUS_MAP) as exc: | ||
| status_code = _CUSTOM_EXCEPTION_TO_STATUS_MAP[type(exc)] | ||
| return create_response(status_code=status_code, body=exc.to_operation_outcome()) | ||
| except Exception: # pylint: disable = broad-exception-caught | ||
| logger.exception("Unhandled exception") | ||
| server_error = create_operation_outcome( | ||
| resource_id=str(uuid.uuid4()), | ||
| severity=Severity.error, | ||
| code=Code.server_error, | ||
| diagnostics=GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE, | ||
| ) | ||
| return create_response(500, server_error) | ||
|
|
||
| return wrapper | ||
|
|
4 changes: 2 additions & 2 deletions
4
backend/src/fhir_batch_controller.py → ...d/src/controller/fhir_batch_controller.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
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.