Skip to content

Commit 34c6886

Browse files
committed
Refactor Patient::NextActivity
This simplifies the next activity generation and moves it to a method on to the `PatientSession` model since it's only used in once place.
1 parent 38c93af commit 34c6886

File tree

6 files changed

+82
-122
lines changed

6 files changed

+82
-122
lines changed

app/components/app_patient_session_search_result_card_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def action_required
7373
tag.ul(class: "nhsuk-list nhsuk-list--bullet") do
7474
safe_join(
7575
patient_session.programmes.map do |programme|
76-
status = patient_session.patient.next_activity.status[programme]
76+
status = patient_session.next_activity(programme:)
7777
tag.li("#{I18n.t(status, scope: :activity)} for #{programme.name}")
7878
end
7979
)

app/models/patient.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ def year_group_changed?
276276
birth_academic_year_changed?
277277
end
278278

279-
def next_activity
280-
@next_activity ||= Patient::NextActivity.new(self)
281-
end
282-
283279
def consent_status(programme:)
284280
# Use `find` to allow for preloading.
285281
consent_statuses.find { it.programme_id == programme.id } ||

app/models/patient/next_activity.rb

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/models/patient_session.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ def ready_for_vaccinator?(programme: nil)
167167
end
168168
end
169169

170+
def next_activity(programme:)
171+
return :report if patient.vaccination_status(programme:).vaccinated?
172+
173+
return :record if patient.consent_given_and_safe_to_vaccinate?(programme:)
174+
175+
return :triage if patient.triage_status(programme:).required?
176+
177+
consent_status = patient.consent_status(programme:)
178+
179+
return :consent if consent_status.no_response? || consent_status.conflicts?
180+
181+
:do_not_record
182+
end
183+
170184
def outstanding_programmes
171185
# If this patient hasn't been seen yet by a nurse for any of the programmes,
172186
# we don't want to show the banner.

spec/models/patient/next_activity_spec.rb

Lines changed: 0 additions & 75 deletions
This file was deleted.

spec/models/patient_session_spec.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,71 @@
109109
end
110110
end
111111
end
112+
113+
describe "#next_activity" do
114+
subject { patient_session.next_activity(programme:) }
115+
116+
let(:patient) { patient_session.patient }
117+
118+
context "with no consent" do
119+
it { should be(:consent) }
120+
end
121+
122+
context "with consent refused" do
123+
before { create(:patient_consent_status, :refused, patient:, programme:) }
124+
125+
it { should be(:do_not_record) }
126+
end
127+
128+
context "with triaged as do not vaccinate" do
129+
before do
130+
create(:patient_consent_status, :given, patient:, programme:)
131+
create(:patient_triage_status, :do_not_vaccinate, patient:, programme:)
132+
end
133+
134+
it { should be(:do_not_record) }
135+
end
136+
137+
context "with consent needing triage" do
138+
before do
139+
create(:patient_consent_status, :given, patient:, programme:)
140+
create(:patient_triage_status, :required, patient:, programme:)
141+
end
142+
143+
it { should be(:triage) }
144+
end
145+
146+
context "with triaged as safe to vaccinate" do
147+
before do
148+
create(:patient_consent_status, :given, patient:, programme:)
149+
create(:patient_triage_status, :safe_to_vaccinate, patient:, programme:)
150+
end
151+
152+
it { should be(:record) }
153+
end
154+
155+
context "with consent no triage needed" do
156+
before { create(:patient_consent_status, :given, patient:, programme:) }
157+
158+
it { should be(:record) }
159+
end
160+
161+
context "with an administered vaccination record" do
162+
before do
163+
create(:patient_consent_status, :given, patient:, programme:)
164+
create(:patient_vaccination_status, :vaccinated, patient:, programme:)
165+
end
166+
167+
it { should be(:report) }
168+
end
169+
170+
context "with an un-administered vaccination record" do
171+
before do
172+
create(:patient_consent_status, :given, patient:, programme:)
173+
create(:patient_vaccination_status, patient:, programme:)
174+
end
175+
176+
it { should be(:record) }
177+
end
178+
end
112179
end

0 commit comments

Comments
 (0)