Skip to content

Commit 870197e

Browse files
committed
Refactor VaccinateForm
This refactors the form to pass only the vaccine method to the controller rather than whether the vaccination was administered or not. This allows for the form to be updated to support choosing from multiple vaccine methods. Jira-Issue: MAV-1338
1 parent e51df32 commit 870197e

6 files changed

Lines changed: 31 additions & 25 deletions

File tree

app/components/app_vaccinate_form_component.html.erb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565

6666
<% hint = "Pre-screening checks must be completed for vaccination to go ahead" %>
6767

68-
<%= f.govuk_radio_buttons_fieldset :administered, legend: nil do %>
68+
<%= f.govuk_radio_buttons_fieldset :vaccine_method, legend: nil do %>
6969
<% if common_delivery_sites_options.length > 1 %>
70-
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true do %>
70+
<%= f.govuk_radio_button :vaccine_method, vaccine_method, label: { text: "Yes" }, hint: { text: hint }, link_errors: true do %>
7171
<%= f.govuk_collection_radio_buttons :delivery_site,
7272
common_delivery_sites_options,
7373
:value,
@@ -78,13 +78,12 @@
7878
} %>
7979
<% end %>
8080
<% else %>
81-
<%= f.govuk_radio_button :administered, true, label: { text: "Yes" }, hint: { text: hint }, link_errors: true %>
81+
<%= f.govuk_radio_button :vaccine_method, vaccine_method, label: { text: "Yes" }, hint: { text: hint }, link_errors: true %>
8282
<%= f.hidden_field :delivery_site, value: common_delivery_sites_options.first.value %>
8383
<% end %>
84-
<%= f.govuk_radio_button :administered, false, label: { text: "No" } %>
84+
<%= f.govuk_radio_button :vaccine_method, "none", label: { text: "No" } %>
8585
<% end %>
8686

87-
<%= f.hidden_field :delivery_method, value: delivery_method %>
8887
<%= f.hidden_field :dose_sequence, value: dose_sequence %>
8988
<%= f.hidden_field :programme_id, value: programme.id %>
9089

app/components/app_vaccinate_form_component.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ def vaccine_method
2222
patient.approved_vaccine_methods(programme:).first
2323
end
2424

25-
def delivery_method
26-
Vaccine::AVAILABLE_DELIVERY_METHODS.fetch(vaccine_method).first
27-
end
28-
2925
def dose_sequence
3026
programme.default_dose_sequence
3127
end

app/controllers/patient_sessions/vaccinations_controller.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ def create
5454
def vaccinate_form_params
5555
params.expect(
5656
vaccinate_form: %i[
57-
administered
58-
delivery_method
5957
delivery_site
6058
dose_sequence
6159
identity_check_confirmed_by_other_name
@@ -64,15 +62,13 @@ def vaccinate_form_params
6462
pre_screening_confirmed
6563
pre_screening_notes
6664
vaccine_id
65+
vaccine_method
6766
]
6867
)
6968
end
7069

7170
def set_todays_batch
72-
vaccine_method =
73-
Vaccine.delivery_method_to_vaccine_method(
74-
vaccinate_form_params[:delivery_method]
75-
)
71+
vaccine_method = vaccinate_form_params[:vaccine_method]
7672
return if vaccine_method.nil?
7773

7874
id = todays_batch_id(programme: @programme, vaccine_method:)

app/forms/vaccinate_form.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class VaccinateForm
1313
attribute :pre_screening_confirmed, :boolean
1414
attribute :pre_screening_notes, :string
1515

16-
attribute :administered, :boolean
17-
attribute :delivery_method, :string
16+
attribute :vaccine_method, :string
1817
attribute :delivery_site, :string
1918
attribute :dose_sequence, :integer
2019
attribute :programme_id, :integer
@@ -32,12 +31,11 @@ class VaccinateForm
3231
maximum: 300
3332
}
3433

35-
validates :administered, inclusion: [true, false]
34+
validates :vaccine_method, inclusion: { in: :vaccine_method_options }
3635
validates :pre_screening_notes, length: { maximum: 1000 }
3736

38-
with_options if: :administered do
37+
with_options if: :administered? do
3938
validates :pre_screening_confirmed, presence: true
40-
validates :delivery_method, presence: true
4139
validates :delivery_site, presence: true
4240
end
4341

@@ -48,7 +46,7 @@ def save(draft_vaccination_record:)
4846

4947
draft_vaccination_record.reset!
5048

51-
if administered
49+
if administered?
5250
draft_vaccination_record.outcome = "administered"
5351

5452
if delivery_site != "other"
@@ -80,6 +78,18 @@ def save(draft_vaccination_record:)
8078

8179
delegate :organisation, to: :patient_session
8280

81+
def administered? = vaccine_method != "none"
82+
83+
def vaccine_method_options
84+
programme.vaccine_methods + ["none"]
85+
end
86+
87+
def delivery_method
88+
if administered?
89+
Vaccine::AVAILABLE_DELIVERY_METHODS.fetch(vaccine_method).first
90+
end
91+
end
92+
8393
def pre_screening
8494
@pre_screening ||=
8595
patient_session.pre_screenings.build(

config/locales/en.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ en:
121121
inclusion: Choose a status
122122
vaccinate_form:
123123
attributes:
124-
administered:
125-
inclusion: Choose if they are ready to vaccinate
126124
delivery_site:
127125
blank: Choose where the injection will be given
128126
identity_check_confirmed_by_other_name:
@@ -137,6 +135,8 @@ en:
137135
blank: Confirm you’ve checked the pre-screening statements are true
138136
pre_screening_notes:
139137
too_long: Enter notes that are less than %{count} characters long
138+
vaccine_method:
139+
inclusion: Choose if they are ready to vaccinate
140140
vaccination_report:
141141
attributes:
142142
file_format:

spec/forms/vaccinate_form_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

33
describe VaccinateForm do
4-
subject(:form) { described_class.new }
4+
subject(:form) { described_class.new(programme:) }
5+
6+
let(:programme) { create(:programme) }
57

68
describe "validations" do
79
it do
@@ -24,7 +26,10 @@
2426

2527
context "when confirmed by someone else" do
2628
subject(:form) do
27-
described_class.new(identity_check_confirmed_by_patient: false)
29+
described_class.new(
30+
identity_check_confirmed_by_patient: false,
31+
programme:
32+
)
2833
end
2934

3035
it do

0 commit comments

Comments
 (0)