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

refactor: expose court report methods #5590

Merged
merged 1 commit into from
Apr 14, 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
42 changes: 23 additions & 19 deletions app/models/case_court_report_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,40 @@ def initialize(args = {})
end

def context
prepare_context(@path_to_template.end_with?("default_report_template.docx"))
end

private

def prepare_context(is_default_template)
latest_hearing_date = @casa_case.most_recent_past_court_date

{
created_date: I18n.l(Time.current.in_time_zone(@time_zone).to_date, format: :full, default: nil),
casa_case: prepare_case_details,
case_contacts: prepare_case_contacts,
case_court_orders: prepare_case_orders,
case_mandates: prepare_case_orders, # backwards compatible with old Montgomery template - keep this! TODO test full generation
latest_hearing_date: latest_hearing_date.nil? ? "___<LATEST HEARING DATE>____" : I18n.l(latest_hearing_date.date, format: :full, default: nil),
org_address: org_address(is_default_template),
casa_case: case_details,
case_contacts: case_contacts,
case_court_orders: case_orders(@case_court_orders),
case_mandates: case_orders(@case_court_orders), # backwards compatible with old Montgomery template - keep this! TODO test full generation
latest_hearing_date: latest_hearing_date,
org_address: org_address(@path_to_template),
volunteer: volunteer_info,
hearing_type_name: @court_date&.hearing_type&.name || "None"
}
end

def prepare_case_contacts
# @return [Array<Hash>]
# Each hash includes:
# - :name [String]
# - :type [String]
# - :dates [Array<String>]
# - :dates_by_medium_type [Array<String>]
def case_contacts
cccts = CaseContactContactType.includes(:case_contact, :contact_type).where("case_contacts.casa_case_id": @casa_case.id)
interviewees = filter_out_old_case_contacts(cccts)
return [] unless interviewees.size.positive?

CaseContactsContactDates.new(interviewees).contact_dates_details
end

def prepare_case_orders
@case_court_orders.map do |case_order|
def latest_hearing_date
latest_hearing_date = @casa_case.most_recent_past_court_date
latest_hearing_date.nil? ? "___<LATEST HEARING DATE>____" : I18n.l(latest_hearing_date.date, format: :full, default: nil)
end

def case_orders(orders)
orders.map do |case_order|
{
order: case_order.text,
status: case_order.implementation_status&.humanize
Expand All @@ -62,7 +65,7 @@ def filter_out_old_case_contacts(interviewees)
end
end

def prepare_case_details
def case_details
{
court_date: I18n.l(@court_date&.date, format: :full, default: nil),
case_number: @casa_case.case_number,
Expand All @@ -82,7 +85,8 @@ def volunteer_info
end
end

def org_address(is_default_template)
def org_address(path_to_template)
is_default_template = path_to_template.end_with?("default_report_template.docx")
@volunteer.casa_org.address if @volunteer && is_default_template
end
end
4 changes: 2 additions & 2 deletions spec/factories/case_court_report_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
volunteer_for_context = volunteer.nil? ? create(:volunteer) : volunteer
casa_case_for_context = casa_case.nil? ? create(:casa_case) : casa_case

unless volunteer_for_context.casa_cases.where(id: casa_case_for_context.id).exists?
if volunteer_for_context && volunteer_for_context.casa_cases.where(id: casa_case_for_context.id).none?
volunteer_for_context.casa_cases << casa_case_for_context
end

new(
case_id: casa_case_for_context.id,
volunteer_id: volunteer_for_context.id,
volunteer_id: volunteer_for_context.try(:id),
path_to_report: path_to_report,
path_to_template: path_to_template,
court_date: court_date,
Expand Down
Loading
Loading