Skip to content

Commit c8ffcec

Browse files
NPA-4749: Add scenarios for patient:identifier for single relationships
1 parent 7ef7a93 commit c8ffcec

File tree

4 files changed

+74
-29
lines changed

4 files changed

+74
-29
lines changed

sandbox/api/get_consent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,25 @@ def get_consent_response() -> Union[dict, tuple]:
4343
return errors
4444

4545
performer_identifier = remove_system(request.args.get("performer:identifier"))
46+
patient_identifier = remove_system(request.args.get("patient:identifier"))
4647
status = request.args.getlist("status")
4748
_include = request.args.getlist("_include")
4849

4950
# Single consenting adult relationship
50-
if performer_identifier == "9000000010":
51+
if performer_identifier == "9000000010" or patient_identifier == "9000000005":
5152
return check_for_consent_include_params(
5253
_include,
5354
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP,
5455
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH,
5556
)
5657
# Single mother child relationship
57-
elif performer_identifier == "9000000019":
58+
elif performer_identifier == "9000000019" or patient_identifier == "9000000009":
5859
return check_for_consent_include_params(
5960
_include,
6061
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP,
6162
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH,
6263
)
64+
# TODO: for patient identifier
6365
# Filtering
6466
elif performer_identifier == "9000000017":
6567
return check_for_consent_filtering(

sandbox/api/tests/test_get_consent.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,17 @@ def test_get_consent_returns_expected_responses__mocked_get_consent(
8989
200,
9090
),
9191
(
92-
"performer:identifier=9000000010",
92+
"performer:identifier=9000000010", # performer:identifier resulting in single adult relationship
93+
"./api/examples/GET_Consent/single-consenting-adult-relationship.yaml",
94+
200,
95+
),
96+
(
97+
"patient:identifier=9000000005",
98+
"./api/examples/GET_Consent/single-consenting-adult-relationship.yaml",
99+
200,
100+
),
101+
(
102+
"performer:identifier=9000000010&patient:identifier=9000000005",
93103
"./api/examples/GET_Consent/single-consenting-adult-relationship.yaml",
94104
200,
95105
),
@@ -98,16 +108,46 @@ def test_get_consent_returns_expected_responses__mocked_get_consent(
98108
"./api/examples/GET_Consent/single-consenting-adult-relationship-include-performer-patient.yaml",
99109
200,
100110
),
111+
(
112+
"patient:identifier=9000000005&_include=Consent:performer&_include=Consent:patient",
113+
"./api/examples/GET_Consent/single-consenting-adult-relationship-include-performer-patient.yaml",
114+
200,
115+
),
116+
(
117+
"performer:identifier=9000000010&patient:identifier=9000000005&_include=Consent:performer&_include=Consent:patient",
118+
"./api/examples/GET_Consent/single-consenting-adult-relationship-include-performer-patient.yaml",
119+
200,
120+
),
101121
(
102122
"performer:identifier=9000000019",
103123
"./api/examples/GET_Consent/single-mother-child-relationship.yaml",
104124
200,
105125
),
126+
(
127+
"patient:identifier=9000000009",
128+
"./api/examples/GET_Consent/single-mother-child-relationship.yaml",
129+
200,
130+
),
131+
(
132+
"performer:identifier=9000000019&patient:identifier=9000000009",
133+
"./api/examples/GET_Consent/single-mother-child-relationship.yaml",
134+
200,
135+
),
106136
(
107137
"performer:identifier=9000000019&_include=Consent:performer&_include=Consent:patient",
108138
"./api/examples/GET_Consent/single-mother-child-relationship-include-performer-patient.yaml",
109139
200,
110140
),
141+
(
142+
"patient:identifier=9000000009&_include=Consent:performer&_include=Consent:patient",
143+
"./api/examples/GET_Consent/single-mother-child-relationship-include-performer-patient.yaml",
144+
200,
145+
),
146+
(
147+
"performer:identifier=9000000019&patient:identifier=9000000009&_include=Consent:performer&_include=Consent:patient",
148+
"./api/examples/GET_Consent/single-mother-child-relationship-include-performer-patient.yaml",
149+
200,
150+
),
111151
(
112152
"performer:identifier=9000000017&status=test", # Invalid status parameter error
113153
"./api/examples/GET_Consent/errors/invalid-status-parameter.yaml",

sandbox/api/utils.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,31 @@ def check_for_get_consent_errors(request: Request) -> Optional[tuple]:
7070
Returns:
7171
Optional[tuple]: Tuple with response and status code if error is found
7272
"""
73-
identifier_key = "performer:identifier"
74-
identifier = request.args.get(identifier_key)
75-
identifier_without_system = remove_system(request.args.get(identifier_key))
73+
performer_identifier = request.args.get("performer:identifier")
74+
patient_identifier = request.args.get("patient:identifier")
7675

77-
if not identifier:
76+
if not performer_identifier and not patient_identifier:
7877
return generate_response_from_example("./api/examples/GET_Consent/errors/missing-identifier.yaml", 400)
79-
elif identifier and len(identifier_without_system) != 10:
80-
# invalid identifier
81-
return generate_response_from_example("./api/examples/GET_Consent/errors/invalid-identifier.yaml", 422)
82-
elif (
83-
isinstance(identifier, str)
84-
and "|" in identifier
85-
and "https://fhir.nhs.uk/Id/nhs-number" == identifier.split("|", maxsplit=2)[0]
86-
):
87-
# invalid identifier system
88-
return generate_response_from_example(
89-
"./api/examples/GET_Consent/errors/invalid-identifier-system.yaml",
90-
422,
91-
)
92-
elif identifier_without_system == "9000000012":
93-
# invalid status
94-
return generate_response_from_example(f"{GET_CONSENT_ERRORS}/gp-practice-not-found.yaml", 404)
78+
79+
for identifier in [performer_identifier, patient_identifier]:
80+
identifier_without_system = remove_system(identifier)
81+
82+
if identifier and len(identifier_without_system) != 10:
83+
# invalid identifier
84+
return generate_response_from_example("./api/examples/GET_Consent/errors/invalid-identifier.yaml", 422)
85+
elif (
86+
isinstance(identifier, str)
87+
and "|" in identifier
88+
and "https://fhir.nhs.uk/Id/nhs-number" == identifier.split("|", maxsplit=2)[0]
89+
):
90+
# invalid identifier system
91+
return generate_response_from_example(
92+
"./api/examples/GET_Consent/errors/invalid-identifier-system.yaml",
93+
422,
94+
)
95+
elif identifier_without_system == "9000000012":
96+
# invalid status
97+
return generate_response_from_example(f"{GET_CONSENT_ERRORS}/gp-practice-not-found.yaml", 404)
9598

9699

97100
def check_for_empty(identifier: str, patient_identifier: str) -> Response:

specification/validated-relationships-service-api.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,12 @@ paths:
457457
| Multiple proxy relationships including patient details | `performer:identifier`=`9000000022` and `_include` = `Consent:patient` | HTTP Status 200 Bundle containing a multiple proxy relationships including patient details |
458458
| Multiple proxy relationships including performer and patient details | `performer:identifier`=`9000000022` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` | HTTP Status 200 Bundle containing a multiple proxy relationships including performer and patient details |
459459
| No proxy relationships | `performer:identifier`=`9000000025` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` and `status` = `active` | HTTP Status 200 empty bundle |
460-
| A single proxy relationship between consenting adults | `performer:identifier`=`9000000010` | HTTP Status 200 Bundle containing a single proxy relationship |
461-
| A single proxy relationship between consenting adults including details | `performer:identifier`=`9000000010` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` | HTTP Status 200 Bundle containing a single proxy relationship including performer and patient details |
462-
| A single proxy relationship between a mother and child | `performer:identifier`=`9000000019` | HTTP Status 200 Bundle containing a single proxy relationship |
463-
| A single proxy relationship between a mother and child including details | `performer:identifier`=`9000000019` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` | HTTP Status 200 Bundle containing a single proxy relationship including performer and patient details |
464-
| Invalid status parameter | `performer:identifier`=`9000000019` and `status` = `test` | HTTP Status 422 and INVALID_VALUE error response |
465-
| Invalid include parameter | `performer:identifier`=`9000000019` and `_include` = `test` | HTTP Status 422 and INVALID_VALUE error response |
460+
| A single proxy relationship between consenting adults | `performer:identifier`=`9000000010` and/or `patient:identifier`=`9000000005` | HTTP Status 200 Bundle containing a single proxy relationship |
461+
| A single proxy relationship between consenting adults including details | `performer:identifier`=`9000000010` and/or `patient:identifier`=`9000000005` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` | HTTP Status 200 Bundle containing a single proxy relationship including performer and patient details |
462+
| A single proxy relationship between a mother and child | `performer:identifier`=`9000000019` and/or `patient:identifier`=`9000000009` | HTTP Status 200 Bundle containing a single proxy relationship |
463+
| A single proxy relationship between a mother and child including details | `performer:identifier`=`9000000019` and/or `patient:identifier`=`9000000009` and `_include` = `Consent:patient` and `_include` = `Consent:proxy` | HTTP Status 200 Bundle containing a single proxy relationship including performer and patient details |
464+
| Invalid status parameter | `performer:identifier`=`9000000019` and/or `patient:identifier`=`9000000009` and `status` = `test` | HTTP Status 422 and INVALID_VALUE error response |
465+
| Invalid include parameter | `performer:identifier`=`9000000019` and/or `patient:identifier`=`9000000009` and `_include` = `test` | HTTP Status 422 and INVALID_VALUE error response |
466466
| Missing identifier | `patient:identifier`=`9000000009` | HTTP Status 400 and MISSING_IDENTIFIER_VALUE error response |
467467
| Invalid identifier | `identifier`=`900000000` Note: This identifier is 9 characters long, too short to be NHS Number | HTTP Status 422 and INVALID_IDENTIFIER_VALUE error response |
468468
| Invalid identifier system | `identifier`=`https://fhir.nhs.uk/Id/nhs-number/9730675929` | HTTP Status 422 and INVALID_IDENTIFIER_SYSTEM error response |

0 commit comments

Comments
 (0)