Skip to content

Commit

Permalink
feat: adds case contact topics
Browse files Browse the repository at this point in the history
case_contact_topics:
  active      :boolean          default(FALSE)
  answer      :string
  details     :string
  title       :string
  source(polymorphic): belongs_to casa_org or casa_case_contact

feat: adds case contact topics model
- shoulda matcher validations

feat: adds default topics
- adds default topics in yml file
- adds checks to only allow certain keys

feat: adds tests for case contact methods
- tests generation for casa orgs
- tests creation of dupes

feat: add contact topics seeding

feat: tests for form controller
- case_contact form_controller update step only updates correct values
- case contact controller create step creates default topics from org on
  case contact

feat: adds tests for casa admin
Tests that when a admin creates a casa org the default contact topics are created.
  • Loading branch information
elasticspoon committed Feb 14, 2024
1 parent 963e53f commit 7331a5d
Show file tree
Hide file tree
Showing 21 changed files with 414 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/controllers/all_casa_admins/casa_orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
@casa_org = CasaOrg.new(casa_org_params)

if @casa_org.save
@casa_org.generate_contact_types_and_hearing_types
@casa_org.generate_defaults
respond_to do |format|
format.html do
redirect_to all_casa_admins_casa_org_path(@casa_org),
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def create_additional_case_contacts(case_contact)
other_expenses_describe: ae.other_expenses_describe
)
end
case_contact.case_contact_topics.each do |cct|
new_case_contact.case_contact_topics << cct.dup
end

new_case_contact.save!
end
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def new
end

@case_contact = CaseContact.create(creator: current_user, draft_case_ids: draft_case_ids)
@case_contact.create_court_topics(current_organization)
redirect_to case_contact_form_path(CaseContact::FORM_STEPS.first, case_contact_id: @case_contact.id)
end

Expand Down
5 changes: 4 additions & 1 deletion app/models/casa_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CasaOrg < ApplicationRecord
has_many :case_groups, dependent: :destroy
has_one_attached :logo
has_one_attached :court_report_template
has_many :case_contact_topics, as: :source, dependent: :destroy

encrypts :twilio_account_sid
encrypts :twilio_api_key_sid
Expand Down Expand Up @@ -85,8 +86,10 @@ def set_slug
self.slug = name.parameterize
end

def generate_contact_types_and_hearing_types
# generates default: contact types, hearing types, contact topics
def generate_defaults
ActiveRecord::Base.transaction do
CaseContactTopic.generate_for_org!(self)
ContactTypeGroup.generate_for_org!(self)
HearingType.generate_for_org!(self)
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CaseContact < ApplicationRecord
}, primary_key: :creator_id, foreign_key: :volunteer_id
has_one :supervisor, through: :creator
has_many :followups
has_many :case_contact_topics, dependent: :destroy, as: :source

# Draft support requires the casa_case to be nil if the contact is in_progress
belongs_to :casa_case, optional: true
Expand Down Expand Up @@ -49,6 +50,7 @@ def active_or_expenses?

accepts_nested_attributes_for :case_contact_contact_type
accepts_nested_attributes_for :casa_case
accepts_nested_attributes_for :case_contact_topics, update_only: true, reject_if: :all_blank

scope :supervisors, ->(supervisor_ids = nil) {
joins(:supervisor_volunteer).where(supervisor_volunteers: {supervisor_id: supervisor_ids}) if supervisor_ids.present?
Expand Down Expand Up @@ -282,6 +284,14 @@ def self.case_hash_from_cases(cases)
contact_made_desc: "Contact made ('yes' first)"
}
end

def create_court_topics(casa_org)
casa_org.case_contact_topics.each do |topic|
case_contact_topics << topic.dup
end

save!
end
end

# == Schema Information
Expand Down
42 changes: 42 additions & 0 deletions app/models/case_contact_topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class CaseContactTopic < ApplicationRecord
CASA_DEFAULT_COURT_TOPICS = Rails.root.join("data", "default_contact_topics.yml")
REQUIRED_ATTRS = %w[title details].freeze

belongs_to :source, polymorphic: true

validates :title, :details, presence: true

class << self
def generate_for_org!(casa_org)
default_contact_topics.each do |topic|
filtered_topic = topic.select { |key, _| REQUIRED_ATTRS.include?(key) }
find_or_create_by!(source: casa_org, **filtered_topic)
end
end

private

def default_contact_topics
YAML.load_file(CASA_DEFAULT_COURT_TOPICS)
end
end
end

# == Schema Information
#
# Table name: case_contact_topics
#
# id :bigint not null, primary key
# active :boolean default(FALSE)
# answer :string
# details :string
# source_type :string not null
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# source_id :bigint not null
#
# Indexes
#
# index_case_contact_topics_on_source (source_type,source_id)
#
1 change: 1 addition & 0 deletions app/models/learning_hour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def user_org_learning_topic_enable?
# id :bigint not null, primary key
# duration_hours :integer not null
# duration_minutes :integer not null
# learning_type :integer default(5)
# name :string not null
# occurred_at :datetime not null
# created_at :datetime not null
Expand Down
3 changes: 2 additions & 1 deletion app/values/case_contact_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def initialize(params)
:volunteer_address,
draft_case_ids: [],
case_contact_contact_type_attributes: [:contact_type_id],
additional_expenses_attributes: [:id, :other_expense_amount, :other_expenses_describe]
case_contact_topics_attributes: %i[case_contact_topic_id id answer active],
additional_expenses_attributes: %i[id other_expense_amount other_expenses_describe]
)
if params.dig(:case_contact, :duration_minutes)
new_params[:duration_minutes] = convert_duration_minutes(params)
Expand Down
36 changes: 36 additions & 0 deletions data/default_contact_topics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- title: "Background information"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
- title: "Current situation"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
- title: "Education, vocation, or daycare"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
- title: "Health and mental health"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
- title: "Family and community connections"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
- title: "Child’s strengths"
details:
"a) When did the family first come into contact with the Department of Social Services or Department of Juvenile Justice – how many times?
b) Tell the history of their involvement with the department and any facts about their life that could help determine the need for placement and/or services.
c) Discuss the child’s history – behavior problems, educational history, medical history, psychological history (any hospitalizations, previous counseling, etc.)
d) If child has been placed previously give a history of the child’s placements (placed with different parents, relatives, DSS, etc)."
13 changes: 13 additions & 0 deletions db/migrate/20240128015203_create_case_contact_topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateCaseContactTopics < ActiveRecord::Migration[7.0]
def change
create_table :case_contact_topics do |t|
t.string :title
t.string :details
t.string :answer
t.boolean :active, default: false
t.references :source, polymorphic: true, null: false

t.timestamps
end
end
end
15 changes: 14 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_11_25_150721) do
ActiveRecord::Schema[7.1].define(version: 2024_01_28_015203) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -184,6 +184,18 @@
t.index ["contact_type_id"], name: "index_case_contact_contact_types_on_contact_type_id"
end

create_table "case_contact_topics", force: :cascade do |t|
t.string "title"
t.string "details"
t.string "answer"
t.boolean "active", default: false
t.string "source_type", null: false
t.bigint "source_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["source_type", "source_id"], name: "index_case_contact_topics_on_source"
end

create_table "case_contacts", force: :cascade do |t|
t.bigint "creator_id", null: false
t.bigint "casa_case_id"
Expand Down Expand Up @@ -395,6 +407,7 @@

create_table "learning_hours", force: :cascade do |t|
t.bigint "user_id", null: false
t.integer "learning_type", default: 5
t.string "name", null: false
t.integer "duration_minutes", null: false
t.integer "duration_hours", null: false
Expand Down
4 changes: 3 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require_relative "../lib/tasks/data_post_processors/case_contact_populator"
require_relative "../lib/tasks/data_post_processors/contact_type_populator"
require_relative "../lib/tasks/data_post_processors/sms_notification_event_populator"
require_relative "../lib/tasks/data_post_processors/contact_topic_populator"

class SeederMain
attr_reader :db_populator, :rng
Expand Down Expand Up @@ -76,6 +77,7 @@ def active_record_classes
def post_process_data
ContactTypePopulator.populate
CaseContactPopulator.populate
ContactTopicPopulator.populate
end

def get_seed_specification
Expand All @@ -97,7 +99,7 @@ def get_seed_specification
def report_object_counts
log "\nRecords written to the DB:\n\nCount Class Name\n----- ----------\n\n"
active_record_classes.each do |klass|
log "%5d %s" % [klass.count, klass.name]
log format("%5d %s", klass.count, klass.name)
end
log "\n\nVolunteers, Supervisors and CasaAdmins are types of Users"
end
Expand Down
7 changes: 7 additions & 0 deletions lib/tasks/data_post_processors/contact_topic_populator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ContactTopicPopulator
def self.populate
CasaOrg.all.each do |casa_org|
CaseContactTopic.generate_for_org!(casa_org)
end
end
end
16 changes: 16 additions & 0 deletions spec/factories/case_contact_topics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FactoryBot.define do
factory :case_contact_topic do
title { Faker::Lorem.sentence }
details { Faker::Lorem.paragraph }

for_org

trait :for_case_contact do
association(:source, factory: :case_contact)
end

trait :for_org do
association(:source, factory: :casa_org)
end
end
end
Loading

0 comments on commit 7331a5d

Please sign in to comment.