diff --git a/app/models/application_digest.rb b/app/models/application_digest.rb index f07dddf314..e3e9d125fd 100644 --- a/app/models/application_digest.rb +++ b/app/models/application_digest.rb @@ -14,6 +14,12 @@ class ApplicationDigest < ApplicationRecord family_linked legal_linked no_fixed_address + biological_parent + parental_responsibility_agreement + parental_responsibility_court_order + child_subject + parental_responsibility_evidence + autogranted ].freeze class << self @@ -64,6 +70,12 @@ def map_attrs(application_id) legal_linked_lead_or_associated: laa.legal_linked_lead_or_associated, number_of_legal_linked_applications: laa.legal_linked_applications_count, no_fixed_address: laa.applicant.no_fixed_residence?, + biological_parent: laa.biological_parent_relationship?, + parental_responsibility_agreement: laa.parental_responsibility_agreement_relationship?, + parental_responsibility_court_order: laa.parental_responsibility_court_order_relationship?, + child_subject: laa.child_subject_relationship?, + parental_responsibility_evidence: laa.parental_responsibility_evidence?, + autogranted: laa.auto_grant_special_children_act?(nil), } end diff --git a/app/models/legal_aid_application.rb b/app/models/legal_aid_application.rb index 58cbb160e3..0c7447b774 100644 --- a/app/models/legal_aid_application.rb +++ b/app/models/legal_aid_application.rb @@ -650,6 +650,31 @@ def related_proceedings proceedings.where(sca_type: "related") end + def biological_parent_relationship? + proceedings.any? { |proceeding| proceeding.relationship_to_child.eql?("biological") } + end + + def parental_responsibility_court_order_relationship? + proceedings.any? { |proceeding| proceeding.relationship_to_child.eql?("court_order") } + end + + def parental_responsibility_agreement_relationship? + proceedings.any? { |proceeding| proceeding.relationship_to_child.eql?("parental_responsibility_agreement") } + end + + def child_subject_relationship? + proceedings.any? { |proceeding| proceeding.relationship_to_child.eql?("child_subject") } + end + + def parental_responsibility_evidence? + attachments&.parental_responsibility&.exists? + end + + def auto_grant_special_children_act?(_options) + # TODO: extract autogrant logic into model + false + end + private def expired_by_2023_surname_at_birth_issue? diff --git a/app/services/reports/mis/application_detail_csv_line.rb b/app/services/reports/mis/application_detail_csv_line.rb index c629f323a5..7ffd6721b0 100644 --- a/app/services/reports/mis/application_detail_csv_line.rb +++ b/app/services/reports/mis/application_detail_csv_line.rb @@ -173,6 +173,13 @@ def self.header_row "Number of legal links", "No fixed address", "Previous CCMS ref?", + "Child subject client involvment type?", + "Biological parent relationship?", + "Parental responsibility agreement relationship?", + "Parental responsibility court order relationship?", + "Child subject relationship?", + "Parental responsibility evidence?", + "Autogranted?", ] end @@ -209,6 +216,9 @@ def call linked_applications home_address previous_ccms_ref + child_subject_client_involvement_type + sca + autogranted sanitise end @@ -454,6 +464,32 @@ def previous_ccms_ref @line << yesno(laa.applicant.previous_reference.present?) end + def child_subject_client_involvement_type + @line << yesno(proceedings.any? { |proceeding| proceeding.client_involvement_type_ccms_code.eql?("W") }) + end + + def sca + if laa.special_children_act_proceedings? + @line << yesno(laa.biological_parent_relationship?) + @line << yesno(laa.parental_responsibility_agreement_relationship?) + @line << yesno(laa.parental_responsibility_court_order_relationship?) + @line << yesno(laa.child_subject_relationship?) + @line << if laa.parental_responsibility_agreement_relationship? || laa.parental_responsibility_court_order_relationship? + yesno(laa.parental_responsibility_evidence?) + end + else + @line << nil + @line << nil + @line << nil + @line << nil + @line << nil + end + end + + def autogranted + @line << yesno(laa.auto_grant_special_children_act?(nil)) + end + def yesno(value) value == true ? "Yes" : "No" end diff --git a/db/migrate/20241107092712_add_sca_fields_to_application_digest.rb b/db/migrate/20241107092712_add_sca_fields_to_application_digest.rb new file mode 100644 index 0000000000..d8b1d15799 --- /dev/null +++ b/db/migrate/20241107092712_add_sca_fields_to_application_digest.rb @@ -0,0 +1,10 @@ +class AddSCAFieldsToApplicationDigest < ActiveRecord::Migration[7.2] + def change + add_column :application_digests, :biological_parent, :boolean + add_column :application_digests, :parental_responsibility_agreement, :boolean + add_column :application_digests, :parental_responsibility_court_order, :boolean + add_column :application_digests, :child_subject, :boolean + add_column :application_digests, :parental_responsibility_evidence, :boolean + add_column :application_digests, :autogranted, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index b744609869..c4449972d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_10_30_094958) do +ActiveRecord::Schema[7.2].define(version: 2024_11_07_092712) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -183,6 +183,12 @@ t.string "legal_linked_lead_or_associated" t.integer "number_of_legal_linked_applications" t.boolean "no_fixed_address" + t.boolean "biological_parent" + t.boolean "parental_responsibility_agreement" + t.boolean "parental_responsibility_court_order" + t.boolean "child_subject" + t.boolean "parental_responsibility_evidence" + t.boolean "autogranted" t.index ["legal_aid_application_id"], name: "index_application_digests_on_legal_aid_application_id", unique: true end diff --git a/spec/factories/attachments.rb b/spec/factories/attachments.rb index ba591aeb88..6e5b3d8e14 100644 --- a/spec/factories/attachments.rb +++ b/spec/factories/attachments.rb @@ -32,6 +32,12 @@ attachment_name { "bank_transaction_report.csv" } end + trait :parental_responsibility do + attachment_type { "parental_responsibility" } + sequence(:attachment_name) { |n| "parental_responsibility_#{n}" } + sequence(:original_filename) { "original_filename.pdf" } + end + trait :uploaded_evidence_collection do attachment_type { "uncategorised" } attachment_name { "uploaded_evidence_collection" } diff --git a/spec/models/application_digest_spec.rb b/spec/models/application_digest_spec.rb index 02d1edc43c..6826a82447 100644 --- a/spec/models/application_digest_spec.rb +++ b/spec/models/application_digest_spec.rb @@ -522,5 +522,82 @@ end end end + + describe "sca fields" do + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child:) } + + before { laa.proceedings << sca_proceeding } + + context "when the application has a proceeding with relationship_to_child biological" do + let(:relationship_to_child) { "biological" } + + it "returns the expected data" do + application_digest + expect(digest.biological_parent).to be true + expect(digest.parental_responsibility_agreement).to be false + expect(digest.parental_responsibility_court_order).to be false + expect(digest.child_subject).to be false + expect(digest.parental_responsibility_evidence).to be false + end + end + + context "when the application has a proceeding with relationship_to_child parental_responsibility_agreement" do + let(:relationship_to_child) { "parental_responsibility_agreement" } + let(:parental_responsibility_evidence) { create(:attachment, :parental_responsibility, attachment_name: "parental_responsibility") } + + before do + laa.proceedings << sca_proceeding + laa.attachments << parental_responsibility_evidence + end + + it "returns the expected data" do + application_digest + expect(digest.biological_parent).to be false + expect(digest.parental_responsibility_agreement).to be true + expect(digest.parental_responsibility_court_order).to be false + expect(digest.child_subject).to be false + expect(digest.parental_responsibility_evidence).to be true + end + end + + context "when the application has a proceeding with relationship_to_child court_order" do + let(:relationship_to_child) { "court_order" } + + before { laa.proceedings << sca_proceeding } + + it "returns the expected data" do + application_digest + expect(digest.biological_parent).to be false + expect(digest.parental_responsibility_agreement).to be false + expect(digest.parental_responsibility_court_order).to be true + expect(digest.child_subject).to be false + expect(digest.parental_responsibility_evidence).to be false + end + end + + context "when the application has a proceeding with relationship_to_child child_subject" do + let(:relationship_to_child) { "child_subject" } + + before { laa.proceedings << sca_proceeding } + + it "returns the expected data" do + application_digest + expect(digest.biological_parent).to be false + expect(digest.parental_responsibility_agreement).to be false + expect(digest.parental_responsibility_court_order).to be false + expect(digest.child_subject).to be true + expect(digest.parental_responsibility_evidence).to be false + end + end + end + + describe "autogranted" do + context "when the application is not autogranted" do + it "returns autogranted false" do + application_digest + expect(digest.autogranted).to be false + end + end + end end end diff --git a/spec/models/legal_aid_application_spec.rb b/spec/models/legal_aid_application_spec.rb index 3942609ff2..daa54d6ba2 100644 --- a/spec/models/legal_aid_application_spec.rb +++ b/spec/models/legal_aid_application_spec.rb @@ -2194,6 +2194,85 @@ end end + describe "#biological_parent_relationship?" do + subject { legal_aid_application.biological_parent_relationship? } + + context "with a proceeding with a biological_parent relationship" do + before { legal_aid_application.proceedings << sca_proceeding } + + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child: "biological") } + + it { is_expected.to be true } + end + + context "without a proceeding with a biological parent relationship" do + it { is_expected.to be false } + end + end + + describe "#parental_responsibility_court_order_relationship?" do + subject { legal_aid_application.parental_responsibility_court_order_relationship? } + + context "with a proceeding with a parental_responsibility_court_order relationship" do + before { legal_aid_application.proceedings << sca_proceeding } + + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child: "court_order") } + + it { is_expected.to be true } + end + + context "without a proceeding with a parental_responsibility_court_order relationship" do + it { is_expected.to be false } + end + end + + describe "#parental_responsibility_agreement_relationship?" do + subject { legal_aid_application.parental_responsibility_agreement_relationship? } + + context "with a proceeding with a parental_responsibility_agreement relationship" do + before { legal_aid_application.proceedings << sca_proceeding } + + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child: "parental_responsibility_agreement") } + + it { is_expected.to be true } + end + + context "without a proceeding with a parental_responsibility_agreement relationship" do + it { is_expected.to be false } + end + end + + describe "#child_subject_relationship?" do + subject { legal_aid_application.child_subject_relationship? } + + context "with a proceeding with a child_subject relationship" do + before { legal_aid_application.proceedings << sca_proceeding } + + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child: "child_subject") } + + it { is_expected.to be true } + end + + context "without a proceeding with a child_subject relationship" do + it { is_expected.to be false } + end + end + + describe "#parental_responsibility_evidence?" do + subject { legal_aid_application.parental_responsibility_evidence? } + + context "with aan application that has parental responsibility evidence" do + let(:legal_aid_application) { create(:legal_aid_application, attachments: [parental_responsibility_evidence]) } + let(:parental_responsibility_evidence) { create(:attachment, :parental_responsibility, attachment_name: "parental_responsibility") } + + it { is_expected.to be true } + end + + context "without a proceeding with a child_subject relationship" do + it { is_expected.to be false } + end + end + private def uploaded_evidence_output diff --git a/spec/services/reports/mis/application_detail_csv_line_spec.rb b/spec/services/reports/mis/application_detail_csv_line_spec.rb index ebb268f064..5c4223f9ec 100644 --- a/spec/services/reports/mis/application_detail_csv_line_spec.rb +++ b/spec/services/reports/mis/application_detail_csv_line_spec.rb @@ -853,6 +853,111 @@ module MIS end end + describe "child subject client involvement type" do + context "when the provider has selected child subject for any of the application proceedings" do + before { legal_aid_application.proceedings << proceeding } + + let(:proceeding) { create(:proceeding, :pb059, client_involvement_type_ccms_code: "W") } + + it "sets child subject client involement type to Yes" do + expect(value_for("Child subject client involvment type?")).to eq "Yes" + end + end + + context "when the provider has not selected child subject for any of the application proceedings" do + it "sets child subject client involement type to No" do + expect(value_for("Child subject client involvment type?")).to eq "No" + end + end + end + + describe "SCA fields" do + context "when the application has no SCA proceedings" do + it "returns the expected data" do + expect(value_for("Biological parent relationship?")).to be_nil + expect(value_for("Parental responsibility agreement relationship?")).to be_nil + expect(value_for("Parental responsibility court order relationship?")).to be_nil + expect(value_for("Child subject relationship?")).to be_nil + expect(value_for("Parental responsibility evidence?")).to be_nil + end + end + + context "when the application has an sca proceeding" do + let(:sca_proceeding) { create(:proceeding, :pb059, relationship_to_child:) } + + before { legal_aid_application.proceedings << sca_proceeding } + + context "when the application has a proceeding with relationship_to_child biological" do + let(:relationship_to_child) { "biological" } + + it "returns the expected data" do + expect(value_for("Biological parent relationship?")).to eq "Yes" + expect(value_for("Parental responsibility agreement relationship?")).to eq "No" + expect(value_for("Parental responsibility court order relationship?")).to eq "No" + expect(value_for("Child subject relationship?")).to eq "No" + expect(value_for("Parental responsibility evidence?")).to be_nil + end + end + + context "when the application has a proceeding with relatitionship_to_child parental_responsibl;ity_agreement" do + let(:relationship_to_child) { "parental_responsibility_agreement" } + + it "returns the expected data" do + expect(value_for("Biological parent relationship?")).to eq "No" + expect(value_for("Parental responsibility agreement relationship?")).to eq "Yes" + expect(value_for("Parental responsibility court order relationship?")).to eq "No" + expect(value_for("Child subject relationship?")).to eq "No" + expect(value_for("Parental responsibility evidence?")).to eq "No" + end + end + + context "when the application has a proceeding with relationship_to_child court_order" do + let(:relationship_to_child) { "court_order" } + let(:parental_responsibility_evidence) { create(:attachment, :parental_responsibility, attachment_name: "parental_responsibility") } + + before { legal_aid_application.attachments << parental_responsibility_evidence } + + it "returns the expected data" do + expect(value_for("Biological parent relationship?")).to eq "No" + expect(value_for("Parental responsibility agreement relationship?")).to eq "No" + expect(value_for("Parental responsibility court order relationship?")).to eq "Yes" + expect(value_for("Child subject relationship?")).to eq "No" + expect(value_for("Parental responsibility evidence?")).to eq "Yes" + end + end + + context "when the application has a proceeding with relationship_to_child child_subject" do + let(:relationship_to_child) { "child_subject" } + + it "returns the expected data" do + expect(value_for("Biological parent relationship?")).to eq "No" + expect(value_for("Parental responsibility agreement relationship?")).to eq "No" + expect(value_for("Parental responsibility court order relationship?")).to eq "No" + expect(value_for("Child subject relationship?")).to eq "Yes" + expect(value_for("Parental responsibility evidence?")).to be_nil + end + end + end + end + + describe "autogranted" do + context "when the application is autogranted" do + before { allow(legal_aid_application).to receive(:auto_grant_special_children_act?).and_return(true) } + + it "sets autogranted? to Yes" do + expect(value_for("Autogranted?")).to eq "Yes" + end + end + + context "when the application is not autogranted" do + before { allow(legal_aid_application).to receive(:auto_grant_special_children_act?).and_return(false) } + + it "sets autogranted? to No" do + expect(value_for("Autogranted?")).to eq "No" + end + end + end + context "when the applicant age cannot be generated" do let(:legal_aid_application) { create(:legal_aid_application, applicant:) } let(:applicant) do