Skip to content

Commit b576a6f

Browse files
authored
Merge pull request #4963 from nhsuk/next
Version 5.2.3
2 parents 40d5268 + 0d6c27b commit b576a6f

29 files changed

+301
-254
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ GEM
101101
public_suffix (>= 2.0.2, < 7.0)
102102
aes_key_wrap (1.1.0)
103103
amazing_print (2.0.0)
104-
annotaterb (4.19.0)
104+
annotaterb (4.20.0)
105105
activerecord (>= 6.0.0)
106106
activesupport (>= 6.0.0)
107107
array_enum (1.6.0)
108108
activemodel
109-
asciidoctor (2.0.24)
109+
asciidoctor (2.0.25)
110110
asciidoctor-diagram (3.0.1)
111111
asciidoctor (>= 1.5.7, < 3.x)
112112
rexml
@@ -447,7 +447,7 @@ GEM
447447
date
448448
stringio
449449
public_suffix (6.0.2)
450-
puma (7.0.4)
450+
puma (7.1.0)
451451
nio4r (~> 2.0)
452452
pundit (2.5.2)
453453
activesupport (>= 3.0.0)
@@ -700,8 +700,8 @@ GEM
700700
unicode-display_width (~> 3.1)
701701
temple (0.10.0)
702702
thor (1.4.0)
703-
thruster (0.1.15-arm64-darwin)
704-
thruster (0.1.15-x86_64-linux)
703+
thruster (0.1.16-arm64-darwin)
704+
thruster (0.1.16-x86_64-linux)
705705
tilt (2.6.1)
706706
timeout (0.4.3)
707707
tsort (0.2.0)

app/components/app_consent_form_card_component.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ def call
4343

4444
def refusal_reason
4545
{
46-
title:
47-
Consent.human_enum_name(
48-
:reason_for_refusal,
49-
@consent_form.reason
50-
).presence,
51-
notes: @consent_form.reason_notes
46+
title: @consent_form.human_enum_name(:reason_for_refusal),
47+
notes: @consent_form.reason_for_refusal_notes
5248
}
5349
end
5450

app/controllers/draft_consents_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def update_params
131131
parent_responsibility
132132
],
133133
questions: questions_params,
134-
reason: %i[reason_for_refusal],
134+
reason_for_refusal: %i[reason_for_refusal],
135135
route: %i[route],
136136
who: %i[new_or_existing_contact]
137137
}.fetch(current_step)

app/controllers/parent_interface/consent_forms/edit_controller.rb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,31 @@ def finish_wizard_path
8080

8181
def update_params
8282
permitted_attributes = {
83-
name: %i[
84-
given_name
85-
family_name
86-
use_preferred_name
87-
preferred_given_name
88-
preferred_family_name
83+
address: %i[
84+
address_line_1
85+
address_line_2
86+
address_town
87+
address_postcode
88+
],
89+
confirm_school: %i[school_confirmed],
90+
contact_method: %i[
91+
parent_contact_method_type
92+
parent_contact_method_other_details
8993
],
9094
date_of_birth: %i[
9195
date_of_birth(3i)
9296
date_of_birth(2i)
9397
date_of_birth(1i)
9498
],
95-
confirm_school: %i[school_confirmed],
9699
education_setting: %i[education_setting],
97-
school: %i[school_id],
100+
injection_alternative: %i[injection_alternative],
101+
name: %i[
102+
given_name
103+
family_name
104+
use_preferred_name
105+
preferred_given_name
106+
preferred_family_name
107+
],
98108
parent: %i[
99109
parent_email
100110
parent_full_name
@@ -104,17 +114,12 @@ def update_params
104114
parent_relationship_type
105115
parental_responsibility
106116
],
107-
contact_method: %i[
108-
parent_contact_method_type
109-
parent_contact_method_other_details
110-
],
111-
reason: %i[reason],
112-
reason_notes: %i[reason_notes],
117+
reason_for_refusal: %i[reason_for_refusal],
118+
reason_for_refusal_notes: %i[reason_for_refusal_notes],
113119
response_doubles: %i[response chosen_programme],
114120
response_flu: %i[response],
115121
response_hpv: %i[response],
116-
injection_alternative: %i[injection_alternative],
117-
address: %i[address_line_1 address_line_2 address_town address_postcode]
122+
school: %i[school_id]
118123
}.fetch(current_step)
119124

120125
params.fetch(:consent_form, {}).permit(permitted_attributes)

app/lib/govuk_notify_personalisation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ def reason_did_not_vaccinate
232232
end
233233

234234
def reason_for_refusal
235-
reason = consent_form&.reason || consent&.reason_for_refusal
235+
reason = consent_form&.reason_for_refusal || consent&.reason_for_refusal
236236
return if reason.nil?
237237

238-
I18n.t("mailers.consent_form_mailer.reasons_for_refusal.#{reason}")
238+
I18n.t(reason, scope: "mailers.consent_form_mailer.reasons_for_refusal")
239239
end
240240

241241
def short_patient_name

app/lib/programme_grouper.rb

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# frozen_string_literal: true
22

33
class ProgrammeGrouper
4-
def initialize(programmes)
5-
@programmes = programmes
4+
def initialize(objects)
5+
@objects = objects
66
end
77

88
def call
9-
programmes
10-
.group_by { programme_group(it) }
11-
.transform_values { it.sort_by(&:type) }
12-
.to_h
9+
objects.group_by { group(it) }.transform_values { sorted(it) }.to_h
1310
end
1411

1512
def self.call(...) = new(...).call
@@ -18,19 +15,13 @@ def self.call(...) = new(...).call
1815

1916
private
2017

21-
attr_reader :programmes
22-
23-
def programme_group(programme)
24-
if programme.flu?
25-
:flu
26-
elsif programme.hpv?
27-
:hpv
28-
elsif programme.doubles?
29-
:doubles
30-
elsif programme.mmr?
31-
:mmr
32-
else
33-
raise UnsupportedProgramme, programme
34-
end
35-
end
18+
attr_reader :objects
19+
20+
def programme(object) = object.try(:programme) || object
21+
22+
def group(object) = programme(object).group
23+
24+
def type(object) = programme(object).type
25+
26+
def sorted(objects) = objects.sort_by { type(it) }
3627
end

app/models/concerns/refusable.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module Refusable
4+
extend ActiveSupport::Concern
5+
6+
include Notable
7+
8+
REASON_FOR_REFUSAL_REQUIRES_NOTES = %w[
9+
already_vaccinated
10+
medical_reasons
11+
other
12+
will_be_vaccinated_elsewhere
13+
].freeze
14+
15+
included do
16+
enum :reason_for_refusal,
17+
{
18+
contains_gelatine: 0,
19+
already_vaccinated: 1,
20+
will_be_vaccinated_elsewhere: 2,
21+
medical_reasons: 3,
22+
personal_choice: 4,
23+
other: 5
24+
},
25+
prefix: true,
26+
validate: {
27+
if: :requires_reason_for_refusal?
28+
}
29+
end
30+
31+
def requires_reason_for_refusal?
32+
response_refused?
33+
end
34+
35+
def reason_for_refusal_requires_notes?
36+
reason_for_refusal.in?(REASON_FOR_REFUSAL_REQUIRES_NOTES)
37+
end
38+
39+
def requires_notes?
40+
requires_reason_for_refusal? && reason_for_refusal_requires_notes?
41+
end
42+
end

app/models/consent.rb

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Consent < ApplicationRecord
5353
include HasVaccineMethods
5454
include Invalidatable
5555
include Notable
56+
include Refusable
5657

5758
audited associated_with: :patient
5859

@@ -83,20 +84,6 @@ class Consent < ApplicationRecord
8384
prefix: "via",
8485
validate: true
8586

86-
enum :reason_for_refusal,
87-
{
88-
contains_gelatine: 0,
89-
already_vaccinated: 1,
90-
will_be_vaccinated_elsewhere: 2,
91-
medical_reasons: 3,
92-
personal_choice: 4,
93-
other: 5
94-
},
95-
prefix: true,
96-
validate: {
97-
if: -> { response_refused? || withdrawn? }
98-
}
99-
10087
validates :parent, presence: true, unless: :via_self_consent?
10188
validates :recorded_by,
10289
presence: true,
@@ -132,6 +119,10 @@ def responded_at
132119
invalidated_at || withdrawn_at || submitted_at
133120
end
134121

122+
def requires_reason_for_refusal? = super || withdrawn?
123+
124+
def requires_notes? = super || invalidated?
125+
135126
def requires_triage?
136127
response_given? && health_answers_require_triage?
137128
end
@@ -156,27 +147,14 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
156147
.consent_form_programmes
157148
.includes(:programme)
158149
.map do |consent_form_programme|
159-
notes =
160-
if consent_form_programme.response_given?
161-
""
162-
else
163-
consent_form.reason_notes.presence || ""
164-
end
165-
reason_for_refusal =
166-
if consent_form_programme.response_given?
167-
nil
168-
else
169-
consent_form.reason
170-
end
171-
172150
patient.consents.create!(
173151
consent_form:,
174152
health_answers: consent_form.health_answers,
175-
notes:,
153+
notes: consent_form_programme.notes,
176154
team: consent_form.team,
177155
parent:,
178156
programme: consent_form_programme.programme,
179-
reason_for_refusal:,
157+
reason_for_refusal: consent_form_programme.reason_for_refusal,
180158
recorded_by: current_user,
181159
response: consent_form_programme.response,
182160
route: "website",
@@ -192,21 +170,6 @@ def self.from_consent_form!(consent_form, patient:, current_user:)
192170
end
193171
end
194172

195-
REASON_FOR_REFUSAL_REQUIRES_NOTES = %w[
196-
other
197-
will_be_vaccinated_elsewhere
198-
medical_reasons
199-
already_vaccinated
200-
].freeze
201-
202-
def requires_notes?
203-
withdrawn? || invalidated? ||
204-
(
205-
response_refused? &&
206-
reason_for_refusal.in?(REASON_FOR_REFUSAL_REQUIRES_NOTES)
207-
)
208-
end
209-
210173
def update_vaccination_records_no_notify!
211174
vaccination_records = VaccinationRecord.where(patient:, programme:)
212175

0 commit comments

Comments
 (0)