Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAP-1917 Add a PerSuicideAndSelfHarm event #2443

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 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,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
10 changes: 10 additions & 0 deletions spec/factories/generic_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 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,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
Loading