Skip to content

Commit 0be240e

Browse files
authored
Merge pull request #556 from NHSDigital/feature/made14-NRL-520-fix-asids
[NRL-520] Move ASIDs to context.related for SSP content URLs
2 parents 7545d9d + f5d58f1 commit 0be240e

File tree

14 files changed

+1095
-54
lines changed

14 files changed

+1095
-54
lines changed

api/producer/createDocumentReference/tests/test_create_document_reference.py

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,71 @@ def test_create_document_reference_happy_path(repository: DocumentPointerReposit
8585
}
8686

8787

88+
@mock_aws
89+
@mock_repository
90+
@freeze_time("2024-03-21T12:34:56.789")
91+
@freeze_uuid("00000000-0000-0000-0000-000000000001")
92+
def test_create_document_reference_happy_path_with_ssp(
93+
repository: DocumentPointerRepository,
94+
):
95+
doc_ref_data = load_document_reference_data(
96+
"Y05868-736253002-Valid-with-ssp-content"
97+
)
98+
99+
event = create_test_api_gateway_event(
100+
headers=create_headers(),
101+
body=doc_ref_data,
102+
)
103+
104+
result = handler(event, create_mock_context())
105+
body = result.pop("body")
106+
107+
assert result == {
108+
"statusCode": "201",
109+
"headers": {
110+
"Location": "/nrl-producer-api/FHIR/R4/DocumentReference/Y05868-00000000-0000-0000-0000-000000000001"
111+
},
112+
"isBase64Encoded": False,
113+
}
114+
115+
parsed_body = json.loads(body)
116+
assert parsed_body == {
117+
"resourceType": "OperationOutcome",
118+
"issue": [
119+
{
120+
"severity": "information",
121+
"code": "informational",
122+
"details": {
123+
"coding": [
124+
{
125+
"code": "RESOURCE_CREATED",
126+
"display": "Resource created",
127+
"system": "https://fhir.nhs.uk/ValueSet/NRL-ResponseCode",
128+
}
129+
],
130+
},
131+
"diagnostics": "The document has been created",
132+
}
133+
],
134+
}
135+
136+
created_doc_pointer = repository.get_by_id(
137+
"Y05868-00000000-0000-0000-0000-000000000001"
138+
)
139+
140+
assert created_doc_pointer is not None
141+
assert created_doc_pointer.created_on == "2024-03-21T12:34:56.789Z"
142+
assert created_doc_pointer.updated_on is None
143+
assert json.loads(created_doc_pointer.document) == {
144+
**json.loads(doc_ref_data),
145+
"meta": {
146+
"lastUpdated": "2024-03-21T12:34:56.789Z",
147+
},
148+
"date": "2024-03-21T12:34:56.789Z",
149+
"id": "Y05868-00000000-0000-0000-0000-000000000001",
150+
}
151+
152+
88153
def test_create_document_reference_no_body():
89154
event = create_test_api_gateway_event(
90155
headers=create_headers(),
@@ -633,6 +698,176 @@ def test_create_document_reference_invalid_relatesto_type(
633698
}
634699

635700

701+
@mock_aws
702+
@mock_repository
703+
def test_create_document_reference_with_no_context_related_for_ssp_url(
704+
repository: DocumentPointerRepository,
705+
):
706+
doc_ref = load_document_reference("Y05868-736253002-Valid-with-ssp-content")
707+
708+
del doc_ref.context.related
709+
710+
event = create_test_api_gateway_event(
711+
headers=create_headers(
712+
pointer_types=[
713+
"http://snomed.info/sct|861421000000109",
714+
"http://snomed.info/sct|736253002",
715+
]
716+
),
717+
body=doc_ref.json(exclude_none=True),
718+
)
719+
720+
result = handler(event, create_mock_context())
721+
body = result.pop("body")
722+
723+
assert result == {
724+
"statusCode": "400",
725+
"headers": {},
726+
"isBase64Encoded": False,
727+
}
728+
729+
parsed_body = json.loads(body)
730+
731+
assert parsed_body == {
732+
"resourceType": "OperationOutcome",
733+
"issue": [
734+
{
735+
"severity": "error",
736+
"code": "required",
737+
"details": {
738+
"coding": [
739+
{
740+
"code": "INVALID_RESOURCE",
741+
"display": "Invalid validation of resource",
742+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
743+
}
744+
]
745+
},
746+
"diagnostics": "Missing context.related. It must be provided and contain a single valid ASID identifier when content contains an SSP URL",
747+
"expression": ["context.related"],
748+
}
749+
],
750+
}
751+
752+
753+
@mock_aws
754+
@mock_repository
755+
def test_create_document_reference_with_no_asid_in_for_ssp_url(
756+
repository: DocumentPointerRepository,
757+
):
758+
doc_ref = load_document_reference("Y05868-736253002-Valid-with-ssp-content")
759+
760+
doc_ref.context.related = [
761+
{
762+
"identifier": {
763+
"system": "https://fhir.nhs.uk/Id/not-an-asid",
764+
"value": "some-other-value",
765+
}
766+
}
767+
]
768+
769+
event = create_test_api_gateway_event(
770+
headers=create_headers(
771+
pointer_types=[
772+
"http://snomed.info/sct|861421000000109",
773+
"http://snomed.info/sct|736253002",
774+
]
775+
),
776+
body=doc_ref.json(exclude_none=True),
777+
)
778+
779+
result = handler(event, create_mock_context())
780+
body = result.pop("body")
781+
782+
assert result == {
783+
"statusCode": "400",
784+
"headers": {},
785+
"isBase64Encoded": False,
786+
}
787+
788+
parsed_body = json.loads(body)
789+
790+
assert parsed_body == {
791+
"resourceType": "OperationOutcome",
792+
"issue": [
793+
{
794+
"severity": "error",
795+
"code": "required",
796+
"details": {
797+
"coding": [
798+
{
799+
"code": "INVALID_RESOURCE",
800+
"display": "Invalid validation of resource",
801+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
802+
}
803+
]
804+
},
805+
"diagnostics": "Missing ASID identifier. context.related must contain a single valid ASID identifier when content contains an SSP URL",
806+
"expression": ["context.related"],
807+
}
808+
],
809+
}
810+
811+
812+
@mock_aws
813+
@mock_repository
814+
def test_create_document_reference_with_invalid_asid_for_ssp_url(
815+
repository: DocumentPointerRepository,
816+
):
817+
doc_ref = load_document_reference("Y05868-736253002-Valid-with-ssp-content")
818+
819+
doc_ref.context.related = [
820+
{
821+
"identifier": {
822+
"system": "https://fhir.nhs.uk/Id/nhsSpineASID",
823+
"value": "not-a-valid-asid",
824+
}
825+
}
826+
]
827+
828+
event = create_test_api_gateway_event(
829+
headers=create_headers(
830+
pointer_types=[
831+
"http://snomed.info/sct|861421000000109",
832+
"http://snomed.info/sct|736253002",
833+
]
834+
),
835+
body=doc_ref.json(exclude_none=True),
836+
)
837+
838+
result = handler(event, create_mock_context())
839+
body = result.pop("body")
840+
841+
assert result == {
842+
"statusCode": "400",
843+
"headers": {},
844+
"isBase64Encoded": False,
845+
}
846+
847+
parsed_body = json.loads(body)
848+
849+
assert parsed_body == {
850+
"resourceType": "OperationOutcome",
851+
"issue": [
852+
{
853+
"severity": "error",
854+
"code": "value",
855+
"details": {
856+
"coding": [
857+
{
858+
"code": "INVALID_IDENTIFIER_VALUE",
859+
"display": "Invalid identifier value",
860+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
861+
}
862+
]
863+
},
864+
"diagnostics": "Invalid ASID value 'not-a-valid-asid'. context.related must contain a single valid ASID identifier when content contains an SSP URL",
865+
"expression": ["context.related[0].identifier.value"],
866+
}
867+
],
868+
}
869+
870+
636871
@mock_aws
637872
@mock_repository
638873
@freeze_uuid("00000000-0000-0000-0000-000000000001")

api/producer/record-locator/producer.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,29 @@ paths:
355355
]
356356
```
357357
* `author` SHOULD have an entry with an `Organization` reference using a valid ODS code.
358-
* `author` MUST include an ASID if the document is to be accessed via SSP, e.g.
359358
```
360359
"author": [
361360
{
362361
"identifier": {
363362
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
364363
"value": "Y05868"
365364
}
366-
},
367-
{
368-
"identifier": {
369-
"system": "https://fhir.nhs.uk/Id/nhsSpineASID",
370-
"value": "230811201350"
371-
}
372365
}
373366
]
374367
```
368+
* `context` MUST include a `related` entry containing the ASID if the document is to be accessed via SSP, e.g.
369+
```
370+
"context": {
371+
"related": [
372+
{
373+
"identifier": {
374+
"system": "https://fhir.nhs.uk/Id/nhsSpineASID",
375+
"value": "230811201350"
376+
}
377+
}
378+
]
379+
}
380+
```
375381
376382
To supersede existing pointers you must further specify:
377383
@@ -1292,9 +1298,6 @@ components:
12921298
- identifier:
12931299
system: https://fhir.nhs.uk/Id/ods-organization-code
12941300
value: Y05868
1295-
- identifier:
1296-
system: https://fhir.nhs.uk/Id/nhsSpineASID
1297-
value: 012345678910
12981301
custodian:
12991302
identifier:
13001303
system: https://fhir.nhs.uk/Id/ods-organization-code
@@ -1328,6 +1331,10 @@ components:
13281331
identifier:
13291332
system: https://fhir.nhs.uk/Id/nhs-number
13301333
value: "6700028191"
1334+
related:
1335+
- identifier:
1336+
system: https://fhir.nhs.uk/Id/nhsSpineASID
1337+
value: 012345678910
13311338
required: true
13321339
schemas:
13331340
OperationOutcome:

api/producer/swagger.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,29 @@ paths:
334334
]
335335
```
336336
* `author` SHOULD have an entry with an `Organization` reference using a valid ODS code.
337-
* `author` MUST include an ASID if the document is to be accessed via SSP, e.g.
338337
```
339338
"author": [
340339
{
341340
"identifier": {
342341
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
343342
"value": "Y05868"
344343
}
345-
},
346-
{
347-
"identifier": {
348-
"system": "https://fhir.nhs.uk/Id/nhsSpineASID",
349-
"value": "230811201350"
350-
}
351344
}
352345
]
353346
```
347+
* `context` MUST include a `related` entry containing the ASID if the document is to be accessed via SSP, e.g.
348+
```
349+
"context": {
350+
"related": [
351+
{
352+
"identifier": {
353+
"system": "https://fhir.nhs.uk/Id/nhsSpineASID",
354+
"value": "230811201350"
355+
}
356+
}
357+
]
358+
}
359+
```
354360
355361
To supersede existing pointers you must further specify:
356362
@@ -1168,9 +1174,6 @@ components:
11681174
- identifier:
11691175
system: https://fhir.nhs.uk/Id/ods-organization-code
11701176
value: Y05868
1171-
- identifier:
1172-
system: https://fhir.nhs.uk/Id/nhsSpineASID
1173-
value: 012345678910
11741177
custodian:
11751178
identifier:
11761179
system: https://fhir.nhs.uk/Id/ods-organization-code
@@ -1204,6 +1207,10 @@ components:
12041207
identifier:
12051208
system: https://fhir.nhs.uk/Id/nhs-number
12061209
value: "6700028191"
1210+
related:
1211+
- identifier:
1212+
system: https://fhir.nhs.uk/Id/nhsSpineASID
1213+
value: 012345678910
12071214
required: true
12081215
schemas:
12091216
OperationOutcome:

0 commit comments

Comments
 (0)