Skip to content
Open
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

35 changes: 17 additions & 18 deletions sandbox/api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from logging import INFO, basicConfig, getLogger
from typing import Union

from flask import Flask
from flask import Flask, Response

from .get_consent import get_consent_response
from .get_consent_by_id import get_consent_by_id_response
Expand Down Expand Up @@ -32,84 +31,84 @@ def health() -> dict:


@app.route(f"/{COMMON_PATH}/RelatedPerson", methods=["GET"])
def get_related_persons() -> Union[dict, tuple]:
def get_related_persons() -> Response:
"""Sandbox API for GET /RelatedPerson

Returns:
Union[dict, tuple]: Response for GET /RelatedPerson
Response: Response for GET /RelatedPerson
"""
return get_related_person_response()


@app.route(f"/{COMMON_PATH}/QuestionnaireResponse", methods=["GET"])
@app.route(f"/{COMMON_PATH}/QuestionnaireResponse/", methods=["GET"])
def get_questionnaire_response() -> Union[dict, tuple]:
def get_questionnaire_response() -> Response:
"""Sandbox API for GET /QuestionnaireResponse

Returns:
Union[dict, tuple]: Response for GET /QuestionnaireResponse
Response: Response for GET /QuestionnaireResponse
"""
return generate_response_from_example(METHOD_NOT_ALLOWED, 405)


@app.route(f"/{COMMON_PATH}/QuestionnaireResponse/<identifier>", methods=["GET"])
def get_questionnaire_response_id(identifier: str) -> Union[dict, tuple]:
def get_questionnaire_response_id(identifier: str) -> Response:
"""Sandbox API for GET /QuestionnaireResponse

Returns:
Union[dict, tuple]: Response for GET /QuestionnaireResponse
Response: Response for GET /QuestionnaireResponse
"""
return get_questionnaire_response_by_path_id_response(identifier)


@app.route(f"/{COMMON_PATH}/QuestionnaireResponse", methods=["POST"])
def post_questionnaire_response() -> Union[dict, tuple]:
def post_questionnaire_response() -> Response:
"""Sandbox API for POST /QuestionnaireResponse

Returns:
Union[dict, tuple]: Response for POST /QuestionnaireResponse
Response: Response for POST /QuestionnaireResponse
"""
return post_questionnaire_response_response()


@app.route(f"/{COMMON_PATH}/Consent", methods=["GET"])
def get_consent() -> Union[dict, tuple]:
def get_consent() -> Response:
"""Sandbox API for GET /Consent

Returns:
Union[dict, tuple]: Response for GET /Consent
Response: Response for GET /Consent
"""
return get_consent_response()


@app.route(f"/{COMMON_PATH}/Consent/<identifier>", methods=["GET"])
def get_consent_by_id(identifier: str) -> Union[dict, tuple]:
def get_consent_by_id(identifier: str) -> Response:
"""Sandbox API for GET /Consent/{id}

Returns:
Union[dict, tuple]: Response for GET /Consent/{id}
Response: Response for GET /Consent/{id}
"""
return get_consent_by_id_response(identifier)


@app.route(f"/{COMMON_PATH}/Consent", methods=["POST"])
def post_consent() -> Union[dict, tuple]:
def post_consent() -> Response:
"""Sandbox API for POST /Consent

Returns:
Union[dict, tuple]: Response for POST /Consent
Response: Response for POST /Consent
"""
return post_consent_response()


@app.route(f"/{COMMON_PATH}/Consent/<identifier>", methods=["PATCH"])
def patch_consent(identifier: str) -> Union[dict, tuple]:
def patch_consent(identifier: str) -> Response:
"""Sandbox API for PATCH /Consent

Args:
identifier (str): Consent identifier to be patched

Returns:
Union[dict, tuple]: Response for PATCH /Consent
Response: Response for PATCH /Consent
"""
return patch_consent_response(identifier)
7 changes: 3 additions & 4 deletions sandbox/api/get_consent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from logging import INFO, basicConfig, getLogger
from typing import Union

from flask import request
from flask import request, Response

from .constants import (
GET_CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE,
Expand Down Expand Up @@ -36,11 +35,11 @@
logger = getLogger(__name__)


def get_consent_response() -> Union[dict, tuple]:
def get_consent_response() -> Response:
"""Sandbox API for GET /Consent

Returns:
Union[dict, tuple]: Response for GET /Consent
Response: Response for GET /Consent
"""
try:
# Check Headers
Expand Down
7 changes: 3 additions & 4 deletions sandbox/api/get_consent_by_id.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from logging import getLogger
from typing import Union

from flask import request
from flask import request, Response

from .constants import (
INTERNAL_SERVER_ERROR_EXAMPLE,
Expand All @@ -22,11 +21,11 @@
logger = getLogger(__name__)


def get_consent_by_id_response(identifier: str) -> Union[dict, tuple]:
def get_consent_by_id_response(identifier: str) -> Response:
"""Sandbox API for GET /Consent/{id}

Returns:
Union[dict, tuple]: Response for GET /Consent/{id}
Response: Response for GET /Consent/{id}
"""
try:
params = request.args.to_dict()
Expand Down
6 changes: 3 additions & 3 deletions sandbox/api/get_questionnaire_response_by_path_id.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import INFO, basicConfig, getLogger
from typing import Union
from flask import Response

from .constants import (
GET_QUESTIONNAIRE_RESPONSE__INVALID,
Expand All @@ -14,11 +14,11 @@
logger = getLogger(__name__)


def get_questionnaire_response_by_path_id_response(access_request_id: str) -> Union[dict, tuple]:
def get_questionnaire_response_by_path_id_response(access_request_id: str) -> Response:
"""Sandbox API for GET /QuestionnaireResponse/{id}

Returns:
Union[dict, tuple]: Response for GET /QuestionnaireResponse/{id}
Response: Response for GET /QuestionnaireResponse/{id}
"""
try:
if access_request_id == "156e1560-e532-4e2a-85ad-5aeff03dc43e":
Expand Down
9 changes: 4 additions & 5 deletions sandbox/api/get_related_person.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from logging import INFO, basicConfig, getLogger
from typing import Union

from flask import request
from flask import request, Response

from .constants import (
INTERNAL_SERVER_ERROR_EXAMPLE,
Expand All @@ -27,11 +26,11 @@
logger = getLogger(__name__)


def get_related_person_response() -> Union[dict, tuple]:
def get_related_person_response() -> Response:
"""Sandbox API for GET /RelatedPerson

Returns:
Union[dict, tuple]: Response for GET /RelatedPerson
Response: Response for GET /RelatedPerson
"""
try:
# Check Headers
Expand All @@ -42,7 +41,7 @@ def get_related_person_response() -> Union[dict, tuple]:
print("******** ERROR**** ")
identifier = remove_system(request.args.get("identifier"))
patient_identifier = remove_system(request.args.get("patient:identifier"))
include = request.args.get("_include")
include = request.args.get("_include", "")

if empty := check_for_empty(identifier, patient_identifier):
return empty
Expand Down
43 changes: 21 additions & 22 deletions sandbox/api/patch_consent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import INFO, basicConfig, getLogger
from typing import Union
from flask import Response

from .constants import (
INTERNAL_SERVER_ERROR_EXAMPLE,
Expand All @@ -23,14 +23,14 @@
logger = getLogger(__name__)


def patch_consent_response(id: str) -> Union[dict, tuple]:
def patch_consent_response(id: str) -> Response:

Check failure on line 26 in sandbox/api/patch_consent.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=NHSDigital_validated-relationships-service-api&issues=AaCgIAndTc_oGj4jNaNi&open=AaCgIAndTc_oGj4jNaNi&pullRequest=391
"""Sandbox API for PATCH /Consent

Args:
id (str): Consent id to be patched

Returns:
Union[dict, tuple]: Response for PATCH /Consent
Response: Response for PATCH /Consent
"""
try:
logger.debug("Received request to PATCH consent")
Expand All @@ -41,75 +41,74 @@
# Successful status update
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

elif id == "6b71ac92-baa3-4b76-b0f5-a601257e2722":
if id == "6b71ac92-baa3-4b76-b0f5-a601257e2722":
# Successful end date for a role
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

elif id == "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5":
if id == "43003db8-ffcd-4bd6-ab2f-b49b9656f9e5":
# Multiple valid changes
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

elif id == "849ea584-2318-471b-a24c-cee1b5ad0137":
if id == "849ea584-2318-471b-a24c-cee1b5ad0137":
# Invalid patch format
return generate_response_from_example(PATCH_CONSENT__INVALID_PATCH_FORMAT, 400)

elif id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f":
if id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f":
# Invalid path
return generate_response_from_example(PATCH_CONSENT__INVALID_PATH, 400)

elif id == "78c35330-fa2f-4934-a5dd-fff847f38de5":
if id == "78c35330-fa2f-4934-a5dd-fff847f38de5":
# Invalid status code
return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_CODE, 422)

elif id == "51fb4df5-815a-45cd-8427-04d6558336b7":
if 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":
if id == "7b7f47b8-96e5-43eb-b733-283bf1449f2c":
# Invalid state transition
return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422)

# Mandatory free text for OTHER reason codes
elif id == "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d":
if id == "d4e8a6f2-1c3b-4a7e-9d2f-8b5c7e9f1a3d":
# Missing free text for OTHER reason code (should fail)
return generate_response_from_example(PATCH_CONSENT__MISSING_FREE_TEXT_FOR_OTHER, 400)

elif id == "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7":
if id == "a1b2c3d4-e5f6-4789-a0b1-c2d3e4f5a6b7":
# Valid OTHER reason code WITH free text (should succeed)
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

# Optional free text for non-OTHER reason codes
elif id == "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8":
if id == "b2c3d4e5-f6a7-4890-b1c2-d3e4f5a6b7c8":
# Non-OTHER reason code WITHOUT free text (should succeed)
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

elif id == "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9":
if id == "c3d4e5f6-a7b8-4901-c2d3-e4f5a6b7c8d9":
# Non-OTHER reason code WITH free text (should succeed)
return generate_response_from_example(PATCH_CONSENT__SUCCESS, 200)

elif id == "90957744-b971-496e-b7c3-ab971868ce14":
if id == "90957744-b971-496e-b7c3-ab971868ce14":
# Missing grantor extension
return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR, 400)

elif id == "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1":
if id == "b68cbfc8-ccc2-48ad-b97b-b7410d773dc1":
# Invalid grantor identifier value
return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_VALUE, 422)

elif id == "fd189522-68e5-42dc-b44c-989be0eaa2bf":
if id == "fd189522-68e5-42dc-b44c-989be0eaa2bf":
# Invalid grantor identifier system
return generate_response_from_example(PATCH_CONSENT__INVALID_GRANTOR_SYSTEM, 422)

elif id == "7e764160-38b6-41eb-9012-a3e476cbc517":
if id == "7e764160-38b6-41eb-9012-a3e476cbc517":
# Missing grantor reference
return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_REFERENCE, 400)

elif id == "faefd8c5-5e24-4415-8252-96e9241c7e78":
if id == "faefd8c5-5e24-4415-8252-96e9241c7e78":
# Missing grantor identifier
return generate_response_from_example(PATCH_CONSENT__MISSING_GRANTOR_IDENTIFIER, 400)

else:
# Resource not found
return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404)
# Resource not found
return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404)

except Exception:
# Handle any general error
Expand Down
6 changes: 3 additions & 3 deletions sandbox/api/post_consent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import INFO, basicConfig, getLogger
from typing import Union
from flask import Response

from flask import request

Expand All @@ -21,11 +21,11 @@
logger = getLogger(__name__)


def post_consent_response() -> Union[dict, tuple]:
def post_consent_response() -> Response:
"""Sandbox API for POST /Consent

Returns:
Union[dict, tuple]: Response for POST /Consent
Response: Response for POST /Consent
"""
try:
logger.debug("Received request to POST consent")
Expand Down
6 changes: 3 additions & 3 deletions sandbox/api/post_questionnaire_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import INFO, basicConfig, getLogger
from typing import Union
from flask import Response

from flask import request

Expand All @@ -17,11 +17,11 @@
logger = getLogger(__name__)


def post_questionnaire_response_response() -> Union[dict, tuple]:
def post_questionnaire_response_response() -> Response:
"""Sandbox API for POST /QuestionnaireResponse

Returns:
Union[dict, tuple]: Response for POST /QuestionnaireResponse
Response: Response for POST /QuestionnaireResponse
"""
try:
logger.debug("Received request to POST questionnaire response")
Expand Down
Loading
Loading