Skip to content

Commit

Permalink
Merge pull request #7405 from ministryofjustice/ap-5338-add-sca-info-…
Browse files Browse the repository at this point in the history
…to-digest

ap-5338: add sca fields to application details report
  • Loading branch information
kmahern authored Nov 13, 2024
2 parents 1962e5f + 6890b6b commit f998a0b
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/models/application_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions app/models/legal_aid_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
36 changes: 36 additions & 0 deletions app/services/reports/mis/application_detail_csv_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -209,6 +216,9 @@ def call
linked_applications
home_address
previous_ccms_ref
child_subject_client_involvement_type
sca
autogranted
sanitise
end

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20241107092712_add_sca_fields_to_application_digest.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 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.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"
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions spec/factories/attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
77 changes: 77 additions & 0 deletions spec/models/application_digest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
79 changes: 79 additions & 0 deletions spec/models/legal_aid_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f998a0b

Please sign in to comment.