Browse Source

Fix errors during import process (#507)

pull/512/head
Stéphane Meny 3 years ago committed by GitHub
parent
commit
beedcf2d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/services/imports/case_logs_import_service.rb
  2. 5
      db/migrate/20220426122618_add_joint_to_case_logs.rb
  3. 3
      db/schema.rb
  4. 1
      spec/fixtures/exports/case_logs.xml

22
app/services/imports/case_logs_import_service.rb

@ -139,7 +139,7 @@ module Imports
attributes["la"] = string_or_nil(xml_doc, "Q28ONS")
attributes["postcode_full"] = compose_postcode(xml_doc, "POSTCODE", "POSTCOD2")
attributes["postcode_known"] = attributes["postcode_full"].nil? ? 0 : 1
attributes["postcode_known"] = postcode_known(attributes)
# Not specific to our form but required for consistency (present in import)
attributes["old_form_id"] = safe_string_as_integer(xml_doc, "FORM")
@ -148,7 +148,7 @@ module Imports
attributes["old_id"] = field_value(xml_doc, "meta", "document-id")
# Required for our form invalidated questions (not present in import)
attributes["previous_la_known"] = 1 # Defaulting to Yes (Required)
attributes["previous_la_known"] = attributes["prevloc"].nil? ? 0 : 1
attributes["is_la_inferred"] = false # Always keep the given LA
attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"])
attributes["declaration"] = declaration(xml_doc)
@ -327,7 +327,7 @@ module Imports
end
def age_known(xml_doc, index, hhmemb)
return nil if index > hhmemb
return nil if hhmemb.present? && index > hhmemb
age_refused = string_or_nil(xml_doc, "P#{index}AR")
if age_refused == "AGE_REFUSED"
@ -338,9 +338,9 @@ module Imports
end
def details_known(index, attributes)
if index > attributes["hhmemb"]
nil
elsif attributes["age#{index}_known"] == 1 &&
return nil if attributes["hhmemb"].present? && index > attributes["hhmemb"]
if attributes["age#{index}_known"] == 1 &&
attributes["sex#{index}"] == "R" &&
attributes["relat#{index}"] == "R" &&
attributes["ecstat#{index}"] == 10
@ -465,5 +465,15 @@ module Imports
1
end
end
def postcode_known(attributes)
if attributes["postcode_full"].nil? && attributes["la"].nil?
nil
elsif attributes["postcode_full"].nil?
0 # Assumes we selected No in the form since the LA is present
else
1
end
end
end
end

5
db/migrate/20220426122618_add_joint_to_case_logs.rb

@ -0,0 +1,5 @@
class AddJointToCaseLogs < ActiveRecord::Migration[7.0]
def change
add_column :case_logs, :joint, :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_04_25_145228) do
ActiveRecord::Schema[7.0].define(version: 2022_04_26_122618) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -219,6 +219,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_25_145228) do
t.integer "lar"
t.integer "irproduct"
t.string "old_id"
t.integer "joint"
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
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"

1
spec/fixtures/exports/case_logs.xml vendored

@ -161,6 +161,7 @@
<lar/>
<irproduct/>
<old_id/>
<joint/>
<providertype>1</providertype>
</form>
</forms>

Loading…
Cancel
Save