From f8c7d8224c9f0a31373d936d167aab6465d3bf34 Mon Sep 17 00:00:00 2001 From: Toby Privett Date: Tue, 3 Dec 2024 13:43:21 +0000 Subject: [PATCH] Add a PerSuicideAndSelfHarm event with details attributes --- app/models/generic_event.rb | 2 ++ .../per_suicide_and_self_harm.rb | 32 +++++++++++++++++ spec/factories/generic_event.rb | 10 ++++++ .../per_suicide_and_self_harm_spec.rb | 34 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 app/models/generic_event/per_suicide_and_self_harm.rb create mode 100644 spec/models/generic_event/per_suicide_and_self_harm_spec.rb diff --git a/app/models/generic_event.rb b/app/models/generic_event.rb index 9bff78c39..0b9730ed3 100644 --- a/app/models/generic_event.rb +++ b/app/models/generic_event.rb @@ -87,6 +87,7 @@ class GenericEvent < ApplicationRecord PerPrisonerWelfare PerPropertyChange PerSelfHarm + PerSuicideAndSelfHarm PerUpdated PerViolentDangerous PerWeapons @@ -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 diff --git a/app/models/generic_event/per_suicide_and_self_harm.rb b/app/models/generic_event/per_suicide_and_self_harm.rb new file mode 100644 index 000000000..8f237db32 --- /dev/null +++ b/app/models/generic_event/per_suicide_and_self_harm.rb @@ -0,0 +1,32 @@ +class GenericEvent + class PerSuicideAndSelfHarm < GenericEvent + LOCATION_ATTRIBUTE_KEY = :location_id + + details_attributes :indication_of_self_harm_or_suicide, + :nature_of_self_harm, + :history_of_self_harm, + :history_of_self_harm_recency, + :history_of_self_harm_method, + :history_of_self_harm_details, + :actions_of_self_harm_undertaken, + :observation_level, + :comments, + :reporting_officer, + :reporting_officer_signed_at, + :reception_officer, + :reception_officer_signed_at, + :supplier_personnel_number, + :police_personnel_number + + relationship_attributes location_id: :locations + eventable_types 'PersonEscortRecord' + + include PersonnelNumberValidations + include LocationFeed + include LocationValidations + + def event_classification + :suicide_and_self_harm + end + end +end diff --git a/spec/factories/generic_event.rb b/spec/factories/generic_event.rb index 93eed8e4b..f14d549f6 100644 --- a/spec/factories/generic_event.rb +++ b/spec/factories/generic_event.rb @@ -669,6 +669,16 @@ factory :event_per_self_harm, parent: :per_incident, class: 'GenericEvent::PerSelfHarm' do end + factory :event_per_suicide_and_self_harm, parent: :generic_event, class: 'GenericEvent::PerSuicideAndSelfHarm' do + eventable { association(:person_escort_record) } + details do + { + location_id: create(:location).id, + supplier_personnel_number: SecureRandom.uuid, + } + end + end + factory :event_per_violent_dangerous, parent: :per_incident, class: 'GenericEvent::PerViolentDangerous' do end diff --git a/spec/models/generic_event/per_suicide_and_self_harm_spec.rb b/spec/models/generic_event/per_suicide_and_self_harm_spec.rb new file mode 100644 index 000000000..31cc0e2a8 --- /dev/null +++ b/spec/models/generic_event/per_suicide_and_self_harm_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe GenericEvent::PerSuicideAndSelfHarm do + subject(:generic_event) { build(:event_per_suicide_and_self_harm) } + + it_behaves_like 'an event with details', :indication_of_self_harm_or_suicide, + :nature_of_self_harm, + :history_of_self_harm, + :history_of_self_harm_recency, + :history_of_self_harm_method, + :history_of_self_harm_details, + :actions_of_self_harm_undertaken, + :observation_level, + :comments, + :reporting_officer, + :reporting_officer_signed_at, + :reception_officer, + :reception_officer_signed_at, + :supplier_personnel_number, + :police_personnel_number + + it_behaves_like 'an event with relationships', location_id: :locations + it_behaves_like 'an event with eventable types', 'PersonEscortRecord' + it_behaves_like 'an event requiring a location', :location_id + it_behaves_like 'an event with a location in the feed', :location_id + + it { is_expected.to validate_presence_of(:supplier_personnel_number) } + + describe '#event_classification' do + subject(:event_classification) { generic_event.event_classification } + + it { expect(event_classification).to eq(:suicide_and_self_harm) } + end +end