|
10 | 10 | _set_create_time_fields, |
11 | 11 | handler, |
12 | 12 | ) |
| 13 | +from nrlf.core.constants import SNOMED_SYSTEM_URL |
13 | 14 | from nrlf.core.dynamodb.repository import DocumentPointer, DocumentPointerRepository |
14 | 15 | from nrlf.producer.fhir.r4.model import ( |
15 | 16 | DocumentReferenceRelatesTo, |
@@ -154,6 +155,71 @@ def test_create_document_reference_happy_path_with_ssp( |
154 | 155 | } |
155 | 156 |
|
156 | 157 |
|
| 158 | +@mock_aws |
| 159 | +@mock_repository |
| 160 | +@freeze_time("2024-03-21T12:34:56.789") |
| 161 | +@freeze_uuid("00000000-0000-0000-0000-000000000001") |
| 162 | +def test_create_document_reference_without_related_value_exception( |
| 163 | + repository: DocumentPointerRepository, |
| 164 | +): |
| 165 | + doc_ref = load_document_reference("Y05868-736253002-Valid-with-ssp-content") |
| 166 | + doc_ref.context = { |
| 167 | + "practiceSetting": { |
| 168 | + "coding": [ |
| 169 | + { |
| 170 | + "system": SNOMED_SYSTEM_URL, |
| 171 | + "code": "788002001", |
| 172 | + "display": "Adult mental health service", |
| 173 | + } |
| 174 | + ] |
| 175 | + }, |
| 176 | + "sourcePatientInfo": { |
| 177 | + "identifier": { |
| 178 | + "system": "https://fhir.nhs.uk/Id/nhs-number", |
| 179 | + "value": "6700028191", |
| 180 | + } |
| 181 | + }, |
| 182 | + "related": [{"identifier": {"system": "https://fhir.nhs.uk/Id/nhsSpineASID"}}], |
| 183 | + } |
| 184 | + |
| 185 | + event = create_test_api_gateway_event( |
| 186 | + headers=create_headers(), |
| 187 | + body=doc_ref.model_dump_json(exclude_none=True), |
| 188 | + ) |
| 189 | + |
| 190 | + result = handler(event, create_mock_context()) |
| 191 | + body = result.pop("body") |
| 192 | + |
| 193 | + assert result == { |
| 194 | + "statusCode": "400", |
| 195 | + "headers": default_response_headers(), |
| 196 | + "isBase64Encoded": False, |
| 197 | + } |
| 198 | + |
| 199 | + parsed_body = json.loads(body) |
| 200 | + |
| 201 | + assert parsed_body == { |
| 202 | + "resourceType": "OperationOutcome", |
| 203 | + "issue": [ |
| 204 | + { |
| 205 | + "severity": "error", |
| 206 | + "code": "value", |
| 207 | + "details": { |
| 208 | + "coding": [ |
| 209 | + { |
| 210 | + "code": "INVALID_IDENTIFIER_VALUE", |
| 211 | + "display": "Invalid identifier value", |
| 212 | + "system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1", |
| 213 | + } |
| 214 | + ] |
| 215 | + }, |
| 216 | + "diagnostics": "Invalid ASID value ''. A single ASID consisting of 12 digits can be provided in the context.related field.", |
| 217 | + "expression": ["context.related[0].identifier.value"], |
| 218 | + } |
| 219 | + ], |
| 220 | + } |
| 221 | + |
| 222 | + |
157 | 223 | def test_create_document_reference_no_body(): |
158 | 224 | event = create_test_api_gateway_event( |
159 | 225 | headers=create_headers(), |
|
0 commit comments