Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/eligibility_signposting_api/common/api_error_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ class FHIRIssueCode(str, Enum):
FORBIDDEN = "forbidden"
PROCESSING = "processing"
VALUE = "value"
INVALID = "invalid"


class FHIRSpineErrorCode(str, Enum):
INVALID_NHS_NUMBER = "INVALID_NHS_NUMBER"
INVALID_PARAMETER = "INVALID_PARAMETER"
BAD_REQUEST = "BAD_REQUEST"
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
REFERENCE_NOT_FOUND = "REFERENCE_NOT_FOUND"

Expand Down Expand Up @@ -145,3 +147,13 @@ def log_and_generate_response(
fhir_error_code=FHIRSpineErrorCode.INVALID_NHS_NUMBER,
fhir_display_message="The provided NHS number does not match the record.",
)


NHS_NUMBER_MISSING_ERROR = APIErrorResponse(
status_code=HTTPStatus.BAD_REQUEST,
fhir_issue_code=FHIRIssueCode.INVALID,
fhir_issue_severity=FHIRIssueSeverity.ERROR,
fhir_coding_system="https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
fhir_error_code=FHIRSpineErrorCode.BAD_REQUEST,
fhir_display_message="Bad Request",
)
7 changes: 7 additions & 0 deletions src/eligibility_signposting_api/common/request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
INVALID_CONDITION_FORMAT_ERROR,
INVALID_INCLUDE_ACTIONS_ERROR,
NHS_NUMBER_MISMATCH_ERROR,
NHS_NUMBER_MISSING_ERROR,
)
from eligibility_signposting_api.config.contants import NHS_NUMBER_HEADER

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

if not path_nhs_no:
message = "Missing required NHS Number from path parameters"
return NHS_NUMBER_MISSING_ERROR.log_and_generate_response(
log_message=message, diagnostics=message, location_param="id"
)

if not validate_nhs_number(path_nhs_no, header_nhs_no):
message = f"NHS Number {path_nhs_no or ''} does not match the header NHS Number {header_nhs_no or ''}"
return NHS_NUMBER_MISMATCH_ERROR.log_and_generate_response(
Expand Down
Loading