Skip to content

Commit 39a012d

Browse files
committed
Fix: ignore dismissed notices when generating new important notices
`ImportantNoticeGeneratorJob` builds an in-memory index of "existing notices" and uses it to decide whether to create missing notices for a patient. Previously that index included dismissed notices, so a dismissed notice was treated as "already exists". This meant notices could fail to reappear when a patient status was cleared and later re-applied (e.g. restricted -> dismissed when cleared -> restricted again, but no new active restricted notice created). Change: - Build existing notices from active notices only by filtering on `dismissed_at: nil` - Simplify dismissal selection logic since existing notices is now active-only
1 parent f4da219 commit 39a012d

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

app/jobs/important_notice_generator_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def process_batch(patients)
3131

3232
existing_notices =
3333
ImportantNotice
34-
.where(patient_id: patients.map(&:id))
34+
.where(patient_id: patients.map(&:id), dismissed_at: nil)
3535
.index_by { notice_key(it) }
3636

3737
patients.each do |patient|
@@ -104,7 +104,7 @@ def dismiss_existing_notices_based_on_patient_status(
104104

105105
existing_notices.each_value do |notice|
106106
unless notice.patient_id == patient.id && notice.team_id == team_id &&
107-
notice.type == type.to_s && notice.dismissed_at.nil?
107+
notice.type == type.to_s
108108
next
109109
end
110110

spec/jobs/important_notice_generator_job_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,37 @@
7676
}.from(1).to(0)
7777
end
7878
end
79+
80+
context "when a restricted notice was dismissed and the patient becomes restricted again" do
81+
before do
82+
# Create initial notices
83+
patient.update_column(:restricted_at, Time.current)
84+
described_class.perform_now([patient.id])
85+
86+
# Clear restriction and dismiss notices
87+
patient.update_column(:restricted_at, nil)
88+
described_class.perform_now([patient.id])
89+
90+
# Re-apply restriction
91+
patient.update_column(:restricted_at, Time.current)
92+
end
93+
94+
it "creates a new active restricted notice (dismissed notices do not block re-creation)" do
95+
expect { described_class.perform_now([patient.id]) }.to change {
96+
ImportantNotice
97+
.active(team: team_a)
98+
.where(patient:, type: :restricted)
99+
.count
100+
}.from(0).to(1)
101+
102+
expect(
103+
ImportantNotice
104+
.dismissed(team: team_a)
105+
.where(patient:, type: :restricted)
106+
.count
107+
).to be >= 1
108+
end
109+
end
79110
end
80111

81112
context "invalidated" do

0 commit comments

Comments
 (0)