Skip to content

Commit b4186b9

Browse files
committed
Send vaccinations to NHS on offline import
Jira-Issue: MAV-1482
1 parent b39ec21 commit b4186b9

9 files changed

Lines changed: 237 additions & 33 deletions

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def handle_confirm
120120

121121
send_vaccination_confirmation(@vaccination_record) if should_notify_parents
122122

123-
EnqueueSyncVaccinationRecordToNHSE.call(@vaccination_record)
123+
EnqueueSyncVaccinationRecordToNHS.call(@vaccination_record)
124124

125125
# In case the user navigates back to try and edit the newly created
126126
# vaccination record.

app/lib/enqueue_sync_vaccination_record_to_nhs.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
# frozen_string_literal: true
22

33
module EnqueueSyncVaccinationRecordToNHS
4+
PROGRAMME_TYPES = %w[flu hpv].freeze
5+
46
def self.call(vaccination_record)
5-
if Flipper.enabled?(:sync_vaccination_records_to_nhs_on_create) &&
6-
vaccination_record.programme.type.in?(%w[flu hpv]) &&
7-
vaccination_record.administered?
7+
return unless Flipper.enabled?(:sync_vaccination_records_to_nhs_on_create)
8+
9+
vaccination_records =
10+
if vaccination_record.respond_to?(:klass)
11+
vaccination_record
12+
.recorded_in_service
13+
.administered
14+
.where(programmes: { type: PROGRAMME_TYPES })
15+
.includes(:programme)
16+
elsif vaccination_record.programme.type.in?(PROGRAMME_TYPES) &&
17+
vaccination_record.administered? &&
18+
vaccination_record.recorded_in_service?
19+
Array(vaccination_record)
20+
else
21+
return
22+
end
23+
24+
vaccination_records.each do |vaccination_record|
825
SyncVaccinationRecordToNHSJob.perform_later(vaccination_record)
926
end
1027
end

app/models/immunisation_import.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,7 @@ def count_column(vaccination_record)
109109

110110
def postprocess_rows!
111111
StatusUpdater.call(patient: patients)
112+
113+
EnqueueSyncVaccinationRecordToNHS.call(vaccination_records)
112114
end
113115
end

spec/features/flu_vaccination_administered_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
given_i_am_signed_in_with_flu_programme
88
and_there_is_a_flu_session_today_with_two_patients_ready_to_vaccinate
99
and_there_are_nasal_and_injection_batches
10-
and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
10+
and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
1111

1212
when_i_go_to_the_nasal_only_patient
1313
and_i_record_that_the_patient_has_been_vaccinated_with_nasal_spray
1414
then_i_see_the_check_and_confirm_page_for_nasal_spray
1515
and_i_get_confirmation_after_recording
16-
and_the_vaccination_record_is_synced_to_nhse
16+
and_the_vaccination_record_is_synced_to_nhs
1717
end
1818

1919
scenario "Administered with injection" do
@@ -93,8 +93,8 @@ def and_there_are_nasal_and_injection_batches
9393
)
9494
end
9595

96-
def and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
97-
Flipper.enable(:sync_vaccination_records_to_nhse_on_create)
96+
def and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
97+
Flipper.enable(:sync_vaccination_records_to_nhs_on_create)
9898
end
9999

100100
def when_i_go_to_the_nasal_only_patient
@@ -177,7 +177,7 @@ def and_i_pick_a_batch_for_injection
177177
click_button "Continue"
178178
end
179179

180-
def and_the_vaccination_record_is_synced_to_nhse
181-
assert_enqueued_with(job: SyncVaccinationRecordToNHSEJob)
180+
def and_the_vaccination_record_is_synced_to_nhs
181+
assert_enqueued_with(job: SyncVaccinationRecordToNHSJob)
182182
end
183183
end

spec/features/hpv_vaccination_administered_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
scenario "Administered with common delivery site" do
77
given_i_am_signed_in
8-
and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
8+
and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
99

1010
when_i_go_to_a_patient_that_is_ready_to_vaccinate
1111
and_i_fill_in_pre_screening_questions
@@ -42,7 +42,7 @@
4242
then_i_see_a_success_message
4343
and_i_can_no_longer_vaccinate_the_patient
4444
and_i_no_longer_see_the_patient_in_the_record_tab
45-
and_the_vaccination_record_is_synced_to_nhse
45+
and_the_vaccination_record_is_synced_to_nhs
4646

4747
when_i_go_back
4848
and_i_save_changes
@@ -106,8 +106,8 @@ def given_i_am_signed_in
106106
sign_in organisation.users.first
107107
end
108108

109-
def and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
110-
Flipper.enable(:sync_vaccination_records_to_nhse_on_create)
109+
def and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
110+
Flipper.enable(:sync_vaccination_records_to_nhs_on_create)
111111
end
112112

113113
def when_i_go_to_a_patient_that_is_ready_to_vaccinate
@@ -249,7 +249,7 @@ def and_a_text_is_sent_to_the_parent_confirming_the_vaccination
249249
)
250250
end
251251

252-
def and_the_vaccination_record_is_synced_to_nhse
253-
assert_enqueued_with(job: SyncVaccinationRecordToNHSEJob)
252+
def and_the_vaccination_record_is_synced_to_nhs
253+
assert_enqueued_with(job: SyncVaccinationRecordToNHSJob)
254254
end
255255
end

spec/features/menacwy_vaccination_administered_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
scenario "Administered" do
77
given_i_am_signed_in
8-
and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
8+
and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
99

1010
when_i_go_to_a_patient_that_is_ready_to_vaccinate
1111
and_i_record_that_the_patient_has_been_vaccinated
@@ -38,7 +38,7 @@
3838
when_i_confirm_the_details
3939
then_i_see_a_success_message
4040
and_i_no_longer_see_the_patient_in_the_record_tab
41-
and_the_vaccination_record_is_not_synced_to_nhse
41+
and_the_vaccination_record_is_not_synced_to_nhs
4242

4343
when_i_go_back
4444
and_i_save_changes
@@ -84,8 +84,8 @@ def given_i_am_signed_in
8484
sign_in organisation.users.first
8585
end
8686

87-
def and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
88-
Flipper.enable(:sync_vaccination_records_to_nhse_on_create)
87+
def and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
88+
Flipper.enable(:sync_vaccination_records_to_nhs_on_create)
8989
end
9090

9191
def when_i_go_to_a_patient_that_is_ready_to_vaccinate
@@ -207,7 +207,7 @@ def and_a_text_is_sent_to_the_parent_confirming_the_vaccination
207207
)
208208
end
209209

210-
def and_the_vaccination_record_is_not_synced_to_nhse
211-
assert_no_enqueued_jobs(only: SyncVaccinationRecordToNHSEJob)
210+
def and_the_vaccination_record_is_not_synced_to_nhs
211+
assert_no_enqueued_jobs(only: SyncVaccinationRecordToNHSJob)
212212
end
213213
end

spec/features/td_ipv_vaccination_administered_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
scenario "Administered" do
77
given_i_am_signed_in
8-
and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
8+
and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
99

1010
when_i_go_to_a_patient_that_is_ready_to_vaccinate
1111
and_i_record_that_the_patient_has_been_vaccinated
@@ -38,7 +38,7 @@
3838
when_i_confirm_the_details
3939
then_i_see_a_success_message
4040
and_i_no_longer_see_the_patient_in_the_record_tab
41-
and_the_vaccination_record_is_not_synced_to_nhse
41+
and_the_vaccination_record_is_not_synced_to_nhs
4242

4343
when_i_go_back
4444
and_i_save_changes
@@ -84,8 +84,8 @@ def given_i_am_signed_in
8484
sign_in organisation.users.first
8585
end
8686

87-
def and_sync_vaccination_records_to_nhse_on_create_feature_is_enabled
88-
Flipper.enable(:sync_vaccination_records_to_nhse_on_create)
87+
def and_sync_vaccination_records_to_nhs_on_create_feature_is_enabled
88+
Flipper.enable(:sync_vaccination_records_to_nhs_on_create)
8989
end
9090

9191
def when_i_go_to_a_patient_that_is_ready_to_vaccinate
@@ -207,7 +207,7 @@ def and_a_text_is_sent_to_the_parent_confirming_the_vaccination
207207
)
208208
end
209209

210-
def and_the_vaccination_record_is_not_synced_to_nhse
211-
assert_no_enqueued_jobs(only: SyncVaccinationRecordToNHSEJob)
210+
def and_the_vaccination_record_is_not_synced_to_nhs
211+
assert_no_enqueued_jobs(only: SyncVaccinationRecordToNHSJob)
212212
end
213213
end

spec/lib/enqueue_sync_vaccination_record_to_nhs_spec.rb

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
context "when the feature flag is enabled" do
1717
before { Flipper.enable(:sync_vaccination_records_to_nhs_on_create) }
1818

19-
let(:vaccination_record) do
20-
create(:vaccination_record, outcome:, programme:)
21-
end
2219
let(:outcome) { "administered" }
2320
let(:programme) { create(:programme, type: "flu") }
21+
let(:session) { create(:session, programmes: [programme]) }
22+
let(:vaccination_record) do
23+
create(:vaccination_record, outcome:, programme:, session:)
24+
end
2425

25-
context "when the vaccination record is eligible for syncing" do
26-
it "enqueues the job" do
26+
context "with a single vaccination record" do
27+
it "enqueues the job if the vaccination record is elligible to sync" do
2728
expect {
2829
described_class.call(vaccination_record)
2930
}.to have_enqueued_job(SyncVaccinationRecordToNHSJob)
@@ -57,5 +58,69 @@
5758
end
5859
end
5960
end
61+
62+
context "with a vaccinaton record relation" do
63+
# The strategy is to create a vaccination record for each of the various
64+
# variations, and test that only the correct ones are allowed through
65+
66+
before do
67+
# Generate historic vaccination record (no session)
68+
create(:vaccination_record, outcome:, programme:)
69+
70+
# Generate vaccination records for all programme types
71+
Programme.defined_enums["type"].each_key do |programme_type|
72+
next if programme_type == "flu"
73+
programme = create(:programme, type: programme_type)
74+
create(:vaccination_record, outcome: "refused", session:, programme:)
75+
end
76+
77+
# Generate vaccination records for all outcomes
78+
VaccinationRecord.defined_enums["outcome"].each_key do |outcome|
79+
next if outcome == "administered"
80+
create(:vaccination_record, outcome:, session:, programme:)
81+
end
82+
end
83+
84+
let(:flu_programme) { Programme.flu.first || create(:programme, :flu) }
85+
let(:hpv_programme) { Programme.hpv.first || create(:programme, :hpv) }
86+
let!(:flu_vaccination_record) do
87+
create(
88+
:vaccination_record,
89+
programme: flu_programme,
90+
session:,
91+
outcome: :administered
92+
)
93+
end
94+
let!(:hpv_vaccination_record) do
95+
create(
96+
:vaccination_record,
97+
programme: hpv_programme,
98+
session:,
99+
outcome: :administered
100+
)
101+
end
102+
103+
it "enqueues the job for each eligible vaccination record" do
104+
expect {
105+
described_class.call(VaccinationRecord.all)
106+
}.to have_enqueued_job(SyncVaccinationRecordToNHSJob).exactly(2).times
107+
end
108+
109+
it "enqueues the eligible flu job" do
110+
expect {
111+
described_class.call(VaccinationRecord.all)
112+
}.to have_enqueued_job(SyncVaccinationRecordToNHSJob).with(
113+
flu_vaccination_record
114+
)
115+
end
116+
117+
it "enqueues the eligible hpv job" do
118+
expect {
119+
described_class.call(VaccinationRecord.all)
120+
}.to have_enqueued_job(SyncVaccinationRecordToNHSJob).with(
121+
hpv_vaccination_record
122+
)
123+
end
124+
end
60125
end
61126
end

0 commit comments

Comments
 (0)