From 8fce7cb64ddcb3949cd09a0e42b6d5cbbd163068 Mon Sep 17 00:00:00 2001 From: Megan Date: Thu, 4 Dec 2025 10:13:02 +0000 Subject: [PATCH] [NDR-288] WIP - Give upload nhs id error details --- lambdas/services/post_fhir_document_reference_service.py | 5 ++++- .../e2e/api/fhir/test_upload_document_fhir_api_failure.py | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lambdas/services/post_fhir_document_reference_service.py b/lambdas/services/post_fhir_document_reference_service.py index f6c1e3c3f7..2a142e04e7 100644 --- a/lambdas/services/post_fhir_document_reference_service.py +++ b/lambdas/services/post_fhir_document_reference_service.py @@ -79,7 +79,10 @@ def process_fhir_document_reference( except (ValidationError, InvalidNhsNumberException) as e: logger.error(f"FHIR document validation error: {str(e)}") - raise DocumentRefException(400, LambdaError.DocRefNoParse) + base_error = LambdaError.DocRefNoParse.value # Get the dict + error_payload = {**base_error, "details": str(e)} + raise DocumentRefException(400, error_payload) + except ClientError as e: logger.error(f"AWS client error: {str(e)}") raise DocumentRefException(500, LambdaError.InternalServerError) diff --git a/lambdas/tests/e2e/api/fhir/test_upload_document_fhir_api_failure.py b/lambdas/tests/e2e/api/fhir/test_upload_document_fhir_api_failure.py index f5c360d275..b083cb7ce1 100644 --- a/lambdas/tests/e2e/api/fhir/test_upload_document_fhir_api_failure.py +++ b/lambdas/tests/e2e/api/fhir/test_upload_document_fhir_api_failure.py @@ -88,24 +88,26 @@ def condition(response_json): @pytest.mark.parametrize( - "nhs_number,expected_status,expected_code,expected_diagnostics", + "nhs_number,expected_status,expected_code,expected_diagnostics,expected_details", [ ( "9999999993", 400, "VALIDATION_ERROR", "Failed to parse document upload request data", + "Invalid NHS number format", ), ( "123", 400, "VALIDATION_ERROR", "Failed to parse document upload request data", + "Invalid NHS number length", ), ], ) def test_search_edge_cases( - nhs_number, expected_status, expected_code, expected_diagnostics + nhs_number, expected_status, expected_code, expected_diagnostics, expected_details ): record = { "ods": "H81109", @@ -120,11 +122,13 @@ def test_search_edge_cases( assert response.status_code == expected_status body = response.json() + print('body:', body) issue = body["issue"][0] details = issue.get("details", {}) coding = details.get("coding", [{}])[0] assert coding.get("code") == expected_code assert issue.get("diagnostics") == expected_diagnostics + assert details.get("text") == expected_details def test_forbidden_with_invalid_cert(temp_cert_and_key):