Skip to content

Commit

Permalink
Add a PerSuicideAndSelfHarm event with details attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyprivett committed Dec 13, 2024
1 parent ba188eb commit 6108316
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/generic_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class GenericEvent < ApplicationRecord
PerPrisonerWelfare
PerPropertyChange
PerSelfHarm
PerSuicideAndSelfHarm
PerUpdated
PerViolentDangerous
PerWeapons
Expand All @@ -110,6 +111,7 @@ class GenericEvent < ApplicationRecord
incident: 'incident',
medical: 'medical',
notification: 'notification',
suicide_and_self_harm: 'suicide_and_self_harm',
}

belongs_to :eventable, polymorphic: true, touch: true
Expand Down
24 changes: 24 additions & 0 deletions app/models/generic_event/per_suicide_and_self_harm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class GenericEvent
class PerSuicideAndSelfHarm < GenericEvent
details_attributes :concerns,
:history,
:sash_methods,
:source_type,
:source_summary,
:source_observations,
:safety_actions,
:observation_level,
:observation_level_comment,
:comments,
:reporting_officer,
:reporting_officer_signed_at,
:reception_officer,
:reception_officer_signed_at

eventable_types 'PersonEscortRecord'

def event_classification
:suicide_and_self_harm
end
end
end
21 changes: 21 additions & 0 deletions spec/factories/generic_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,27 @@
factory :event_per_self_harm, parent: :per_incident, class: 'GenericEvent::PerSelfHarm' do
end

factory :event_per_suicide_and_self_harm, parent: :per_incident, class: 'GenericEvent::PerSuicideAndSelfHarm' do
eventable { association(:person_escort_record, :confirmed) }
details do
{
concerns: 'They have said they will self-harm',
history: 'Previous incident in 2024',
method: 'Cutting, ligatgure - picked at a scab',
source: 'Third party',
source_summary: 'Police officer stated he would self-harm',
source_observations: 'Something was observed',
safety_actions: 'Referred to a medical professional',
observation_level: 'Every 10 minutes',
comments: 'A comment was recorded',
reporting_officer: 'PCO Roberts',
reporting_officer_signed_at: 1.hour.ago,
reception_officer: 'PCO Smith',
reception_officer_signed_at: 55.minutes.ago,
}
end
end

factory :event_per_violent_dangerous, parent: :per_incident, class: 'GenericEvent::PerViolentDangerous' do
end

Expand Down
17 changes: 17 additions & 0 deletions spec/models/generic_event/per_suicide_and_self_harm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.describe GenericEvent::PerSuicideAndSelfHarm do
let(:per_suicide_and_self_harm_event) { build(:event_per_suicide_and_self_harm) }

it_behaves_like 'an event with details', :concerns, :history, :sash_methods, :source_type, :source_summary, :source_observations,
:safety_actions, :observation_level, :observation_level_comment, :comments, :reporting_officer,
:reporting_officer_signed_at, :reception_officer, :reception_officer_signed_at

it_behaves_like 'an event with eventable types', 'PersonEscortRecord'

describe '#event_classification' do
subject(:event_classification) { per_suicide_and_self_harm_event.event_classification }

it { is_expected.to eq(:suicide_and_self_harm) }
end
end

0 comments on commit 6108316

Please sign in to comment.