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
26 changes: 13 additions & 13 deletions sandbox/api/patch_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sandbox/api/post_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions sandbox/api/tests/test_patch_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
Expand Down
14 changes: 8 additions & 6 deletions sandbox/api/tests/test_post_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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:
Expand All @@ -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)
Expand Down
42 changes: 13 additions & 29 deletions specification/validated-relationships-service-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down