Skip to content

Commit

Permalink
Api 27078 526 v2 allow yyyy mm date format 2 (#12957)
Browse files Browse the repository at this point in the history
* API-27078-526-v2-allow-yyyy-mm-date-format-2

* Updates 526.json and related json fles to be inline with new date formats
* Updates valdations file to handle new date formats
* Updates validation specs t handle tests with new date formats
	* Also adds some new tests for handling new scenarios
* Updates swagger docs
Changes to be committed:
	modified:   modules/claims_api/app/controllers/concerns/claims_api/v2/disability_compensation_validation.rb
	modified:   modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json
	modified:   modules/claims_api/config/schemas/v2/526.json
	modified:   modules/claims_api/config/schemas/v2/request_bodies/disability_compensation/example.json
	modified:   modules/claims_api/config/schemas/v2/request_bodies/disability_compensation/request.json
	modified:   modules/claims_api/spec/fixtures/v2/veterans/disability_compensation/form_526_json_api.json
	modified:   modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb
	modified:   modules/claims_api/spec/requests/v2/veterans/disability_compensation_request_spec.rb
	modified:   spec/support/schemas/claims_api/v2/forms/disability/submission.json

* Merges master and updates swagger file to make sure it is inline with these changes
  • Loading branch information
rockwellwindsor-va authored Jun 13, 2023
1 parent 935fbd2 commit 4c43ff8
Show file tree
Hide file tree
Showing 9 changed files with 1,509 additions and 1,239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def validate_form_526_disability_approximate_begin_date!
approx_begin_date = disability['approximateDate']
next if approx_begin_date.blank?

next if Date.parse(approx_begin_date) < Time.zone.today
next if date_is_valid_against_current_time_after_check_on_format?(approx_begin_date)

raise ::Common::Exceptions::InvalidFieldValue.new('disability.approximateDate', approx_begin_date)
end
Expand Down Expand Up @@ -245,7 +245,7 @@ def validate_form_526_disability_secondary_disability_classification_code_matche
end

def validate_form_526_disability_secondary_disability_approximate_begin_date!(secondary_disability)
return if Date.parse(secondary_disability['approximateDate']) < Time.zone.today
return if date_is_valid_against_current_time_after_check_on_format?(secondary_disability['approximateDate'])

raise ::Common::Exceptions::InvalidFieldValue.new(
'disabilities.secondaryDisabilities.approximateDate',
Expand Down Expand Up @@ -368,7 +368,7 @@ def validate_form_526_separation_pay_received_date!
'datePaymentReceived')
return if separation_pay_received_date.blank?

return if Date.parse(separation_pay_received_date) < Time.zone.today
return if date_is_valid_against_current_time_after_check_on_format?(separation_pay_received_date)

raise ::Common::Exceptions::InvalidFieldValue.new('separationSeverancePay.datePaymentReceived',
separation_pay_received_date)
Expand Down Expand Up @@ -416,7 +416,7 @@ def collect_primary_secondary_disability_names(disabilities)
names = []
disabilities.each do |disability|
names << disability['name'].strip.downcase
disability['secondaryDisabilities']&.each do |secondary|
disability['secondaryDisabilities'].each do |secondary|
names << secondary['name'].strip.downcase
end
end
Expand Down Expand Up @@ -468,7 +468,8 @@ def validate_confinements!
service_information['confinements'].each do |confinement|
approximate_begin_date = confinement['approximateBeginDate']
approximate_end_date = confinement['approximateEndDate']
if Date.parse(approximate_begin_date) > Date.parse(approximate_end_date)

if begin_date_is_not_after_end_date?(approximate_begin_date, approximate_end_date)
raise ::Common::Exceptions::UnprocessableEntity.new(
detail: 'Approximate end date must be after approximate begin date.'
)
Expand Down Expand Up @@ -576,6 +577,54 @@ def raise_exception_if_value_present(val)
detail: "The #{val} is required for direct deposit."
)
end

private

def begin_date_is_not_after_end_date?(begin_date, end_date)
# see what format each date is in
begin_date_has_day = date_has_day?(begin_date)
end_date_has_day = date_has_day?(end_date)
# determine how to compare, being = is ok
if (begin_date_has_day && end_date_has_day) || (!begin_date_has_day && !end_date_has_day) # same format
begin_date > end_date
else # mixed formats on dates
begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
end
end

# Either date could be in MM-YYYY or MM-DD-YYYY format
def begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
# figure out which one has the day and remove it
if date_has_day?(begin_date)
begin_date = remove_chars(begin_date.dup)
elsif date_has_day?(end_date)
end_date = remove_chars(end_date.dup)
end
Date.strptime(begin_date, '%m-%Y') > Date.strptime(end_date, '%m-%Y') # = is ok
end

def date_is_valid_against_current_time_after_check_on_format?(date)
if date_has_day?(date)
param_date = Date.strptime(date, '%m-%d-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%d-%Y'), '%m-%d-%Y')
else
param_date = Date.strptime(date, '%m-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%Y'), '%m-%Y')
end
param_date <= now_date # Since it is approximate we go with <=
end

# just need to know if day is present or not
def date_has_day?(date)
date.length == 10
end

# making date approximate to compare
def remove_chars(str)
indices = [2, 3, 4] # MM| -DD |-YYYY
indices.reverse_each { |i| str[i] = '' }
str
end
end
end
end
Loading

0 comments on commit 4c43ff8

Please sign in to comment.