Skip to content

Commit cadfd6c

Browse files
authored
Merge pull request #3903 from nhsuk/govuk-notify-personalisation-programmes
Get programmes for GOV.UK Notify personalisation
2 parents cbf7080 + 21d07ae commit cadfd6c

5 files changed

Lines changed: 31 additions & 9 deletions

File tree

app/lib/govuk_notify_personalisation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def initialize(
3030
consent&.organisation || vaccination_record&.organisation
3131
@team = session&.team || consent_form&.team || vaccination_record&.team
3232
@vaccination_record = vaccination_record
33+
34+
if @programmes.empty? && @session.present? && @patient.present?
35+
@programmes = @session.eligible_programmes_for(patient: @patient)
36+
end
3337
end
3438

3539
def to_h

app/models/note.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class Note < ApplicationRecord
3333

3434
validates :body, presence: true, length: { maximum: 1000 }
3535

36-
def programmes
37-
session.programmes.select { it.year_groups.include?(year_group) }
38-
end
36+
def programmes = session.eligible_programmes_for(year_group:)
3937

4038
private
4139

app/models/patient_session.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ def can_record_as_already_vaccinated?(programme:)
201201
!session.today? && patient.vaccination_status(programme:).none_yet?
202202
end
203203

204-
def programmes
205-
session.programmes.select { it.year_groups.include?(patient.year_group) }
206-
end
204+
def programmes = session.eligible_programmes_for(patient:)
207205

208206
def session_status(programme:)
209207
session_statuses.find { it.programme_id == programme.id } ||

app/models/session.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ def vaccine_methods
164164
programmes.flat_map(&:vaccine_methods).uniq.sort
165165
end
166166

167+
def eligible_programmes_for(patient: nil, year_group: nil)
168+
year_group ||= patient.year_group
169+
programmes.select { it.year_groups.include?(year_group) }
170+
end
171+
167172
def dates
168173
session_dates.map(&:value).compact
169174
end

spec/lib/govuk_notify_personalisation_spec.rb

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

33
describe GovukNotifyPersonalisation do
4-
subject(:to_h) do
5-
described_class.new(
4+
subject(:to_h) { described_class.new(**params).to_h }
5+
6+
let(:params) do
7+
{
68
patient:,
79
session:,
810
consent:,
911
consent_form:,
1012
programmes:,
1113
vaccination_record:
12-
).to_h
14+
}
1315
end
1416

1517
let(:programmes) { [create(:programme, :hpv)] }
@@ -256,5 +258,20 @@
256258
)
257259
)
258260
end
261+
262+
context "when programmes comes from the session" do
263+
let(:params) do
264+
{ patient:, session:, consent:, consent_form:, vaccination_record: }
265+
end
266+
267+
it do
268+
expect(to_h).to match(
269+
hash_including(
270+
vaccine_side_effects:
271+
"- generally feeling unwell\n- swelling or pain where the injection was given"
272+
)
273+
)
274+
end
275+
end
259276
end
260277
end

0 commit comments

Comments
 (0)