diff --git a/app/models/patient.rb b/app/models/patient.rb index 782d325a5..62e8db887 100644 --- a/app/models/patient.rb +++ b/app/models/patient.rb @@ -247,7 +247,7 @@ def as_json private def confirm_appointment_after_initial_call - if appointment_date.present? && initial_call_date&.send(:>, appointment_date) + if appointment_date.present? && initial_call_date.present? && (initial_call_date - 60.days)&.send(:>, appointment_date) errors.add(:appointment_date, 'must be after date of initial call') end end diff --git a/test/models/patient_test.rb b/test/models/patient_test.rb index 663f5daae..d555f338f 100644 --- a/test/models/patient_test.rb +++ b/test/models/patient_test.rb @@ -79,19 +79,19 @@ class PatientTest < ActiveSupport::TestCase end end - it 'should require appointment_date to be after initial_call_date' do + it 'should require appointment_date to be reasonably after initial_call_date' do # when initial call date is nil @patient.appointment_date = '2016-05-01' @patient.initial_call_date = nil refute @patient.valid? # when initial call date is after appointment date - @patient.initial_call_date = '2016-06-01' + @patient.initial_call_date = '2016-09-01' refute @patient.valid? # when appointment date is nil @patient.appointment_date = nil assert @patient.valid? # when appointment date is after initial call date - @patient.appointment_date = '2016-07-01' + @patient.appointment_date = '2016-08-01' assert @patient.valid? end