Skip to content

Commit

Permalink
Merge pull request #82 from NHSDigital/NPA-1736-Sandbox-postman-colle…
Browse files Browse the repository at this point in the history
…ction-fix

NPA-1736: Reworked module import to resolve issue with gunicorn
  • Loading branch information
kamran-iqbal4-NHSD authored May 16, 2024
2 parents 965f602 + a5ccbb6 commit 775f60c
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions sandbox/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@

from flask import Flask, request

import sandbox.api.utils as utils
from .utils import (
VALIDATE_RELATIONSHIP_009,
VALIDATE_RELATIONSHIP_INCLUDE_009,
VALIDATE_RELATIONSHIP_025,
VALIDATE_RELATIONSHIP_INCLUDE_025,
LIST_RELATIONSHIP,
LIST_RELATIONSHIP_INCLUDE,
ERROR_RESPONSE,
check_for_errors,
check_for_empty,
check_for_validate,
check_for_list,
generate_response,
load_json_file,
)

app = Flask(__name__)
basicConfig(level=INFO, format="%(asctime)s - %(message)s")
Expand Down Expand Up @@ -31,48 +45,48 @@ def get_related_persons() -> Union[dict, tuple]:

try:
# Check Headers
if errors := utils.check_for_errors(request):
if errors := check_for_errors(request):
return errors

identifier = request.args.get("identifier")
patient_identifier = request.args.get("patient:identifier")
include = request.args.get("_include")

if empty := utils.check_for_empty(identifier, patient_identifier):
if empty := check_for_empty(identifier, patient_identifier):
return empty

# Successful request, select response
if zero_nine := utils.check_for_validate(
if zero_nine := check_for_validate(
"9000000009",
identifier,
patient_identifier,
include,
utils.VALIDATE_RELATIONSHIP_009,
utils.VALIDATE_RELATIONSHIP_INCLUDE_009,
VALIDATE_RELATIONSHIP_009,
VALIDATE_RELATIONSHIP_INCLUDE_009,
):
return zero_nine

if two_five := utils.check_for_validate(
if two_five := check_for_validate(
"9000000025",
identifier,
patient_identifier,
include,
utils.VALIDATE_RELATIONSHIP_025,
utils.VALIDATE_RELATIONSHIP_INCLUDE_025,
VALIDATE_RELATIONSHIP_025,
VALIDATE_RELATIONSHIP_INCLUDE_025,
):
return two_five

if one_seven := utils.check_for_list(
if one_seven := check_for_list(
"9000000017",
identifier,
include,
utils.LIST_RELATIONSHIP,
utils.LIST_RELATIONSHIP_INCLUDE,
LIST_RELATIONSHIP,
LIST_RELATIONSHIP_INCLUDE,
):
return one_seven

raise ValueError("Invalid request")

except Exception as e:
logger.error(e)
return utils.generate_response(utils.load_json_file(utils.ERROR_RESPONSE), 500)
return generate_response(load_json_file(ERROR_RESPONSE), 500)

0 comments on commit 775f60c

Please sign in to comment.