Skip to content

Commit 9b6ec85

Browse files
Warn if OperationOutcome is severity: warning
Previously this would throw an error if any `OperationOutcome` resource existed. Now it only errors if the severity is either `fatal` or `error`. If the severity is `warning`, then Mavis warns and reports to Sentry, but continues the thread running. Jira-Issue: MAV-2652
1 parent ae4ef00 commit 9b6ec85

6 files changed

Lines changed: 634 additions & 16 deletions

app/lib/nhs/immunisations_api.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,25 @@ def check_bundle_link_params(bundle, request_params)
438438
end
439439

440440
def check_operation_outcome_entry(bundle)
441-
operation_outcome_entry =
442-
bundle.entry&.find { it.resource.resourceType == "OperationOutcome" }
443-
444-
if operation_outcome_entry.present?
445-
raise NHS::ImmunisationsAPI::OperationOutcomeInBundle,
446-
"OperationOutcome entry found in bundle: #{operation_outcome_entry.resource}"
441+
operation_outcome_entries =
442+
bundle.entry&.select { it.resource.resourceType == "OperationOutcome" }
443+
444+
operation_outcome_entries.each do |operation_outcome|
445+
operation_outcome.resource.issue.each do |issue|
446+
message =
447+
"OperationOutcome entry found in bundle with severity #{issue.severity}: #{issue}"
448+
449+
case issue.severity.downcase
450+
when "error", "fatal"
451+
raise OperationOutcomeInBundle, message
452+
when "information", "success"
453+
# Ignore these outcomes
454+
else
455+
# Includes `warning`, and any unexpected response
456+
Rails.logger.warn(message)
457+
Sentry.capture_exception(OperationOutcomeInBundle.new(message))
458+
end
459+
end
447460
end
448461
end
449462

spec/fixtures/files/fhir/search_response_operation_outcome_entry.json renamed to spec/fixtures/files/fhir/search_response_operation_outcome_error.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"fullUrl": "urn:uuid:4e7f3c91-a14d-4139-bbcf-859e998d2028",
153153
"resource": {
154154
"resourceType": "OperationOutcome",
155-
"id": "a5abca2a-4eda-41da-b2cc-95d48c6b791d",
155+
"id": "f1753822-5667-4562-a288-1544a0b66d00",
156156
"meta": {
157157
"profile": [
158158
"https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome"
@@ -161,16 +161,16 @@
161161
"issue": [
162162
{
163163
"severity": "error",
164-
"code": "forbidden",
164+
"code": "invalid",
165165
"details": {
166166
"coding": [
167167
{
168168
"system": "https://fhir.nhs.uk/Codesystem/http-error-codes",
169-
"code": "SEND_UNAUTHORIZED"
169+
"code": "INVALID"
170170
}
171171
]
172172
},
173-
"diagnostics": "The sender does not have permissions to access this resource. Please check your credentials and permissions."
173+
"diagnostics": "immunization-target must be one or more of the following: COVID19,FLU,HPV,MMR,3IN1,MENACWY,RSV"
174174
}
175175
]
176176
},
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"resourceType": "Bundle",
3+
"type": "searchset",
4+
"link": [
5+
{
6+
"relation": "self",
7+
"url": "https://int.api.service.nhs.uk/immunisation-fhir-api/Immunization?-date.from=2025-08-01\u0026-date.to=2025-10-01\u0026immunization.target=FLU,HPV,MENACWY,3IN1,MMR\u0026patient.identifier=https%3A%2F%2Ffhir.nhs.uk%2FId%2Fnhs-number%7C9449308357"
8+
}
9+
],
10+
"entry": [
11+
{
12+
"fullUrl": "https://api.service.nhs.uk/immunisation-fhir-api/Immunization/4e7f3c91-a14d-4139-bbcf-859e998d2028",
13+
"resource": {
14+
"resourceType": "Immunization",
15+
"id": "4e7f3c91-a14d-4139-bbcf-859e998d2028",
16+
"extension": [
17+
{
18+
"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure",
19+
"valueCodeableConcept": {
20+
"coding": [
21+
{
22+
"system": "http://snomed.info/sct",
23+
"code": "884861000000100",
24+
"display": "Seasonal influenza vaccination (procedure)"
25+
}
26+
]
27+
}
28+
}
29+
],
30+
"identifier": [
31+
{
32+
"use": "official",
33+
"system": "http://manage-vaccinations-in-schools.nhs.uk/vaccination_records",
34+
"value": "71f538d8-1171-4204-aee4-17ff0b0ba0b0"
35+
}
36+
],
37+
"status": "completed",
38+
"vaccineCode": {
39+
"coding": [
40+
{
41+
"system": "http://snomed.info/sct",
42+
"code": "43208811000001106",
43+
"display": "Fluenz (trivalent) vaccine nasal suspension 0.2ml unit dose (AstraZeneca UK Ltd) (product)"
44+
}
45+
]
46+
},
47+
"patient": {
48+
"reference": "urn:uuid:b1feab34-a7dd-41cd-a764-1c6dc45e2880",
49+
"type": "Patient",
50+
"identifier": {
51+
"system": "https://fhir.nhs.uk/Id/nhs-number",
52+
"value": "9449308357"
53+
}
54+
},
55+
"occurrenceDateTime": "2025-08-22T14:16:03+01:00",
56+
"recorded": "2025-08-22T14:16:05.246000+01:00",
57+
"primarySource": true,
58+
"location": {
59+
"identifier": {
60+
"system": "https://fhir.hl7.org.uk/Id/urn-school-number",
61+
"value": "100001"
62+
}
63+
},
64+
"manufacturer": {
65+
"display": "AstraZeneca"
66+
},
67+
"lotNumber": "BU5086",
68+
"expirationDate": "2025-09-30",
69+
"site": {
70+
"coding": [
71+
{
72+
"system": "http://snomed.info/sct",
73+
"code": "279549004",
74+
"display": "Nasal cavity structure"
75+
}
76+
]
77+
},
78+
"route": {
79+
"coding": [
80+
{
81+
"system": "http://snomed.info/sct",
82+
"code": "46713006",
83+
"display": "Nasal"
84+
}
85+
]
86+
},
87+
"doseQuantity": {
88+
"value": 0.2,
89+
"unit": "ml",
90+
"system": "http://snomed.info/sct",
91+
"code": "258773002"
92+
},
93+
"performer": [
94+
{
95+
"actor": {
96+
"type": "Organization",
97+
"identifier": {
98+
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
99+
"value": "R1L"
100+
}
101+
}
102+
}
103+
],
104+
"reasonCode": [
105+
{
106+
"coding": [
107+
{
108+
"system": "http://snomed.info/sct",
109+
"code": "723620004"
110+
}
111+
]
112+
}
113+
],
114+
"protocolApplied": [
115+
{
116+
"targetDisease": [
117+
{
118+
"coding": [
119+
{
120+
"system": "http://snomed.info/sct",
121+
"code": "6142004",
122+
"display": "Influenza"
123+
}
124+
]
125+
}
126+
],
127+
"doseNumberPositiveInt": 1
128+
}
129+
]
130+
},
131+
"search": {
132+
"mode": "match"
133+
}
134+
},
135+
{
136+
"fullUrl": "urn:uuid:b1feab34-a7dd-41cd-a764-1c6dc45e2880",
137+
"resource": {
138+
"resourceType": "Patient",
139+
"id": "9449308357",
140+
"identifier": [
141+
{
142+
"system": "https://fhir.nhs.uk/Id/nhs-number",
143+
"value": "9449308357"
144+
}
145+
]
146+
},
147+
"search": {
148+
"mode": "include"
149+
}
150+
},
151+
{
152+
"fullUrl": "urn:uuid:4e7f3c91-a14d-4139-bbcf-859e998d2028",
153+
"resource": {
154+
"resourceType": "OperationOutcome",
155+
"id": "f1753822-5667-4562-a288-1544a0b66d00",
156+
"meta": {
157+
"profile": [
158+
"https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome"
159+
]
160+
},
161+
"issue": [
162+
{
163+
"severity": "fatal",
164+
"code": "invalid",
165+
"details": {
166+
"coding": [
167+
{
168+
"system": "https://fhir.nhs.uk/Codesystem/http-error-codes",
169+
"code": "INVALID"
170+
}
171+
]
172+
},
173+
"diagnostics": "immunization-target must be one or more of the following: COVID19,FLU,HPV,MMR,3IN1,MENACWY,RSV"
174+
}
175+
]
176+
},
177+
"search": {
178+
"mode": "include"
179+
}
180+
}
181+
],
182+
"total": 1
183+
}

0 commit comments

Comments
 (0)