Browse Source

CLDC-1304: Export fixes

pull/650/head
Stéphane Meny 3 years ago
parent
commit
998ff5bb58
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 4
      app/services/exports/case_log_export_constants.rb
  2. 67
      app/services/exports/case_log_export_service.rb
  3. 4
      spec/fixtures/exports/case_logs.csv
  4. 5
      spec/fixtures/exports/case_logs.xml

4
app/services/exports/case_log_export_constants.rb

@ -36,6 +36,7 @@ module Exports::CaseLogExportConstants
"hbrentshortfall", "hbrentshortfall",
"hcnum", "hcnum",
"hhmemb", "hhmemb",
"hhtype",
"homeless", "homeless",
"housingneeds", "housingneeds",
"illness", "illness",
@ -92,7 +93,7 @@ module Exports::CaseLogExportConstants
"scharge", "scharge",
"scheme", "scheme",
"schtype", "schtype",
"shelteredaccom", "sheltered",
"startdate", "startdate",
"startertenancy", "startertenancy",
"supcharg", "supcharg",
@ -114,6 +115,7 @@ module Exports::CaseLogExportConstants
"unittype_sh", "unittype_sh",
"uploaddate", "uploaddate",
"username", "username",
"vacdays",
"voiddate", "voiddate",
"waityear", "waityear",
"wchair", "wchair",

67
app/services/exports/case_log_export_service.rb

@ -181,15 +181,82 @@ module Exports
attribute_hash["uploaddate"] = attribute_hash["updated_at"] attribute_hash["uploaddate"] = attribute_hash["updated_at"]
attribute_hash["tenancycode"] = attribute_hash["tenant_code"] attribute_hash["tenancycode"] = attribute_hash["tenant_code"]
attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"] attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"]
attribute_hash["sheltered"] = attribute_hash["shelteredaccom"]
# Age refused # Age refused
(1..8).each do |index| (1..8).each do |index|
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["hhtype"] = get_hhtype(case_log)
attribute_hash["new_old"] = get_new_old(case_log)
attribute_hash["vacdays"] = get_vacdays(case_log)
attribute_hash attribute_hash
end end
def get_vacdays(case_log)
return if case_log.startdate.nil?
if case_log.mrcdate.present?
(case_log.startdate - case_log.mrcdate).to_i / 1.day
elsif case_log.voiddate.present?
(case_log.startdate - case_log.voiddate).to_i / 1.day
end
end
def get_new_old(case_log)
if [6, 8, 30, 31, 32, 33].include?(case_log.prevten) || [1, 10].include?(case_log.referral)
2 # Tenant existing in social housing sector
else
1 # Tenant new to social housing sector
end
end
def get_hhtype(case_log)
return if case_log.totelder.nil? || case_log.totadult.nil? || case_log.totchild.nil?
if only_one_elder?(case_log)
1
elsif two_adults_including_elders?(case_log)
2
elsif only_one_adult?(case_log)
3
elsif only_two_adults?(case_log)
4
elsif one_adult_with_at_least_one_child?(case_log)
5
elsif two_adults_with_at_least_one_child?(case_log)
6
else
9
end
end
def two_adults_with_at_least_one_child?(case_log)
case_log.totelder.zero? && case_log.totadult >= 2 && case_log.totchild >= 1
end
def one_adult_with_at_least_one_child?(case_log)
case_log.totelder.zero? && case_log.totadult == 1 && case_log.totchild >= 1
end
def only_two_adults?(case_log)
case_log.totelder.zero? && case_log.totadult == 2 && case_log.totchild.zero?
end
def only_one_adult?(case_log)
case_log.totelder.zero? && case_log.totadult == 1 && case_log.totchild.zero?
end
def two_adults_including_elders?(case_log)
(case_log.totelder + case_log.totadult) == 2 && case_log.totelder >= 1
end
def only_one_elder?(case_log)
case_log.totelder == 1 && case_log.totadult.zero? && case_log.totchild.zero?
end
def filter_keys!(attributes) def filter_keys!(attributes)
attributes.reject! { |attribute| is_omitted_field?(attribute) } attributes.reject! { |attribute| is_omitted_field?(attribute) }
end end

4
spec/fixtures/exports/case_logs.csv vendored

@ -1,2 +1,2 @@
status,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,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,shelteredaccom,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk status,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,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk,sheltered,hhtype,new_old,vacdays
2,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,0,,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,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,{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,BZ737,1 2,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,0,,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,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,{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,BZ737,1,0,4,2,638

1 status 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 has_benefits renewal wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat2 relat3 relat4 relat5 relat6 relat7 relat8 lar irproduct joint shelteredaccom form owningorgid owningorgname hcnum maningorgid maningorgname manhcnum createddate uploaddate tenancycode ppcodenk sheltered hhtype new_old vacdays
2 2 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 0 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 0 100.0 25.0 20.0 17.5 162.5 6.0 0 1 2 P 0 {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 BZ737 1 0 4 2 638

5
spec/fixtures/exports/case_logs.xml vendored

@ -129,7 +129,6 @@
<relat8/> <relat8/>
<lar/> <lar/>
<irproduct/> <irproduct/>
<shelteredaccom>0</shelteredaccom>
<form>{id}</form> <form>{id}</form>
<owningorgid>{owning_org_id}</owningorgid> <owningorgid>{owning_org_id}</owningorgid>
<owningorgname>DLUHC</owningorgname> <owningorgname>DLUHC</owningorgname>
@ -141,6 +140,10 @@
<uploaddate>2022-02-08 16:52:15 UTC</uploaddate> <uploaddate>2022-02-08 16:52:15 UTC</uploaddate>
<tenancycode>BZ737</tenancycode> <tenancycode>BZ737</tenancycode>
<ppcodenk>1</ppcodenk> <ppcodenk>1</ppcodenk>
<sheltered>0</sheltered>
<hhtype>4</hhtype>
<new_old>2</new_old>
<vacdays>638</vacdays>
<providertype>1</providertype> <providertype>1</providertype>
</form> </form>
</forms> </forms>

Loading…
Cancel
Save