From d487f4446ba879a14347d45c433355f9b6f1464e Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 25 Apr 2024 16:24:28 -0400 Subject: [PATCH] Fix EP400 Merge eligibility logic to be compatible with LH Benefits Claims API --- .../form526_claim_fast_tracking_concern.rb | 15 +- .../lighthouse_claims_service_provider.rb | 1 + .../responses/claims_service_response.rb | 1 + .../submit_form526_all_claim_spec.rb | 26 ++++ ...aims_with_single_open_disability_claim.yml | 134 ++++++++++++++++++ 5 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 spec/support/vcr_cassettes/lighthouse/benefits_claims/index/claims_with_single_open_disability_claim.yml diff --git a/app/models/concerns/form526_claim_fast_tracking_concern.rb b/app/models/concerns/form526_claim_fast_tracking_concern.rb index 90e6032c238..839dec90de0 100644 --- a/app/models/concerns/form526_claim_fast_tracking_concern.rb +++ b/app/models/concerns/form526_claim_fast_tracking_concern.rb @@ -26,6 +26,15 @@ module Form526ClaimFastTrackingConcern CLAIM_REVIEW_BASE_CODES = %w[030 040].freeze CLAIM_REVIEW_TYPES = %w[higherLevelReview supplementalClaim].freeze + def claim_age_in_days(pending_ep) + date = if pending_ep.respond_to?(:claim_date) + Date.strptime(pending_ep.claim_date, '%Y-%m-%d') + else + Date.strptime(pending_ep['date'], '%m/%d/%Y') + end + (Time.zone.today - date).round + end + def send_rrd_alert_email(subject, message, error = nil, to = Settings.rrd.alerts.recipients) RrdAlertMailer.build(self, subject, message, error, to).deliver_now end @@ -132,19 +141,19 @@ def prepare_for_ep_merge! Rails.logger.info('EP Merge total open EPs', id:, count: pending_eps.count) return unless pending_eps.count == 1 - date = Date.strptime(pending_eps.first['date'], '%m/%d/%Y') - days_ago = (Time.zone.today - date).round feature_enabled = Flipper.enabled?(:disability_526_ep_merge_api, User.find(user_uuid)) open_claim_review = open_claim_review? Rails.logger.info( 'EP Merge open EP eligibility', { id:, feature_enabled:, open_claim_review:, - pending_ep_age: days_ago, pending_ep_status: pending_eps.first['status'] } + pending_ep_age: claim_age_in_days(pending_eps.first), pending_ep_status: pending_eps.first['status'] } ) if feature_enabled && !open_claim_review save_metadata(ep_merge_pending_claim_id: pending_eps.first['id']) add_ep_merge_special_issue! end + rescue => e + Rails.logger.error("EP400 Merge eligibility failed #{e.message}.", backtrace: e.backtrace) end def get_claim_type diff --git a/lib/disability_compensation/providers/claims_service/lighthouse_claims_service_provider.rb b/lib/disability_compensation/providers/claims_service/lighthouse_claims_service_provider.rb index d09b7e8f63d..e152ef1246b 100644 --- a/lib/disability_compensation/providers/claims_service/lighthouse_claims_service_provider.rb +++ b/lib/disability_compensation/providers/claims_service/lighthouse_claims_service_provider.rb @@ -24,6 +24,7 @@ def transform(data) DisabilityCompensation::ApiProvider::Claim.new( id: open_claim['id'], base_end_product_code: open_claim['attributes']['baseEndProductCode'], + claim_date: open_claim['attributes']['claimDate'], claim_phase_dates: open_claim['attributes']['claimPhaseDates'], development_letter_sent: open_claim['attributes']['developmentLetterSent'], status: open_claim['attributes']['status'] # make sure words/strings syntax is perfect match diff --git a/lib/disability_compensation/responses/claims_service_response.rb b/lib/disability_compensation/responses/claims_service_response.rb index 360d6b6767b..0a74534e616 100644 --- a/lib/disability_compensation/responses/claims_service_response.rb +++ b/lib/disability_compensation/responses/claims_service_response.rb @@ -18,6 +18,7 @@ class Claim attribute :base_end_product_code, String attribute :development_letter_sent, Boolean attribute :status, String + attribute :claim_date, String attribute :claim_phase_dates, ClaimPhaseDates end diff --git a/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb b/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb index 1fa60273a7d..5d6b9eb8b58 100644 --- a/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/submit_form526_all_claim_spec.rb @@ -27,8 +27,10 @@ let(:saved_claim) { FactoryBot.create(:va526ez) } let(:submitted_claim_id) { 600_130_094 } + let(:user_account) { create(:user_account, icn: '123498767V234859') } let(:submission) do create(:form526_submission, + user_account_id: user_account.id, user_uuid: user.uuid, auth_headers_json: auth_headers.to_json, saved_claim_id: saved_claim.id) @@ -158,6 +160,30 @@ def expect_retryable_error(error_class) ) end + context 'when using LH Benefits Claims API instead of EVSS' do + before do + Flipper.enable(:disability_compensation_lighthouse_claims_service_provider) + allow_any_instance_of(BenefitsClaims::Configuration).to receive(:access_token).and_return('access_token') + end + + after { Flipper.disable(:disability_compensation_lighthouse_claims_service_provider) } + + let(:open_claims_cassette) { 'lighthouse/benefits_claims/index/claims_with_single_open_disability_claim' } + + it 'logs the expected data for EP 400 merge eligibility' do + subject.perform_async(submission.id) + VCR.use_cassette('virtual_regional_office/contention_classification') do + described_class.drain + end + expect(Rails.logger).to have_received(:info).with('EP Merge total open EPs', id: submission.id, count: 1) + expect(Rails.logger).to have_received(:info).with( + 'EP Merge open EP eligibility', + { id: submission.id, feature_enabled: true, open_claim_review: false, + pending_ep_age: 365, pending_ep_status: 'INITIAL_REVIEW' } + ) + end + end + context 'when EP400 merge API call is enabled' do before do Flipper.enable(:disability_526_ep_merge_api, user) diff --git a/spec/support/vcr_cassettes/lighthouse/benefits_claims/index/claims_with_single_open_disability_claim.yml b/spec/support/vcr_cassettes/lighthouse/benefits_claims/index/claims_with_single_open_disability_claim.yml new file mode 100644 index 00000000000..b35ab7d722a --- /dev/null +++ b/spec/support/vcr_cassettes/lighthouse/benefits_claims/index/claims_with_single_open_disability_claim.yml @@ -0,0 +1,134 @@ +--- +http_interactions: +- request: + method: get + uri: https://sandbox-api.va.gov/services/claims/v2/veterans/123498767V234859/claims + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Authorization: + - Bearer fake_access_token + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Sun, 09 Jul 2023 20:18:33 GMT + Content-Type: + - application/json; charset=utf-8 + Connection: + - keep-alive + X-Ratelimit-Remaining-Minute: + - '57' + X-Ratelimit-Limit-Minute: + - '60' + Ratelimit-Limit: + - '60' + Ratelimit-Remaining: + - '57' + Ratelimit-Reset: + - '30' + Etag: + - W/"b5a51c7379c34e017d07228732153262" + Referrer-Policy: + - strict-origin-when-cross-origin + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + X-Git-Sha: + - bcf87c84c487e5f21187f052ee057c86c76cf903 + X-Github-Repository: + - https://github.com/department-of-veterans-affairs/vets-api + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 13138c49-dff2-45db-8e83-33937e19e1ea + X-Runtime: + - '2.372224' + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Cache-Control: + - no-cache, no-store + Pragma: + - no-cache + Transfer-Encoding: + - chunked + body: + encoding: ASCII-8BIT + string: '{ + "data": [ + { + "id": "600173992", + "type": "claim", + "attributes": { + "baseEndProductCode": "020", + "claimDate": "2017-09-28", + "claimPhaseDates": { "phaseChangeDate": "2017-09-30" }, + "claimType": "Compensation", + "closeDate": null, + "decisionLetterSent": false, + "developmentLetterSent": false, + "documentsNeeded": false, + "evidenceWaiverSubmitted5103": false, + "lighthouseId": null, + "status": "INITIAL_REVIEW" + } + }, + { + "id": "600131025", + "type": "claim", + "attributes": { + "baseEndProductCode": "683", + "claimDate": "2018-06-08", + "claimPhaseDates": { "phaseChangeDate": "2018-10-15" }, + "claimType": "Appeal", + "closeDate": "2018-10-15", + "decisionLetterSent": true, + "developmentLetterSent": false, + "documentsNeeded": false, + "evidenceWaiverSubmitted5103": false, + "lighthouseId": null, + "status": "COMPLETE" + } + }, + { + "id": "244352", + "type": "claim", + "attributes": { + "baseEndProductCode": "930", + "claimDate": "2012-09-24", + "claimPhaseDates": { "phaseChangeDate": "2012-11-16" }, + "claimType": "Administrative Review", + "closeDate": "2012-11-16", + "decisionLetterSent": false, + "developmentLetterSent": false, + "documentsNeeded": false, + "evidenceWaiverSubmitted5103": false, + "lighthouseId": null, + "status": "COMPLETE" + } + } + ] + }' + recorded_at: Sun, 09 Jul 2023 20:18:33 GMT +recorded_with: VCR 6.1.0