Skip to content

Commit acaf477

Browse files
authored
Merge pull request #6634 from NHSDigital/MAV-6739-notify-purpose-from-template-frontmatter
Improvements to the purpose field on notify log entries
2 parents a02150c + 26113c0 commit acaf477

62 files changed

Lines changed: 163 additions & 138 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/jobs/email_delivery_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def perform(
103103
subject: rendered[:subject],
104104
template_id: template.id,
105105
type: :email,
106-
purpose: NotifyLogEntry.purpose_for_template_name(template_name_sym),
106+
purpose: template.purpose,
107107
notify_log_entry_programmes_attributes:
108108
personalisation.programmes.map do
109109
{ programme_type: it.type, disease_types: it.disease_types }

app/jobs/sms_delivery_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def perform(
9393
sent_by:,
9494
template_id: template.id,
9595
type: :sms,
96-
purpose: NotifyLogEntry.purpose_for_template_name(template_name_sym),
96+
purpose: template.purpose,
9797
notify_log_entry_programmes_attributes:
9898
personalisation.programmes.map do
9999
{ programme_type: it.type, disease_types: it.disease_types }

app/lib/notify_template.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# frozen_string_literal: true
22

33
class NotifyTemplate
4+
include ActiveModel::Model
5+
6+
validates :purpose, presence: true
7+
validates :purpose,
8+
inclusion: {
9+
in: ->(_) { NotifyLogEntry.purposes.keys.map(&:to_sym) }
10+
},
11+
if: -> { purpose.present? }
12+
413
class << self
514
def find(name, channel:)
615
local_templates(channel)[name]
@@ -43,19 +52,21 @@ def scan_templates(channel)
4352
template = new(name:, channel:, content:)
4453
next unless template.id
4554

55+
template.validate!
4656
hash[name] = template
4757
end
4858
end
4959
end
5060

51-
attr_reader :name, :channel, :id, :body, :subject
61+
attr_reader :name, :channel, :id, :body, :subject, :purpose
5262

5363
def initialize(name:, channel:, content:)
5464
@name = name.to_sym
5565
@channel = channel.to_sym
5666
frontmatter, @body = parse_frontmatter(content)
5767
@id = frontmatter["template_id"]
5868
@subject = frontmatter["subject"].to_s
69+
@purpose = frontmatter["purpose"]&.to_sym
5970
end
6071

6172
def render(personalisation)

app/models/notify_log_entry.rb

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# id :bigint not null, primary key
88
# body :text
99
# delivery_status :integer default("sending"), not null
10-
# purpose :integer
10+
# purpose :integer not null
1111
# recipient :string not null
1212
# subject :text
1313
# type :integer not null
@@ -128,6 +128,7 @@ class NotifyLogEntry < ApplicationRecord
128128
vaccination_deleted: 13
129129
}
130130

131+
validates :purpose, presence: true
131132
validates :recipient, presence: true
132133
validates :template_id, presence: true
133134

@@ -158,40 +159,6 @@ def title
158159

159160
def programmes = notify_log_entry_programmes.map(&:programme)
160161

161-
def self.purpose_for_template_name(template_name_sym)
162-
name = template_name_sym.to_s
163-
164-
if name.include?("consent") && name.include?("request")
165-
:consent_request
166-
elsif name.include?("consent") && name.include?("reminder")
167-
:consent_reminder
168-
elsif name.include?("consent_confirmation")
169-
:consent_confirmation
170-
elsif name.include?("consent") && name.include?("warning")
171-
:consent_warning
172-
elsif name.include?("clinic") && name.include?("invitation")
173-
:clinic_invitation
174-
elsif name.include?("session_school_reminder")
175-
:session_reminder
176-
elsif name.include?("triage_vaccination_will_happen")
177-
:triage_vaccination_will_happen
178-
elsif name.include?("triage_vaccination_wont_happen")
179-
:triage_vaccination_wont_happen
180-
elsif name.include?("triage_vaccination_at_clinic")
181-
:triage_vaccination_at_clinic
182-
elsif name.include?("triage_delay_vaccination")
183-
:triage_delay_vaccination
184-
elsif name.include?("vaccination_administered")
185-
:vaccination_administered
186-
elsif name.include?("vaccination_already_had")
187-
:vaccination_already_had
188-
elsif name.include?("vaccination_not_administered")
189-
:vaccination_not_administered
190-
elsif name.include?("vaccination_deleted")
191-
:vaccination_deleted
192-
end
193-
end
194-
195162
private
196163

197164
def template_name

app/views/notify_templates/email/clinic_initial_invitation.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "ceea5ff5-2250-4eb2-ab35-4e9e840b2a6f"
3+
purpose: clinic_invitation
34
template_name: clinic_initial_invitation
45
subject: "<%= short_patient_name %> has still not had their <%= vaccination %>"
56
---

app/views/notify_templates/email/clinic_initial_invitation_rt5.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "17e63d67-53fc-4e9a-a533-74974412aac0"
3+
purpose: clinic_invitation
34
template_name: clinic_initial_invitation_rt5
45
subject: "<%= short_patient_name %> has still not had their <%= vaccination %>"
56
---

app/views/notify_templates/email/clinic_initial_invitation_ryg.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "5fe4fb4d-6f0a-4149-a80a-232bdfdf4f73"
3+
purpose: clinic_invitation
34
template_name: clinic_initial_invitation_ryg
45
subject: "<%= short_patient_name %> has still not had their <%= vaccination %>"
56
---

app/views/notify_templates/email/clinic_subsequent_invitation.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "a86a3b3f-a848-41d8-9a6f-d38174981388"
3+
purpose: clinic_invitation
34
template_name: clinic_subsequent_invitation
45
subject: "Your child can still get their <%= vaccination %> at a clinic"
56
---

app/views/notify_templates/email/clinic_subsequent_invitation_ryg.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "eee59c1b-3af4-4ccd-8653-940887066390"
3+
purpose: clinic_invitation
34
template_name: clinic_subsequent_invitation_ryg
45
subject: "Your child can still get their <%= vaccination %> at a clinic"
56
---

app/views/notify_templates/email/consent_clinic_request.text.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
template_id: "14e88a09-4281-4257-9574-6afeaeb42715"
3+
purpose: consent_request
34
template_name: consent_clinic_request
45
subject: "We still need consent for your child’s <%= vaccination %>"
56
---

0 commit comments

Comments
 (0)