Browse Source

CLDC-4141: simplify export year filtering

pull/3156/head
Nat Dean-Lewis 2 weeks ago
parent
commit
34ba227c5a
  1. 105
      app/services/exports/lettings_log_export_constants.rb
  2. 30
      app/services/exports/lettings_log_export_service.rb

105
app/services/exports/lettings_log_export_constants.rb

@ -7,19 +7,17 @@ module Exports::LettingsLogExportConstants
csv: 2, csv: 2,
}.freeze }.freeze
EXPORT_FIELDS = Set[ ALL_YEAR_EXPORT_FIELDS = Set[
"armedforces", "armedforces",
"beds", "beds",
"benefits", "benefits",
"brent", "brent",
"builtype",
"cap", "cap",
"cbl", "cbl",
"chcharge",
"chr", "chr",
"cligrp1", "cligrp1",
"cligrp2", "cligrp2",
"createddate", # New metadata coming from our system "createddate",
"creation_method", "creation_method",
"confidential", "confidential",
"discarded_at", "discarded_at",
@ -53,12 +51,10 @@ module Exports::LettingsLogExportConstants
"mantype", "mantype",
"mobstand", "mobstand",
"mrcdate", "mrcdate",
"national",
"needstype", "needstype",
"new_old", "new_old",
"newprop", "newprop",
"nocharge", "nocharge",
"offered",
"owningorgid", "owningorgid",
"owningorgname", "owningorgname",
"period", "period",
@ -102,7 +98,7 @@ module Exports::LettingsLogExportConstants
"startertenancy", "startertenancy",
"supcharg", "supcharg",
"support", "support",
"status", # New metadata coming from our system "status",
"tcharge", "tcharge",
"tshortfall", "tshortfall",
"tenancy", "tenancy",
@ -138,6 +134,49 @@ module Exports::LettingsLogExportConstants
"location_status", "location_status",
"amended_by", "amended_by",
"duplicate_set_id", "duplicate_set_id",
"assigned_to",
"created_by",
]
(1..8).each do |index|
ALL_YEAR_EXPORT_FIELDS << "age#{index}"
ALL_YEAR_EXPORT_FIELDS << "ecstat#{index}"
ALL_YEAR_EXPORT_FIELDS << "sex#{index}"
end
(2..8).each do |index|
ALL_YEAR_EXPORT_FIELDS << "relat#{index}"
end
(1..10).each do |index|
ALL_YEAR_EXPORT_FIELDS << "illness_type_#{index}"
end
%w[a b c d e f g h].each do |letter|
ALL_YEAR_EXPORT_FIELDS << "housingneeds_#{letter}"
end
YEAR_2021_EXPORT_FIELDS = Set[
"builtype",
"chcharge",
"national",
"offered",
]
YEAR_2022_EXPORT_FIELDS = Set[
"builtype",
"chcharge",
"national",
"offered",
]
YEAR_2023_EXPORT_FIELDS = Set[
"builtype",
"chcharge",
"national",
"offered",
]
YEAR_2024_EXPORT_FIELDS = Set[
"builtype",
"chcharge",
"accessible_register", "accessible_register",
"nationality_all", "nationality_all",
"bulk_upload_id", "bulk_upload_id",
@ -153,27 +192,10 @@ module Exports::LettingsLogExportConstants
"pscharge_value_check", "pscharge_value_check",
"supcharg_value_check", "supcharg_value_check",
"carehome_charges_value_check", "carehome_charges_value_check",
"assigned_to",
"created_by",
] ]
(1..8).each do |index| YEAR_2025_EXPORT_FIELDS = Set[
EXPORT_FIELDS << "age#{index}" "builtype",
EXPORT_FIELDS << "ecstat#{index}"
EXPORT_FIELDS << "sex#{index}"
EXPORT_FIELDS << "sexrab#{index}"
end
(2..8).each do |index|
EXPORT_FIELDS << "relat#{index}"
end
(1..10).each do |index|
EXPORT_FIELDS << "illness_type_#{index}"
end
%w[a b c d e f g h].each do |letter|
EXPORT_FIELDS << "housingneeds_#{letter}"
end
POST_2024_EXPORT_FIELDS = Set[
"accessible_register", "accessible_register",
"nationality_all", "nationality_all",
"bulk_upload_id", "bulk_upload_id",
@ -188,25 +210,26 @@ module Exports::LettingsLogExportConstants
"scharge_value_check", "scharge_value_check",
"pscharge_value_check", "pscharge_value_check",
"supcharg_value_check", "supcharg_value_check",
"carehome_charges_value_check",
]
PRE_2024_EXPORT_FIELDS = Set[
"national",
"offered"
] ]
PRE_2025_EXPORT_FIELDS = Set[ YEAR_2026_EXPORT_FIELDS = Set[
"carehome_charges_value_check", "accessible_register",
"chcharge" "nationality_all",
] "bulk_upload_id",
"address_line1_as_entered",
PRE_2026_EXPORT_FIELDS = Set[ "address_line2_as_entered",
"builtype" "town_or_city_as_entered",
"county_as_entered",
"postcode_full_as_entered",
"la_as_entered",
"net_income_value_check",
"rent_value_check",
"scharge_value_check",
"pscharge_value_check",
"supcharg_value_check",
] ]
POST_2026_EXPORT_FIELDS = Set[]
(1..8).each do |index| (1..8).each do |index|
POST_2026_EXPORT_FIELDS << "sexrab#{index}" YEAR_2026_EXPORT_FIELDS << "sexrab#{index}"
end end
end end

30
app/services/exports/lettings_log_export_service.rb

@ -171,24 +171,26 @@ module Exports
pattern_age = /age\d_known/ pattern_age = /age\d_known/
details_known_prefix = "details_known_" details_known_prefix = "details_known_"
included_fields = Set[] included_fields = Set[]
included_fields.merge(EXPORT_FIELDS) included_fields.merge(ALL_YEAR_EXPORT_FIELDS)
if lettings_log.form.start_year_2024_or_later? year_fields = case lettings_log.collection_start_year
included_fields.subtract(PRE_2024_EXPORT_FIELDS) when 2021
else YEAR_2021_EXPORT_FIELDS
included_fields.subtract(POST_2024_EXPORT_FIELDS) when 2022
end YEAR_2022_EXPORT_FIELDS
when 2023
if lettings_log.form.start_year_2025_or_later? YEAR_2023_EXPORT_FIELDS
included_fields.subtract(PRE_2025_EXPORT_FIELDS) when 2024
end YEAR_2024_EXPORT_FIELDS
when 2025
if lettings_log.form.start_year_2026_or_later? YEAR_2025_EXPORT_FIELDS
included_fields.subtract(PRE_2026_EXPORT_FIELDS) when 2026
YEAR_2026_EXPORT_FIELDS
else else
included_fields.subtract(POST_2026_EXPORT_FIELDS) Set[]
end end
included_fields.merge(year_fields)
included_fields.reject! { |field| field.starts_with?(details_known_prefix) || pattern_age.match(field) } included_fields.reject! { |field| field.starts_with?(details_known_prefix) || pattern_age.match(field) }
included_fields included_fields

Loading…
Cancel
Save