Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements new endpoint behind feature flag #19445

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/concerns/form526_claim_fast_tracking_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ 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
if Flipper.enabled?(:disability_526_expanded_contention_classification, user)
response = vro_client.classify_vagov_contentions_expanded(params)
return response.body
end
response = vro_client.classify_vagov_contentions(params)
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 @@ -1645,6 +1645,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,61 @@ 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 })
Flipper.enable(:disability_526_expanded_contention_classification, user)
end

after do
Flipper.disable(:disability_526_expanded_contention_classification)
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.

Loading