Skip to content

Commit

Permalink
Show notify log entries in activity logs
Browse files Browse the repository at this point in the history
When looking at the activity log for a patient, we can show the notify
log entries which allows us to see clearly which emails and texts have
been sent out.
  • Loading branch information
thomasleese committed Oct 26, 2024
1 parent 007dd7b commit b52501c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 45 deletions.
29 changes: 6 additions & 23 deletions app/components/app_activity_log_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ def events_by_day
def all_events
[
consent_events,
consent_notification_events,
notify_events,
session_events,
session_notification_events,
triage_events,
vaccination_events
].flatten
Expand All @@ -31,16 +30,12 @@ def consent_events
end
end

def consent_notification_events
@patient_session.patient.consent_notifications.map do
def notify_events
@patient_session.patient.notify_log_entries.map do
{
title:
if _1.request?
"Consent request sent for #{_1.programme.name}"
else
"Consent reminder sent for #{_1.programme.name}"
end,
time: _1.sent_at
title: "#{_1.title} sent",
time: _1.created_at,
notes: @patient_session.patient.restricted? ? "" : _1.recipient
}
end
end
Expand All @@ -54,18 +49,6 @@ def session_events
]
end

def session_notification_events
@patient_session.patient.session_notifications.map do |notification|
title =
if notification.school_reminder?
"School session reminder sent"
elsif notification.clinic_invitation?
"Clinic invitation sent"
end
{ title:, time: notification.sent_at }
end
end

def triage_events
@patient_session.triages.map do
{
Expand Down
15 changes: 15 additions & 0 deletions app/models/notify_log_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@ class NotifyLogEntry < ApplicationRecord
validates :recipient, presence: true

encrypts :recipient

def title
template_name&.to_s&.humanize.presence ||
"Unknown #{human_enum_name(:type)}"
end

private

def template_name
if email?
GOVUK_NOTIFY_EMAIL_TEMPLATES.key(template_id)
elsif sms?
GOVUK_NOTIFY_TEXT_TEMPLATES.key(template_id)
end
end
end
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ en:
given: Consent given
not_provided: Not provided
refused: Consent refused
notify_log_entry:
types:
email: Email
sms: SMS
parent:
contact_method_types:
any: No specific needs
Expand Down
31 changes: 9 additions & 22 deletions spec/components/app_activity_log_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,13 @@
)

create(
:consent_notification,
:request,
programme:,
patient:,
sent_at: Date.new(2024, 5, 10)
)

create(
:session_notification,
:school_reminder,
session:,
:notify_log_entry,
:email,
template_id: GOVUK_NOTIFY_EMAIL_TEMPLATES[:consent_school_request],
patient:,
sent_at: Date.new(2024, 5, 30)
consent_form: nil,
recipient: "[email protected]",
created_at: Date.new(2024, 5, 10)
)

create(
Expand Down Expand Up @@ -140,14 +134,6 @@
date: "31 May 2024 at 1:00pm",
notes: "Some notes"

include_examples "card",
title: "School session reminder sent",
date: "30 May 2024 at 12:00am"

include_examples "card",
title: "Clinic invitation sent",
date: "30 May 2024 at 12:00am"

include_examples "card",
title: "Triaged decision: Safe to vaccinate",
date: "30 May 2024 at 2:30pm",
Expand All @@ -172,8 +158,9 @@
date: "29 May 2024 at 12:00pm"

include_examples "card",
title: "Consent request sent for HPV",
date: "10 May 2024 at 12:00am"
title: "Consent school request sent",
date: "10 May 2024 at 12:00am",
notes: "[email protected]"
end

describe "self-consent" do
Expand Down
25 changes: 25 additions & 0 deletions spec/models/notify_log_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,29 @@

it { should be_valid }
end

describe "#title" do
subject(:title) { notify_log_entry.title }

context "with a known template" do
let(:notify_log_entry) do
build(
:notify_log_entry,
:email,
template_id:
GOVUK_NOTIFY_EMAIL_TEMPLATES.fetch(:consent_clinic_request)
)
end

it { should eq("Consent clinic request") }
end

context "with an unknown template" do
let(:notify_log_entry) do
build(:notify_log_entry, :sms, template_id: SecureRandom.uuid)
end

it { should eq("Unknown SMS") }
end
end
end

0 comments on commit b52501c

Please sign in to comment.