Skip to content

Commit dba1a10

Browse files
authored
Merge pull request #113 from NHSDigital/docs/NPA-3887_Document_Relation_Person_Sandbox_Scenarios_rebased
NPA-3887 Document Sandbox Responses
2 parents 0092e61 + d76d3ef commit dba1a10

File tree

7 files changed

+90
-28
lines changed

7 files changed

+90
-28
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ smoketest-report.xml
1919
env
2020
.dir-locals.el
2121
*.pyc
22+
23+
sandbox/output.json
24+
sandbox/pytest_html_report.html
25+
sandbox/archive/
26+
sandbox/.hypothesis/

sandbox/api/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
check_for_validate,
1919
generate_response,
2020
load_json_file,
21+
remove_system,
2122
)
2223

2324
app = Flask(__name__)
@@ -50,8 +51,8 @@ def get_related_persons() -> Union[dict, tuple]:
5051
if errors := check_for_errors(request):
5152
return errors
5253

53-
identifier = request.args.get("identifier")
54-
patient_identifier = request.args.get("patient:identifier")
54+
identifier = remove_system(request.args.get("identifier"))
55+
patient_identifier = remove_system(request.args.get("patient:identifier"))
5556
include = request.args.get("_include")
5657

5758
if empty := check_for_empty(identifier, patient_identifier):

sandbox/api/responses/GET_RelatedPerson/bad_request_missing_parameters.json renamed to sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_invalid.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"issue": [
33
{
4-
"code": "exception",
4+
"code": "invalid",
55
"details": {
66
"coding": [
77
{
8-
"code": "BAD_REQUEST",
9-
"display": "Required parameter(s) are missing.",
8+
"code": "INVALID_IDENTIFIER_VALUE",
9+
"display": "Provided value is invalid",
1010
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
1111
"version": "1"
1212
}
1313
]
1414
},
15-
"diagnostics": "Invalid request with error - One or more required parameters are missing.",
15+
"diagnostics": "Not a valid NHS Number provided for the 'identifier' parameter",
1616
"severity": "error"
1717
}
1818
],

sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_not_as_expected.json renamed to sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json

File renamed without changes.

sandbox/api/tests/test_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ def test_get_response(mock_open: MagicMock) -> None:
3232
),
3333
(
3434
"identifier=123456789", # identifier length is less than 10
35-
"./api/responses/GET_RelatedPerson/bad_request_identifier_not_as_expected.json",
35+
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid.json",
36+
400,
37+
),
38+
(
39+
"identifier=https://fhir.nhs.uk/ID/nhs-number|1234567890", # identifier system invalid
40+
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json",
3641
400,
3742
),
3843
],

sandbox/api/utils.py

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from json import load, dumps
2-
from typing import Optional
2+
from typing import Optional, Any
33

44
from flask import request, Response
55

@@ -49,17 +49,33 @@ def check_for_errors(request: request) -> Optional[tuple]:
4949
Returns:
5050
Optional[tuple]: Tuple with response and status code if error is found
5151
"""
52-
if not request.args.get("identifier"):
52+
identifier = request.args.get("identifier")
53+
identifier_without_system = remove_system(request.args.get("identifier"))
54+
55+
if not identifier:
5356
return (
5457
load_json_file(
5558
"./api/responses/GET_RelatedPerson/bad_request_identifier_missing.json"
5659
),
5760
400,
5861
)
59-
elif request.args.get("identifier") and len(request.args.get("identifier")) != 10:
62+
elif identifier and len(identifier_without_system) != 10:
63+
# invalid identifier
64+
return (
65+
load_json_file(
66+
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid.json"
67+
),
68+
400,
69+
)
70+
elif (
71+
isinstance(identifier, str)
72+
and "|" in identifier
73+
and "https://fhir.nhs.uk/Id/nhs-number" != identifier.split("|", maxsplit=2)[0]
74+
):
75+
# invalid identifier system
6076
return (
6177
load_json_file(
62-
"./api/responses/GET_RelatedPerson/bad_request_identifier_not_as_expected.json"
78+
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json"
6379
),
6480
400,
6581
)
@@ -91,8 +107,8 @@ def check_for_validate(
91107
identifier: str,
92108
patient_identifier: str,
93109
include: str,
94-
basefile: str,
95-
incfile: str,
110+
base_file: str,
111+
inc_file: str,
96112
) -> Response:
97113
"""Checks for validate request responses for a given relationship record
98114
@@ -101,41 +117,41 @@ def check_for_validate(
101117
identifier (str): The identifier supplied to the request
102118
patient_identifier (str): The patient:identifier supplied to the request
103119
include (str): The include parameter supplied to the request
104-
basefile (str): The file to return when record matches but does not request includeded data
105-
incfile (str): The file to return when record matches and does request included data
120+
base_file (str): The file to return when record matches but does not request included data
121+
inc_file (str): The file to return when record matches and does request included data
106122
107123
Returns:
108124
Response: Resultant response or None
109125
"""
110126
if identifier and patient_identifier == value and include == INCLUDE_FLAG:
111127
# Request with identifier, patient and _include=patient
112-
return generate_response(load_json_file(incfile))
128+
return generate_response(load_json_file(inc_file))
113129
elif identifier and patient_identifier == value:
114130
# Request with identifier and patient
115-
return generate_response(load_json_file(basefile))
131+
return generate_response(load_json_file(base_file))
116132

117133

118134
def check_for_list(
119-
value: str, identifier: str, include: str, basefile: str, incfile: str
135+
value: str, identifier: str, include: str, base_file: str, inc_file: str
120136
) -> Response:
121137
"""Check for a list relationship response for a given NHS number
122138
123139
Args:
124140
value (str): NHS number of the relationship to look for
125141
identifier (str): The identifier supplied to the request
126142
include (str): The include parameter supplied to the request
127-
basefile (str): The file to return when record matches but does not request includeded data
128-
incfile (str): The file to return when record matches and does request included data
143+
base_file (str): The file to return when record matches but does not request included data
144+
inc_file (str): The file to return when record matches and does request included data
129145
130146
Returns:
131147
Response: Resultant response or None
132148
"""
133149
if identifier == value and include == INCLUDE_FLAG:
134150
# Request with identifier and _include=patient
135-
return generate_response(load_json_file(incfile))
151+
return generate_response(load_json_file(inc_file))
136152
elif identifier:
137153
# Request with identifier
138-
return generate_response(load_json_file(basefile))
154+
return generate_response(load_json_file(base_file))
139155

140156

141157
def generate_response(content: str, status: int = 200):
@@ -149,3 +165,12 @@ def generate_response(content: str, status: int = 200):
149165
Response: Resultant Response object based on input.
150166
"""
151167
return Response(dumps(content), status=status, mimetype="application/fhir+json")
168+
169+
170+
def remove_system(identifier: Any) -> str:
171+
if isinstance(identifier, str):
172+
if "|" in identifier:
173+
# Identifier includes system
174+
return identifier.split("|", maxsplit=1)[1]
175+
return identifier
176+
return ""

specification/validated-relationships-service-api.yaml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ paths:
162162
163163
## Sandbox test scenarios
164164
165-
For details of sandbox test scenarios, or to try out the sandbox using our 'Try it out' feature, see the documentation for each endpoint.
165+
| Scenario | Request | Response |
166+
| --------------- | ----------------------------------------------- | -------------------------------- |
167+
| Example request | Example questionnaire response from try it now | HTTP Status 200 Success response |
168+
169+
### Sandbox constraints
170+
- Questionnaire Response is not validated.
171+
- Headers are not tested. `X-Request-ID` and `X-Correlation-ID` are disregarded.
172+
173+
Or perhaps you'd like to try out the sandbox using our 'Try it out' feature.
166174
167175
operationId: new-access-request
168176
parameters:
@@ -253,7 +261,25 @@ paths:
253261
254262
## Sandbox test scenarios
255263
256-
For details of sandbox test scenarios, or to try out the sandbox using our 'Try it out' feature, see the documentation for each endpoint.
264+
| Scenario | Request | Response |
265+
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
266+
| List Relationship | `identifier`=`9000000017` | HTTP Status 200 List of relationships for the proxy |
267+
| List Relationship and include patient's details | `identifier`=`9000000017` and `_include`=`RelatedPerson:patient` | HTTP Status 200 List of relationships for the proxy and includes patient data |
268+
| List Relationship and no relationships returned | `identifier`=`9000000033` | HTTP Status 200 Empty bundle |
269+
| Verify Relationship between proxy and patient | `identifier`=`9000000017` and `patient:identifier`=`9000000009` | HTTP Status 200 Verified relationship between patient and proxy |
270+
| Verify Relationship between proxy and patient and include patient's details | `identifier`=`9000000017` and `patient:identifier`=`9000000009` and `_include`=`RelatedPerson:patient` | HTTP Status 200 Verified relationship between patient and proxy and includes patient's details |
271+
| Verify Relationship between proxy and patient | `identifier`=`9000000017` and `patient:identifier`=`9000000025` | HTTP Status 200 Verified relationship between patient and proxy |
272+
| Verify Relationship between proxy and patient and include patient's details | `identifier`=`9000000017` and `patient:identifier`=`9000000025` and `_include`=`RelatedPerson:patient` | HTTP Status 200 Verified relationship between patient and proxy and includes patient's details |
273+
| Missing identifier | `patient:identifier`=`9000000009` | HTTP Status 400 and MISSING_IDENTIFIER_VALUE error response |
274+
| Invalid identifier | `identifier`=`900000000` Note: This identifier is 9 characters long, too short to be NHS Number | HTTP Status 400 and INVALID_IDENTIFIER_VALUE error response |
275+
| Invalid identifier system | `identifier`=`https://fhir.nhs.uk/Id/nhs-number/9730675929` | HTTP Status 400 and INVALID_IDENTIFIER_SYSTEM error response |
276+
| Identifier not supported in sandbox | `identifier`=`1000000001` | HTTP Status 404 and INVALIDATED_RESOURCE error response |
277+
278+
### Sandbox constraints
279+
- Headers are not tested. `X-Request-ID` and `X-Correlation-ID` are disregarded.
280+
- `patient:identifier` is not validated.
281+
282+
Or perhaps you'd like to try out the sandbox using our 'Try it out' feature.
257283
258284
operationId: get-validated-relationships
259285
parameters:
@@ -1684,10 +1710,10 @@ components:
16841710
format: token
16851711
examples:
16861712
withoutSystem:
1687-
value: 9000000009
1713+
value: 9000000017
16881714
summary: NHS number specified without system.
16891715
withSystem:
1690-
value: https://fhir.nhs.uk/Id/nhs-number|9000000009
1716+
value: https://fhir.nhs.uk/Id/nhs-number|9000000017
16911717
summary: System and NHS number specified
16921718

16931719
PatientIdentifier:
@@ -1701,10 +1727,10 @@ components:
17011727
format: token
17021728
examples:
17031729
withoutSystem:
1704-
value: 9000000017
1730+
value: 9000000009
17051731
summary: NHS number specified without system
17061732
withSystem:
1707-
value: https://fhir.nhs.uk/Id/nhs-number|9000000017
1733+
value: https://fhir.nhs.uk/Id/nhs-number|9000000009
17081734
summary: System and NHS number specified
17091735

17101736
ConsentBundlePerformerIdentifier:

0 commit comments

Comments
 (0)