Skip to content

Commit eb3fd35

Browse files
committed
refactor: formatting updates
1 parent 6a972c4 commit eb3fd35

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed

sandbox/api/app.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CONSENT__NO_RELATIONSHIPS,
2626
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE,
2727
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE,
28-
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE
28+
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE,
2929
)
3030
from .utils import (
3131
check_for_empty,
@@ -37,7 +37,7 @@
3737
load_json_file,
3838
remove_system,
3939
check_for_consent_include_params,
40-
check_for_consent_filtering_params
40+
check_for_consent_filtering_params,
4141
)
4242

4343
app = Flask(__name__)
@@ -146,30 +146,30 @@ def get_consent() -> Union[dict, tuple]:
146146
_include = request.args.get("_include")
147147

148148
# Single consenting adult relationship
149-
if (performer_identifier == "9000000010"):
149+
if performer_identifier == "9000000010":
150150
return check_for_consent_include_params(
151151
_include,
152152
logger,
153153
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP,
154154
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH,
155155
)
156156
# Single mother child relationship
157-
elif (performer_identifier == "9000000019"):
157+
elif performer_identifier == "9000000019":
158158
return check_for_consent_include_params(
159159
_include,
160160
logger,
161161
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP,
162-
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH
162+
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH,
163163
)
164164
# Filtering
165-
elif (performer_identifier == "9000000017"):
165+
elif performer_identifier == "9000000017":
166166
return check_for_consent_filtering_params(
167167
status,
168168
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE,
169169
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE,
170-
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE
170+
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE,
171171
)
172-
elif (performer_identifier == "9000000022"):
172+
elif performer_identifier == "9000000022":
173173
return check_for_consent_include_params(
174174
_include,
175175
logger,
@@ -179,7 +179,7 @@ def get_consent() -> Union[dict, tuple]:
179179
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER,
180180
)
181181
# No relationships
182-
elif (performer_identifier == "9000000025"):
182+
elif performer_identifier == "9000000025":
183183
return generate_response_from_example(CONSENT__NO_RELATIONSHIPS, 200)
184184
else:
185185
logger.error(f"Performer identifier does not match examples")

sandbox/api/constants.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,44 @@
3434

3535
# Common examples
3636
INTERNAL_SERVER_ERROR_EXAMPLE = "./api/examples/errors/internal-server-error.yaml"
37-
BAD_REQUEST_INCLUDE_PARAM_INVALID = "./api/examples/errors/invalid-include-parameter.yaml"
37+
BAD_REQUEST_INCLUDE_PARAM_INVALID = (
38+
"./api/examples/errors/invalid-include-parameter.yaml"
39+
)
3840
NOT_FOUND = "./api/examples/errors/not-found.yaml"
3941
MISSING_IDENTIFIER = "./api/examples/errors/missing-identifier.yaml"
4042
INVALID_IDENTIFIER = "./api/examples/errors/invalid-identifier.yaml"
4143

4244
# Consent examples
4345
consent_dir = "./api/examples/GET_Consent/"
44-
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE = consent_dir + "filtered-relationships-status-active.yaml"
45-
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE = consent_dir + "filtered-relationships-status-inactive.yaml"
46+
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE = (
47+
consent_dir + "filtered-relationships-status-active.yaml"
48+
)
49+
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE = (
50+
consent_dir + "filtered-relationships-status-inactive.yaml"
51+
)
4652
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE = (
4753
consent_dir + "filtered-relationships-status-proposed-active.yaml"
4854
)
4955
CONSENT__MULTIPLE_RELATIONSHIPS = consent_dir + "multiple-relationships.yaml"
50-
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH = consent_dir + "multiple-relationships-include-performer-patient.yaml"
51-
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT = consent_dir + "multiple-relationships-include-patient.yaml"
52-
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER = consent_dir + "multiple-relationships-include-performer.yaml"
56+
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH = (
57+
consent_dir + "multiple-relationships-include-performer-patient.yaml"
58+
)
59+
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT = (
60+
consent_dir + "multiple-relationships-include-patient.yaml"
61+
)
62+
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER = (
63+
consent_dir + "multiple-relationships-include-performer.yaml"
64+
)
5365
CONSENT__NO_RELATIONSHIPS = consent_dir + "no-relationships.yaml"
54-
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP = consent_dir + "single-consenting-adult-relationship.yaml"
66+
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP = (
67+
consent_dir + "single-consenting-adult-relationship.yaml"
68+
)
5569
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH = (
5670
consent_dir + "single-consenting-adult-relationship-include-performer-patient.yaml"
5771
)
58-
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = consent_dir + "single-mother-child-relationship.yaml"
72+
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = (
73+
consent_dir + "single-mother-child-relationship.yaml"
74+
)
5975
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH = (
6076
consent_dir + "single-mother-child-relationship-include-performer-patient.yaml"
6177
)

sandbox/api/utils.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CONSENT_PATIENT,
1717
INTERNAL_SERVER_ERROR_EXAMPLE,
1818
CONSENT__STATUS_PARAM_INVALID,
19-
BAD_REQUEST_INCLUDE_PARAM_INVALID
19+
BAD_REQUEST_INCLUDE_PARAM_INVALID,
2020
)
2121

2222
FHIR_MIMETYPE = "application/fhir+json"
@@ -28,7 +28,7 @@ def load_json_file(file_name: str) -> dict:
2828
return load(file)
2929

3030

31-
def check_for_errors(request: Request, identifier_key : str) -> Optional[tuple]:
31+
def check_for_errors(request: Request, identifier_key: str) -> Optional[tuple]:
3232
"""Check for shared in the request headers and arguments
3333
3434
Args:
@@ -45,31 +45,22 @@ def check_for_errors(request: Request, identifier_key : str) -> Optional[tuple]:
4545
print(f"Identifier_without_system = {identifier_without_system}")
4646

4747
if not identifier:
48-
return (
49-
generate_response_from_example(
50-
"./api/examples/errors/missing-identifier.yaml"
51-
,
52-
400)
48+
return generate_response_from_example(
49+
"./api/examples/errors/missing-identifier.yaml", 400
5350
)
5451
elif identifier and len(identifier_without_system) != 10:
5552
# invalid identifier
56-
return (
57-
generate_response_from_example(
58-
"./api/examples/errors/invalid-identifier.yaml"
59-
,
60-
400)
53+
return generate_response_from_example(
54+
"./api/examples/errors/invalid-identifier.yaml", 400
6155
)
6256
elif (
6357
isinstance(identifier, str)
6458
and "|" in identifier
6559
and "https://fhir.nhs.uk/Id/nhs-number" != identifier.split("|", maxsplit=2)[0]
6660
):
6761
# invalid identifier system
68-
return (
69-
generate_response_from_example(
70-
"./api/examples/errors/invalid-identifier-system.yaml"
71-
,
72-
400)
62+
return generate_response_from_example(
63+
"./api/examples/errors/invalid-identifier-system.yaml", 400
7364
)
7465

7566

@@ -194,12 +185,12 @@ def generate_response_from_example(example_path: str, status_code: int) -> Respo
194185

195186

196187
def check_for_consent_include_params(
197-
_include : str,
188+
_include: str,
198189
logger: logging.Logger,
199190
include_none_response_yaml: str,
200-
include_both_response_yaml : str,
191+
include_both_response_yaml: str,
201192
include_patient_response_yaml: str = None,
202-
include_performer_response_yaml: str = None
193+
include_performer_response_yaml: str = None,
203194
) -> Response:
204195
"""Checks the GET consent request include params and provides the related response
205196
@@ -222,29 +213,32 @@ def check_for_consent_include_params(
222213
and _include != None
223214
):
224215
return generate_response_from_example(BAD_REQUEST_INCLUDE_PARAM_INVALID, 400)
225-
elif (_include == CONSENT_PERFORMER):
216+
elif _include == CONSENT_PERFORMER:
226217
if include_performer_response_yaml:
227218
return generate_response_from_example(include_performer_response_yaml, 200)
228219
else:
229220
logger.error("No consent performer example provided")
230221
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
231-
elif (_include == CONSENT_PATIENT):
222+
elif _include == CONSENT_PATIENT:
232223
if include_performer_response_yaml:
233224
return generate_response_from_example(include_patient_response_yaml, 200)
234225
else:
235226
logger.error("No consent:patient example provided")
236227
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
237-
elif (_include == f"{CONSENT_PATIENT},{CONSENT_PERFORMER}" or _include == f"{CONSENT_PERFORMER},{CONSENT_PATIENT}"):
228+
elif (
229+
_include == f"{CONSENT_PATIENT},{CONSENT_PERFORMER}"
230+
or _include == f"{CONSENT_PERFORMER},{CONSENT_PATIENT}"
231+
):
238232
return generate_response_from_example(include_both_response_yaml, 200)
239233
else:
240234
return generate_response_from_example(include_none_response_yaml, 200)
241235

242236

243237
def check_for_consent_filtering_params(
244-
status : str,
245-
status_active_response_yaml : str,
246-
status_inactive_response_yaml : str,
247-
status_proposed_and_inactive_response_yaml : str
238+
status: str,
239+
status_active_response_yaml: str,
240+
status_inactive_response_yaml: str,
241+
status_proposed_and_inactive_response_yaml: str,
248242
) -> Response:
249243
"""Checks the GET consent request status params and provides related response
250244
@@ -257,11 +251,13 @@ def check_for_consent_filtering_params(
257251
Returns:
258252
response: Resultant Response object based on input.
259253
"""
260-
if (status == "active"):
254+
if status == "active":
261255
return generate_response_from_example(status_active_response_yaml, 200)
262-
elif (status == "inactive"):
256+
elif status == "inactive":
263257
return generate_response_from_example(status_inactive_response_yaml, 200)
264-
elif (status == "proposed,inactive" or status == "inactive,proposed"):
265-
return generate_response_from_example(status_proposed_and_inactive_response_yaml, 200)
258+
elif status == "proposed,inactive" or status == "inactive,proposed":
259+
return generate_response_from_example(
260+
status_proposed_and_inactive_response_yaml, 200
261+
)
266262
else:
267263
return generate_response_from_example(CONSENT__STATUS_PARAM_INVALID, 400)

0 commit comments

Comments
 (0)