Skip to content

Commit fc991b2

Browse files
committed
Add feature flag for immunisations fhir api
This flag is designed to control any and all connectivity to the Immunisations FHIR API. Jira-Issue: MAV-1477
1 parent b1a9976 commit fc991b2

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

app/lib/nhs/immunisations_api.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
module NHS::ImmunisationsAPI
44
class << self
55
def record_immunisation(vaccination_record)
6+
unless Flipper.enabled?(:immunisations_fhir_api_integration)
7+
Rails.logger.info(
8+
"Not syncing vaccination record to immunisations API as the feature" \
9+
" flag is disabled: #{vaccination_record.id}"
10+
)
11+
return
12+
end
13+
614
response =
715
NHS::API.connection.post(
816
"/immunisation-fhir-api/FHIR/R4/Immunization",
@@ -26,7 +34,7 @@ def record_immunisation(vaccination_record)
2634
end
2735
rescue Faraday::ClientError => e
2836
if (diagnostics = extract_error_diagnostics(e&.response)).present?
29-
raise "Error syncing vaccination #{vaccination_record.id} record to" \
37+
raise "Error syncing vaccination record #{vaccination_record.id} to" \
3038
" Immunisations API: #{diagnostics}"
3139
else
3240
raise

config/feature_flags.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ dev_tools: Developer tools useful for testing and debugging.
88
mesh_jobs: Export vaccination records to MESH automatically.
99

1010
offline_working: Prototype support for using Mavis offline.
11+
12+
immunisations_fhir_api_integration: Master switch to control communications with
13+
NHS Immunistaions FHIR API.

spec/features/cli_vaccination_records_sync_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def and_the_nhs_api_is_available
7878
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/11112222-3333-4444-5555-666677778888"
7979
}
8080
)
81+
82+
Flipper.enable :immunisations_fhir_api_integration
8183
end
8284

8385
def when_i_run_the_sync_command

spec/lib/nhs/immunisations_api_spec.rb

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@
4747
created_at: Time.zone.parse("2021-02-07T13:28:17.271+00:00")
4848
)
4949
end
50+
let!(:stubbed_request) do
51+
stub_request(
52+
:post,
53+
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization"
54+
).to_return(
55+
status: 201,
56+
body: "",
57+
headers: {
58+
location:
59+
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444"
60+
}
61+
)
62+
end
5063

5164
describe "record_immunisation" do
52-
before do
53-
stub_request(
54-
:post,
55-
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization"
56-
).to_return(
57-
status: 201,
58-
body: "",
59-
headers: {
60-
location:
61-
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444"
62-
}
63-
)
64-
end
65+
before { Flipper.enable(:immunisations_fhir_api_integration) }
6566

6667
it "sends the correct JSON payload" do
6768
expected_body =
@@ -171,13 +172,14 @@
171172

172173
context "4XX error" do
173174
let(:status) { 404 }
175+
let(:diagnostics) { "Invalid patient ID" }
174176

175177
it "raises an error with the diagnostic message" do
176178
expect {
177179
described_class.record_immunisation(vaccination_record)
178180
}.to raise_error(
179181
StandardError,
180-
"Error syncing vaccination #{vaccination_record.id} record to" \
182+
"Error syncing vaccination record #{vaccination_record.id} to" \
181183
" Immunisations API: Invalid patient ID"
182184
)
183185
end
@@ -198,5 +200,15 @@
198200
end
199201
end
200202
end
203+
204+
context "the immunisations_fhir_api_integration feature flag is disabled" do
205+
before { Flipper.disable(:immunisations_fhir_api_integration) }
206+
207+
it "does not make a request to the NHS API" do
208+
described_class.record_immunisation(vaccination_record)
209+
210+
expect(stubbed_request).not_to have_been_made
211+
end
212+
end
201213
end
202214
end

0 commit comments

Comments
 (0)