diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb
index 7ce66d8df..c42bc476e 100644
--- a/app/services/imports/case_logs_import_service.rb
+++ b/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
diff --git a/db/migrate/20220426122618_add_joint_to_case_logs.rb b/db/migrate/20220426122618_add_joint_to_case_logs.rb
new file mode 100644
index 000000000..3621b9bbf
--- /dev/null
+++ b/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
diff --git a/db/schema.rb b/db/schema.rb
index 94a44efde..449c77cdd 100644
--- a/db/schema.rb
+++ b/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"
diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml
index dfc14f8e5..27ec5eb92 100644
--- a/spec/fixtures/exports/case_logs.xml
+++ b/spec/fixtures/exports/case_logs.xml
@@ -161,6 +161,7 @@
+
1