Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sandbox/api/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INCLUDE_FLAG = "RelatedPerson:patient"

PATIENT_IDENTIFIERS = ["9000000017", "9000000033"]
RELATED_IDENTIFIERS = ["9000000009", "9000000025"]
PATIENT_IDENTIFIERS = ["9000000017", "9000000033", "9000000042"]
RELATED_IDENTIFIERS = ["9000000009", "9000000025", "9000000042"]

CONSENT_PERFORMER = "Consent:performer"
CONSENT_PATIENT = "Consent:patient"
Expand Down Expand Up @@ -92,9 +92,12 @@
RELATED__ERROR_IDENTIFIER_MISSING = f"{RELATED_DIRECTORY}errors/invalid-identifier-missing.yaml"
RELATED__ERROR_IDENTIFIER_SYSTEM = f"{RELATED_DIRECTORY}errors/invalid-identifier-system.yaml"
RELATED__ERROR_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-identifier.yaml"
RELATED__ERROR_PATIENT_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-patient-identifier.yaml"
RELATED__EMPTY_RESPONSE = f"{RELATED_DIRECTORY}empty_response.yaml"
RELATED__LIST_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000017.yaml"
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000017_include.yaml"
RELATED__LIST_CHILD_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000042.yaml"
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000042_include.yaml"
RELATED__VERIFY_RELATIONSHIP_09 = f"{RELATED_DIRECTORY}verify_relationship_9000000009.yaml"
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE = f"{RELATED_DIRECTORY}verify_relationship_9000000009_include.yaml"
RELATED__VERIFY_RELATIONSHIP_25 = f"{RELATED_DIRECTORY}verify_relationship_9000000025.yaml"
Expand Down
13 changes: 13 additions & 0 deletions sandbox/api/get_related_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE,
RELATED__VERIFY_RELATIONSHIP_25,
RELATED__VERIFY_RELATIONSHIP_25_WITH_INCLUDE,
RELATED__LIST_CHILD_RELATIONSHIP,
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE,
)
from .utils import (
check_for_empty,
Expand All @@ -34,8 +36,10 @@ def get_related_person_response() -> Union[dict, tuple]:
try:
# Check Headers
if errors := check_for_get_related_person_errors(request):

return errors

print("******** ERROR**** ")
identifier = remove_system(request.args.get("identifier"))
patient_identifier = remove_system(request.args.get("patient:identifier"))
include = request.args.get("_include")
Expand Down Expand Up @@ -72,6 +76,15 @@ def get_related_person_response() -> Union[dict, tuple]:
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE,
):
return one_seven
print("four2")
if four_two := check_for_list(
"9000000042",
patient_identifier,
include,
RELATED__LIST_CHILD_RELATIONSHIP,
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE,
):
return four_two

raise ValueError("Invalid request")

Expand Down
10 changes: 10 additions & 0 deletions sandbox/api/tests/test_get_related_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
"./api/examples/GET_RelatedPerson/list_relationship_9000000017_include.yaml",
200,
),
(
"patient:identifier=9000000042",
"./api/examples/GET_RelatedPerson/list_relationship_9000000042.yaml",
200,
),
(
"patient:identifier=9000000042&_include=RelatedPerson:patient",
"./api/examples/GET_RelatedPerson/list_relationship_9000000042_include.yaml",
200,
),
(
"identifier=9000000017&_include=any",
"./api/examples/GET_RelatedPerson/list_relationship_9000000017.yaml",
Expand Down
8 changes: 7 additions & 1 deletion sandbox/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RELATED__ERROR_IDENTIFIER_MISSING,
RELATED__ERROR_IDENTIFIER_SYSTEM,
RELATED_IDENTIFIERS,
RELATED__ERROR_PATIENT_IDENTIFIER,
)

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

if not identifier:
if not identifier and not patient:
return generate_response_from_example(RELATED__ERROR_IDENTIFIER_MISSING, 400)
elif identifier and len(identifier_without_system) != 10:
# invalid identifier
return generate_response_from_example(RELATED__ERROR_IDENTIFIER, 400)
elif patient and len(patient_without_system) != 10:
# invalid patient identifier
return generate_response_from_example(RELATED__ERROR_PATIENT_IDENTIFIER, 400)
elif (
isinstance(identifier, str)
and "|" in identifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
InvalidIdentifierPatientError:
summary: Invalid Patient identifier
description: Error raised due to an invalid Patient identifier request parameter being specified.
value:
issue:
- code: invalid
diagnostics: "Not a valid NHS Number provided for the 'patient:identifier' parameter"
details:
coding:
- "system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode"
version: "1"
code: "INVALID_PATIENT_IDENTIFIER_VALUE"
display: "Provided value is invalid"
severity: error
resourceType: "OperationOutcome"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ListRelationship9000000017Include:
summary: List relationship response for 9000000017
summary: List relationship response for 9000000017 with include
description: |
Example response containing the details of a list of matched candidate proxy relationship between a birth mother and her children.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ListRelationship9000000042:
summary: List relationship response for 9000000042
description: |
Example response containing the details of a list of matched relationship between a child and their birth mother.

The FHIR Bundle contains a `RelatedPerson` resource for each of the relationships verified against authoritative sources.

value:
entry:
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742
resource:
birthDate: '2017-09-23'
id: BE974742
identifier:
- system: https://fhir.nhs.uk/Id/nhs-number
value: '9000000042'
name:
- family: MOGAJI
given:
- GADIL
id: BLnbA
period:
start: '2021-07-08'
prefix:
- MR
use: usual
patient:
identifier:
system: https://fhir.nhs.uk/Id/nhs-number
value: '9000000009'
type: Patient
relationship:
- coding:
- code: CHILD
display: child
system: http://terminology.hl7.org/CodeSystem/v3-RoleCode
resourceType: RelatedPerson
search:
mode: match
link:
- relation: self
url: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson?patient:identifier=9000000042
resourceType: Bundle
timestamp: '2024-01-01T00:00:00+00:00'
total: 1
type: searchset
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
ListRelationship9000000042Include:
summary: List relationship response for 9000000042 with include
description: |
Example response containing the details of a list of matched relationship between a child and their birth mother.

The FHIR Bundle contains a `RelatedPerson` resource for each of the relationships verified against authoritative sources.

`Patient` resources are included in the bundle when the `_include=RelatedPerson:patient` query parameter is specified.

value:
entry:
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742
resource:
birthDate: '2017-09-23'
id: BE974742
identifier:
- system: https://fhir.nhs.uk/Id/nhs-number
value: '9000000042'
name:
- family: MOGAJI
given:
- GADIL
id: BLnbA
period:
start: '2021-07-08'
prefix:
- MR
use: usual
patient:
identifier:
system: https://fhir.nhs.uk/Id/nhs-number
value: '9000000009'
type: Patient
relationship:
- coding:
- code: CHILD
display: child
system: http://terminology.hl7.org/CodeSystem/v3-RoleCode
resourceType: RelatedPerson
search:
mode: match
- fullUrl: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/9000000009
resource:
birthDate: '2017-09-23'
id: '9000000009'
identifier:
- system: https://fhir.nhs.uk/Id/nhs-number
value: '9000000009'
name:
- family: MOGAJI
given:
- GADIL
id: BLnbA
period:
start: '2021-07-08'
prefix:
- MR
use: usual
resourceType: Patient
search:
mode: include
link:
- relation: self
url: https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson?patient:identifier=9000000042
resourceType: Bundle
timestamp: '2024-01-01T00:00:00+00:00'
total: 2
type: searchset
8 changes: 8 additions & 0 deletions specification/validated-relationships-service-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ paths:
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| List Relationship | `identifier`=`9000000017` | HTTP Status 200 List of relationships for the proxy |
| 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 |
| List Patient Relationship | `patient:identifier`=`9000000042` | HTTP Status 200 List of relationships for the patient |
| 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 |
| List Relationship and no relationships returned | `identifier`=`9000000033` | HTTP Status 200 Empty bundle |
| Verify Relationship between proxy and patient | `identifier`=`9000000017` and `patient:identifier`=`9000000009` | HTTP Status 200 Verified relationship between patient and proxy |
| 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 |
Expand Down Expand Up @@ -398,6 +400,10 @@ paths:
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000017.yaml#/ListRelationship9000000017"
listRelationshipIncludePatient:
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml#/ListRelationship9000000017Include"
listChildRelationship:
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml#/ListRelationship9000000042"
listChildRelationshipIncludePatient:
$ref: "./examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml#/ListRelationship9000000042Include"
verifyRelationshipExample1:
$ref: "./examples/responses/GET_RelatedPerson/verify_relationship_9000000009.yaml#/VerifyRelationship9000000009"
verifyRelationshipExample1Include:
Expand Down Expand Up @@ -1955,13 +1961,15 @@ components:
- "MTH"
- "PRN"
- "Personal"
- "CHILD"
display:
type: string
description: FHIR relationship type.
enum:
- "mother"
- "parent"
- "Personal relationship with the patient"
- "Child"

Patient:
type: object
Expand Down
Loading