Browse Source

Read declaration value from XML field

pull/500/head
Stéphane Meny 3 years ago
parent
commit
bc5c4addd0
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 35
      app/services/imports/case_logs_import_service.rb

35
app/services/imports/case_logs_import_service.rb

@ -152,7 +152,7 @@ module Imports
attributes["la_known"] = 1 # Defaulting to Yes (Required) attributes["la_known"] = 1 # Defaulting to Yes (Required)
attributes["is_la_inferred"] = false # Always keep the given LA attributes["is_la_inferred"] = false # Always keep the given LA
attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"]) attributes["first_time_property_let_as_social_housing"] = first_time_let(attributes["rsnvac"])
attributes["declaration"] = 1 attributes["declaration"] = declaration(xml_doc)
unless attributes["brent"].nil? && unless attributes["brent"].nil? &&
attributes["scharge"].nil? && attributes["scharge"].nil? &&
@ -205,8 +205,8 @@ module Imports
# Safe: A string that represents only a decimal (or empty/nil) # Safe: A string that represents only a decimal (or empty/nil)
def safe_string_as_decimal(xml_doc, attribute) def safe_string_as_decimal(xml_doc, attribute)
str = field_value(xml_doc, "xmlns", attribute) str = string_or_nil(xml_doc, attribute)
if str.blank? if str.nil?
nil nil
else else
BigDecimal(str, exception: false) BigDecimal(str, exception: false)
@ -215,8 +215,8 @@ module Imports
# Unsafe: A string that has more than just the integer value # Unsafe: A string that has more than just the integer value
def unsafe_string_as_integer(xml_doc, attribute) def unsafe_string_as_integer(xml_doc, attribute)
str = field_value(xml_doc, "xmlns", attribute) str = string_or_nil(xml_doc, attribute)
if str.blank? if str.nil?
nil nil
else else
str.to_i str.to_i
@ -300,7 +300,7 @@ module Imports
end end
def sex(xml_doc, index) def sex(xml_doc, index)
sex = field_value(xml_doc, "xmlns", "P#{index}Sex") sex = string_or_nil(xml_doc, "P#{index}Sex")
case sex case sex
when "Male" when "Male"
"M" "M"
@ -314,7 +314,7 @@ module Imports
end end
def relat(xml_doc, index) def relat(xml_doc, index)
relat = field_value(xml_doc, "xmlns", "P#{index}Rel") relat = string_or_nil(xml_doc, "P#{index}Rel")
case relat case relat
when "Child" when "Child"
"C" "C"
@ -330,7 +330,7 @@ module Imports
def age_known(xml_doc, index, hhmemb) def age_known(xml_doc, index, hhmemb)
return nil if index > hhmemb return nil if index > hhmemb
age_refused = field_value(xml_doc, "xmlns", "P#{index}AR") age_refused = string_or_nil(xml_doc, "P#{index}AR")
if age_refused == "AGE_REFUSED" if age_refused == "AGE_REFUSED"
1 # No 1 # No
else else
@ -352,7 +352,7 @@ module Imports
end end
def previous_postcode_known(xml_doc, previous_postcode) def previous_postcode_known(xml_doc, previous_postcode)
previous_postcode_known = field_value(xml_doc, "xmlns", "Q12bnot") previous_postcode_known = string_or_nil(xml_doc, "Q12bnot")
if previous_postcode_known == "Temporary or Unknown" if previous_postcode_known == "Temporary or Unknown"
0 0
elsif previous_postcode.nil? elsif previous_postcode.nil?
@ -363,9 +363,9 @@ module Imports
end end
def compose_postcode(xml_doc, outcode, incode) def compose_postcode(xml_doc, outcode, incode)
outcode_value = field_value(xml_doc, "xmlns", outcode) outcode_value = string_or_nil(xml_doc, outcode)
incode_value = field_value(xml_doc, "xmlns", incode) incode_value = string_or_nil(xml_doc, incode)
if outcode_value.blank? || incode_value.blank? if outcode_value.nil? || incode_value.nil?
nil nil
else else
"#{outcode_value}#{incode_value}" "#{outcode_value}#{incode_value}"
@ -421,7 +421,7 @@ module Imports
# Letters should be lowercase to match case # Letters should be lowercase to match case
def housing_needs(xml_doc, letter) def housing_needs(xml_doc, letter)
housing_need = field_value(xml_doc, "xmlns", "Q10-#{letter}") housing_need = string_or_nil(xml_doc, "Q10-#{letter}")
if housing_need == "Yes" if housing_need == "Yes"
1 1
else else
@ -430,7 +430,7 @@ module Imports
end end
def net_income_known(xml_doc, earnings) def net_income_known(xml_doc, earnings)
incref = field_value(xml_doc, "xmlns", "Q8Refused") incref = string_or_nil(xml_doc, "Q8Refused")
if incref == "Refused" if incref == "Refused"
# Tenant prefers not to say # Tenant prefers not to say
2 2
@ -459,5 +459,12 @@ module Imports
0 0
end end
end end
def declaration(xml_doc)
declaration = string_or_nil(xml_doc, "Qdp")
if declaration == "Yes"
1
end
end
end end
end end

Loading…
Cancel
Save