Skip to content

Commit ff1b83e

Browse files
NRL-1215 Add logging for duplicate key checks and integration tests for create, upsert, update
1 parent 3b0844c commit ff1b83e

File tree

7 files changed

+436
-0
lines changed

7 files changed

+436
-0
lines changed

layer/nrlf/core/log_references.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class LogReference(Enum):
3535
)
3636
HANDLER016 = _Reference("INFO", "Set response headers")
3737
HANDLER017 = _Reference("WARN", "Correlation ID not found in request headers")
38+
HANDLER018 = _Reference("INFO", "Checking for duplicate keys in request body")
3839
HANDLER999 = _Reference("INFO", "Request handler returned successfully")
3940

4041
# Error Logs

layer/nrlf/core/request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def raise_when_duplicate_keys(json_content: str) -> None:
105105
"""
106106
Raises an error if duplicate keys are found in the JSON content.
107107
"""
108+
logger.log(LogReference.HANDLER018)
108109
duplicates, paths = check_duplicate_keys(json_content)
109110
if duplicates:
110111
raise OperationOutcomeError(
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Feature: Producer - createDocumentReference - Duplicate Field Scenarios
2+
3+
Scenario: Duplicate url field in attachment
4+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
5+
And the organisation 'TSTCUS' is authorised to access pointer types:
6+
| system | value |
7+
| http://snomed.info/sct | 736253002 |
8+
When producer 'TSTCUS' requests creation of a DocumentReference with default test values except 'content' is:
9+
"""
10+
"content": [
11+
{
12+
"attachment": {
13+
"contentType": "application/pdf",
14+
"url": "https://example.org/my-doc.pdf",
15+
"url": "https://example.org/duplicate-url.pdf"
16+
},
17+
"format": {
18+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
19+
"code": "urn:nhs-ic:unstructured",
20+
"display": "Unstructured Document"
21+
},
22+
"extension": [
23+
{
24+
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
25+
"valueCodeableConcept": {
26+
"coding": [
27+
{
28+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
29+
"code": "static",
30+
"display": "Static"
31+
}
32+
]
33+
}
34+
}
35+
]
36+
}
37+
]
38+
"""
39+
Then the response status code is 400
40+
And the response is an OperationOutcome with 1 issue
41+
And the OperationOutcome contains the issue:
42+
"""
43+
{
44+
"severity": "error",
45+
"code": "invalid",
46+
"details": {
47+
"coding": [
48+
{
49+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
50+
"code": "MESSAGE_NOT_WELL_FORMED",
51+
"display": "Message not well formed"
52+
}
53+
]
54+
},
55+
"diagnostics": "Duplicate keys found in FHIR document: ['url']",
56+
"expression": [
57+
"root.content[0].attachment.url"
58+
]
59+
}
60+
"""
61+
62+
Scenario: Duplicate format and attachement field in content
63+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
64+
And the organisation 'TSTCUS' is authorised to access pointer types:
65+
| system | value |
66+
| http://snomed.info/sct | 736253002 |
67+
When producer 'TSTCUS' requests creation of a DocumentReference with default test values except 'content' is:
68+
"""
69+
"content": [
70+
{
71+
"attachment": {
72+
"contentType": "application/pdf",
73+
"url": "https://example.org/my-doc.pdf"
74+
},
75+
"attachment": {
76+
"contentType": "text/html",
77+
"url": "https://example.org/contact-details.html"
78+
},
79+
"format": {
80+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
81+
"code": "urn:nhs-ic:unstructured",
82+
"display": "Unstructured Document"
83+
},
84+
"format": {
85+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
86+
"code": "urn:nhs-ic:record-contact",
87+
"display": "Contact details (HTTP Unsecured)"
88+
},
89+
"extension": [
90+
{
91+
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
92+
"valueCodeableConcept": {
93+
"coding": [
94+
{
95+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
96+
"code": "static",
97+
"display": "Static"
98+
}
99+
]
100+
}
101+
}
102+
]
103+
}
104+
]
105+
"""
106+
Then the response status code is 400
107+
And the response is an OperationOutcome with 1 issue
108+
And the OperationOutcome contains the issue:
109+
"""
110+
{
111+
"severity": "error",
112+
"code": "invalid",
113+
"details": {
114+
"coding": [
115+
{
116+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
117+
"code": "MESSAGE_NOT_WELL_FORMED",
118+
"display": "Message not well formed"
119+
}
120+
]
121+
},
122+
"diagnostics": "Duplicate keys found in FHIR document: ['attachment', 'format']",
123+
"expression": [
124+
"root.content[0].attachment",
125+
"root.content[0].format"
126+
]
127+
}
128+
"""
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
Feature: Producer - updateDocumentReference - Duplicate Field Scenarios
2+
3+
Scenario: Duplicate url field in attachment
4+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
5+
And the organisation 'TSTCUS' is authorised to access pointer types:
6+
| system | value |
7+
| http://snomed.info/sct | 736253002 |
8+
And a DocumentReference resource exists with values:
9+
| property | value |
10+
| id | TSTCUS-updateDuplicateTest-1234 |
11+
| subject | 9999999999 |
12+
| status | current |
13+
| type | 736253002 |
14+
| category | 734163000 |
15+
| contentType | application/pdf |
16+
| url | https://example.org/my-doc.pdf |
17+
| custodian | TSTCUS |
18+
| author | TSTCUS |
19+
When producer 'TSTCUS' requests update of a DocumentReference with pointerId 'TSTCUS-updateDuplicateTest-1234' but replacing 'content':
20+
"""
21+
[
22+
{
23+
"attachment": {
24+
"contentType": "application/pdf",
25+
"url": "https://example.org/my-doc.pdf",
26+
"url": "https://example.org/duplicate-url.pdf"
27+
},
28+
"format": {
29+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
30+
"code": "urn:nhs-ic:unstructured",
31+
"display": "Unstructured Document"
32+
},
33+
"extension": [
34+
{
35+
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
36+
"valueCodeableConcept": {
37+
"coding": [
38+
{
39+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
40+
"code": "static",
41+
"display": "Static"
42+
}
43+
]
44+
}
45+
}
46+
]
47+
}
48+
]
49+
"""
50+
Then the response status code is 400
51+
And the response is an OperationOutcome with 1 issue
52+
And the OperationOutcome contains the issue:
53+
"""
54+
{
55+
"severity": "error",
56+
"code": "invalid",
57+
"details": {
58+
"coding": [
59+
{
60+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
61+
"code": "MESSAGE_NOT_WELL_FORMED",
62+
"display": "Message not well formed"
63+
}
64+
]
65+
},
66+
"diagnostics": "Duplicate keys found in FHIR document: ['url']",
67+
"expression": [
68+
"root.content[0].attachment.url"
69+
]
70+
}
71+
"""
72+
73+
Scenario: Duplicate format and attachment field in content
74+
Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API
75+
And the organisation 'TSTCUS' is authorised to access pointer types:
76+
| system | value |
77+
| http://snomed.info/sct | 736253002 |
78+
And a DocumentReference resource exists with values:
79+
| property | value |
80+
| id | TSTCUS-updateDuplicateTest-1235 |
81+
| subject | 9999999999 |
82+
| status | current |
83+
| type | 736253002 |
84+
| category | 734163000 |
85+
| contentType | application/pdf |
86+
| url | https://example.org/my-doc.pdf |
87+
| custodian | TSTCUS |
88+
| author | TSTCUS |
89+
When producer 'TSTCUS' requests update of a DocumentReference with pointerId 'TSTCUS-updateDuplicateTest-1235' but replacing 'content':
90+
"""
91+
[
92+
{
93+
"attachment": {
94+
"contentType": "application/pdf",
95+
"url": "https://example.org/my-doc.pdf"
96+
},
97+
"attachment": {
98+
"contentType": "text/html",
99+
"url": "https://example.org/contact-details.html"
100+
},
101+
"format": {
102+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
103+
"code": "urn:nhs-ic:unstructured",
104+
"display": "Unstructured Document"
105+
},
106+
"format": {
107+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLFormatCode",
108+
"code": "urn:nhs-ic:record-contact",
109+
"display": "Contact details (HTTP Unsecured)"
110+
},
111+
"extension": [
112+
{
113+
"url": "https://fhir.nhs.uk/England/StructureDefinition/Extension-England-ContentStability",
114+
"valueCodeableConcept": {
115+
"coding": [
116+
{
117+
"system": "https://fhir.nhs.uk/England/CodeSystem/England-NRLContentStability",
118+
"code": "static",
119+
"display": "Static"
120+
}
121+
]
122+
}
123+
}
124+
]
125+
}
126+
]
127+
"""
128+
Then the response status code is 400
129+
And the response is an OperationOutcome with 1 issue
130+
And the OperationOutcome contains the issue:
131+
"""
132+
{
133+
"severity": "error",
134+
"code": "invalid",
135+
"details": {
136+
"coding": [
137+
{
138+
"system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1",
139+
"code": "MESSAGE_NOT_WELL_FORMED",
140+
"display": "Message not well formed"
141+
}
142+
]
143+
},
144+
"diagnostics": "Duplicate keys found in FHIR document: ['attachment', 'format']",
145+
"expression": [
146+
"root.content[0].attachment",
147+
"root.content[0].format"
148+
]
149+
}
150+
"""

0 commit comments

Comments
 (0)