Skip to content

Commit

Permalink
Implements new endpoint behind feature flag (#19445)
Browse files Browse the repository at this point in the history
* added new endpoint and implemented feature flag check, adds tests

* corrected test failure and added integration test for new endpoint

* refactored if statement based on code review

* corrects linting errors

* mocked feature flag rather than enabling and disabling

* corrected linting
  • Loading branch information
tyler-spangler6 authored Nov 20, 2024
1 parent 7ba1f71 commit 486286a
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 9 deletions.
9 changes: 8 additions & 1 deletion app/models/concerns/form526_claim_fast_tracking_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,15 @@ def update_form_with_classification_codes(classified_contentions)
end

def classify_vagov_contentions(params)
user = OpenStruct.new({ flipper_id: user_uuid })
vro_client = VirtualRegionalOffice::Client.new
response = vro_client.classify_vagov_contentions(params)

response = if Flipper.enabled?(:disability_526_expanded_contention_classification, user)
vro_client.classify_vagov_contentions_expanded(params)
else
vro_client.classify_vagov_contentions(params)
end

response.body
end

Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ virtual_regional_office:
api_key: 9d3868d1-ec15-4889-8002-2bff1b50ba62
evidence_pdf_path: evidence-pdf
vagov_classification_path: contention-classification/va-gov-claim-classifier
expanded_classification_path: contention-classification/expanded-contention-classification
max_cfi_path: employee-experience/max-ratings
ep_merge_path: employee-experience-ep-merge-app/merge

Expand Down
6 changes: 6 additions & 0 deletions lib/virtual_regional_office/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def classify_vagov_contentions(params)
end
end

def classify_vagov_contentions_expanded(params)
with_monitoring do
perform(:post, Settings.virtual_regional_office.expanded_classification_path, params.to_json.to_s, headers_hash)
end
end

def get_max_rating_for_diagnostic_codes(diagnostic_codes_array)
with_monitoring do
params = { diagnostic_codes: diagnostic_codes_array }
Expand Down
32 changes: 32 additions & 0 deletions spec/lib/virtual_regional_office/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
contention_text: 'Asthma',
contention_type: 'NEW'
},
{
contention_text: 'right acl tear',
contention_type: 'NEW'
}
],
claim_id: 4567,
Expand Down Expand Up @@ -51,6 +55,34 @@
expect(subject).to eq generic_response
end
end

describe 'when requesting expanded classification' do
subject { client.classify_vagov_contentions_expanded(classification_contention_params) }

let(:generic_response) do
double(
'virtual regional office response', status: 200,
body: {
contentions: [
{ classification_code: '99999', classification_name: 'namey' },
{ classification_code: '9012', classification_name: 'Respiratory' },
{
classification_code: '8997',
classification_name: 'Musculoskeletal - Knee'
}
]
}.as_json
)
end

before do
allow(client).to receive(:perform).and_return generic_response
end

it 'returns the api response for the expanded classification' do
expect(subject).to eq generic_response
end
end
end

context 'unsuccessful requests' do
Expand Down
67 changes: 66 additions & 1 deletion spec/lib/virtual_regional_office/integration/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
contention_type: 'NEW' },
{ contention_text: 'additional free text entry',
contention_type: 'NEW',
diagnostic_code: 9999 }
diagnostic_code: 9999 },
{ contention_text: 'acl tear in right knee',
contention_type: 'NEW' }
] }
)
end
Expand All @@ -49,6 +51,11 @@
'classification_name' => nil,
'diagnostic_code' => 9999,
'contention_type' => 'NEW'
},
{
'classification_code' => nil,
'classification_name' => nil,
'contention_type' => 'NEW'
}
]
)
Expand All @@ -70,6 +77,64 @@
end
end

describe '#classify_vagov_contentions_expanded' do
context 'when the expanded classification feature flag is enabled' do
subject do
client.classify_vagov_contentions_expanded(
{ claim_id: 366,
form526_submission_id: 366,
contentions: [
{ contention_text: 'Asthma bronchial',
contention_type: 'INCREASE',
diagnostic_code: 6602 },
{ contention_text: 'plantar fasciitis',
contention_type: 'NEW' },
{ contention_text: 'additional free text entry',
contention_type: 'NEW',
diagnostic_code: 9999 },
{ contention_text: 'acl tear in right knee',
contention_type: 'NEW' }
] }
)
end

it 'returns a classification and logs monitor metric' do
VCR.use_cassette('virtual_regional_office/expanded_classification') do
expect(subject.body['contentions']).to eq(
[
{ 'classification_code' => 9012,
'classification_name' => 'Respiratory',
'diagnostic_code' => 6602,
'contention_type' => 'INCREASE' },
{
'classification_code' => 8994,
'classification_name' => 'Musculoskeletal - Foot',
'diagnostic_code' => nil,
'contention_type' => 'NEW'

},
{
'classification_code' => nil,
'classification_name' => nil,
'diagnostic_code' => 9999,
'contention_type' => 'NEW'
},
{
'classification_code' => 8997,
'classification_name' => 'Musculoskeletal - Knee',
'contention_type' => 'NEW'
}
]
)
expect(StatsD).not_to have_received(:increment).with(
'api.vro.classify_vagov_contentions_expanded.fail', anything
)
expect(StatsD).to have_received(:increment).with('api.vro.classify_vagov_contentions_expanded.total')
end
end
end
end

describe '#get_max_rating_for_diagnostic_codes' do
context 'whe the request is successful' do
subject { client.get_max_rating_for_diagnostic_codes(diagnostic_codes: [6260]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rails_helper'
require 'disability_compensation/factories/api_provider_factory'
require 'virtual_regional_office/client'

# pulled from vets-api/spec/support/disability_compensation_form/submissions/only_526.json
ONLY_526_JSON_CLASSIFICATION_CODE = 'string'
Expand All @@ -14,6 +15,7 @@
Flipper.disable(:disability_compensation_lighthouse_claims_service_provider)
Flipper.disable(:disability_compensation_production_tester)
Flipper.disable(:disability_compensation_fail_submission)
Flipper.disable(:disability_526_expanded_contention_classification)
end

let(:user) { FactoryBot.create(:user, :loa3) }
Expand Down Expand Up @@ -317,15 +319,59 @@ def expect_non_retryable_error
submission.reload

classification_codes = submission.form['form526']['form526']['disabilities'].pluck('classificationCode')
expect(classification_codes).to eq([9012, 8994, nil])
expect(classification_codes).to eq([9012, 8994, nil, nil])
end

it 'calls va-gov-claim-classifier' do
it 'calls va-gov-claim-classifier as default' do
vro_client_mock = instance_double(VirtualRegionalOffice::Client)
allow(VirtualRegionalOffice::Client).to receive(:new).and_return(vro_client_mock)
allow(vro_client_mock).to receive_messages(
classify_vagov_contentions_expanded: OpenStruct.new(body: 'expanded classification'),
classify_vagov_contentions: OpenStruct.new(body: 'regular response')
)

expect_any_instance_of(Form526Submission).to receive(:classify_vagov_contentions).and_call_original
expect(vro_client_mock).to receive(:classify_vagov_contentions)
subject.perform_async(submission.id)
expect_any_instance_of(Form526Submission).to receive(:classify_vagov_contentions)
described_class.drain
end

context 'when the expanded classification endpoint is enabled' do
before do
user = OpenStruct.new({ flipper_id: submission.user_uuid })
allow(Flipper).to receive(:enabled?).and_call_original
allow(Flipper).to receive(:enabled?).with(:disability_526_expanded_contention_classification,
user).and_return(true)
end

it 'calls the expanded classification endpoint' do
vro_client_mock = instance_double(VirtualRegionalOffice::Client)
allow(VirtualRegionalOffice::Client).to receive(:new).and_return(vro_client_mock)
allow(vro_client_mock).to receive_messages(
classify_vagov_contentions_expanded: OpenStruct.new(body: 'expanded classification'),
classify_vagov_contentions: OpenStruct.new(body: 'regular response')
)

expect_any_instance_of(Form526Submission).to receive(:classify_vagov_contentions).and_call_original
expect(vro_client_mock).to receive(:classify_vagov_contentions_expanded)
subject.perform_async(submission.id)
described_class.drain
end

it 'uses expanded classification to classify contentions' do
subject.perform_async(submission.id)
expect do
VCR.use_cassette('virtual_regional_office/expanded_classification') do
described_class.drain
end
end.not_to change(Sidekiq::Form526BackupSubmissionProcess::Submit.jobs, :size)
submission.reload

classification_codes = submission.form['form526']['form526']['disabilities'].pluck('classificationCode')
expect(classification_codes).to eq([9012, 8994, nil, 8997])
end
end

context 'when the disabilities array is empty' do
before do
allow(Rails.logger).to receive(:info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
"ratedDisabilityId": null,
"diagnosticCode": 9999,
"secondaryDisabilities": []
},
{
"name": "acl tear in right knee",
"classificationCode": null,
"disabilityActionType": "NEW",
"ratedDisabilityId": null,
"diagnosticCode": null,
"secondaryDisabilities": []
}
],
"treatments": [
Expand Down Expand Up @@ -143,5 +151,4 @@
"form0781": null,
"form8940": null,
"flashes": []
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 486286a

Please sign in to comment.