Skip to content

Commit 4336ffe

Browse files
committed
Don't attach teams or performed by to next dose triages
This allows the delay vaccination triages to be created from historical uploads and not just vaccination records that were recorded in the service. Jira-Issue: MAV-2991
1 parent 26f9f91 commit 4336ffe

2 files changed

Lines changed: 11 additions & 39 deletions

File tree

app/lib/next_dose_triage_factory.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ def initialize(vaccination_record:)
88
def call
99
return unless should_create?
1010

11-
# This factory should only be called for vaccination records performed in
12-
# the service, meaning there should always be a `performed_by` set.
13-
raise UnknownPerformedBy if performed_by_user_id.nil?
14-
1511
ActiveRecord::Base.transaction do
1612
Triage
1713
.create!(attributes:)
@@ -29,13 +25,12 @@ def self.call(...) = new(...).call
2925

3026
attr_reader :vaccination_record
3127

32-
delegate :academic_year, :patient, :programme, :team, to: :vaccination_record
28+
delegate :academic_year, :patient, :programme, to: :vaccination_record
3329

3430
def should_create?
35-
unless vaccination_record.sourced_from_service? &&
36-
vaccination_record.administered? && programme.mmr?
37-
return false
38-
end
31+
return false unless vaccination_record.administered? && programme.mmr?
32+
33+
return false if next_date.past?
3934

4035
dose_sequence =
4136
patient.vaccination_status(programme:, academic_year:).dose_sequence
@@ -45,21 +40,14 @@ def should_create?
4540

4641
def next_date = vaccination_record.performed_at + 28.days
4742

48-
def performed_by_user_id = vaccination_record.performed_by_user_id
49-
5043
def attributes
5144
{
5245
patient:,
53-
team:,
5446
programme:,
55-
performed_by_user_id:,
5647
status: "delay_vaccination",
5748
academic_year:,
5849
notes: "Next dose #{next_date.to_fs(:long)}",
5950
delay_vaccination_until: next_date
6051
}
6152
end
62-
63-
class UnknownPerformedBy < StandardError
64-
end
6553
end

spec/lib/next_dose_triage_factory_spec.rb

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
describe NextDoseTriageFactory do
44
subject(:call) { described_class.call(vaccination_record:) }
55

6-
let(:vaccination_record) { create(:vaccination_record, session:, programme:) }
7-
8-
let(:session) { create(:session, programmes: [programme]) }
6+
let(:vaccination_record) { create(:vaccination_record, programme:) }
97

108
context "with a single dose programme" do
119
let(:programme) { Programme.hpv }
@@ -24,31 +22,17 @@
2422
triage = vaccination_record.reload.next_dose_delay_triage
2523
expect(triage).to be_delay_vaccination
2624
expect(triage.delay_vaccination_until).to eq(28.days.from_now.to_date)
27-
expect(triage.performed_by).to eq(vaccination_record.performed_by_user)
25+
expect(triage.performed_by).to be_nil
26+
expect(triage.team).to be_nil
2827
end
2928

30-
context "when not recorded in the service" do
31-
let(:session) { nil }
32-
33-
it "does not create a triage" do
34-
expect { call }.not_to(change(Triage, :count))
35-
end
36-
end
37-
38-
context "when the vaccination record is missing a performed by user" do
29+
context "when performed over 28 days ago" do
3930
let(:vaccination_record) do
40-
create(
41-
:vaccination_record,
42-
session:,
43-
programme:,
44-
performed_by_user: nil
45-
)
31+
create(:vaccination_record, programme:, performed_at: 29.days.ago)
4632
end
4733

48-
it "raises an error" do
49-
expect { call }.to raise_error(
50-
NextDoseTriageFactory::UnknownPerformedBy
51-
)
34+
it "does not create a triage" do
35+
expect { call }.not_to(change(Triage, :count))
5236
end
5337
end
5438
end

0 commit comments

Comments
 (0)