Skip to content

Commit 32d461f

Browse files
authored
Merge pull request #771 from NHSDigital/feature/eema1-NRL-1076-IdentifyLinkedStudiesAndReports
NRL-1076 add integration and unit tests for accession number
2 parents 0db9d07 + 19ad615 commit 32d461f

File tree

14 files changed

+169
-11
lines changed

14 files changed

+169
-11
lines changed

api/consumer/searchDocumentReference/search_document_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def handler(
5353
pointer_types=metadata.pointer_types,
5454
)
5555
return SpineErrorResponse.INVALID_CODE_SYSTEM(
56-
diagnostics="Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
56+
diagnostics="Invalid query parameter (The provided type does not match the allowed types for this organisation)",
5757
expression="type",
5858
)
5959

api/consumer/searchDocumentReference/tests/test_search_document_reference_consumer.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,56 @@ def test_search_document_reference_happy_path(repository: DocumentPointerReposit
5959
}
6060

6161

62+
@mock_aws
63+
@mock_repository
64+
def test_search_document_reference_accession_number_in_pointer(
65+
repository: DocumentPointerRepository,
66+
):
67+
doc_ref = load_document_reference("Y05868-736253002-Valid")
68+
doc_ref.identifier = [
69+
{"type": {"text": "Accession-Number"}, "value": "Y05868.123456789"}
70+
]
71+
doc_pointer = DocumentPointer.from_document_reference(doc_ref)
72+
repository.create(doc_pointer)
73+
74+
event = create_test_api_gateway_event(
75+
headers=create_headers(),
76+
query_string_parameters={
77+
"subject:identifier": "https://fhir.nhs.uk/Id/nhs-number|6700028191",
78+
},
79+
)
80+
81+
result = handler(event, create_mock_context())
82+
body = result.pop("body")
83+
84+
assert result == {
85+
"statusCode": "200",
86+
"headers": default_response_headers(),
87+
"isBase64Encoded": False,
88+
}
89+
90+
parsed_body = json.loads(body)
91+
assert parsed_body == {
92+
"resourceType": "Bundle",
93+
"type": "searchset",
94+
"total": 1,
95+
"link": [
96+
{
97+
"relation": "self",
98+
"url": "https://pytest.api.service.nhs.uk/record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|6700028191",
99+
}
100+
],
101+
"entry": [{"resource": doc_ref.model_dump(exclude_none=True)}],
102+
}
103+
104+
created_doc_pointer = repository.get_by_id("Y05868-99999-99999-999999")
105+
106+
assert created_doc_pointer is not None
107+
assert json.loads(created_doc_pointer.document)["identifier"] == [
108+
{"type": {"text": "Accession-Number"}, "value": "Y05868.123456789"}
109+
]
110+
111+
62112
@mock_aws
63113
@mock_repository
64114
def test_search_document_reference_happy_path_with_custodian(
@@ -451,7 +501,7 @@ def test_search_document_reference_invalid_type(repository: DocumentPointerRepos
451501
}
452502
]
453503
},
454-
"diagnostics": "Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
504+
"diagnostics": "Invalid query parameter (The provided type does not match the allowed types for this organisation)",
455505
"expression": ["type"],
456506
}
457507
],

api/consumer/searchPostDocumentReference/search_post_document_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def handler(
5757
pointer_types=metadata.pointer_types,
5858
)
5959
return SpineErrorResponse.INVALID_CODE_SYSTEM(
60-
diagnostics="Invalid type (The provided type system does not match the allowed types for this organisation)",
60+
diagnostics="The provided type does not match the allowed types for this organisation",
6161
expression="type",
6262
)
6363

api/consumer/searchPostDocumentReference/tests/test_search_post_document_reference_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_search_post_document_reference_invalid_type(
424424
}
425425
]
426426
},
427-
"diagnostics": "Invalid type (The provided type system does not match the allowed types for this organisation)",
427+
"diagnostics": "The provided type does not match the allowed types for this organisation",
428428
"expression": ["type"],
429429
}
430430
],

api/producer/searchDocumentReference/search_document_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def handler(
5555
pointer_types=metadata.pointer_types,
5656
)
5757
return SpineErrorResponse.INVALID_CODE_SYSTEM(
58-
diagnostics="Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
58+
diagnostics="Invalid query parameter (The provided type does not match the allowed types for this organisation)",
5959
expression="type",
6060
)
6161

api/producer/searchDocumentReference/tests/test_search_document_reference_producer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_search_document_reference_invalid_type(repository: DocumentPointerRepos
201201
}
202202
]
203203
},
204-
"diagnostics": "Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
204+
"diagnostics": "Invalid query parameter (The provided type does not match the allowed types for this organisation)",
205205
"expression": ["type"],
206206
}
207207
],

api/producer/searchPostDocumentReference/search_post_document_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def handler(
4949
pointer_types=metadata.pointer_types,
5050
)
5151
return SpineErrorResponse.INVALID_CODE_SYSTEM(
52-
diagnostics="The provided type system does not match the allowed types for this organisation",
52+
diagnostics="The provided type does not match the allowed types for this organisation",
5353
expression="type",
5454
)
5555

api/producer/searchPostDocumentReference/tests/test_search_post_document_reference_producer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_search_document_reference_invalid_type(repository: DocumentPointerRepos
206206
}
207207
]
208208
},
209-
"diagnostics": "The provided type system does not match the allowed types for this organisation",
209+
"diagnostics": "The provided type does not match the allowed types for this organisation",
210210
"expression": ["type"],
211211
}
212212
],

layer/nrlf/core/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
def validate_type(type_: Optional[RequestQueryType], pointer_types: List[str]) -> bool:
2828
"""
29-
Validates if the given type system is present in the list of pointer types.
29+
Validates if the given type is present in the list of pointer types.
3030
"""
3131
if not type_:
3232
return True

tests/features/consumer/searchDocumentReference-failure.feature

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,35 @@ Feature: Consumer - searchDocumentReference - Failure Scenarios
7777
"display": "Invalid code system"
7878
}]
7979
},
80-
"diagnostics": "Invalid query parameter (The provided type system does not match the allowed types for this organisation)",
80+
"diagnostics": "Invalid query parameter (The provided type does not match the allowed types for this organisation)",
81+
"expression": ["type"]
82+
}
83+
"""
84+
85+
Scenario: Search rejects request with type they are not allowed to use
86+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
87+
And the organisation 'RX898' is authorised to access pointer types:
88+
| system | value |
89+
| http://snomed.info/sct | 736253002 |
90+
When consumer 'RX898' searches for DocumentReferences with parameters:
91+
| parameter | value |
92+
| subject | 9278693472 |
93+
| type | http://snomed.info/sct\|887701000000100 |
94+
Then the response status code is 400
95+
And the response is an OperationOutcome with 1 issue
96+
And the OperationOutcome contains the issue:
97+
"""
98+
{
99+
"severity": "error",
100+
"code": "code-invalid",
101+
"details": {
102+
"coding": [{
103+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
104+
"code": "INVALID_CODE_SYSTEM",
105+
"display": "Invalid code system"
106+
}]
107+
},
108+
"diagnostics": "Invalid query parameter (The provided type does not match the allowed types for this organisation)",
81109
"expression": ["type"]
82110
}
83111
"""

0 commit comments

Comments
 (0)