Browse Source

April 13 changes

pull/470/head
Stéphane Meny 3 years ago
parent
commit
a86b036941
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 2
      app/models/bulk_upload.rb
  2. 140
      app/services/imports/case_logs_import_service.rb
  3. 2
      config/forms/2021_2022.json
  4. 3
      db/migrate/20220411092231_update_case_logs_fields.rb
  5. 3
      db/schema.rb
  6. 2
      spec/factories/case_log.rb
  7. 2
      spec/features/form/check_answers_page_spec.rb

2
app/models/bulk_upload.rb

@ -124,7 +124,7 @@ class BulkUpload
# ppostc2: row[64], # ppostc2: row[64],
# prevpco_unknown: row[65], # prevpco_unknown: row[65],
layear: row[66], layear: row[66],
lawaitlist: row[67], waityear: row[67],
homeless: row[68], homeless: row[68],
reasonpref: row[69], reasonpref: row[69],
rp_homeless: row[70], rp_homeless: row[70],

140
app/services/imports/case_logs_import_service.rb

@ -39,38 +39,82 @@ module Imports
other_intermediate_rent_product: 5, other_intermediate_rent_product: 5,
}.freeze }.freeze
# Order matters since we derive from previous values (uses attributes)
def create_log(xml_doc) def create_log(xml_doc)
attributes = {} attributes = {}
# Required fields for status complete or logic to work # Required fields for status complete or logic to work
# Note: order matters when we derive from previous values (attributes parameter)
attributes["startdate"] = start_date(xml_doc) attributes["startdate"] = start_date(xml_doc)
attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID") attributes["owning_organisation_id"] = find_organisation_id(xml_doc, "OWNINGORGID")
attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID") attributes["managing_organisation_id"] = find_organisation_id(xml_doc, "MANINGORGID")
attributes["previous_postcode_known"] = previous_postcode_known(xml_doc) attributes["previous_postcode_known"] = previous_postcode_known(xml_doc)
attributes["ppostcode_full"] = previous_postcode(xml_doc, attributes) attributes["ppostcode_full"] = previous_postcode(xml_doc, attributes["previous_postcode_known"])
attributes["needstype"] = needs_type(xml_doc) attributes["needstype"] = needs_type(xml_doc)
attributes["lar"] = london_affordable_rent(xml_doc) attributes["lar"] = london_affordable_rent(xml_doc)
attributes["irproduct"] = unsafe_string_as_integer(xml_doc, "IRPRODUCT") attributes["irproduct"] = unsafe_string_as_integer(xml_doc, "IRPRODUCT")
attributes["irproduct_other"] = field_value(xml_doc, "xmlns", "IRPRODUCTOTHER") attributes["irproduct_other"] = field_value(xml_doc, "xmlns", "IRPRODUCTOTHER")
attributes["rent_type"] = rent_type(xml_doc, attributes) attributes["rent_type"] = rent_type(xml_doc, attributes["lar"], attributes["irproduct"])
attributes["rsnvac"] = unsafe_string_as_integer(xml_doc, "Q27") attributes["rsnvac"] = unsafe_string_as_integer(xml_doc, "Q27")
attributes["renewal"] = renewal(attributes) attributes["renewal"] = renewal(attributes["rsnvac"])
attributes["hhmemb"] = safe_string_as_integer(xml_doc, "HHMEMB")
(1..8).each do |index| (1..8).each do |index|
attributes["age#{index}"] = age(xml_doc, index) attributes["age#{index}"] = safe_string_as_integer(xml_doc, "P#{index}Age")
attributes["age#{index}_known"] = age_known(xml_doc, index, attributes["hhmemb"])
attributes["sex#{index}"] = sex(xml_doc, index) attributes["sex#{index}"] = sex(xml_doc, index)
attributes["ecstat#{index}"] = unsafe_string_as_integer(xml_doc, "P#{index}Eco") attributes["ecstat#{index}"] = unsafe_string_as_integer(xml_doc, "P#{index}Eco")
end end
# attributes["hhmemb"] = attributes["ethnic"] = unsafe_string_as_integer(xml_doc, "P1Eth")
attributes["ethnic_group"] = ethnic_group(attributes["ethnic"])
attributes["national"] = unsafe_string_as_integer(xml_doc, "P1Nat")
attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a")
attributes["armedforces"] = unsafe_string_as_integer(xml_doc, "ArmedF")
attributes["preg_occ"] = unsafe_string_as_integer(xml_doc, "Preg")
%w[a b c f g h].each do |letter|
attributes["housingneeds_#{letter}"] = housing_needs(xml_doc, letter)
end
attributes["hb"] = unsafe_string_as_integer(xml_doc, "Q6Ben")
attributes["benefits"] = unsafe_string_as_integer(xml_doc, "Q7Ben")
attributes["underoccupation_benefitcap"] = unsafe_string_as_integer(xml_doc, "_9b")
attributes["illness"] = unsafe_string_as_integer(xml_doc, "Q10ia")
attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c")
attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d")
attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13")
# Note recheck boolean values for 0 instead of nil
attributes["reasonpref"] = unsafe_string_as_integer(xml_doc, "Q14a")
attributes["rp_homeless"] = unsafe_string_as_integer(xml_doc, "Q14b1")
attributes["rp_insan_unsat"] = unsafe_string_as_integer(xml_doc, "Q14b2")
attributes["rp_medwel"] = unsafe_string_as_integer(xml_doc, "Q14b3")
attributes["rp_hardship"] = unsafe_string_as_integer(xml_doc, "Q14b4")
attributes["rp_dontknow"] = unsafe_string_as_integer(xml_doc, "Q14b5")
attributes["cbl"] = unsafe_string_as_integer(xml_doc, "Q15CBL")
attributes["chr"] = unsafe_string_as_integer(xml_doc, "Q15CHR")
attributes["cap"] = unsafe_string_as_integer(xml_doc, "Q15CAP")
attributes["period"] = unsafe_string_as_integer(xml_doc, "Q17")
attributes["beds"] = safe_string_as_integer(xml_doc, "Q22")
attributes["unittype_gn"] = unsafe_string_as_integer(xml_doc, "Q23")
attributes["builtype"] = unsafe_string_as_integer(xml_doc, "Q24")
attributes["wchair"] = unsafe_string_as_integer(xml_doc, "Q25")
attributes["net_income_known"] = ""
# Not specific to our form but required for CDS and can't be inferred # Not specific to our form but required for CDS and can't be inferred
# attributes["form"] = Integer(field_value(xml_doc, "xmlns", "FORM")) attributes["old_form_id"] = Integer(field_value(xml_doc, "xmlns", "FORM"))
# attributes["lettype"] = let_type(xml_doc, attributes)
case_log = CaseLog.new(attributes) # Required for us
case_log.save! attributes["previous_la_known"] = 1 # Defaulting to Yes (Required)
attributes["la_known"] = 1 # Defaulting to Yes (Required)
# pp attributes # Derived and compared
attributes["earnings"] = ""
pp attributes
# case_log = CaseLog.new(attributes)
# case_log.save!
# pp case_log.status # pp case_log.status
# pp case_log.send(:mandatory_fields) # pp case_log.send(:mandatory_fields)
end end
@ -100,27 +144,29 @@ module Imports
end end
end end
# This does not match renttype (CDS) which is derived by case logs logic # This does not match renttype (CDS) which is derived by case log logic
def rent_type(xml_doc, attributes) def rent_type(xml_doc, lar, irproduct)
sr_ar_ir = get_form_name_component(xml_doc, -2) sr_ar_ir = get_form_name_component(xml_doc, -2)
case sr_ar_ir case sr_ar_ir
when "SR" when "SR"
RENT_TYPE[:social_rent] RENT_TYPE[:social_rent]
when "AR" when "AR"
if attributes["lar"] == 1 if lar == 1
RENT_TYPE[:london_affordable_rent] RENT_TYPE[:london_affordable_rent]
else else
RENT_TYPE[:affordable_rent] RENT_TYPE[:affordable_rent]
end end
when "IR" when "IR"
if attributes["irproduct"] == IRPRODUCT[:rent_to_buy] if irproduct == IRPRODUCT[:rent_to_buy]
RENT_TYPE[:rent_to_buy] RENT_TYPE[:rent_to_buy]
elsif attributes["irproduct"] == IRPRODUCT[:london_living_rent] elsif irproduct == IRPRODUCT[:london_living_rent]
RENT_TYPE[:london_living_rent] RENT_TYPE[:london_living_rent]
elsif attributes["irproduct"] == IRPRODUCT[:other_intermediate_rent_product] elsif irproduct == IRPRODUCT[:other_intermediate_rent_product]
RENT_TYPE[:other_intermediate_rent_product] RENT_TYPE[:other_intermediate_rent_product]
end end
else
raise "Could not infer rent type with '#{sr_ar_ir}'"
end end
end end
@ -202,10 +248,6 @@ module Imports
organisation.id organisation.id
end end
def age(xml_doc, index)
Integer(field_value(xml_doc, "xmlns", "P#{index}Age"), exception: false)
end
def sex(xml_doc, index) def sex(xml_doc, index)
sex = field_value(xml_doc, "xmlns", "P#{index}Sex") sex = field_value(xml_doc, "xmlns", "P#{index}Sex")
case sex case sex
@ -217,6 +259,19 @@ module Imports
"X" "X"
when "Refused" when "Refused"
"R" "R"
else
nil
end
end
def age_known(xml_doc, index, hhmemb)
return nil if index > hhmemb
age_refused = field_value(xml_doc, "xmlns", "P#{index}AR")
if age_refused == "AGE_REFUSED"
1 # No
else
0 # Yes
end end
end end
@ -229,8 +284,7 @@ module Imports
end end
end end
def previous_postcode(xml_doc, attributes) def previous_postcode(xml_doc, previous_postcode_known)
previous_postcode_known = attributes["previous_postcode_known"]
if previous_postcode_known.zero? if previous_postcode_known.zero?
nil nil
else else
@ -250,9 +304,9 @@ module Imports
end end
end end
def renewal(attributes) def renewal(rsnvac)
# Relet – renewal of fixed-term tenancy # Relet – renewal of fixed-term tenancy
if attributes["rsnvac"] == 14 if rsnvac == 14
1 1
else else
0 0
@ -274,5 +328,41 @@ module Imports
str.to_i str.to_i
end end
end end
def ethnic_group(ethnic)
case ethnic
when 1,2,3,18
# White
0
when 4,5,6,7
# Mixed
1
when 8,9,10,11,15
# Asian
2
when 12,13,14
# Black
3
when 16,19
# Others
4
when 17
# Refused
5
else
nil
end
end
# Letters should be lowercase to match case
def housing_needs(xml_doc, letter)
housing_need = field_value(xml_doc, "xmlns", "Q10-#{letter}")
if housing_need == "Yes"
1
else
0
end
end
end end
end end

2
config/forms/2021_2022.json

@ -3279,7 +3279,7 @@
"header": "", "header": "",
"description": "", "description": "",
"questions": { "questions": {
"lawaitlist": { "waityear": {
"check_answer_label": "Length of time on local authority waiting list", "check_answer_label": "Length of time on local authority waiting list",
"header": "How long has the household been on the local authority waiting list for the new letting?", "header": "How long has the household been on the local authority waiting list for the new letting?",
"hint_text": "", "hint_text": "",

3
db/migrate/20220411092231_update_case_logs_fields.rb

@ -2,9 +2,10 @@ class UpdateCaseLogsFields < ActiveRecord::Migration[7.0]
def change def change
change_table :case_logs, bulk: true do |t| change_table :case_logs, bulk: true do |t|
t.integer :old_form_id, :lar, :irproduct t.integer :old_form_id, :lar, :irproduct
t.remove :day, :month, :year, :other_hhmemb, type: :integer t.remove :day, :month, :year, :other_hhmemb, :accessibility_requirements_prefer_not_to_say, type: :integer
t.remove :ppostc1, :ppostc2, type: :string t.remove :ppostc1, :ppostc2, type: :string
t.rename :intermediate_rent_product_name, :irproduct_other t.rename :intermediate_rent_product_name, :irproduct_other
t.rename :lawaitlist, :waityear
end end
end end
end end

3
db/schema.rb

@ -98,7 +98,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_11_092231) do
t.integer "benefits" t.integer "benefits"
t.integer "period" t.integer "period"
t.integer "layear" t.integer "layear"
t.integer "lawaitlist" t.integer "waityear"
t.string "postcode_full" t.string "postcode_full"
t.integer "reasonpref" t.integer "reasonpref"
t.integer "cbl" t.integer "cbl"
@ -111,7 +111,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_11_092231) do
t.integer "housingneeds_f" t.integer "housingneeds_f"
t.integer "housingneeds_g" t.integer "housingneeds_g"
t.integer "housingneeds_h" t.integer "housingneeds_h"
t.integer "accessibility_requirements_prefer_not_to_say"
t.integer "illness_type_1" t.integer "illness_type_1"
t.integer "illness_type_2" t.integer "illness_type_2"
t.integer "illness_type_3" t.integer "illness_type_3"

2
spec/factories/case_log.rb

@ -77,7 +77,7 @@ FactoryBot.define do
supcharg { 35 } supcharg { 35 }
tcharge { 325 } tcharge { 325 }
layear { 2 } layear { 2 }
lawaitlist { 1 } waityear { 1 }
postcode_full { "NW1 5TY" } postcode_full { "NW1 5TY" }
reasonpref { 1 } reasonpref { 1 }
cbl { 1 } cbl { 1 }

2
spec/features/form/check_answers_page_spec.rb

@ -197,7 +197,7 @@ RSpec.describe "Form Check Answers Page" do
tenant_code: nil, tenant_code: nil,
age1: nil, age1: nil,
layear: 2, layear: 2,
lawaitlist: 1, waityear: 1,
postcode_full: "NW1 5TY", postcode_full: "NW1 5TY",
reason: 4, reason: 4,
ppostcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT",

Loading…
Cancel
Save