Skip to content

Commit 393b993

Browse files
CodeCorvinthomasleese
authored andcommitted
Merge pull request #6402 from NHSDigital/enable_dismiss_important_notices_for_archived_patients
Enable dismiss important notices for archived patients
2 parents adbe6d5 + 59c2074 commit 393b993

11 files changed

Lines changed: 42 additions & 22 deletions

app/models/concerns/patient_import_concern.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def school_move_does_not_move_patient?(school_move:, patient:)
149149
end
150150

151151
def patient_archived_and_not_in_another_team?(patient:, team:)
152-
patient.archived?(team:) && patient.teams.where.not(id: team.id).empty?
152+
patient.archived?(team_id: team.id) &&
153+
patient.teams.where.not(id: team.id).empty?
153154
end
154155

155156
def reset_counts(import)

app/models/important_notice.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def message
9090
end
9191

9292
def can_dismiss?
93-
type.in?(%w[deceased restricted gillick_no_notify team_changed])
93+
type.in?(%w[deceased restricted gillick_no_notify team_changed]) ||
94+
patient.archived?(team_id:)
9495
end
9596
end

app/models/patient.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,11 @@ def sessions
511511
.distinct
512512
end
513513

514-
def archived?(team:)
514+
def archived?(team_id:)
515515
if archive_reasons.loaded?
516-
archive_reasons.any? { it.team_id == team.id }
516+
archive_reasons.any? { it.team_id == team_id }
517517
else
518-
archive_reasons.exists?(team:)
518+
archive_reasons.exists?(team_id:)
519519
end
520520
end
521521

app/models/patient_changeset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def school_move
277277

278278
if patient.new_record? || patient.school != school ||
279279
patient.not_in_team?(team:, academic_year:) ||
280-
patient.archived?(team:) || patient.school_moves.any?
280+
patient.archived?(team_id: team.id) || patient.school_moves.any?
281281
school_move =
282282
patient.school_moves.includes(:teams).first ||
283283
SchoolMove.new(patient:)

app/views/patients/_header.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% end %>
44

55
<%= render AppActionListComponent.new do |action_list| %>
6-
<% if @patient.archived?(team: current_team) && !current_team.has_national_reporting_access? %>
6+
<% if @patient.archived?(team_id: current_team.id) && !current_team.has_national_reporting_access? %>
77
<% action_list.with_item do %>
88
<%= govuk_tag(text: "Archived", colour: "grey") %>
99
<% end %>

spec/features/import_vaccination_records_national_reporting_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ def and_the_patients_should_now_be_associated_with_the_team
270270

271271
def and_the_newly_created_patients_should_be_archived
272272
new_patient = Patient.find_by(nhs_number: "9999075320")
273-
expect(new_patient.archived?(team: @team)).to be true
273+
expect(new_patient.archived?(team_id: @team.id)).to be true
274274
expect(new_patient.archive_reasons.first.type).to eq "immunisation_import"
275275
end
276276

277277
def and_the_existing_patients_should_not_be_archived
278-
expect(@existing_patient.archived?(team: @team)).to be false
278+
expect(@existing_patient.archived?(team_id: @team.id)).to be false
279279
end
280280

281281
def and_the_vaccination_records_are_sent_to_the_imms_api

spec/features/import_vaccination_records_point_of_care_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ def and_the_patients_should_now_be_associated_with_the_team
164164

165165
def and_the_newly_created_patients_should_be_archived
166166
new_patient = Patient.find_by(nhs_number: "7420180008")
167-
expect(new_patient.archived?(team: @team)).to be true
167+
expect(new_patient.archived?(team_id: @team.id)).to be true
168168
expect(new_patient.archive_reasons.first.type).to eq "immunisation_import"
169169
end
170170

171171
def and_the_existing_patients_should_not_be_archived
172-
expect(@existing_patient.archived?(team: @team)).to be false
172+
expect(@existing_patient.archived?(team_id: @team.id)).to be false
173173
end
174174

175175
def when_i_go_back

spec/lib/patient_merger_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346

347347
it "removes the archive reasons from the patient" do
348348
expect { call }.to change(ArchiveReason, :count).by(-1)
349-
expect(patient_to_keep.archived?(team:)).to be(false)
349+
expect(patient_to_keep.archived?(team_id: team.id)).to be(false)
350350
end
351351
end
352352

@@ -362,7 +362,7 @@
362362

363363
it "removes the archive reason from the patient" do
364364
expect { call }.to change(ArchiveReason, :count).by(-1)
365-
expect(patient_to_keep.archived?(team:)).to be(false)
365+
expect(patient_to_keep.archived?(team_id: team.id)).to be(false)
366366
end
367367
end
368368

@@ -405,7 +405,7 @@
405405

406406
it "keeps the archive reason on the merged patient" do
407407
expect { call }.to change(ArchiveReason, :count).by(-1)
408-
expect(patient_to_keep.archived?(team:)).to be(true)
408+
expect(patient_to_keep.archived?(team_id: team.id)).to be(true)
409409
end
410410
end
411411

spec/models/important_notice_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@
8888
end
8989
end
9090
end
91+
92+
describe "#can_dismiss?" do
93+
subject(:can_dismiss) { important_notice.can_dismiss? }
94+
95+
let(:important_notice) do
96+
create(:important_notice, :invalidated, team_id: team.id, patient:)
97+
end
98+
99+
context "important notices for invalidated patients cannot be dismissed" do
100+
it { should be(false) }
101+
end
102+
103+
context "important notices for invalidated patients can be dismissed when archived" do
104+
before { create(:archive_reason, :moved_out_of_area, team:, patient:) }
105+
106+
it { should be(true) }
107+
end
108+
end
91109
end

spec/models/patient_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@
730730
end
731731

732732
context "without preloading" do
733-
subject(:archived?) { patient.archived?(team:) }
733+
subject(:archived?) { patient.archived?(team_id: team.id) }
734734

735735
include_examples "archived? behavior"
736736
end
@@ -740,7 +740,7 @@
740740
described_class
741741
.includes(:archive_reasons)
742742
.find(patient.id)
743-
.archived?(team:)
743+
.archived?(team_id: team.id)
744744
end
745745

746746
include_examples "archived? behavior"

0 commit comments

Comments
 (0)