Browse Source

Save correct la if postcode is invalid (#551)

pull/619/head
kosiakkatrina 3 years ago committed by baarkerlounger
parent
commit
4c4f52f021
  1. 9
      app/services/imports/case_logs_import_service.rb
  2. 8
      spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml

9
app/services/imports/case_logs_import_service.rb

@ -99,7 +99,7 @@ module Imports
attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11") attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11")
attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS") attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS")
attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2") attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2")
attributes["previous_postcode_known"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"]) attributes["previous_postcode_known"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"])
attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c") attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c")
attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d") attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d")
attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13") attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13")
@ -375,9 +375,9 @@ module Imports
end end
end end
def previous_postcode_known(xml_doc, previous_postcode) def previous_postcode_known(xml_doc, previous_postcode, prevloc)
previous_postcode_known = string_or_nil(xml_doc, "Q12bnot") previous_postcode_known = string_or_nil(xml_doc, "Q12bnot")
if previous_postcode_known == "Temporary_or_Unknown" if previous_postcode_known == "Temporary_or_Unknown" || (previous_postcode.nil? && prevloc.present?)
0 0
elsif previous_postcode.nil? elsif previous_postcode.nil?
nil nil
@ -386,10 +386,11 @@ module Imports
end end
end end
POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP
def compose_postcode(xml_doc, outcode, incode) def compose_postcode(xml_doc, outcode, incode)
outcode_value = string_or_nil(xml_doc, outcode) outcode_value = string_or_nil(xml_doc, outcode)
incode_value = string_or_nil(xml_doc, incode) incode_value = string_or_nil(xml_doc, incode)
if outcode_value.nil? || incode_value.nil? if outcode_value.nil? || incode_value.nil? || !"#{outcode_value}#{incode_value}".match(POSTCODE_REGEXP)
nil nil
else else
"#{outcode_value}#{incode_value}" "#{outcode_value}#{incode_value}"

8
spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

@ -524,9 +524,9 @@
<MRCDAY/> <MRCDAY/>
<MRCMONTH/> <MRCMONTH/>
<MRCYEAR/> <MRCYEAR/>
<PPOSTC1>LS8</PPOSTC1> <PPOSTC1>SR7</PPOSTC1>
<PPOSTC2>3HX</PPOSTC2> <PPOSTC2>0A5</PPOSTC2>
<POSTCODE>LS16</POSTCODE> <POSTCODE>TS27</POSTCODE>
<POSTCOD2>6FT</POSTCOD2> <POSTCOD2>5B7</POSTCOD2>
</Group> </Group>
</Group> </Group>

Loading…
Cancel
Save