diff --git a/sandbox/api/patch_consent.py b/sandbox/api/patch_consent.py index 3066a3d5..15e6e73b 100644 --- a/sandbox/api/patch_consent.py +++ b/sandbox/api/patch_consent.py @@ -17,11 +17,11 @@ logger = getLogger(__name__) -def patch_consent_response(identifier: str) -> Union[dict, tuple]: +def patch_consent_response(id: str) -> Union[dict, tuple]: """Sandbox API for PATCH /Consent Args: - identifier (str): Consent identifier to be patched + id (str): Consent id to be patched Returns: Union[dict, tuple]: Response for PATCH /Consent @@ -31,38 +31,38 @@ def patch_consent_response(identifier: str) -> Union[dict, tuple]: # Validate body - validation is beyond the scope of the sandbox. # Assume all requests are valid - if identifier == "c6f48e4d": + if id == "c512b0db-6702-43ee-8c21-bbded2552da9": # Successful status update return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - elif identifier == "0c56a594": + elif id == "6b71ac92-baa3-4b76-b0f5-a601257e2722": # Successful end date for a role return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - elif identifier == "b02ea26c": + elif id == "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5": # Multiple valid changes return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200) - elif identifier == "3a2679eb": + elif id == "849ea584-2318-471b-a24c-cee1b5ad0137": # Invalid patch format return generate_response_from_example(PATCH_CONSENT__INVALID_PATCH_FORMAT, 400) - elif identifier == "94df7c8f": + elif id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f": # Invalid path return generate_response_from_example(PATCH_CONSENT__INVALID_PATH, 400) - elif identifier == "2a7b736d": + elif id == "78c35330-fa2f-4934-a5dd-fff847f38de5": # Invalid status code return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_CODE, 422) - elif identifier == "6fb4361b": - # Invalid state transition - return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422) - - elif identifier == "4b6792be": + elif id == "51fb4df5-815a-45cd-8427-04d6558336b7": # Invalid status reason return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_REASON, 422) + elif id == "7b7f47b8-96e5-43eb-b733-283bf1449f2c": + # Invalid state transition + return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422) + else: # Resource not found return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404) diff --git a/sandbox/api/post_consent.py b/sandbox/api/post_consent.py index 8cc38aeb..cd15be78 100644 --- a/sandbox/api/post_consent.py +++ b/sandbox/api/post_consent.py @@ -32,7 +32,7 @@ def post_consent_response() -> Union[dict, tuple]: # Successful parent-child proxy creation # Successful adult-adult proxy creation if patient_identifier == "9000000009" or patient_identifier == "9000000017": - header = {"location": f"{CONSENT_APP_BASE_PATH}/{patient_identifier}"} + header = {"location": f"{CONSENT_APP_BASE_PATH}/90b9863e-e33c-4895-a333-fd0ea0e23205"} response = generate_response_from_example(POST_CONSENT__SUCCESS, 201, headers=header) # Duplicate relationship diff --git a/sandbox/api/tests/test_patch_consent.py b/sandbox/api/tests/test_patch_consent.py index 60e52102..2c08e482 100644 --- a/sandbox/api/tests/test_patch_consent.py +++ b/sandbox/api/tests/test_patch_consent.py @@ -20,14 +20,14 @@ @pytest.mark.parametrize( ("nhs_num", "response_file_name", "status_code"), [ - ("c6f48e4d", PATCH_CONSENT__SUCCESS, 200), - ("0c56a594", PATCH_CONSENT__SUCCESS, 200), - ("b02ea26c", PATCH_CONSENT__SUCCESS, 200), - ("3a2679eb", PATCH_CONSENT__INVALID_PATCH_FORMAT, 400), - ("94df7c8f", PATCH_CONSENT__INVALID_PATH, 400), - ("2a7b736d", PATCH_CONSENT__INVALID_STATUS_CODE, 422), - ("4b6792be", PATCH_CONSENT__INVALID_STATUS_REASON, 422), - ("6fb4361b", PATCH_CONSENT__INVALID_STATE_TRANSITION, 422), + ("c512b0db-6702-43ee-8c21-bbded2552da9", PATCH_CONSENT__SUCCESS, 200), + ("6b71ac92-baa3-4b76-b0f5-a601257e2722", PATCH_CONSENT__SUCCESS, 200), + ("43003db8-ffcd-4bd6-ab2f-b49b9656f9e5", PATCH_CONSENT__SUCCESS, 200), + ("849ea584-2318-471b-a24c-cee1b5ad0137", PATCH_CONSENT__INVALID_PATCH_FORMAT, 400), + ("01abb0c5-b1ac-499d-9655-9cd0b8d3588f", PATCH_CONSENT__INVALID_PATH, 400), + ("78c35330-fa2f-4934-a5dd-fff847f38de5", PATCH_CONSENT__INVALID_STATUS_CODE, 422), + ("51fb4df5-815a-45cd-8427-04d6558336b7", PATCH_CONSENT__INVALID_STATUS_REASON, 422), + ("7b7f47b8-96e5-43eb-b733-283bf1449f2c", PATCH_CONSENT__INVALID_STATE_TRANSITION, 422), ("xxxxxxxx", PATCH_CONSENT__RESOURCE_NOT_FOUND, 404), ("12345678", PATCH_CONSENT__RESOURCE_NOT_FOUND, 404), ], diff --git a/sandbox/api/tests/test_post_consent.py b/sandbox/api/tests/test_post_consent.py index c41429a2..936cd596 100644 --- a/sandbox/api/tests/test_post_consent.py +++ b/sandbox/api/tests/test_post_consent.py @@ -14,19 +14,19 @@ @pytest.mark.parametrize( - ("nhs_num", "response_file_name", "status_code", "location"), + ("nhs_num", "response_file_name", "status_code", "id"), [ ( "9000000009", POST_CONSENT__SUCCESS, 201, - "https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/9000000009", + "90b9863e-e33c-4895-a333-fd0ea0e23205", ), ( "9000000017", POST_CONSENT__SUCCESS, 201, - "https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/9000000017", + "90b9863e-e33c-4895-a333-fd0ea0e23205", ), ("9000000000", POST_CONSENT__PERFORMER_IDENTIFIER_ERROR, 422, None), ("9000000049", POST_CONSENT__DUPLICATE_RELATIONSHIP_ERROR, 409, None), @@ -37,7 +37,7 @@ def test_post_consent_when_valid_returns_expected_response( mock_generate_response_from_example: MagicMock, response_file_name: str, nhs_num: str, - location: str, + id: str, client: object, status_code: int, ) -> None: @@ -51,9 +51,11 @@ def test_post_consent_when_valid_returns_expected_response( json = {"performer": [{"identifier": {"value": nhs_num}}]} response = client.post(CONSENT_API_ENDPOINT, json=json) # Assert - if location is not None: + if id is not None: mock_generate_response_from_example.assert_called_once_with( - response_file_name, status_code, headers={"location": location} + response_file_name, + status_code, + headers={"location": f"https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/{id}"}, ) else: mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code) diff --git a/specification/validated-relationships-service-api.yaml b/specification/validated-relationships-service-api.yaml index a6cde4be..6ae72bbf 100644 --- a/specification/validated-relationships-service-api.yaml +++ b/specification/validated-relationships-service-api.yaml @@ -653,7 +653,7 @@ paths: location: schema: type: string - example: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/9000000009 + example: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/90b9863e-e33c-4895-a333-fd0ea0e23205 description: URL for the newly created proxy role content: application/fhir+json: @@ -841,35 +841,19 @@ paths: See the postman collection for example requests. - | Scenario | Request | Response | - | ------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------- | - | Successful status update | Valid patch changing status to 'active', request with id 'c6f48e4d' | HTTP Status 200 and OperationOutcome | - | Successful access level update | Valid patch modifying the role end date, request with id '0c56a594' | HTTP Status 200 and OperationOutcome | - | Multiple valid changes | Valid patch with multiple operations, request with id 'b02ea26c' | HTTP Status 200 and OperationOutcome | - | Invalid patch format | Malformed JSON patch document, request with id '3a2679eb' | HTTP Status 400 and INVALID_PATCH_FORMAT error response | - | Invalid path | Patch targeting non-existent element, request with id '94df7c8f' | HTTP Status 400 and INVALID_PATCH_PATH error response | - | Invalid status code | Patch with invalid status value, request with id '2a7b736d' | HTTP Status 422 and INVALID_STATUS_CODE error response | - | Invalid status reason | Patch with invalid status reason value, request with id '4b6792be' | HTTP Status 422 and INVALID_STATUS_REASON error response | - | Resource not found | Patch for non-existent Consent, request with an id not listed here | HTTP Status 404 and RESOURCE_NOT_FOUND error response | - | Invalid state transition | Patch attempting invalid status change, request with id '6fb4361b' | HTTP Status 422 and INVALID_STATE_TRANSITION error response | + | Scenario | Request | Response | + | ------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | + | Successful status update | Valid patch changing status to 'active', request with id 'c512b0db-6702-43ee-8c21-bbded2552da9' | HTTP Status 200 and OperationOutcome | + | Successful access level update | Valid patch modifying the role end date, request with id '6b71ac92-baa3-4b76-b0f5-a601257e2722' | HTTP Status 200 and OperationOutcome | + | Multiple valid changes | Valid patch with multiple operations, request with id '43003db8-ffcd-4bd6-ab2f-b49b9656f9e5' | HTTP Status 200 and OperationOutcome | + | Invalid patch format | Malformed JSON patch document, request with id '849ea584-2318-471b-a24c-cee1b5ad0137' | HTTP Status 400 and INVALID_PATCH_FORMAT error response | + | Invalid path | Patch targeting non-existent element, request with id '01abb0c5-b1ac-499d-9655-9cd0b8d3588f' | HTTP Status 400 and INVALID_PATCH_PATH error response | + | Invalid status code | Patch with invalid status value, request with id '78c35330-fa2f-4934-a5dd-fff847f38de5' | HTTP Status 422 and INVALID_STATUS_CODE error response | + | Invalid status reason | Patch with invalid status reason value, request with id '51fb4df5-815a-45cd-8427-04d6558336b7' | HTTP Status 422 and INVALID_STATUS_REASON error response | + | Resource not found | Patch for non-existent Consent, request with an id not listed here | HTTP Status 404 and RESOURCE_NOT_FOUND error response | + | Invalid state transition | Patch attempting invalid status change, request with id '7b7f47b8-96e5-43eb-b733-283bf1449f2c' | HTTP Status 422 and INVALID_STATE_TRANSITION error response | parameters: - # Change id parameter to Component ConsentID when NPA-5088 is complete - - name: id - in: path - required: true - description: The logical id of the Consent resource to update - schema: - type: string - examples: - statusUpdate: - value: c6f48e4d - summary: Update consent status - updateProvision: - value: 0c56a594 - summary: Set an end date for a role - multipleUpdates: - value: b02ea26c - summary: Set status to active with an end date + - $ref: "#/components/parameters/ConsentID" requestBody: required: true content: