diff --git a/app/models/concerns/form526_claim_fast_tracking_concern.rb b/app/models/concerns/form526_claim_fast_tracking_concern.rb index 99d03e94b8b..d09d1793f8d 100644 --- a/app/models/concerns/form526_claim_fast_tracking_concern.rb +++ b/app/models/concerns/form526_claim_fast_tracking_concern.rb @@ -91,6 +91,10 @@ def disabilities form.dig('form526', 'form526', 'disabilities') end + def increase_disabilities + disabilities.select { |disability| disability['disabilityActionType']&.upcase == 'INCREASE' } + end + def increase_only? disabilities.all? { |disability| disability['disabilityActionType']&.upcase == 'INCREASE' } end @@ -188,18 +192,19 @@ def update_form_with_classification_code(classification_code) end def log_max_cfi_metrics_on_submit - ClaimFastTracking::DiagnosticCodesForMetrics::DC.intersection(diagnostic_codes).each do |diagnostic_code| - next unless disabilities.any? do |dis| - diagnostic_code == dis['diagnosticCode'] - end + user = User.find(user_uuid) + max_cfi_enabled = Flipper.enabled?(:disability_526_maximum_rating, user) ? 'on' : 'off' + ClaimFastTracking::DiagnosticCodesForMetrics::DC.each do |diagnostic_code| + next unless max_rated_diagnostic_codes_from_ipf.include?(diagnostic_code) - next unless max_rated_disabilities_from_ipf.any? do |dis| - diagnostic_code == dis['diagnostic_code'] - end + disability_claimed = diagnostic_codes.include?(diagnostic_code) - user = User.find(user_uuid) - max_cfi_enabled = Flipper.enabled?(:disability_526_maximum_rating, user) ? 'on' : 'off' - StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.#{max_cfi_enabled}.submit.#{diagnostic_code}") + if disability_claimed + StatsD.increment("#{MAX_CFI_STATSD_KEY_PREFIX}.#{max_cfi_enabled}.submit.#{diagnostic_code}") + end + Rails.logger.info('Max CFI form526 submission', + id:, max_cfi_enabled:, disability_claimed:, diagnostic_code:, + total_increase_conditions: increase_disabilities.count) end rescue => e # Log the exception but but do not fail, otherwise form will not be submitted @@ -244,6 +249,10 @@ def max_rated_disabilities_from_ipf end end + def max_rated_diagnostic_codes_from_ipf + max_rated_disabilities_from_ipf.pluck('diagnostic_code') + end + # Fetch and memoize all of the veteran's open EPs. Establishing a new EP will make the memoized # value outdated if using the same Form526Submission instance. def open_claims diff --git a/spec/models/form526_submission_spec.rb b/spec/models/form526_submission_spec.rb index 1e858439e05..98b6d027e60 100644 --- a/spec/models/form526_submission_spec.rb +++ b/spec/models/form526_submission_spec.rb @@ -91,9 +91,17 @@ before do allow(StatsD).to receive(:increment) + allow(Rails.logger).to receive(:info) Flipper.disable(:disability_526_maximum_rating) end + def expect_max_cfi_logged(max_cfi_enabled, disability_claimed, diagnostic_code, total_increase_conditions) + expect(Rails.logger).to have_received(:info).with( + 'Max CFI form526 submission', + { id: subject.id, max_cfi_enabled:, disability_claimed:, diagnostic_code:, total_increase_conditions: } + ) + end + context 'the submission is for tinnitus' do let(:form_json) do File.read('spec/support/disability_compensation_form/submissions/only_526_tinnitus.json') @@ -117,6 +125,7 @@ it 'logs CFI metric upon submission' do subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.on.submit.6260') + expect_max_cfi_logged('on', true, 6260, 1) end end @@ -137,6 +146,7 @@ it 'logs CFI metric upon submission' do subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.off.submit.6260') + expect_max_cfi_logged('off', true, 6260, 1) end end @@ -180,7 +190,7 @@ end end - context 'the submission is for tinnitus and hypertension' do + context 'the submission is from a Veteran with rated tinnitus and hypertension' do let(:form_json) do File.read('spec/support/disability_compensation_form/submissions/only_526_two_cfi_with_max_ratings.json') end @@ -218,6 +228,18 @@ subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.on.submit.6260') expect(StatsD).not_to have_received(:increment).with('api.max_cfi.on.submit.7101') + expect_max_cfi_logged('on', true, 6260, 2) + end + + context 'when the submission omits tinnitus' do + let(:form_json) do + File.read('spec/support/disability_compensation_form/submissions/only_526_hypertension.json') + end + + it 'logs CFI metric upon submission for tinnitus being omitted' do + subject.start + expect_max_cfi_logged('on', false, 6260, 1) + end end end @@ -228,6 +250,7 @@ subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.on.submit.6260') expect(StatsD).not_to have_received(:increment).with('api.max_cfi.on.submit.7101') + expect_max_cfi_logged('on', true, 6260, 2) end end @@ -261,6 +284,7 @@ subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.off.submit.6260') expect(StatsD).not_to have_received(:increment).with('api.max_cfi.off.submit.7101') + expect_max_cfi_logged('off', true, 6260, 2) end end @@ -271,6 +295,7 @@ subject.start expect(StatsD).to have_received(:increment).with('api.max_cfi.off.submit.6260') expect(StatsD).not_to have_received(:increment).with('api.max_cfi.off.submit.7101') + expect_max_cfi_logged('off', true, 6260, 2) end end