Browse Source

update unittype mapping when infering the case log value (#735)

* remove unittype_sh column, use a method to access the value instead

* remove inferring builtype

* remove return
pull/738/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
ecf222335a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/case_log.rb
  2. 10
      app/models/derived_variables/case_log_variables.rb
  3. 2
      app/services/exports/case_log_export_service.rb
  4. 5
      db/migrate/20220712143943_remove_unittype_sh.rb
  5. 3
      db/schema.rb
  6. 4
      spec/fixtures/exports/case_logs.csv
  7. 2
      spec/fixtures/exports/case_logs.xml
  8. 10
      spec/models/case_log_spec.rb

4
app/models/case_log.rb

@ -460,6 +460,10 @@ class CaseLog < ApplicationRecord
public_send("age#{person_num}_known") == 1 public_send("age#{person_num}_known") == 1
end end
def unittype_sh
location.type_of_unit_before_type_cast if location
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new

10
app/models/derived_variables/case_log_variables.rb

@ -1,13 +1,5 @@
module DerivedVariables::CaseLogVariables module DerivedVariables::CaseLogVariables
RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze
TYPE_OF_UNIT_MAP = {
"Self-contained flat or bedsit" => 1,
"Self-contained flat or bedsit with common facilities" => 2,
"Shared flat" => 3,
"Shared house or hostel" => 4,
"Bungalow" => 5,
"Self-contained house" => 6,
}.freeze
def supported_housing_schemes_enabled? def supported_housing_schemes_enabled?
FeatureToggle.supported_housing_schemes_enabled? FeatureToggle.supported_housing_schemes_enabled?
@ -83,8 +75,6 @@ module DerivedVariables::CaseLogVariables
if location if location
self.la = location.county self.la = location.county
self.postcode_full = location.postcode self.postcode_full = location.postcode
self.unittype_sh = TYPE_OF_UNIT_MAP[location.type_of_unit]
self.builtype = form.questions.find { |x| x.id == "builtype" }.answer_options.find { |_key, value| value["value"] == location.type_of_building }.first
wheelchair_adaptation_map = { 1 => 1, 0 => 2 } wheelchair_adaptation_map = { 1 => 1, 0 => 2 }
self.wchair = wheelchair_adaptation_map[location.wheelchair_adaptation.to_i] self.wchair = wheelchair_adaptation_map[location.wheelchair_adaptation.to_i]
end end

2
app/services/exports/case_log_export_service.rb

@ -189,6 +189,8 @@ module Exports
attribute_hash["age#{index}"] = -9 if attribute_hash["age#{index}_known"] == 1 attribute_hash["age#{index}"] = -9 if attribute_hash["age#{index}_known"] == 1
end end
attribute_hash["unittype_sh"] = case_log.unittype_sh
attribute_hash attribute_hash
end end

5
db/migrate/20220712143943_remove_unittype_sh.rb

@ -0,0 +1,5 @@
class RemoveUnittypeSh < ActiveRecord::Migration[7.0]
def change
remove_column :case_logs, :unittype_sh, :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. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_07_11_152629) do ActiveRecord::Schema[7.0].define(version: 2022_07_12_143943) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -200,7 +200,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_11_152629) do
t.integer "vacdays" t.integer "vacdays"
t.bigint "scheme_id" t.bigint "scheme_id"
t.bigint "location_id" t.bigint "location_id"
t.integer "unittype_sh"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["location_id"], name: "index_case_logs_on_location_id" t.index ["location_id"], name: "index_case_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"

4
spec/fixtures/exports/case_logs.csv vendored

@ -1,2 +1,2 @@
status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,unittype_sh,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,unittype_sh
2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,4,2,638,,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC 2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC,

1 status tenancycode age1 sex1 ethnic national prevten ecstat1 hhmemb age2 sex2 ecstat2 age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap leftreg reservist illness preg_occ startertenancy tenancylength tenancy ppostcode_full rsnvac unittype_gn beds offered wchair earnings incfreq benefits period layear waityear postcode_full reasonpref cbl chr cap reasonother housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h illness_type_1 illness_type_2 illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother irproduct_other reason propcode la prevloc hb hbrentshortfall mrcdate incref startdate armedforces unitletas builtype voiddate renttype needstype lettype totchild totelder totadult nocharge referral brent scharge pscharge supcharg tcharge tshortfall chcharge ppcodenk has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 lar irproduct joint sheltered hhtype new_old vacdays form owningorgid owningorgname hcnum maningorgid maningorgname manhcnum createddate uploaddate unittype_sh
2 2 BZ737 35 F 2 4 6 0 2 32 M 6 1 0 1 0 1 2 0 5 1 SE26RT 6 7 3 2 1 68 1 1 2 2 1 NW15TY 1 1 1 2 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 4 123 E09000003 E07000105 6 1 2020-05-05 10:36:49 UTC 0 2022-02-02 10:36:49 UTC 1 2 1 2019-11-03 00:00:00 UTC 2 1 7 0 0 2 0 200.0 50.0 40.0 35.0 325.0 12.0 1 1 0 100.0 25.0 20.0 17.5 162.5 6.0 0 1 2 P 0 4 2 638 {id} {owning_org_id} DLUHC 1234 {managing_org_id} DLUHC 1234 2022-02-08 16:52:15 UTC 2022-02-08 16:52:15 UTC

2
spec/fixtures/exports/case_logs.xml vendored

@ -135,7 +135,6 @@
<hhtype>4</hhtype> <hhtype>4</hhtype>
<new_old>2</new_old> <new_old>2</new_old>
<vacdays>638</vacdays> <vacdays>638</vacdays>
<unittype_sh/>
<form>{id}</form> <form>{id}</form>
<owningorgid>{owning_org_id}</owningorgid> <owningorgid>{owning_org_id}</owningorgid>
<owningorgname>DLUHC</owningorgname> <owningorgname>DLUHC</owningorgname>
@ -145,6 +144,7 @@
<manhcnum>1234</manhcnum> <manhcnum>1234</manhcnum>
<createddate>2022-02-08 16:52:15 UTC</createddate> <createddate>2022-02-08 16:52:15 UTC</createddate>
<uploaddate>2022-02-08 16:52:15 UTC</uploaddate> <uploaddate>2022-02-08 16:52:15 UTC</uploaddate>
<unittype_sh/>
<providertype>1</providertype> <providertype>1</providertype>
</form> </form>
</forms> </forms>

10
spec/models/case_log_spec.rb

@ -1726,14 +1726,8 @@ RSpec.describe CaseLog do
expect(record_from_db["postcode_full"]).to eq(location.postcode) expect(record_from_db["postcode_full"]).to eq(location.postcode)
end end
it "correctly infers and saves type of unit" do it "unittype_sh method returns the type_of_unit of the location" do
record_from_db = ActiveRecord::Base.connection.execute("SELECT unittype_sh from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0] expect(supported_housing_case_log.unittype_sh).to eq(1)
expect(record_from_db["unittype_sh"]).to eq(1)
end
it "correctly infers and saves type of building" do
record_from_db = ActiveRecord::Base.connection.execute("SELECT builtype from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0]
expect(record_from_db["builtype"]).to eq(1)
end end
it "correctly infers and saves wchair" do it "correctly infers and saves wchair" do

Loading…
Cancel
Save