diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 08b2fde60..d63d6394c 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -48,8 +48,24 @@ module Validations::SoftValidations end end + def no_females_in_the_household? + (1..8).none? do |n| + public_send("sex#{n}") == "F" + end && preg_occ == 1 + end + + def female_in_pregnant_household_in_soft_validation_range? + (females_in_age_range(11, 15) || females_in_age_range(51, 65)) && !females_in_age_range(16, 50) + end + private + def females_in_age_range(min, max) + (1..8).any? do |n| + public_send("sex#{n}") == "F" && public_send("age#{n}").present? && public_send("age#{n}").between?(min, max) + end + end + def tenant_is_retired?(economic_status) economic_status == 5 end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 5b5954d3f..9b639a426 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -3824,6 +3824,76 @@ } } }, + "no_females_pregnant_household_value_check": { + "depends_on": [{ "no_females_in_the_household?": true }], + "title_text": { + "translation": "soft_validations.pregnancy.title", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "informative_text": { + "translation": "soft_validations.pregnancy.no_females", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "questions": { + "pregnancy_value_check": { + "check_answer_label": "Pregnancy soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "females_in_soft_age_range_in_pregnant_household_value_check": { + "depends_on": [{ "female_in_pregnant_household_in_soft_validation_range?": true }], + "title_text": { + "translation": "soft_validations.pregnancy.title", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "informative_text": { + "translation": "soft_validations.pregnancy.females_not_in_soft_age_range", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "questions": { + "pregnancy_value_check": { + "check_answer_label": "Pregnancy soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "access_needs": { "header": "", "description": "", diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index ef7b49077..1bc7b3da9 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -3876,6 +3876,76 @@ } } }, + "no_females_pregnant_household_value_check": { + "depends_on": [{ "no_females_in_the_household?": true }], + "title_text": { + "translation": "soft_validations.pregnancy.title", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "informative_text": { + "translation": "soft_validations.pregnancy.no_females", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "questions": { + "pregnancy_value_check": { + "check_answer_label": "Pregnancy soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "females_in_soft_age_range_in_pregnant_household_value_check": { + "depends_on": [{ "female_in_pregnant_household_in_soft_validation_range?": true }], + "title_text": { + "translation": "soft_validations.pregnancy.title", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "informative_text": { + "translation": "soft_validations.pregnancy.females_not_in_soft_age_range", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "sex1" + }] + }, + "questions": { + "pregnancy_value_check": { + "check_answer_label": "Pregnancy soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "access_needs": { "header": "", "description": "", diff --git a/config/locales/en.yml b/config/locales/en.yml index 4581ec05f..a0cb371d1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -250,6 +250,10 @@ en: max: title: "You told us this person is %{age} or over and not retired" hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + pregnancy: + title: "You told us somebody in the household is pregnant" + no_females: "You also told us there are no women living at the property." + females_not_in_soft_age_range: "You also told us that any women living at the property are in the following age ranges:" devise: two_factor_authentication: diff --git a/db/migrate/20220523150557_add_pregnancy_value_check.rb b/db/migrate/20220523150557_add_pregnancy_value_check.rb new file mode 100644 index 000000000..37e16ce0a --- /dev/null +++ b/db/migrate/20220523150557_add_pregnancy_value_check.rb @@ -0,0 +1,5 @@ +class AddPregnancyValueCheck < ActiveRecord::Migration[7.0] + def change + add_column :case_logs, :pregnancy_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 2a4f3c6d6..a2b94061b 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.0].define(version: 2022_05_19_112604) do +ActiveRecord::Schema[7.0].define(version: 2022_05_23_150557) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_05_19_112604) do t.integer "tshortfall_known" t.integer "shelteredaccom" t.integer "retirement_value_check" + t.integer "pregnancy_value_check" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 977d49bd0..92f03aadf 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -164,4 +164,35 @@ RSpec.describe Validations::SoftValidations do end end end + + describe "pregnancy soft validations" do + context "when there are no female tenants" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "M", preg_occ: 1) + expect(record.no_females_in_the_household?).to be true + end + end + + context "when female tenants are in 11-16 age range" do + it "shows the interruption screen" do + record.update!(age3: 14, sex3: "F", preg_occ: 1) + expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true + end + end + + context "when female tenants are in 50-65 age range" do + it "shows the interruption screen" do + record.update!(age1: 54, sex1: "F", preg_occ: 1) + expect(record.female_in_pregnant_household_in_soft_validation_range?).to be true + end + end + + context "when female tenants are outside or soft validation ranges" do + it "does not show the interruption screen" do + record.update!(age1: 44, sex1: "F", preg_occ: 1) + expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false + expect(record.female_in_pregnant_household_in_soft_validation_range?).to be false + end + end + end end