Skip to content

Commit 6893966

Browse files
authored
Merge branch 'main' into bug/te-ELI-373-cohortlabel
2 parents d507918 + 1e55114 commit 6893966

3 files changed

Lines changed: 361 additions & 270 deletions

File tree

src/eligibility_signposting_api/common/api_error_response.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class FHIRIssueCode(str, Enum):
2222
FORBIDDEN = "forbidden"
2323
PROCESSING = "processing"
2424
VALUE = "value"
25+
INVALID = "invalid"
2526

2627

2728
class FHIRSpineErrorCode(str, Enum):
2829
INVALID_NHS_NUMBER = "INVALID_NHS_NUMBER"
2930
INVALID_PARAMETER = "INVALID_PARAMETER"
31+
BAD_REQUEST = "BAD_REQUEST"
3032
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
3133
REFERENCE_NOT_FOUND = "REFERENCE_NOT_FOUND"
3234

@@ -145,3 +147,13 @@ def log_and_generate_response(
145147
fhir_error_code=FHIRSpineErrorCode.INVALID_NHS_NUMBER,
146148
fhir_display_message="The provided NHS number does not match the record.",
147149
)
150+
151+
152+
NHS_NUMBER_MISSING_ERROR = APIErrorResponse(
153+
status_code=HTTPStatus.BAD_REQUEST,
154+
fhir_issue_code=FHIRIssueCode.INVALID,
155+
fhir_issue_severity=FHIRIssueSeverity.ERROR,
156+
fhir_coding_system="https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
157+
fhir_error_code=FHIRSpineErrorCode.BAD_REQUEST,
158+
fhir_display_message="Bad Request",
159+
)

src/eligibility_signposting_api/common/request_validator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
INVALID_CONDITION_FORMAT_ERROR,
1212
INVALID_INCLUDE_ACTIONS_ERROR,
1313
NHS_NUMBER_MISMATCH_ERROR,
14+
NHS_NUMBER_MISSING_ERROR,
1415
)
1516
from eligibility_signposting_api.config.contants import NHS_NUMBER_HEADER
1617

@@ -59,6 +60,12 @@ def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None
5960
path_nhs_no = event.get("pathParameters", {}).get("id")
6061
header_nhs_no = event.get("headers", {}).get(NHS_NUMBER_HEADER)
6162

63+
if not path_nhs_no:
64+
message = "Missing required NHS Number from path parameters"
65+
return NHS_NUMBER_MISSING_ERROR.log_and_generate_response(
66+
log_message=message, diagnostics=message, location_param="id"
67+
)
68+
6269
if not validate_nhs_number(path_nhs_no, header_nhs_no):
6370
message = f"NHS Number {path_nhs_no or ''} does not match the header NHS Number {header_nhs_no or ''}"
6471
return NHS_NUMBER_MISMATCH_ERROR.log_and_generate_response(

0 commit comments

Comments
 (0)