Skip to content

Commit

Permalink
AP-4407: Add model, view, controller, forms and steps for child care …
Browse files Browse the repository at this point in the history
…assesments
  • Loading branch information
jsugarman committed Jan 14, 2025
1 parent 4d7813b commit f27bd56
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Providers
module ProceedingMeritsTask
class ChildCareAssessmentsController < ProviderBaseController
def show
@form = ChildCareAssessmentForm.new(model: child_care_assessment)
end

def update
@form = ChildCareAssessmentForm.new(form_params.merge(proceeding_id: proceeding.id))
render :show unless update_task_save_continue_or_draft(proceeding.ccms_code.to_sym, :client_child_care_assessment)
end

private

def child_care_assessment
@child_care_assessment ||= proceeding.child_care_assessment || proceeding.build_child_care_assessment
end

def proceeding
@proceeding ||= Proceeding.find(params[:merits_task_list_id])
end

def legal_aid_application
@legal_aid_application ||= proceeding.legal_aid_application
end

def form_params
merge_with_model(child_care_assessment) do
params
.require(:proceeding_merits_task_child_care_assessment)
.permit(
:assessed,
)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Providers
module ProceedingMeritsTask
class ChildCareAssessmentForm < BaseForm
form_for ::ProceedingMeritsTask::ChildCareAssessment

attr_accessor :proceeding_id, :assessed

validates :assessed, inclusion: %w[true false], unless: :draft?

set_callback :save, :before, :sync_result_details

private

def sync_result_details
if assessed_changed?
attributes["result"] = nil
attributes["details"] = nil
end
end

def assessed_changed?
attributes["assessed"] != model.assessed.to_s
end
end
end
end
1 change: 1 addition & 0 deletions app/models/proceeding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Proceeding < ApplicationRecord

has_one :chances_of_success, class_name: "ProceedingMeritsTask::ChancesOfSuccess", dependent: :destroy
has_one :prohibited_steps, class_name: "ProceedingMeritsTask::ProhibitedSteps", dependent: :destroy
has_one :child_care_assessment, class_name: "ProceedingMeritsTask::ChildCareAssessment", dependent: :destroy

has_many :final_hearings, dependent: :destroy
has_many :proceeding_linked_children, class_name: "ProceedingMeritsTask::ProceedingLinkedChild", dependent: :destroy
Expand Down
5 changes: 5 additions & 0 deletions app/models/proceeding_merits_task/child_care_assessment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ProceedingMeritsTask
class ChildCareAssessment < ApplicationRecord
belongs_to :proceeding
end
end
1 change: 1 addition & 0 deletions app/services/flow/flows/provider_merits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ProviderMerits < FlowSteps
linked_children: Steps::ProviderMerits::LinkedChildrenStep,
specific_issue: Steps::ProviderMerits::SpecificIssueStep,
vary_order: Steps::ProviderMerits::VaryOrderStep,
child_care_assessments: Steps::ProviderMerits::ChildCareAssessmentStep,
is_client_biological_parent: Steps::ProviderMerits::BiologicalParentStep,
does_client_have_parental_responsibilities: Steps::ProviderMerits::ParentalResponsibilitiesStep,
is_client_child_subject: Steps::ProviderMerits::ChildSubjectStep,
Expand Down
1 change: 1 addition & 0 deletions app/services/flow/merits_loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def convert_task_to_flow_name(task)
vary_order: :vary_order,
opponents_application: :opponents_application,
client_relationship_to_proceeding: :is_client_biological_parent,
client_child_care_assessment: :child_care_assessment,
}[task]
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Flow
module Steps
module ProviderMerits
ChildCareAssessmentStep = Step.new(
path: lambda do |application|
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"])
Steps.urls.providers_merits_task_list_child_care_assessment_path(proceeding)
end,
forward: lambda do |application|
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"])
if proceeding.child_care_assessment.assessed?
:child_care_assessment_result
else
Flow::MeritsLoop.forward_flow(application, proceeding.ccms_code.to_sym)
end
end,
check_answers: lambda do |application|
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"])
if proceeding.child_care_assessment.assessed?
:child_care_assessment_result
else
:check_merits_answers
end
end,
)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%= form_with(
model: @form,
url: providers_merits_task_list_child_care_assessment_path(@proceeding),
method: :patch,
local: true,
) do |form| %>

<%= page_template page_title: t(".h1-heading"),
head_title: "#{@proceeding.meaning} - " + t(".h1-heading"),
template: :basic,
form: do %>
<%= form.govuk_collection_radio_buttons :assessed,
yes_no_options(yes: t(".radio_hint_yes")),
:value, # value_method
:label, # text_method
:radio_hint, # hint_method
bold_labels: false,
caption: { text: @proceeding.meaning, size: "xl" },
legend: { text: content_for(:page_title), tag: "h1", size: "xl" },
hint: { text: t(".hint") } %>

<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ en:
attributes:
details:
blank: Enter details of the changes since the original order was made
proceeding_merits_task/child_care_assessment:
attributes:
assessed:
inclusion: Select yes if the local authority has assessed your client's ability to care for the children involved
partner:
attributes:
date_of_birth:
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ en:
show:
page_title: Check who your client is
paragraph: You must answer 'yes' to one of these questions. Check your answers and change the one that is wrong.
child_care_assessments:
show:
h1-heading: Has the local authority assessed your client's ability to care for the children involved?
radio_hint_yes: You'll need to upload supporting evidence later.
hint: For example, if your client is the grandparent, the local authority may check if they could be a suitable carer.
application_merits_task:
involved_children:
new:
Expand Down Expand Up @@ -1428,6 +1433,7 @@ en:
opponents_application_html: <span class="govuk-visually-hidden">%{proceeding} </span>Opponent application
vary_order_html: <span class="govuk-visually-hidden">%{proceeding} </span>Changes since original order was made
client_relationship_to_proceeding_html: <span class="govuk-visually-hidden">%{proceeding} </span>Who your client is in the proceeding
client_child_care_assessment_html: <span class="govuk-visually-hidden">%{proceeding} </span>Assessment of your client
states:
not_started: Not started
waiting_for_dependency: Cannot start yet
Expand Down Expand Up @@ -1457,6 +1463,7 @@ en:
client_relationship_to_proceeding: is_client_biological_parent
check_who_client_is: check_who_client_is
second_appeal: second_appeal
client_child_care_assessment: child_care_assessment
merits_reports:
show:
heading: Merits report
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
resource :does_client_have_parental_responsibility, only: %i[show update]
resource :is_client_child_subject, only: %i[show update], controller: :is_client_child_subject, path: "is_client_a_child_subject_of_proceeding"
resource :check_who_client_is, only: %i[show update]
resource :child_care_assessment, only: %i[show update], path: "assessment_of_client"
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions db/anonymise/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
row_context[:field_1_val] = Faker::Lorem.paragraph(sentence_count: 2) unless original_value.eql?('\N')
end,
},
child_care_assessments: {
details: lambda do |original_value, row_context|
row_context[:field_1_val] = Faker::Lorem.paragraph(sentence_count: 2) unless original_value.eql?('\N')
end,
},
citizen_access_tokens: {},
debugs: {},
dependants: {
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/legal_framework_merits_task_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
serialized_data { build(:legal_framework_serializable_merits_task_list, :pbm01a).to_yaml }
end

trait :pbm32_as_applicant do
serialized_data { build(:legal_framework_serializable_merits_task_list, :pbm32_as_applicant).to_yaml }
end

trait :broken_opponent do
serialized_data { build(:legal_framework_serializable_merits_task_list, :broken_opponent).to_yaml }
end
Expand Down
25 changes: 25 additions & 0 deletions spec/factories/legal_framework_serialized_merits_task_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,31 @@
end
end

trait :pbm32_as_applicant do
lfa_response do
{
request_id: SecureRandom.uuid,
application: {
tasks: {
opponent_name: [],
statement_of_case: [],
children_application: [],
},
},
proceedings: [
{
ccms_code: "PBM32",
tasks: {
children_proceeding: [:children_application],
chances_of_success: [],
client_child_care_assessment: [],
},
},
],
}
end
end

trait :broken_opponent do
lfa_response do
{
Expand Down
18 changes: 18 additions & 0 deletions spec/factories/proceeding_merits_task/child_care_assessments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FactoryBot.define do
factory :child_care_assessment, class: "ProceedingMeritsTask::ChildCareAssessment" do
proceeding
assessed { false }

trait :negative do
assessed { true }
result { false }
details { Faker::Lorem.paragraph(sentence_count: 2) }
end

trait :positive do
assessed { false }
result { true }
details { nil }
end
end
end

0 comments on commit f27bd56

Please sign in to comment.