Skip to content

Commit 5a6bbd3

Browse files
committed
fix: updates to sandbox conditionals
1 parent 4c12c3f commit 5a6bbd3

File tree

6 files changed

+238
-119
lines changed

6 files changed

+238
-119
lines changed

sandbox/api/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
load_json_file,
3939
remove_system,
4040
check_for_consent_include_params,
41-
check_for_consent_filtering_params,
41+
check_for_consent_filtering,
4242
)
4343

4444
app = Flask(__name__)
@@ -162,8 +162,9 @@ def get_consent() -> Union[dict, tuple]:
162162
)
163163
# Filtering
164164
elif performer_identifier == "9000000017":
165-
return check_for_consent_filtering_params(
165+
return check_for_consent_filtering(
166166
status,
167+
_include,
167168
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE,
168169
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE,
169170
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE,

sandbox/api/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Consent examples
4545
CONSENT__DIRECTORY = "./api/examples/GET_Consent/"
4646
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE = (
47-
f"{CONSENT__DIRECTORY}filtered-relationships-status-active.yaml"
47+
f"{CONSENT__DIRECTORY}filtered-relationships-status-active-include-details.yaml"
4848
)
4949
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE = (
5050
f"{CONSENT__DIRECTORY}filtered-relationships-status-inactive.yaml"

sandbox/api/tests/test_utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,22 @@ def test_related_person__not_found(
5252
("request_args,response_file_name,status_code"),
5353
[
5454
(
55-
"performer:identifier=9000000017&status=active",
56-
"./api/examples/GET_Consent/filtered-relationships-status-active.yaml",
55+
"performer:identifier=9000000017&status=active&_include=Consent:performer&_include=Consent:patient",
56+
"./api/examples/GET_Consent/filtered-relationships-status-active-include-details.yaml",
5757
200,
5858
),
59+
(
60+
"performer:identifier=9000000017&status=active",
61+
"./api/examples/errors/invalidated-resource.yaml",
62+
404,
63+
),
5964
(
6065
"performer:identifier=9000000017&status=inactive",
6166
"./api/examples/GET_Consent/filtered-relationships-status-inactive.yaml",
6267
200,
6368
),
6469
(
65-
"performer:identifier=9000000017&status=proposed,active",
70+
"performer:identifier=9000000017&status=proposed&status=active",
6671
"./api/examples/GET_Consent/filtered-relationships-status-proposed-active.yaml",
6772
200,
6873
),
@@ -82,7 +87,7 @@ def test_related_person__not_found(
8287
200,
8388
),
8489
(
85-
"performer:identifier=9000000022&_include=Consent:performer,Consent:patient",
90+
"performer:identifier=9000000022&_include=Consent:performer&_include=Consent:patient",
8691
"./api/examples/GET_Consent/multiple-relationships-include-performer-patient.yaml",
8792
200,
8893
),
@@ -92,7 +97,7 @@ def test_related_person__not_found(
9297
200,
9398
),
9499
(
95-
"performer:identifier=9000000010&_include=Consent:performer,Consent:patient",
100+
"performer:identifier=9000000010&_include=Consent:performer&_include=Consent:patient",
96101
"./api/examples/GET_Consent/single-consenting-adult-relationship-include-performer-patient.yaml",
97102
200,
98103
),
@@ -102,7 +107,7 @@ def test_related_person__not_found(
102107
200,
103108
),
104109
(
105-
"performer:identifier=9000000019&_include=Consent:performer,Consent:patient",
110+
"performer:identifier=9000000019&_include=Consent:performer&_include=Consent:patient",
106111
"./api/examples/GET_Consent/single-mother-child-relationship-include-performer-patient.yaml",
107112
200,
108113
),

sandbox/api/utils.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def check_for_consent_include_params(
233233
"""Checks the GET consent request include params and provides the related response
234234
235235
Args:
236-
_include (list[str]): The include parameters supplied to the request
236+
_include (str): The include parameters supplied to the request
237237
include_none_response_yaml (str): Bundle to return when include params are empty
238238
include_both_response_yaml (str): Bundle to return when include param is Consent:performer,Consent:patient
239239
include_patient_response_yaml (str): (optional) Bundle to return when include param is Consent:patient
@@ -242,60 +242,67 @@ def check_for_consent_include_params(
242242
Returns:
243243
response: Resultant Response object based on input.
244244
"""
245-
if (
246-
CONSENT_PERFORMER not in _include
247-
and CONSENT_PATIENT not in _include
248-
and _include is not None
249-
):
250-
return generate_response_from_example(BAD_REQUEST_INCLUDE_PARAM_INVALID, 400)
251-
elif len(_include) == 1:
252-
if _include == CONSENT_PERFORMER:
253-
if include_performer_response_yaml:
254-
return generate_response_from_example(include_performer_response_yaml, 200)
255-
else:
256-
logger.error("No consent performer example provided")
257-
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
258-
elif _include == CONSENT_PATIENT:
259-
if include_performer_response_yaml:
260-
return generate_response_from_example(include_patient_response_yaml, 200)
261-
else:
262-
logger.error("No consent:patient example provided")
263-
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
245+
if _include == [] or _include is None:
246+
return generate_response_from_example(include_none_response_yaml, 200)
247+
elif _include == [CONSENT_PERFORMER]:
248+
if include_performer_response_yaml:
249+
return generate_response_from_example(include_performer_response_yaml, 200)
250+
else:
251+
logger.error("No consent performer example provided")
252+
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
253+
elif _include == [CONSENT_PATIENT]:
254+
if include_performer_response_yaml:
255+
return generate_response_from_example(include_patient_response_yaml, 200)
256+
else:
257+
logger.error("No consent:patient example provided")
258+
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
264259
elif (
265260
len(_include) == 2
266261
and CONSENT_PATIENT in _include
267262
and CONSENT_PERFORMER in _include
268263
):
269264
return generate_response_from_example(include_both_response_yaml, 200)
270-
elif _include > 2:
271-
return generate_response_from_example(BAD_REQUEST_INCLUDE_PARAM_INVALID, 400)
272265
else:
273-
return generate_response_from_example(include_none_response_yaml, 200)
266+
return generate_response_from_example(BAD_REQUEST_INCLUDE_PARAM_INVALID, 400)
274267

275268

276-
def check_for_consent_filtering_params(
269+
def check_for_consent_filtering(
277270
status: list[str],
278-
status_active_response_yaml: str,
271+
_include: list[str],
272+
status_active_with_details_response_yaml: str,
279273
status_inactive_response_yaml: str,
280274
status_proposed_and_active_response_yaml: str,
281275
) -> Response:
282276
"""Checks the GET consent request status params and provides related response
283277
284278
Args:
285279
status (list[str]): The status parameters supplied to the request
286-
status_active_response_yaml (str): Bundle to return when status param is 'active'
280+
status_none_response_yaml (str): Bundle to return when no status param is provided
281+
status_active_with_details_response_yaml (str): Bundle to return when status param is 'active'
287282
status_inactive_response_yaml (str): Bundle to return when status param is 'inactive'
288283
status_proposed_and_active_response_yaml (str): Bundle to return when status param is 'proposed,inactive'
289284
290285
Returns:
291286
response: Resultant Response object based on input.
292287
"""
293-
if len(status) == 1:
294-
if status == "active":
295-
return generate_response_from_example(status_active_response_yaml, 200)
296-
elif status == "inactive":
297-
return generate_response_from_example(status_inactive_response_yaml, 200)
298-
elif status == ["active","proposed"] or status == ["proposed","active"]:
288+
if status == [] or status is None:
289+
return generate_response_from_example(INVALIDATED_RESOURCE, 404)
290+
if status == ["active"]:
291+
if (
292+
len(_include) == 2
293+
and CONSENT_PERFORMER in _include
294+
and CONSENT_PERFORMER in _include
295+
):
296+
return generate_response_from_example(status_active_with_details_response_yaml, 200)
297+
else:
298+
return generate_response_from_example(INVALIDATED_RESOURCE, 404)
299+
elif status == ["inactive"]:
300+
return generate_response_from_example(status_inactive_response_yaml, 200)
301+
elif (
302+
len(status) == 2
303+
and "active" in status
304+
and "proposed" in status
305+
):
299306
return generate_response_from_example(
300307
status_proposed_and_active_response_yaml, 200
301308
)
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
ConsentMultipleRelationshipsStatusActiveIncludeDetailsBundle:
2+
summary: Multiple active relationships including performer and patient details
3+
description:
4+
A Bundle containing multiple active proxy relationships with varying legal basis' including the details
5+
of the performer and patient.
6+
value:
7+
resourceType: Bundle
8+
timestamp: "2020-08-26T14:00:00+00:00"
9+
total: 2
10+
type: searchset
11+
entry:
12+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742"
13+
resource:
14+
resourceType: RelatedPerson
15+
id: BE974742
16+
identifier:
17+
- system: "https://fhir.nhs.uk/Id/nhs-number"
18+
value: "9000000017"
19+
- system: "https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier"
20+
value: "ABC0000003"
21+
patient:
22+
type: Patient
23+
identifier:
24+
system: "https://fhir.nhs.uk/Id/nhs-number"
25+
value: "9000000017"
26+
relationship:
27+
- coding:
28+
- system: "http://terminology.hl7.org/CodeSystem/v3-RoleCode"
29+
code: PRN
30+
display: Parent
31+
- system: "http://terminology.hl7.org/CodeSystem/v3-RoleCode"
32+
code: MTH
33+
display: mother
34+
search:
35+
mode: include
36+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/A3CC67E2"
37+
resource:
38+
resourceType: Patient
39+
id: A3CC67E2
40+
identifier:
41+
- system: "https://fhir.nhs.uk/Id/nhs-number"
42+
value: "9000000009"
43+
- system: "https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier"
44+
value: "ABC1234567"
45+
name:
46+
- id: "123456"
47+
use: usual
48+
period:
49+
start: "2020-01-01"
50+
end: "2021-12-31"
51+
given:
52+
- "Jane Marie Anne"
53+
family: Smith
54+
prefix:
55+
- Mrs
56+
suffix:
57+
- MBE
58+
- PhD
59+
birthDate: "2022-10-22"
60+
generalPractitioner:
61+
- type: "Organization"
62+
identifier:
63+
value: "ODS12345"
64+
system: "https://fhir.nhs.uk/Id/ods-organization-code"
65+
search:
66+
mode: include
67+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/BBCC67E9"
68+
resource:
69+
resourceType: Consent
70+
id: BBCC67E9
71+
status: active
72+
scope:
73+
coding:
74+
- system: "http://terminology.hl7.org/CodeSystem/consentscope"
75+
code: patient-privacy
76+
display: "Privacy Consent"
77+
text: "Patient Privacy Consent"
78+
category:
79+
- coding:
80+
- system: "http://terminology.hl7.org/CodeSystem/v3-ActCode"
81+
code: INFA
82+
display: "Information Access"
83+
text: "Information Access Consent"
84+
patient:
85+
identifier:
86+
system: "https://fhir.nhs.uk/Id/nhs-number"
87+
value: "9000000009"
88+
dateTime: "2024-07-21T17:32:28Z"
89+
performer:
90+
- identifier:
91+
system: "https://fhir.nhs.uk/Id/nhs-number"
92+
value: "9000000017"
93+
policy:
94+
- authority: "https://www.england.nhs.uk"
95+
uri: "<REPLACE_WITH_LINK_TO_PUBLISHED_NATIONAL_PROXY_STANDARD>"
96+
search:
97+
mode: match
98+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/RP974720"
99+
resource:
100+
resourceType: RelatedPerson
101+
id: RP974720
102+
identifier:
103+
- system: "https://fhir.nhs.uk/Id/nhs-number"
104+
value: "9000000017"
105+
- system: "https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier"
106+
value: "ABC0000003"
107+
patient:
108+
type: Patient
109+
identifier:
110+
system: "https://fhir.nhs.uk/Id/nhs-number"
111+
value: "9000000005"
112+
relationship:
113+
- coding:
114+
- system: "https://fhir.hl7.org.uk/CodeSystem/UKCore-AdditionalPersonRelationshipRole"
115+
code: Personal
116+
display: "Personal relationship with the patient"
117+
search:
118+
mode: include
119+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/DFCC67F5"
120+
resource:
121+
resourceType: Patient
122+
id: DFCC67F5
123+
identifier:
124+
- system: "https://fhir.nhs.uk/Id/nhs-number"
125+
value: "9000000005"
126+
- system: "https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier"
127+
value: "ABC9999999"
128+
name:
129+
- id: "123456"
130+
use: usual
131+
period:
132+
start: "2020-01-01"
133+
end: "2021-12-31"
134+
given:
135+
- "Sally"
136+
family: Evans
137+
prefix:
138+
- Mrs
139+
birthDate: "1995-10-22"
140+
generalPractitioner:
141+
- type: "Organization"
142+
identifier:
143+
value: "ODS12345"
144+
system: "https://fhir.nhs.uk/Id/ods-organization-code"
145+
search:
146+
mode: include
147+
- fullUrl: "https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/WWCC67T1"
148+
resource:
149+
resourceType: Consent
150+
id: WWCC67T1
151+
status: active
152+
scope:
153+
coding:
154+
- system: "http://terminology.hl7.org/CodeSystem/consentscope"
155+
code: patient-privacy
156+
display: "Privacy Consent"
157+
text: "Patient Privacy Consent"
158+
category:
159+
- coding:
160+
- system: "http://terminology.hl7.org/CodeSystem/v3-ActCode"
161+
code: INFA
162+
display: "Information Access"
163+
text: "Information Access Consent"
164+
patient:
165+
identifier:
166+
system: "https://fhir.nhs.uk/Id/nhs-number"
167+
value: "9000000005"
168+
dateTime: "2024-07-21T17:32:28Z"
169+
performer:
170+
- identifier:
171+
system: "https://fhir.nhs.uk/Id/nhs-number"
172+
value: "9000000017"
173+
policy:
174+
- authority: "https://www.england.nhs.uk"
175+
uri: "<REPLACE_WITH_LINK_TO_PUBLISHED_NATIONAL_PROXY_STANDARD>"
176+
verification:
177+
- verified: true
178+
verifiedWith:
179+
identifier:
180+
system: "https://fhir.nhs.uk/Id/nhs-number"
181+
value: "9000000005"
182+
verificationDate: "2024-07-21T17:32:28Z"
183+
search:
184+
mode: match

0 commit comments

Comments
 (0)