diff --git a/sandbox/api/constants.py b/sandbox/api/constants.py index b5930479..adfd45a9 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" @@ -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" diff --git a/sandbox/api/get_related_person.py b/sandbox/api/get_related_person.py index bb23d7f8..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,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") 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/sandbox/api/utils.py b/sandbox/api/utils.py index 601b0d6c..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" @@ -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 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" 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..eaec262b --- /dev/null +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042.yaml @@ -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 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..d049a640 --- /dev/null +++ b/specification/examples/responses/GET_RelatedPerson/list_relationship_9000000042_include.yaml @@ -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 diff --git a/specification/validated-relationships-service-api.yaml b/specification/validated-relationships-service-api.yaml index 8dab3159..da2fba21 100644 --- a/specification/validated-relationships-service-api.yaml +++ b/specification/validated-relationships-service-api.yaml @@ -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 | @@ -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: @@ -1955,6 +1961,7 @@ components: - "MTH" - "PRN" - "Personal" + - "CHILD" display: type: string description: FHIR relationship type. @@ -1962,6 +1969,7 @@ components: - "mother" - "parent" - "Personal relationship with the patient" + - "Child" Patient: type: object