Skip to content

Commit 656cfdc

Browse files
committed
npa-5087 - Added get consent by ID to sandbox
1 parent d9f4a28 commit 656cfdc

9 files changed

+370
-1
lines changed

sandbox/api/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from flask import Flask
55

66
from .get_consent import get_consent_response
7+
from .get_consent_by_id import get_consent_by_id_response
78
from .get_questionnaire_response import get_questionnaire_response_response
89
from .get_related_person import get_related_person_response
910
from .patch_consent import patch_consent_response
@@ -68,6 +69,16 @@ def get_consent() -> Union[dict, tuple]:
6869
return get_consent_response()
6970

7071

72+
@app.route(f"/{COMMON_PATH}/Consent/<identifier>", methods=["GET"])
73+
def get_consent_by_id(identifier: str) -> Union[dict, tuple]:
74+
"""Sandbox API for GET /Consent/{id}
75+
76+
Returns:
77+
Union[dict, tuple]: Response for GET /Consent/{id}
78+
"""
79+
return get_consent_by_id_response(identifier)
80+
81+
7182
@app.route(f"/{COMMON_PATH}/Consent", methods=["POST"])
7283
def post_consent() -> Union[dict, tuple]:
7384
"""Sandbox API for POST /Consent

sandbox/api/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@
4141
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH = (
4242
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer-patient.yaml"
4343
)
44+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PATIENT = f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-patient.yaml"
45+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PERFORMER = (
46+
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer.yaml"
47+
)
4448
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship.yaml"
4549
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH = (
4650
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-performer-patient.yaml"
4751
)
52+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PATIENT = f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-patient.yaml"
53+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PERFORMER = (
54+
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-performer.yaml"
55+
)
4856
GET_CONSENT__STATUS_PARAM_INVALID = f"{GET_CONSENT__DIRECTORY}errors/invalid-status-parameter.yaml"
4957
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT = (
5058
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient.yaml"
@@ -58,6 +66,11 @@
5866
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_BOTH = (
5967
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-performer-patient.yaml"
6068
)
69+
70+
# GET Consent by ID
71+
GET_CONSENT_BY_ID__INVALID_ID_ERROR = f"{GET_CONSENT__DIRECTORY}/ID/errors/invalid-id.yaml"
72+
GET_CONSENT_BY_ID__MISSING_ID_ERROR = f"{GET_CONSENT__DIRECTORY}/ID/errors/missing-id.yaml"
73+
6174
# POST Consent
6275
POST_CONSENT__DIRECTORY = "./api/examples/POST_Consent/"
6376
POST_CONSENT__SUCCESS = f"{POST_CONSENT__DIRECTORY}success.yaml"

sandbox/api/get_consent_by_id.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from logging import INFO, basicConfig, getLogger
2+
from typing import Union
3+
4+
from flask import request
5+
6+
logger = getLogger(__name__)
7+
8+
from .constants import (
9+
INTERNAL_SERVER_ERROR_EXAMPLE,
10+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP,
11+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH,
12+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PATIENT,
13+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PERFORMER,
14+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP,
15+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH,
16+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PATIENT,
17+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PERFORMER,
18+
GET_CONSENT_BY_ID__INVALID_ID_ERROR,
19+
GET_CONSENT_BY_ID__MISSING_ID_ERROR
20+
)
21+
from .utils import (
22+
generate_response_from_example,
23+
check_for_consent_include_params
24+
)
25+
26+
def get_consent_by_id_response(identifier: str) -> Union[dict, tuple]:
27+
"""Sandbox API for GET /Consent/{id}
28+
29+
Returns:
30+
Union[dict, tuple]: Response for GET /Consent/{id}
31+
"""
32+
try:
33+
_include = request.args.getlist("_include")
34+
35+
if identifier == "74eed847-ca25-4e76-8cf2-f2c2d7842a7a":
36+
return check_for_consent_include_params(
37+
_include,
38+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP,
39+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH,
40+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PATIENT,
41+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PERFORMER
42+
)
43+
elif identifier == "39df03a2-1b14-4d19-b1dc-d5d8cbf96948":
44+
return check_for_consent_include_params(
45+
_include,
46+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP,
47+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH,
48+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PATIENT,
49+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PERFORMER
50+
)
51+
elif identifier == "" or identifier is None:
52+
return generate_response_from_example(GET_CONSENT_BY_ID__MISSING_ID_ERROR)
53+
else:
54+
return generate_response_from_example(GET_CONSENT_BY_ID__INVALID_ID_ERROR)
55+
56+
except Exception:
57+
logger.exception("An error occurred while processing the request")
58+
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
ConsentSingleConsentingAdultRelationshipIncludePatientBundle:
2+
summary: Single consenting adult proxy relationship with patient details
3+
description:
4+
A Bundle containing a single proxy relationship between consenting adults including the patient details.
5+
value:
6+
resourceType: Bundle
7+
timestamp: '2020-08-26T14:00:00+00:00'
8+
total: 3
9+
type: searchset
10+
entry:
11+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/DFCC67F5
12+
resource:
13+
resourceType: Patient
14+
id: DFCC67F5
15+
identifier:
16+
- system: 'https://fhir.nhs.uk/Id/nhs-number'
17+
value: '9000000005'
18+
- system: 'https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier'
19+
value: ABC1234567
20+
name:
21+
- id: '123456'
22+
use: usual
23+
period:
24+
start: '2020-01-01'
25+
end: '2021-12-31'
26+
given:
27+
- Sally
28+
family: Evans
29+
prefix:
30+
- Mrs
31+
birthDate: '1995-10-22'
32+
generalPractitioner:
33+
- type: Organization
34+
identifier:
35+
value: ODS12345
36+
system: 'https://fhir.nhs.uk/Id/ods-organization-code'
37+
search:
38+
mode: include
39+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/WWCC67T1
40+
resource:
41+
resourceType: Consent
42+
id: WWCC67T1
43+
status: active
44+
scope:
45+
coding:
46+
- system: 'http://terminology.hl7.org/CodeSystem/consentscope'
47+
code: patient-privacy
48+
display: Privacy Consent
49+
text: Patient Privacy Consent
50+
category:
51+
- coding:
52+
- system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
53+
code: INFA
54+
display: Information Access
55+
text: Information Access Consent
56+
patient:
57+
identifier:
58+
system: 'https://fhir.nhs.uk/Id/nhs-number'
59+
value: '9000000005'
60+
dateTime: '2024-07-21T17:32:28Z'
61+
performer:
62+
- identifier:
63+
system: 'https://fhir.nhs.uk/Id/nhs-number'
64+
value: '9000000010'
65+
verification:
66+
- verified: true
67+
verifiedWith:
68+
identifier:
69+
system: 'https://fhir.nhs.uk/Id/nhs-number'
70+
value: '9000000005'
71+
verificationDate: '2024-07-21T17:32:28Z'
72+
search:
73+
mode: match
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ConsentSingleConsentingAdultRelationshipIncludePerformerBundle:
2+
summary: Single consenting adult proxy relationship with performer details
3+
description:
4+
A Bundle containing a single proxy relationship between consenting adults including the performer details.
5+
value:
6+
resourceType: Bundle
7+
timestamp: '2020-08-26T14:00:00+00:00'
8+
total: 3
9+
type: searchset
10+
entry:
11+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/RP974720
12+
resource:
13+
resourceType: RelatedPerson
14+
id: RP974720
15+
identifier:
16+
- system: 'https://fhir.nhs.uk/Id/nhs-number'
17+
value: '9000000010'
18+
- system: 'https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier'
19+
value: ABC0000008
20+
patient:
21+
type: Patient
22+
identifier:
23+
system: 'https://fhir.nhs.uk/Id/nhs-number'
24+
value: '9000000005'
25+
relationship:
26+
- coding:
27+
- system: >-
28+
https://fhir.hl7.org.uk/CodeSystem/UKCore-AdditionalPersonRelationshipRole
29+
code: Personal
30+
display: Personal relationship with the patient
31+
search:
32+
mode: include
33+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/WWCC67T1
34+
resource:
35+
resourceType: Consent
36+
id: WWCC67T1
37+
status: active
38+
scope:
39+
coding:
40+
- system: 'http://terminology.hl7.org/CodeSystem/consentscope'
41+
code: patient-privacy
42+
display: Privacy Consent
43+
text: Patient Privacy Consent
44+
category:
45+
- coding:
46+
- system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
47+
code: INFA
48+
display: Information Access
49+
text: Information Access Consent
50+
patient:
51+
identifier:
52+
system: 'https://fhir.nhs.uk/Id/nhs-number'
53+
value: '9000000005'
54+
dateTime: '2024-07-21T17:32:28Z'
55+
performer:
56+
- identifier:
57+
system: 'https://fhir.nhs.uk/Id/nhs-number'
58+
value: '9000000010'
59+
verification:
60+
- verified: true
61+
verifiedWith:
62+
identifier:
63+
system: 'https://fhir.nhs.uk/Id/nhs-number'
64+
value: '9000000005'
65+
verificationDate: '2024-07-21T17:32:28Z'
66+
search:
67+
mode: match
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
ConsentSingleAdultChildRelationshipIncludePatientBundle:
2+
summary: Single adult child proxy relationship with patient details
3+
description:
4+
A Bundle containing a single proxy relationship between an adult and child including the patient details.
5+
value:
6+
resourceType: Bundle
7+
timestamp: '2020-08-26T14:00:00+00:00'
8+
total: 3
9+
type: searchset
10+
entry:
11+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Patient/A3CC67E2
12+
resource:
13+
resourceType: Patient
14+
id: A3CC67E2
15+
identifier:
16+
- system: 'https://fhir.nhs.uk/Id/nhs-number'
17+
value: '9000000009'
18+
- system: 'https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier'
19+
value: ABC1234556
20+
name:
21+
- id: '123456'
22+
use: usual
23+
period:
24+
start: '2020-01-01'
25+
end: '2021-12-31'
26+
given:
27+
- Jane Marie Anne
28+
family: Smith
29+
prefix:
30+
- Mrs
31+
suffix:
32+
- MBE
33+
- PhD
34+
birthDate: '2022-10-22'
35+
generalPractitioner:
36+
- type: Organization
37+
identifier:
38+
value: ODS12345
39+
system: 'https://fhir.nhs.uk/Id/ods-organization-code'
40+
search:
41+
mode: include
42+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/BBCC67E9
43+
resource:
44+
resourceType: Consent
45+
id: BBCC67E9
46+
status: active
47+
scope:
48+
coding:
49+
- system: 'http://terminology.hl7.org/CodeSystem/consentscope'
50+
code: patient-privacy
51+
display: Privacy Consent
52+
text: Patient Privacy Consent
53+
category:
54+
- coding:
55+
- system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
56+
code: INFA
57+
display: Information Access
58+
text: Information Access Consent
59+
patient:
60+
identifier:
61+
system: 'https://fhir.nhs.uk/Id/nhs-number'
62+
value: '9000000009'
63+
dateTime: '2024-07-21T17:32:28Z'
64+
performer:
65+
- identifier:
66+
system: 'https://fhir.nhs.uk/Id/nhs-number'
67+
value: '9000000019'
68+
search:
69+
mode: match

specification/examples/responses/GET_Consent/single-mother-child-relationship-include-performer-patient.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ConsentSingleAdultChildRelationshipIncludePerformerPatientBundle:
22
summary: Single adult child proxy relationship with performer and patient details
33
description:
44
A Bundle containing a single proxy relationship between an adult and child including the performer
5-
and proxy details.
5+
and patient details.
66
value:
77
resourceType: Bundle
88
timestamp: '2020-08-26T14:00:00+00:00'
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
ConsentSingleAdultChildRelationshipIncludePerformerBundle:
2+
summary: Single adult child proxy relationship with performer details
3+
description:
4+
A Bundle containing a single proxy relationship between an adult and child including the performer details.
5+
value:
6+
resourceType: Bundle
7+
timestamp: '2020-08-26T14:00:00+00:00'
8+
total: 3
9+
type: searchset
10+
entry:
11+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/RelatedPerson/BE974742
12+
resource:
13+
resourceType: RelatedPerson
14+
id: BE974742
15+
identifier:
16+
- system: 'https://fhir.nhs.uk/Id/nhs-number'
17+
value: '9000000019'
18+
- system: 'https://placeholder.fhir.nhs.uk/Id/local-gp-patient-identifier'
19+
value: ABC0000001
20+
patient:
21+
type: Patient
22+
identifier:
23+
system: 'https://fhir.nhs.uk/Id/nhs-number'
24+
value: '9000000009'
25+
relationship:
26+
- coding:
27+
- system: 'http://terminology.hl7.org/CodeSystem/v3-RoleCode'
28+
code: PRN
29+
display: parent
30+
- system: 'http://terminology.hl7.org/CodeSystem/v3-RoleCode'
31+
code: MTH
32+
display: mother
33+
search:
34+
mode: include
35+
- fullUrl: https://api.service.nhs.uk/validated-relationships/FHIR/R4/Consent/BBCC67E9
36+
resource:
37+
resourceType: Consent
38+
id: BBCC67E9
39+
status: active
40+
scope:
41+
coding:
42+
- system: 'http://terminology.hl7.org/CodeSystem/consentscope'
43+
code: patient-privacy
44+
display: Privacy Consent
45+
text: Patient Privacy Consent
46+
category:
47+
- coding:
48+
- system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
49+
code: INFA
50+
display: Information Access
51+
text: Information Access Consent
52+
patient:
53+
identifier:
54+
system: 'https://fhir.nhs.uk/Id/nhs-number'
55+
value: '9000000009'
56+
dateTime: '2024-07-21T17:32:28Z'
57+
performer:
58+
- identifier:
59+
system: 'https://fhir.nhs.uk/Id/nhs-number'
60+
value: '9000000019'
61+
search:
62+
mode: match

0 commit comments

Comments
 (0)