59 changed files with 717 additions and 207 deletions
@ -0,0 +1,11 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralDirect < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_direct" |
||||||
|
@depends_on = [{ "referral_type" => 1 }] |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralDirect.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralGeneralNeedsPrp < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_prp" |
||||||
|
@copy_key = "lettings.household_situation.referral.general_needs.prp" |
||||||
|
@depends_on = [{ "owning_organisation_provider_type" => "PRP", "needstype" => 1, "renewal" => 0 }] |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralGeneralNeedsPrp.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,11 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralHsc < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_hsc" |
||||||
|
@depends_on = [{ "referral_type" => 4 }] |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralHsc.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,11 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralJustice < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_justice" |
||||||
|
@depends_on = [{ "referral_type" => 5 }] |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralJustice.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,11 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralLa < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_la" |
||||||
|
@depends_on = [{ "referral_type" => 2 }] |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralLa.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,10 @@ |
|||||||
|
class Form::Lettings::Pages::ReferralType < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "referral_type" |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [Form::Lettings::Questions::ReferralType.new(nil, nil, self)] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,26 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralDirect < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral" |
||||||
|
@copy_key = "lettings.household_situation.referral.direct" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
{ |
||||||
|
"20" => { |
||||||
|
"value" => "Homeless households owed a duty and not on a housing register or waiting list", |
||||||
|
}, |
||||||
|
"2" => { |
||||||
|
"value" => "Tenant applied directly for an available property", |
||||||
|
}, |
||||||
|
"8" => { |
||||||
|
"value" => "Relocated through official housing mobility scheme", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze |
||||||
|
end |
@ -1,4 +1,4 @@ |
|||||||
class Form::Lettings::Questions::Referral < ::Form::Question |
class Form::Lettings::Questions::ReferralGeneralNeeds < ::Form::Question |
||||||
def initialize(id, hsh, page) |
def initialize(id, hsh, page) |
||||||
super |
super |
||||||
@id = "referral" |
@id = "referral" |
@ -0,0 +1,105 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralGeneralNeedsPrp < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral" |
||||||
|
@copy_key = "lettings.household_situation.referral.general_needs.prp" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
if form.start_year_2024_or_later? |
||||||
|
{ |
||||||
|
"1" => { |
||||||
|
"value" => "Internal transfer", |
||||||
|
"hint" => "Where the tenant has moved to another social property owned by the same landlord.", |
||||||
|
}, |
||||||
|
"2" => { |
||||||
|
"value" => "Tenant applied directly (no referral or nomination)", |
||||||
|
}, |
||||||
|
"3" => { |
||||||
|
"value" => "Nominated by a local housing authority", |
||||||
|
}, |
||||||
|
"8" => { |
||||||
|
"value" => "Re-located through official housing mobility scheme", |
||||||
|
}, |
||||||
|
"10" => { |
||||||
|
"value" => "Other social landlord", |
||||||
|
}, |
||||||
|
"9" => { |
||||||
|
"value" => "Community learning disability team", |
||||||
|
}, |
||||||
|
"14" => { |
||||||
|
"value" => "Community mental health team", |
||||||
|
}, |
||||||
|
"15" => { |
||||||
|
"value" => "Health service", |
||||||
|
}, |
||||||
|
"18" => { |
||||||
|
"value" => "Police, probation, prison or youth offending team – tenant had custodial sentence", |
||||||
|
}, |
||||||
|
"19" => { |
||||||
|
"value" => "Police, probation, prison or youth offending team – no custodial sentence", |
||||||
|
}, |
||||||
|
"7" => { |
||||||
|
"value" => "Voluntary agency", |
||||||
|
}, |
||||||
|
"17" => { |
||||||
|
"value" => "Children’s Social Care", |
||||||
|
}, |
||||||
|
"16" => { |
||||||
|
"value" => "Other", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
else |
||||||
|
{ |
||||||
|
"1" => { |
||||||
|
"value" => "Internal transfer", |
||||||
|
"hint" => "Where the tenant has moved to another social property owned by the same landlord.", |
||||||
|
}, |
||||||
|
"2" => { |
||||||
|
"value" => "Tenant applied directly (no referral or nomination)", |
||||||
|
}, |
||||||
|
"3" => { |
||||||
|
"value" => "Nominated by a local housing authority", |
||||||
|
}, |
||||||
|
"4" => { |
||||||
|
"value" => "Referred by local authority housing department", |
||||||
|
}, |
||||||
|
"8" => { |
||||||
|
"value" => "Re-located through official housing mobility scheme", |
||||||
|
}, |
||||||
|
"10" => { |
||||||
|
"value" => "Other social landlord", |
||||||
|
}, |
||||||
|
"9" => { |
||||||
|
"value" => "Community learning disability team", |
||||||
|
}, |
||||||
|
"14" => { |
||||||
|
"value" => "Community mental health team", |
||||||
|
}, |
||||||
|
"15" => { |
||||||
|
"value" => "Health service", |
||||||
|
}, |
||||||
|
"12" => { |
||||||
|
"value" => "Police, probation or prison", |
||||||
|
}, |
||||||
|
"7" => { |
||||||
|
"value" => "Voluntary agency", |
||||||
|
}, |
||||||
|
"13" => { |
||||||
|
"value" => "Youth offending team", |
||||||
|
}, |
||||||
|
"17" => { |
||||||
|
"value" => "Children’s Social Care", |
||||||
|
}, |
||||||
|
"16" => { |
||||||
|
"value" => "Other", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2023 => 85, 2024 => 84 }.freeze |
||||||
|
end |
@ -0,0 +1,32 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralHsc < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral" |
||||||
|
@copy_key = "lettings.household_situation.referral.hsc" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
{ |
||||||
|
"15" => { |
||||||
|
"value" => "Health service", |
||||||
|
}, |
||||||
|
"9" => { |
||||||
|
"value" => "Community learning disability team", |
||||||
|
}, |
||||||
|
"14" => { |
||||||
|
"value" => "Community mental health team", |
||||||
|
}, |
||||||
|
"24" => { |
||||||
|
"value" => "Adult social services", |
||||||
|
}, |
||||||
|
"17" => { |
||||||
|
"value" => "Children's social care", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze |
||||||
|
end |
@ -0,0 +1,23 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralJustice < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral" |
||||||
|
@copy_key = "lettings.household_situation.referral.justice" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
{ |
||||||
|
"18" => { |
||||||
|
"value" => "With a custodial sentence", |
||||||
|
}, |
||||||
|
"19" => { |
||||||
|
"value" => "No custodial sentence", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze |
||||||
|
end |
@ -0,0 +1,29 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralLa < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral" |
||||||
|
@copy_key = "lettings.household_situation.referral.la" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
{ |
||||||
|
"21" => { |
||||||
|
"value" => "Local authority lettings", |
||||||
|
}, |
||||||
|
"3" => { |
||||||
|
"value" => "PRP lettings nominated by a local authority", |
||||||
|
}, |
||||||
|
"4" => { |
||||||
|
"value" => "PRP support lettings referred by a local authority", |
||||||
|
}, |
||||||
|
"22" => { |
||||||
|
"value" => "Other", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze |
||||||
|
end |
@ -0,0 +1,38 @@ |
|||||||
|
class Form::Lettings::Questions::ReferralType < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "referral_type" |
||||||
|
@copy_key = "lettings.household_situation.referral.type" |
||||||
|
@type = "radio" |
||||||
|
@check_answers_card_number = 0 |
||||||
|
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] |
||||||
|
end |
||||||
|
|
||||||
|
def answer_options |
||||||
|
{ |
||||||
|
"1" => { |
||||||
|
"value" => "Direct", |
||||||
|
}, |
||||||
|
"2" => { |
||||||
|
"value" => "From a local authority housing register or waiting list", |
||||||
|
}, |
||||||
|
"3" => { |
||||||
|
"value" => "From a PRP-only housing register or waiting list (no local authority involvement)", |
||||||
|
}, |
||||||
|
"4" => { |
||||||
|
"value" => "Health and social care services", |
||||||
|
}, |
||||||
|
"5" => { |
||||||
|
"value" => "Police, probation, prison or youth offending team", |
||||||
|
}, |
||||||
|
"6" => { |
||||||
|
"value" => "Voluntary agency", |
||||||
|
}, |
||||||
|
"7" => { |
||||||
|
"value" => "Other", |
||||||
|
}, |
||||||
|
}.freeze |
||||||
|
end |
||||||
|
|
||||||
|
QUESTION_NUMBER_FROM_YEAR = { 2025 => 84 }.freeze |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
class AddReferralTypeToLettingsLogs < ActiveRecord::Migration[7.2] |
||||||
|
def change |
||||||
|
add_column :lettings_logs, :referral_type, :integer |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,12 @@ |
|||||||
|
desc "Bulk update logs with invalid rp_dontknow values" |
||||||
|
task recalculate_invalid_rpdontknow: :environment do |
||||||
|
validation_trigger_condition = "rp_dontknow = 1 AND (rp_homeless = 1 OR rp_insan_unsat = 1 OR rp_medwel = 1 OR rp_hardship = 1)" |
||||||
|
|
||||||
|
LettingsLog.filter_by_year(2024).where(validation_trigger_condition).find_each do |log| |
||||||
|
log.rp_dontknow = 0 |
||||||
|
|
||||||
|
unless log.save |
||||||
|
Rails.logger.info "Could not save changes to lettings log #{log.id}" |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,70 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "recalculate_invalid_reasonpref_dontknow" do |
||||||
|
subject(:task) { Rake::Task["recalculate_invalid_rpdontknow"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/recalculate_invalid_reasonpref_dontknow") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
end |
||||||
|
|
||||||
|
let(:invalid_logs) { create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0)) } |
||||||
|
let(:pre_2024_invalid_logs) do |
||||||
|
create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2)).each do |log| |
||||||
|
log.startdate = Time.zone.local(rand(2021..2023), 4, 1) |
||||||
|
log.save!(validate: false) |
||||||
|
end |
||||||
|
end |
||||||
|
let(:valid_logs) { create_list(:lettings_log, 3, :completed, reasonpref: 1, rp_dontknow: 0, rp_homeless: 1, rp_insan_unsat: 1, rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0)) } |
||||||
|
|
||||||
|
it "updates the logs from 2024/25 with invalid rp_dontknow values" do |
||||||
|
invalid_logs.each do |log| |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(1) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
end |
||||||
|
task.invoke |
||||||
|
invalid_logs.each do |log| |
||||||
|
log.reload |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(0) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
expect(log.updated_at).not_to eq(Time.zone.local(2024, 4, 2, 12, 0, 0)) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs pre 2024 with invalid rp_dontknow values" do |
||||||
|
pre_2024_invalid_logs.each do |log| |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(1) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
end |
||||||
|
task.invoke |
||||||
|
pre_2024_invalid_logs.each do |log| |
||||||
|
log.reload |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(1) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the logs with valid rp_dontknow values" do |
||||||
|
valid_logs.each do |log| |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(0) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
expect(log.rp_insan_unsat).to eq(1) |
||||||
|
end |
||||||
|
task.invoke |
||||||
|
valid_logs.each do |log| |
||||||
|
log.reload |
||||||
|
expect(log.reasonpref).to eq(1) |
||||||
|
expect(log.rp_dontknow).to eq(0) |
||||||
|
expect(log.rp_homeless).to eq(1) |
||||||
|
expect(log.rp_insan_unsat).to eq(1) |
||||||
|
expect(log.updated_at).to eq(Time.zone.local(2024, 4, 2, 12, 0, 0)) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -1,6 +1,6 @@ |
|||||||
require "rails_helper" |
require "rails_helper" |
||||||
|
|
||||||
RSpec.describe Form::Lettings::Questions::ReferralPrp, type: :model do |
RSpec.describe Form::Lettings::Questions::ReferralGeneralNeedsPrp, type: :model do |
||||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||||
|
|
||||||
let(:question_id) { nil } |
let(:question_id) { nil } |
@ -1,6 +1,6 @@ |
|||||||
require "rails_helper" |
require "rails_helper" |
||||||
|
|
||||||
RSpec.describe Form::Lettings::Questions::Referral, type: :model do |
RSpec.describe Form::Lettings::Questions::ReferralGeneralNeeds, type: :model do |
||||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||||
|
|
||||||
let(:question_id) { nil } |
let(:question_id) { nil } |
Loading…
Reference in new issue