Skip to content

Commit 4963801

Browse files
authored
Merge pull request #3712 from nhsuk/flu-vaccination-criteria
Add vaccination criteria for Flu
2 parents c3b6eb5 + 869ecd5 commit 4963801

6 files changed

Lines changed: 71 additions & 23 deletions

File tree

app/lib/programme_grouper.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ def call
1212
.to_h
1313
end
1414

15-
def self.call(*args, **kwargs)
16-
new(*args, **kwargs).call
17-
end
15+
def self.call(...) = new(...).call
1816

1917
private_class_method :new
2018

@@ -30,7 +28,7 @@ def programme_group(programme)
3028
elsif programme.doubles?
3129
:doubles
3230
else
33-
raise "Unknown programme type #{programme.type}"
31+
raise UnsupportedProgramme, programme
3432
end
3533
end
3634
end

app/lib/unsupported_programme.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class UnsupportedProgramme < RuntimeError
4+
def initialize(programme)
5+
super("Unsupported programme: #{programme.name}")
6+
end
7+
end

app/lib/vaccinated_criteria.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@ def call
1111
vaccination_records_for_programme =
1212
vaccination_records.select { it.programme_id == programme.id }
1313

14-
return true if vaccination_records_for_programme.any?(&:already_had?)
15-
16-
administered_records =
17-
vaccination_records_for_programme.select(&:administered?)
18-
19-
if programme.menacwy?
20-
administered_records.any? { patient.age(now: it.performed_at) >= 10 }
21-
elsif programme.td_ipv?
22-
administered_records.any? do
23-
(
24-
it.dose_sequence == programme.vaccinated_dose_sequence ||
25-
(it.dose_sequence.nil? && it.recorded_in_service?)
26-
) && patient.age(now: it.performed_at) >= 10
27-
end
14+
if programme.flu?
15+
vaccination_records_for_programme
16+
.select { it.administered? || it.already_had? }
17+
.any?(&:performed_this_academic_year?)
2818
else
29-
administered_records.any?
19+
return true if vaccination_records_for_programme.any?(&:already_had?)
20+
21+
administered_records =
22+
vaccination_records_for_programme.select(&:administered?)
23+
24+
if programme.hpv?
25+
administered_records.any?
26+
elsif programme.menacwy?
27+
administered_records.any? { patient.age(now: it.performed_at) >= 10 }
28+
elsif programme.td_ipv?
29+
administered_records.any? do
30+
(
31+
it.dose_sequence == programme.vaccinated_dose_sequence ||
32+
(it.dose_sequence.nil? && it.recorded_in_service?)
33+
) && patient.age(now: it.performed_at) >= 10
34+
end
35+
else
36+
raise UnsupportedProgramme, programme
37+
end
3038
end
3139
end
3240

app/models/vaccination_record.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ def academic_year
174174
performed_at.to_date.academic_year
175175
end
176176

177+
def performed_this_academic_year?
178+
academic_year == Date.current.academic_year
179+
end
180+
177181
private
178182

179183
def requires_location_name?

lib/tasks/vaccines.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace :vaccines do
4040
elsif programme.td_ipv?
4141
create_td_ipv_health_questions(vaccine)
4242
else
43-
raise "Unknown programme: #{programme.name}"
43+
raise UnsupportedProgramme, programme
4444
end
4545
end
4646
end

spec/lib/vaccinated_criteria_spec.rb

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
describe VaccinatedCriteria do
44
describe "#call" do
5-
subject(:call) do
6-
described_class.call(programme:, patient:, vaccination_records:)
7-
end
5+
subject { described_class.call(programme:, patient:, vaccination_records:) }
86

97
let(:patient) { create(:patient, date_of_birth: 15.years.ago.to_date) }
108
let(:vaccination_records) { [] }
@@ -45,6 +43,39 @@
4543

4644
it { should be(true) }
4745
end
46+
47+
context "with an administered vaccination record from last year" do
48+
let(:vaccination_records) do
49+
[
50+
create(
51+
:vaccination_record,
52+
:administered,
53+
patient:,
54+
programme:,
55+
performed_at: 1.year.ago
56+
)
57+
]
58+
end
59+
60+
it { should be(false) }
61+
end
62+
63+
context "with an already had vaccination record from last year" do
64+
let(:vaccination_records) do
65+
[
66+
create(
67+
:vaccination_record,
68+
:not_administered,
69+
:already_had,
70+
patient:,
71+
programme:,
72+
performed_at: 1.year.ago
73+
)
74+
]
75+
end
76+
77+
it { should be(false) }
78+
end
4879
end
4980

5081
context "with an HPV programme" do

0 commit comments

Comments
 (0)