diff --git a/modules/claims_api/lib/claims_api/v2/disability_compensation_pdf_mapper.rb b/modules/claims_api/lib/claims_api/v2/disability_compensation_pdf_mapper.rb index 8a86590c1e1..f991a626ca9 100644 --- a/modules/claims_api/lib/claims_api/v2/disability_compensation_pdf_mapper.rb +++ b/modules/claims_api/lib/claims_api/v2/disability_compensation_pdf_mapper.rb @@ -24,6 +24,9 @@ class DisabilityCompensationPdfMapper # rubocop:disable Metrics/ClassLength 4 => :convert_date_string_to_format_yyyy }.freeze + BDD_LOWER_LIMIT = 90 + BDD_UPPER_LIMIT = 180 + def initialize(auto_claim, pdf_data, auth_headers, middle_initial, created_at) @auto_claim = auto_claim @pdf_data = pdf_data @@ -299,6 +302,8 @@ def veteran_info # rubocop:disable Metrics/MethodLength @pdf_data[:data][:attributes].delete(:veteranIdentification) + date_of_release + @pdf_data end @@ -337,6 +342,25 @@ def zip @pdf_data end + def date_of_release + if @pdf_data[:data][:attributes][:claimProcessType] == 'BDD_PROGRAM_CLAIM' + claim_date = Date.parse(@created_at.to_s) + service_information = @auto_claim['serviceInformation'] + + active_dates = service_information['servicePeriods']&.pluck('activeDutyEndDate') + active_dates << service_information&.dig('federalActivation', 'anticipatedSeparationDate') + + end_or_separation_date = active_dates.compact.find do |a| + Date.strptime(a, '%Y-%m-%d').between?(claim_date.next_day(BDD_LOWER_LIMIT), + claim_date.next_day(BDD_UPPER_LIMIT)) + end + + @pdf_data[:data][:attributes][:identificationInformation][:dateOfReleaseFromActiveDuty] = regex_date_conversion(end_or_separation_date) + end + + @pdf_data + end + def disability_attributes @pdf_data[:data][:attributes][:claimInformation] = {} @pdf_data[:data][:attributes][:claimInformation].merge!( diff --git a/modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb b/modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb index 3a8ba3a982c..81dbc1df257 100644 --- a/modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb +++ b/modules/claims_api/spec/lib/claims_api/v2/disability_compensation_pdf_mapper_spec.rb @@ -53,7 +53,10 @@ end describe 'when the claimProcessType is BDD_PROGRAM' do + date = DateTime.now + 4.months let(:claim_process_type) { 'BDD_PROGRAM' } + let(:anticipated_seperation_date) { date.strftime('%Y-%m-%d') } + let(:active_duty_end_date) { date.strftime('%Y-%m-%d') } it 'maps correctly to BDD_PROGRAM_CLAIM' do form_attributes['claimProcessType'] = claim_process_type @@ -62,6 +65,42 @@ claim_process_type = pdf_data[:data][:attributes][:claimProcessType] expect(claim_process_type).to eq('BDD_PROGRAM_CLAIM') end + + it 'maps anticipatedSeparationDate correctly' do + form_attributes['claimProcessType'] = claim_process_type + form_attributes['serviceInformation']['federalActivation']['anticipatedSeparationDate'] = + anticipated_seperation_date + mapper.map_claim + + date_of_release_from_active_duty = + pdf_data[:data][:attributes][:identificationInformation][:dateOfReleaseFromActiveDuty] + expect(date_of_release_from_active_duty).to eq({ year: date.strftime('%Y'), month: date.strftime('%m'), + day: date.strftime('%d') }) + end + + it 'maps activeDutyEndDate correctly' do + form_attributes['claimProcessType'] = claim_process_type + form_attributes['serviceInformation']['servicePeriods'][0]['activeDutyEndDate'] = active_duty_end_date + mapper.map_claim + + date_of_release_from_active_duty = + pdf_data[:data][:attributes][:identificationInformation][:dateOfReleaseFromActiveDuty] + expect(date_of_release_from_active_duty).to eq({ year: date.strftime('%Y'), month: date.strftime('%m'), + day: date.strftime('%d') }) + end + + it 'maps activeDutyEndDate correctly when federalActivation & activeDutyBeginDate are nil' do + form_attributes['claimProcessType'] = claim_process_type + form_attributes['serviceInformation']['federalActivation'] = nil + form_attributes['serviceInformation']['servicePeriods'][0]['activeDutyBeginDate'] = nil + form_attributes['serviceInformation']['servicePeriods'][0]['activeDutyEndDate'] = active_duty_end_date + mapper.map_claim + + date_of_release_from_active_duty = + pdf_data[:data][:attributes][:identificationInformation][:dateOfReleaseFromActiveDuty] + expect(date_of_release_from_active_duty).to eq({ year: date.strftime('%Y'), month: date.strftime('%m'), + day: date.strftime('%d') }) + end end end