|
4 | 4 | from flask import Flask, request |
5 | 5 |
|
6 | 6 | from .constants import ( |
7 | | - CONSENT__ADULT_CONSENTING_EXAMPLE, |
8 | | - CONSENT__MIXED_EXAMPLE, |
9 | | - CONSENT__MOTHER_CHILD_EXAMPLE, |
10 | | - CONSENT_PERFORMER, |
11 | 7 | INTERNAL_ERROR_RESPONSE, |
12 | 8 | INTERNAL_SERVER_ERROR_EXAMPLE, |
13 | 9 | LIST_RELATIONSHIP, |
14 | 10 | LIST_RELATIONSHIP_INCLUDE, |
15 | | - NOT_FOUND, |
| 11 | + INVALIDATED_RESOURCE, |
16 | 12 | QUESTIONNAIRE_RESPONSE_SUCCESS, |
17 | 13 | VALIDATE_RELATIONSHIP_009, |
18 | 14 | VALIDATE_RELATIONSHIP_025, |
19 | 15 | VALIDATE_RELATIONSHIP_INCLUDE_009, |
20 | 16 | VALIDATE_RELATIONSHIP_INCLUDE_025, |
| 17 | + CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP, |
| 18 | + CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH, |
| 19 | + CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP, |
| 20 | + CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH, |
| 21 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH, |
| 22 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER, |
| 23 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT, |
| 24 | + CONSENT__MULTIPLE_RELATIONSHIPS, |
| 25 | + CONSENT__NO_RELATIONSHIPS, |
| 26 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE, |
| 27 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE, |
| 28 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE, |
21 | 29 | ) |
22 | 30 | from .utils import ( |
23 | 31 | check_for_empty, |
24 | | - check_for_errors, |
| 32 | + check_for_consent_errors, |
| 33 | + check_for_related_person_errors, |
25 | 34 | check_for_list, |
26 | 35 | check_for_validate, |
27 | 36 | generate_response, |
28 | 37 | generate_response_from_example, |
29 | 38 | load_json_file, |
30 | 39 | remove_system, |
| 40 | + check_for_consent_include_params, |
| 41 | + check_for_consent_filtering, |
31 | 42 | ) |
32 | 43 |
|
33 | 44 | app = Flask(__name__) |
@@ -57,7 +68,7 @@ def get_related_persons() -> Union[dict, tuple]: |
57 | 68 |
|
58 | 69 | try: |
59 | 70 | # Check Headers |
60 | | - if errors := check_for_errors(request): |
| 71 | + if errors := check_for_related_person_errors(request): |
61 | 72 | return errors |
62 | 73 |
|
63 | 74 | identifier = remove_system(request.args.get("identifier")) |
@@ -127,32 +138,52 @@ def get_consent() -> Union[dict, tuple]: |
127 | 138 | Union[dict, tuple]: Response for GET /Consent |
128 | 139 | """ |
129 | 140 | try: |
130 | | - performer_identifier = remove_system(request.args.get("performer:identifier")) |
131 | | - status = request.args.get("status") |
132 | | - _include = request.args.get("_include") |
| 141 | + # Check Headers |
| 142 | + if errors := check_for_consent_errors(request): |
| 143 | + return errors |
133 | 144 |
|
134 | | - if ( |
135 | | - performer_identifier == "9000000010" |
136 | | - and status == "active" |
137 | | - and _include == CONSENT_PERFORMER |
138 | | - ): |
139 | | - return generate_response_from_example( |
140 | | - CONSENT__ADULT_CONSENTING_EXAMPLE, 200 |
| 145 | + performer_identifier = remove_system(request.args.get("performer:identifier")) |
| 146 | + status = request.args.getlist("status") |
| 147 | + _include = request.args.getlist("_include") |
| 148 | + |
| 149 | + # Single consenting adult relationship |
| 150 | + if performer_identifier == "9000000010": |
| 151 | + return check_for_consent_include_params( |
| 152 | + _include, |
| 153 | + CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP, |
| 154 | + CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH, |
141 | 155 | ) |
142 | | - elif ( |
143 | | - performer_identifier == "9000000017" |
144 | | - and status == "active" |
145 | | - and _include == CONSENT_PERFORMER |
146 | | - ): |
147 | | - return generate_response_from_example(CONSENT__MIXED_EXAMPLE, 200) |
148 | | - elif ( |
149 | | - performer_identifier == "9000000019" |
150 | | - and status == "active" |
151 | | - and _include == CONSENT_PERFORMER |
152 | | - ): |
153 | | - return generate_response_from_example(CONSENT__MOTHER_CHILD_EXAMPLE, 200) |
| 156 | + # Single mother child relationship |
| 157 | + elif performer_identifier == "9000000019": |
| 158 | + return check_for_consent_include_params( |
| 159 | + _include, |
| 160 | + CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP, |
| 161 | + CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH, |
| 162 | + ) |
| 163 | + # Filtering |
| 164 | + elif performer_identifier == "9000000017": |
| 165 | + return check_for_consent_filtering( |
| 166 | + status, |
| 167 | + _include, |
| 168 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE, |
| 169 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE, |
| 170 | + CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE, |
| 171 | + ) |
| 172 | + elif performer_identifier == "9000000022": |
| 173 | + return check_for_consent_include_params( |
| 174 | + _include, |
| 175 | + CONSENT__MULTIPLE_RELATIONSHIPS, |
| 176 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH, |
| 177 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT, |
| 178 | + CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER, |
| 179 | + ) |
| 180 | + # No relationships |
| 181 | + elif performer_identifier == "9000000025": |
| 182 | + return generate_response_from_example(CONSENT__NO_RELATIONSHIPS, 200) |
154 | 183 | else: |
155 | | - return generate_response(load_json_file(NOT_FOUND), 400) |
| 184 | + logger.error("Performer identifier does not match examples") |
| 185 | + return generate_response_from_example(INVALIDATED_RESOURCE, 404) |
| 186 | + |
156 | 187 | except Exception as e: |
157 | 188 | logger.error(e) |
158 | 189 | return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500) |
0 commit comments