Browse Source

Add soft validations for pregnancy

pull/602/head
Kat 3 years ago
parent
commit
dd6efe0b80
  1. 16
      app/models/validations/soft_validations.rb
  2. 70
      config/forms/2021_2022.json
  3. 70
      config/forms/2022_2023.json
  4. 4
      config/locales/en.yml
  5. 5
      db/migrate/20220523150557_add_pregnancy_value_check.rb
  6. 3
      db/schema.rb
  7. 31
      spec/models/validations/soft_validations_spec.rb

16
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

70
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": "",

70
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": "",

4
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:<ul><li>11 to 16</li><li>50 to 65</li></ul>"
devise:
two_factor_authentication:

5
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

3
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

31
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

Loading…
Cancel
Save