Skip to content

Commit d946923

Browse files
committed
NRL-1076 add integration and unit tests for identifier accession number and error message fix
1 parent 309c88a commit d946923

File tree

10 files changed

+158
-6
lines changed

10 files changed

+158
-6
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,50 @@ 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+
"entry": [{"resource": doc_ref.model_dump(exclude_none=True)}],
96+
}
97+
98+
created_doc_pointer = repository.get_by_id("Y05868-99999-99999-999999")
99+
100+
assert created_doc_pointer is not None
101+
assert json.loads(created_doc_pointer.document)["identifier"] == [
102+
{"type": {"text": "Accession-Number"}, "value": "Y05868.123456789"}
103+
]
104+
105+
62106
@mock_aws
63107
@mock_repository
64108
def test_search_document_reference_happy_path_with_custodian(

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="Invalid type (The provided type does not match the allowed types for this organisation)",
6161
expression="type",
6262
)
6363

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/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

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
"""

tests/features/consumer/searchDocumentReference-success.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,44 @@ Feature: Consumer - searchDocumentReference - Success Scenarios
3636
| custodian | 02V |
3737
| author | 02V |
3838

39+
Scenario: Search for a DocumentReference and Accession Number is in response
40+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
41+
And the organisation 'RX898' is authorised to access pointer types:
42+
| system | value |
43+
| http://snomed.info/sct | 736253002 |
44+
And a DocumentReference resource exists with values:
45+
| property | value |
46+
| id | 02V-1111111111-SearchDocRefTest |
47+
| subject | 9278693472 |
48+
| status | current |
49+
| type | 736253002 |
50+
| category | 734163000 |
51+
| contentType | application/pdf |
52+
| url | https://example.org/my-doc.pdf |
53+
| custodian | 02V |
54+
| author | 02V |
55+
| identifier | 02V.123456789 |
56+
When consumer 'RX898' searches for DocumentReferences with parameters:
57+
| parameter | value |
58+
| subject | 9278693472 |
59+
Then the response status code is 200
60+
And the response is a searchset Bundle
61+
And the Bundle has a self link matching 'DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|9278693472'
62+
And the Bundle has a total of 1
63+
And the Bundle has 1 entry
64+
And the Bundle contains an DocumentReference with values
65+
| property | value |
66+
| id | 02V-1111111111-SearchDocRefTest |
67+
| subject | 9278693472 |
68+
| status | current |
69+
| type | 736253002 |
70+
| category | 734163000 |
71+
| contentType | application/pdf |
72+
| url | https://example.org/my-doc.pdf |
73+
| custodian | 02V |
74+
| author | 02V |
75+
| identifier | 02V.123456789 |
76+
3977
Scenario: Search for a DocumentReference by NHS Number and Custodian where both search parameters match
4078
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
4179
And the organisation 'RX898' is authorised to access pointer types:

tests/features/consumer/searchPostDocumentReference-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 type (The provided type system does not match the allowed types for this organisation)",
80+
"diagnostics": "Invalid type (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 using POST with request body:
91+
| key | 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 type (The provided type does not match the allowed types for this organisation)",
81109
"expression": ["type"]
82110
}
83111
"""

tests/features/steps/3_assert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ def assert_document_reference_matches_value(
218218
context.response.json(),
219219
)
220220

221+
if identifier := items.get("identifier"):
222+
assert doc_ref.identifier[0].value == identifier, format_error(
223+
"DocumentReference Identifier does not match",
224+
identifier,
225+
doc_ref.identifier[0].value,
226+
context.response.json(),
227+
)
228+
221229

222230
@then("the Bundle contains an DocumentReference with values")
223231
def assert_bundle_contains_documentreference_values_step(context: Context):

tests/features/utils/data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def create_test_document_reference(items: dict) -> DocumentReference:
128128
),
129129
)
130130
]
131+
if items.get("identifier"):
132+
base_doc_ref.identifier = [
133+
Identifier(
134+
type=CodeableConcept(text="Accession-Number"), value=items["identifier"]
135+
)
136+
]
131137

132138
return base_doc_ref
133139

0 commit comments

Comments
 (0)