Skip to content

Commit d86bd94

Browse files
NPA-4707: Added child as a relationship type for /RelatedPerson (#203)
* NPA-4707: Added child as a relationship type for /RelatedPerson * NPA-4707: Examples for usage of patient relations * NPA-4707: Corrected references * NPA-4707: Added error for patient identifier
1 parent 05b457f commit d86bd94

File tree

9 files changed

+173
-4
lines changed

9 files changed

+173
-4
lines changed

sandbox/api/constants.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
INCLUDE_FLAG = "RelatedPerson:patient"
22

3-
PATIENT_IDENTIFIERS = ["9000000017", "9000000033"]
4-
RELATED_IDENTIFIERS = ["9000000009", "9000000025"]
3+
PATIENT_IDENTIFIERS = ["9000000017", "9000000033", "9000000042"]
4+
RELATED_IDENTIFIERS = ["9000000009", "9000000025", "9000000042"]
55

66
CONSENT_PERFORMER = "Consent:performer"
77
CONSENT_PATIENT = "Consent:patient"
@@ -92,9 +92,12 @@
9292
RELATED__ERROR_IDENTIFIER_MISSING = f"{RELATED_DIRECTORY}errors/invalid-identifier-missing.yaml"
9393
RELATED__ERROR_IDENTIFIER_SYSTEM = f"{RELATED_DIRECTORY}errors/invalid-identifier-system.yaml"
9494
RELATED__ERROR_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-identifier.yaml"
95+
RELATED__ERROR_PATIENT_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-patient-identifier.yaml"
9596
RELATED__EMPTY_RESPONSE = f"{RELATED_DIRECTORY}empty_response.yaml"
9697
RELATED__LIST_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000017.yaml"
9798
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000017_include.yaml"
99+
RELATED__LIST_CHILD_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000042.yaml"
100+
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000042_include.yaml"
98101
RELATED__VERIFY_RELATIONSHIP_09 = f"{RELATED_DIRECTORY}verify_relationship_9000000009.yaml"
99102
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE = f"{RELATED_DIRECTORY}verify_relationship_9000000009_include.yaml"
100103
RELATED__VERIFY_RELATIONSHIP_25 = f"{RELATED_DIRECTORY}verify_relationship_9000000025.yaml"

sandbox/api/get_related_person.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE,
1212
RELATED__VERIFY_RELATIONSHIP_25,
1313
RELATED__VERIFY_RELATIONSHIP_25_WITH_INCLUDE,
14+
RELATED__LIST_CHILD_RELATIONSHIP,
15+
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE,
1416
)
1517
from .utils import (
1618
check_for_empty,
@@ -34,8 +36,10 @@ def get_related_person_response() -> Union[dict, tuple]:
3436
try:
3537
# Check Headers
3638
if errors := check_for_get_related_person_errors(request):
39+
3740
return errors
3841

42+
print("******** ERROR**** ")
3943
identifier = remove_system(request.args.get("identifier"))
4044
patient_identifier = remove_system(request.args.get("patient:identifier"))
4145
include = request.args.get("_include")
@@ -72,6 +76,15 @@ def get_related_person_response() -> Union[dict, tuple]:
7276
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE,
7377
):
7478
return one_seven
79+
print("four2")
80+
if four_two := check_for_list(
81+
"9000000042",
82+
patient_identifier,
83+
include,
84+
RELATED__LIST_CHILD_RELATIONSHIP,
85+
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE,
86+
):
87+
return four_two
7588

7689
raise ValueError("Invalid request")
7790

sandbox/api/tests/test_get_related_person.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
"./api/examples/GET_RelatedPerson/list_relationship_9000000017_include.yaml",
2626
200,
2727
),
28+
(
29+
"patient:identifier=9000000042",
30+
"./api/examples/GET_RelatedPerson/list_relationship_9000000042.yaml",
31+
200,
32+
),
33+
(
34+
"patient:identifier=9000000042&_include=RelatedPerson:patient",
35+
"./api/examples/GET_RelatedPerson/list_relationship_9000000042_include.yaml",
36+
200,
37+
),
2838
(
2939
"identifier=9000000017&_include=any",
3040
"./api/examples/GET_RelatedPerson/list_relationship_9000000017.yaml",

sandbox/api/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
RELATED__ERROR_IDENTIFIER_MISSING,
2121
RELATED__ERROR_IDENTIFIER_SYSTEM,
2222
RELATED_IDENTIFIERS,
23+
RELATED__ERROR_PATIENT_IDENTIFIER,
2324
)
2425

2526
FHIR_MIMETYPE = "application/fhir+json"
@@ -42,13 +43,18 @@ def check_for_get_related_person_errors(request: Request) -> Optional[tuple]:
4243
Optional[tuple]: Tuple with response and status code if error is found
4344
"""
4445
identifier = request.args.get("identifier")
46+
patient = request.args.get("patient:identifier")
4547
identifier_without_system = remove_system(request.args.get("identifier"))
48+
patient_without_system = remove_system(request.args.get("patient:identifier"))
4649

47-
if not identifier:
50+
if not identifier and not patient:
4851
return generate_response_from_example(RELATED__ERROR_IDENTIFIER_MISSING, 400)
4952
elif identifier and len(identifier_without_system) != 10:
5053
# invalid identifier
5154
return generate_response_from_example(RELATED__ERROR_IDENTIFIER, 400)
55+
elif patient and len(patient_without_system) != 10:
56+
# invalid patient identifier
57+
return generate_response_from_example(RELATED__ERROR_PATIENT_IDENTIFIER, 400)
5258
elif (
5359
isinstance(identifier, str)
5460
and "|" in identifier
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
InvalidIdentifierPatientError:
2+
summary: Invalid Patient identifier
3+
description: Error raised due to an invalid Patient identifier request parameter being specified.
4+
value:
5+
issue:
6+
- code: invalid
7+
diagnostics: "Not a valid NHS Number provided for the 'patient:identifier' parameter"
8+
details:
9+
coding:
10+
- "system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode"
11+
version: "1"
12+
code: "INVALID_PATIENT_IDENTIFIER_VALUE"
13+
display: "Provided value is invalid"
14+
severity: error
15+
resourceType: "OperationOutcome"

specification/examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ListRelationship9000000017Include:
2-
summary: List relationship response for 9000000017
2+
summary: List relationship response for 9000000017 with include
33
description: |
44
Example response containing the details of a list of matched candidate proxy relationship between a birth mother and her children.
55
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
ListRelationship9000000042:
2+
summary: List relationship response for 9000000042
3+
description: |
4+
Example response containing the details of a list of matched relationship between a child and their birth mother.
5+
6+
The FHIR Bundle contains a `RelatedPerson` resource for each of the relationships verified against authoritative sources.
7+
8+
value:
9+
entry:
10+
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742
11+
resource:
12+
birthDate: '2017-09-23'
13+
id: BE974742
14+
identifier:
15+
- system: https://fhir.nhs.uk/Id/nhs-number
16+
value: '9000000042'
17+
name:
18+
- family: MOGAJI
19+
given:
20+
- GADIL
21+
id: BLnbA
22+
period:
23+
start: '2021-07-08'
24+
prefix:
25+
- MR
26+
use: usual
27+
patient:
28+
identifier:
29+
system: https://fhir.nhs.uk/Id/nhs-number
30+
value: '9000000009'
31+
type: Patient
32+
relationship:
33+
- coding:
34+
- code: CHILD
35+
display: child
36+
system: http://terminology.hl7.org/CodeSystem/v3-RoleCode
37+
resourceType: RelatedPerson
38+
search:
39+
mode: match
40+
link:
41+
- relation: self
42+
url: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson?patient:identifier=9000000042
43+
resourceType: Bundle
44+
timestamp: '2024-01-01T00:00:00+00:00'
45+
total: 1
46+
type: searchset
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
ListRelationship9000000042Include:
2+
summary: List relationship response for 9000000042 with include
3+
description: |
4+
Example response containing the details of a list of matched relationship between a child and their birth mother.
5+
6+
The FHIR Bundle contains a `RelatedPerson` resource for each of the relationships verified against authoritative sources.
7+
8+
`Patient` resources are included in the bundle when the `_include=RelatedPerson:patient` query parameter is specified.
9+
10+
value:
11+
entry:
12+
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742
13+
resource:
14+
birthDate: '2017-09-23'
15+
id: BE974742
16+
identifier:
17+
- system: https://fhir.nhs.uk/Id/nhs-number
18+
value: '9000000042'
19+
name:
20+
- family: MOGAJI
21+
given:
22+
- GADIL
23+
id: BLnbA
24+
period:
25+
start: '2021-07-08'
26+
prefix:
27+
- MR
28+
use: usual
29+
patient:
30+
identifier:
31+
system: https://fhir.nhs.uk/Id/nhs-number
32+
value: '9000000009'
33+
type: Patient
34+
relationship:
35+
- coding:
36+
- code: CHILD
37+
display: child
38+
system: http://terminology.hl7.org/CodeSystem/v3-RoleCode
39+
resourceType: RelatedPerson
40+
search:
41+
mode: match
42+
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/9000000009
43+
resource:
44+
birthDate: '2017-09-23'
45+
id: '9000000009'
46+
identifier:
47+
- system: https://fhir.nhs.uk/Id/nhs-number
48+
value: '9000000009'
49+
name:
50+
- family: MOGAJI
51+
given:
52+
- GADIL
53+
id: BLnbA
54+
period:
55+
start: '2021-07-08'
56+
prefix:
57+
- MR
58+
use: usual
59+
resourceType: Patient
60+
search:
61+
mode: include
62+
link:
63+
- relation: self
64+
url: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson?patient:identifier=9000000042
65+
resourceType: Bundle
66+
timestamp: '2024-01-01T00:00:00+00:00'
67+
total: 2
68+
type: searchset

specification/validated-relationships-service-api.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ paths:
362362
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
363363
| List Relationship | `identifier`=`9000000017` | HTTP Status 200 List of relationships for the proxy |
364364
| 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 |
365+
| List Patient Relationship | `patient:identifier`=`9000000042` | HTTP Status 200 List of relationships for the patient |
366+
| List Patient Relationship and include patient's details | `patient:identifier`=`9000000042` and `_include`=`RelatedPerson:patient` | HTTP Status 200 List of relationships for the patient and includes proxy data |
365367
| List Relationship and no relationships returned | `identifier`=`9000000033` | HTTP Status 200 Empty bundle |
366368
| Verify Relationship between proxy and patient | `identifier`=`9000000017` and `patient:identifier`=`9000000009` | HTTP Status 200 Verified relationship between patient and proxy |
367369
| 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 |
@@ -398,6 +400,10 @@ paths:
398400
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000017.yaml#/ListRelationship9000000017"
399401
listRelationshipIncludePatient:
400402
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml#/ListRelationship9000000017Include"
403+
listChildRelationship:
404+
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml#/ListRelationship9000000042"
405+
listChildRelationshipIncludePatient:
406+
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml#/ListRelationship9000000042Include"
401407
verifyRelationshipExample1:
402408
$ref: "./examples/responses/GET_RelatedPerson/verify_relationship_9000000009.yaml#/VerifyRelationship9000000009"
403409
verifyRelationshipExample1Include:
@@ -1955,13 +1961,15 @@ components:
19551961
- "MTH"
19561962
- "PRN"
19571963
- "Personal"
1964+
- "CHILD"
19581965
display:
19591966
type: string
19601967
description: FHIR relationship type.
19611968
enum:
19621969
- "mother"
19631970
- "parent"
19641971
- "Personal relationship with the patient"
1972+
- "Child"
19651973

19661974
Patient:
19671975
type: object

0 commit comments

Comments
 (0)