Browse Source

move set housing needs fields to case log variables file

pull/826/head
Kat 3 years ago committed by Kat
parent
commit
b08756bbb3
  1. 22
      app/models/case_log.rb
  2. 23
      app/models/derived_variables/case_log_variables.rb
  3. 1
      spec/fixtures/complete_case_log.json

22
app/models/case_log.rb

@ -25,7 +25,6 @@ class CaseLog < ApplicationRecord
before_validation :reset_scheme_location!, if: :scheme_changed?, unless: :location_changed?
before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :set_housingneeds_fields, if: :housingneeds?
before_validation :reset_invalidated_dependent_fields!
before_validation :reset_location_fields!, unless: :postcode_known?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
@ -759,25 +758,4 @@ private
def unknown_housingneeds?
housingneeds == 3
end
def set_housingneeds_fields
set_housingneeds_values_to_zero
self.housingneeds_a = 1 if fully_wheelchair_accessible?
self.housingneeds_b = 1 if essential_wheelchair_access?
self.housingneeds_c = 1 if level_access_housing?
self.housingneeds_f = 1 if other_housingneeds?
set_housingneeds_values_to_zero unless has_housingneeds?
self.housingneeds_g = 1 if no_housingneeds?
self.housingneeds_h = 1 if unknown_housingneeds?
end
def set_housingneeds_values_to_zero
self.housingneeds_a = 0
self.housingneeds_b = 0
self.housingneeds_c = 0
self.housingneeds_f = 0
self.housingneeds_g = 0
self.housingneeds_h = 0
end
end

23
app/models/derived_variables/case_log_variables.rb

@ -69,6 +69,8 @@ module DerivedVariables::CaseLogVariables
self.voiddate = startdate
end
end
set_housingneeds_fields if housingneeds?
end
private
@ -185,4 +187,25 @@ private
self.location = scheme.locations.first
end
end
def set_housingneeds_fields
set_housingneeds_values_to_zero
self.housingneeds_a = 1 if fully_wheelchair_accessible?
self.housingneeds_b = 1 if essential_wheelchair_access?
self.housingneeds_c = 1 if level_access_housing?
self.housingneeds_f = 1 if other_housingneeds?
set_housingneeds_values_to_zero unless has_housingneeds?
self.housingneeds_g = 1 if no_housingneeds?
self.housingneeds_h = 1 if unknown_housingneeds?
end
def set_housingneeds_values_to_zero
self.housingneeds_a = 0
self.housingneeds_b = 0
self.housingneeds_c = 0
self.housingneeds_f = 0
self.housingneeds_g = 0
self.housingneeds_h = 0
end
end

1
spec/fixtures/complete_case_log.json vendored

@ -59,6 +59,7 @@
"housingneeds": 1,
"housingneeds_type": 2,
"housingneeds_other": 0,
"housingneeds_c": 1,
"illness_type_1":null,
"illness_type_2":null,
"illness_type_3":null,

Loading…
Cancel
Save