From d20ae97f6f31cc81ca160ea681a317235dcf9620 Mon Sep 17 00:00:00 2001 From: kamran-iqbal4-NHSD <144686155+kamran-iqbal4-NHSD@users.noreply.github.com> Date: Wed, 21 May 2025 19:08:35 +0100 Subject: [PATCH 1/4] NPA-4707: Added child as a relationship type for /RelatedPerson --- specification/validated-relationships-service-api.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specification/validated-relationships-service-api.yaml b/specification/validated-relationships-service-api.yaml index c2005f11..e8ab0241 100644 --- a/specification/validated-relationships-service-api.yaml +++ b/specification/validated-relationships-service-api.yaml @@ -1952,6 +1952,7 @@ components: - "MTH" - "PRN" - "Personal" + - "CHILD" display: type: string description: FHIR relationship type. @@ -1959,6 +1960,7 @@ components: - "mother" - "parent" - "Personal relationship with the patient" + - "Child" Patient: type: object From 1bc07213f2d1a4e940d3506add9ed9285fa18af8 Mon Sep 17 00:00:00 2001 From: kamran-iqbal4-NHSD <144686155+kamran-iqbal4-NHSD@users.noreply.github.com> Date: Tue, 27 May 2025 14:16:06 +0100 Subject: [PATCH 2/4] NPA-4707: Examples for usage of patient relations --- sandbox/api/constants.py | 2 + sandbox/api/get_related_person.py | 9 +++ sandbox/api/tests/test_get_related_person.py | 10 ++++ .../list_relationship_9000000017_include.yaml | 2 +- .../list_relationship_9000000042.yaml | 35 ++++++++++++ .../list_relationship_9000000042_include.yaml | 57 +++++++++++++++++++ .../validated-relationships-service-api.yaml | 6 ++ 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml create mode 100644 specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml diff --git a/sandbox/api/constants.py b/sandbox/api/constants.py index b5930479..0897bf15 100644 --- a/sandbox/api/constants.py +++ b/sandbox/api/constants.py @@ -95,6 +95,8 @@ 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" diff --git a/sandbox/api/get_related_person.py b/sandbox/api/get_related_person.py index bb23d7f8..65d74b08 100644 --- a/sandbox/api/get_related_person.py +++ b/sandbox/api/get_related_person.py @@ -73,6 +73,15 @@ def get_related_person_response() -> Union[dict, tuple]: ): return one_seven + if four_two := check_for_list( + "9000000042", + patient_identifier, + include, + RELATED__LIST_RELATIONSHIP, + RELATED__LIST_RELATIONSHIP_WITH_INCLUDE, + ): + return four_two + raise ValueError("Invalid request") except Exception: diff --git a/sandbox/api/tests/test_get_related_person.py b/sandbox/api/tests/test_get_related_person.py index a9a539ba..99f621f6 100644 --- a/sandbox/api/tests/test_get_related_person.py +++ b/sandbox/api/tests/test_get_related_person.py @@ -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", diff --git a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml index c4c0e770..c795bb44 100644 --- a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000017_include.yaml @@ -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. diff --git a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml new file mode 100644 index 00000000..91c7c77d --- /dev/null +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml @@ -0,0 +1,35 @@ +ListRelationship9000000042: + summary: List relationship response for 9000000042 + description: | + Example response containing the details of a list of matched candidate proxy 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: + id: BE974742 + identifier: + - system: https://fhir.nhs.uk/Id/nhs-number + value: '9000000042' + 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 diff --git a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml new file mode 100644 index 00000000..3484f0a2 --- /dev/null +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml @@ -0,0 +1,57 @@ +ListRelationship9000000042Include: + summary: List relationship response for 9000000042 with include + description: | + Example response containing the details of a list of matched candidate proxy 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: + id: BE974742 + identifier: + - system: https://fhir.nhs.uk/Id/nhs-number + value: '9000000042' + 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 diff --git a/specification/validated-relationships-service-api.yaml b/specification/validated-relationships-service-api.yaml index e8ab0241..3f14dd01 100644 --- a/specification/validated-relationships-service-api.yaml +++ b/specification/validated-relationships-service-api.yaml @@ -359,6 +359,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 | `identifier`=`9000000042` | HTTP Status 200 List of relationships for the patient | + | List Patient Relationship and include patient's details | `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 | @@ -395,6 +397,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: From 207de29eb6d9a36690bd25e9478fcd8a787610c9 Mon Sep 17 00:00:00 2001 From: kamran-iqbal4-NHSD <144686155+kamran-iqbal4-NHSD@users.noreply.github.com> Date: Thu, 29 May 2025 15:49:16 +0100 Subject: [PATCH 3/4] NPA-4707: Corrected references --- sandbox/api/constants.py | 4 ++-- sandbox/api/get_related_person.py | 10 +++++++--- sandbox/api/utils.py | 4 +++- .../list_relationship_9000000042.yaml | 13 ++++++++++++- .../list_relationship_9000000042_include.yaml | 13 ++++++++++++- .../validated-relationships-service-api.yaml | 4 ++-- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/sandbox/api/constants.py b/sandbox/api/constants.py index 0897bf15..741a3fa3 100644 --- a/sandbox/api/constants.py +++ b/sandbox/api/constants.py @@ -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" diff --git a/sandbox/api/get_related_person.py b/sandbox/api/get_related_person.py index 65d74b08..97efa74a 100644 --- a/sandbox/api/get_related_person.py +++ b/sandbox/api/get_related_person.py @@ -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, @@ -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") @@ -72,13 +76,13 @@ 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_RELATIONSHIP, - RELATED__LIST_RELATIONSHIP_WITH_INCLUDE, + RELATED__LIST_CHILD_RELATIONSHIP, + RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE, ): return four_two diff --git a/sandbox/api/utils.py b/sandbox/api/utils.py index 601b0d6c..ad9d0aa1 100644 --- a/sandbox/api/utils.py +++ b/sandbox/api/utils.py @@ -42,9 +42,11 @@ 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 diff --git a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml index 91c7c77d..eaec262b 100644 --- a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml @@ -1,7 +1,7 @@ ListRelationship9000000042: summary: List relationship response for 9000000042 description: | - Example response containing the details of a list of matched candidate proxy relationship between a child and their birth mother. + 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. @@ -9,10 +9,21 @@ ListRelationship9000000042: 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 diff --git a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml index 3484f0a2..d049a640 100644 --- a/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml @@ -1,7 +1,7 @@ ListRelationship9000000042Include: summary: List relationship response for 9000000042 with include description: | - Example response containing the details of a list of matched candidate proxy relationship between a child and their birth mother. + 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. @@ -11,10 +11,21 @@ ListRelationship9000000042Include: 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 diff --git a/specification/validated-relationships-service-api.yaml b/specification/validated-relationships-service-api.yaml index 3f14dd01..683bb796 100644 --- a/specification/validated-relationships-service-api.yaml +++ b/specification/validated-relationships-service-api.yaml @@ -359,8 +359,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 | `identifier`=`9000000042` | HTTP Status 200 List of relationships for the patient | - | List Patient Relationship and include patient's details | `identifier`=`9000000042` and `_include`=`RelatedPerson:patient` | HTTP Status 200 List of relationships for the patient and includes proxy 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 | From a32e60aec48bf74967d69c4cd99680261360e469 Mon Sep 17 00:00:00 2001 From: kamran-iqbal4-NHSD <144686155+kamran-iqbal4-NHSD@users.noreply.github.com> Date: Thu, 29 May 2025 15:50:26 +0100 Subject: [PATCH 4/4] NPA-4707: Added error for patient identifier --- sandbox/api/constants.py | 1 + sandbox/api/utils.py | 4 ++++ .../errors/invalid-identifier-patient.yaml | 15 +++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 specification/examples/responses/GET_RelatedPerson/errors/invalid-identifier-patient.yaml diff --git a/sandbox/api/constants.py b/sandbox/api/constants.py index 741a3fa3..adfd45a9 100644 --- a/sandbox/api/constants.py +++ b/sandbox/api/constants.py @@ -92,6 +92,7 @@ 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" diff --git a/sandbox/api/utils.py b/sandbox/api/utils.py index ad9d0aa1..563f5a9f 100644 --- a/sandbox/api/utils.py +++ b/sandbox/api/utils.py @@ -20,6 +20,7 @@ RELATED__ERROR_IDENTIFIER_MISSING, RELATED__ERROR_IDENTIFIER_SYSTEM, RELATED_IDENTIFIERS, + RELATED__ERROR_PATIENT_IDENTIFIER, ) FHIR_MIMETYPE = "application/fhir+json" @@ -51,6 +52,9 @@ def check_for_get_related_person_errors(request: Request) -> Optional[tuple]: 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 diff --git a/specification/examples/responses/GET_RelatedPerson/errors/invalid-identifier-patient.yaml b/specification/examples/responses/GET_RelatedPerson/errors/invalid-identifier-patient.yaml new file mode 100644 index 00000000..47fd6462 --- /dev/null +++ b/specification/examples/responses/GET_RelatedPerson/errors/invalid-identifier-patient.yaml @@ -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"