From a40b2acc7ce22a3af8f9986541acd893dfb30a32 Mon Sep 17 00:00:00 2001 From: lihan li Date: Mon, 24 Apr 2023 16:26:08 +0700 Subject: [PATCH] Migrate 1010ez disability rating code to BGS (#12442) * remove prefill compensation type * find rating data method * add rating info method to hca controller * convert disability rating to integer * add swagger * lint --- .../v0/health_care_applications_controller.rb | 15 +- app/models/health_care_application.rb | 17 -- app/serializers/hca_rating_info_serializer.rb | 13 ++ .../requests/health_care_applications.rb | 26 +++ config/routes.rb | 1 + lib/bgs/service.rb | 4 + spec/lib/bgs/service_spec.rb | 11 + spec/models/health_care_application_spec.rb | 47 ----- .../health_care_applications_request_spec.rb | 18 ++ spec/requests/swagger_spec.rb | 15 ++ .../bgs/service/find_rating_data.yml | 193 ++++++++++++++++++ 11 files changed, 295 insertions(+), 65 deletions(-) create mode 100644 app/serializers/hca_rating_info_serializer.rb create mode 100644 spec/support/vcr_cassettes/bgs/service/find_rating_data.yml diff --git a/app/controllers/v0/health_care_applications_controller.rb b/app/controllers/v0/health_care_applications_controller.rb index 639055ad5ab..98b2296b32f 100644 --- a/app/controllers/v0/health_care_applications_controller.rb +++ b/app/controllers/v0/health_care_applications_controller.rb @@ -1,16 +1,29 @@ # frozen_string_literal: true require 'hca/service' +require 'bgs/service' module V0 class HealthCareApplicationsController < ApplicationController FORM_ID = '1010ez' - skip_before_action(:authenticate) + skip_before_action(:authenticate, only: %i[create show enrollment_status healthcheck]) before_action :record_submission_attempt, only: :create before_action :load_user, only: %i[create enrollment_status] + def rating_info + service = BGS::Service.new(current_user) + disability_rating = service.find_rating_data[:disability_rating_record][:service_connected_combined_degree] + + render( + json: { + user_percent_of_disability: disability_rating + }, + serializer: HCARatingInfoSerializer + ) + end + def create @health_care_application.async_compatible = params[:async_all] @health_care_application.google_analytics_client_id = params[:ga_client_id] diff --git a/app/models/health_care_application.rb b/app/models/health_care_application.rb index 085c33fa7e2..42f4d359aba 100644 --- a/app/models/health_care_application.rb +++ b/app/models/health_care_application.rb @@ -203,21 +203,6 @@ def long_form_required_fields end end - def prefill_compensation_type - auth_headers = EVSS::DisabilityCompensationAuthHeaders.new(user).add_headers(EVSS::AuthHeaders.new(user).to_h) - rating_info_service = EVSS::CommonService.new(auth_headers) - response = rating_info_service.get_rating_info - - return if response.user_percent_of_disability.nil? - - Raven.extra_context(disability_rating: response.user_percent_of_disability) - - parsed_form['vaCompensationType'] = 'highDisability' if response.user_percent_of_disability >= DISABILITY_THRESHOLD - rescue => e - Raven.extra_context(disability_rating: 'error') - log_exception_to_sentry(e) - end - def prefill_fields return if user.blank? || !user.loa3? @@ -226,8 +211,6 @@ def prefill_fields 'veteranDateOfBirth' => user.birth_date, 'veteranSocialSecurityNumber' => user.ssn_normalized }.compact) - - prefill_compensation_type end def submit_async(has_email) diff --git a/app/serializers/hca_rating_info_serializer.rb b/app/serializers/hca_rating_info_serializer.rb new file mode 100644 index 00000000000..2ce0c37f810 --- /dev/null +++ b/app/serializers/hca_rating_info_serializer.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class HCARatingInfoSerializer < ActiveModel::Serializer + attribute :user_percent_of_disability + + def user_percent_of_disability + object[:user_percent_of_disability].to_i + end + + def id + nil + end +end diff --git a/app/swagger/swagger/requests/health_care_applications.rb b/app/swagger/swagger/requests/health_care_applications.rb index 7cd55484ccb..5d0f357d04b 100644 --- a/app/swagger/swagger/requests/health_care_applications.rb +++ b/app/swagger/swagger/requests/health_care_applications.rb @@ -7,6 +7,32 @@ module Requests class HealthCareApplications include Swagger::Blocks + swagger_path '/v0/health_care_applications/rating_info' do + operation :get do + key :description, 'Get the user\'s service connected disability rating' + key :operationId, 'getDisabilityRating' + key :tags, %w[benefits_forms] + + response 200 do + key :description, 'disability rating response' + + schema do + property :data, type: :object do + key :required, %i[attributes] + property :id, type: :string + property :type, type: :string + + property :attributes, type: :object do + key :required, %i[user_percent_of_disability] + + property :user_percent_of_disability, type: :integer + end + end + end + end + end + end + swagger_path '/v0/health_care_applications/{id}' do operation :get do key :description, 'Show the status of a health care application' diff --git a/config/routes.rb b/config/routes.rb index aef35d98e09..24ec5c9a92e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,6 +99,7 @@ collection do get(:healthcheck) get(:enrollment_status) + get(:rating_info) end end diff --git a/lib/bgs/service.rb b/lib/bgs/service.rb index 690578d2dfe..03efc5f8a7a 100644 --- a/lib/bgs/service.rb +++ b/lib/bgs/service.rb @@ -38,6 +38,10 @@ def create_proc(proc_state: 'Started') end end + def find_rating_data + service.rating.find_rating_data(@user.ssn) + end + def create_proc_form(vnp_proc_id, form_type_code) # Temporary log proc_id to sentry log_message_to_sentry(vnp_proc_id, :warn, '', { team: 'vfs-ebenefits' }) diff --git a/spec/lib/bgs/service_spec.rb b/spec/lib/bgs/service_spec.rb index ae1a16db49e..43cd27c39c6 100644 --- a/spec/lib/bgs/service_spec.rb +++ b/spec/lib/bgs/service_spec.rb @@ -10,6 +10,17 @@ let(:participant_id) { '149456' } let(:first_name) { 'abraham.lincoln@vets.gov' } + describe '#find_rating_data' do + let(:user_object) { build(:ch33_dd_user) } + + it 'gets the users disability rating data' do + VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do + response = bgs_service.find_rating_data + expect(response[:disability_rating_record][:service_connected_combined_degree]).to eq('100') + end + end + end + context 'direct deposit methods' do let(:user_object) { build(:ch33_dd_user, first_name:) } diff --git a/spec/models/health_care_application_spec.rb b/spec/models/health_care_application_spec.rb index 259d7023b05..6125e37bce5 100644 --- a/spec/models/health_care_application_spec.rb +++ b/spec/models/health_care_application_spec.rb @@ -7,50 +7,7 @@ let(:inelig_character_of_discharge) { HCA::EnrollmentEligibility::Constants::INELIG_CHARACTER_OF_DISCHARGE } let(:login_required) { HCA::EnrollmentEligibility::Constants::LOGIN_REQUIRED } - describe '#prefill_compensation_type' do - before do - health_care_application.user = FactoryBot.build(:evss_user) - allow(Raven).to receive(:extra_context) - end - - it 'prefills compensation type' do - VCR.use_cassette('evss/disability_compensation_form/rating_info_with_disability') do - expect(Raven).to receive(:extra_context).with(disability_rating: 100) - health_care_application.send(:prefill_compensation_type) - expect(health_care_application.parsed_form['vaCompensationType']).to eq('highDisability') - end - end - - context 'when disability_rating is nil' do - it 'does nothing' do - expect_any_instance_of(EVSS::CommonService).to receive( - :get_rating_info - ).and_return(OpenStruct.new(user_percent_of_disability: nil)) - - expect(health_care_application).not_to receive(:log_exception_to_sentry) - - health_care_application.send(:prefill_compensation_type) - - expect(health_care_application.parsed_form['vaCompensationType']).to eq(nil) - end - end - - context 'with an error' do - it 'logs to sentry and doesnt raise the error' do - expect(health_care_application).to receive(:log_exception_to_sentry) - expect(Raven).to receive(:extra_context).with(disability_rating: 'error') - - health_care_application.send(:prefill_compensation_type) - expect(health_care_application.parsed_form['vaCompensationType']).to eq(nil) - end - end - end - describe '#prefill_fields' do - before do - allow(health_care_application).to receive(:prefill_compensation_type) - end - let(:health_care_application) { build(:health_care_application) } context 'with missing fields' do @@ -93,8 +50,6 @@ end it 'doesnt set a field if the user data is null' do - expect(health_care_application).to receive(:prefill_compensation_type) - health_care_application.send(:prefill_fields) parsed_form = health_care_application.parsed_form @@ -104,8 +59,6 @@ end it 'sets uneditable fields using user data' do - expect(health_care_application).to receive(:prefill_compensation_type) - expect(health_care_application.valid?).to eq(false) health_care_application.send(:prefill_fields) expect(health_care_application.valid?).to eq(true) diff --git a/spec/requests/health_care_applications_request_spec.rb b/spec/requests/health_care_applications_request_spec.rb index 8f20e118980..5a75e2a3d41 100644 --- a/spec/requests/health_care_applications_request_spec.rb +++ b/spec/requests/health_care_applications_request_spec.rb @@ -12,6 +12,24 @@ ) end + describe 'GET rating_info' do + let(:current_user) { build(:ch33_dd_user) } + + before do + sign_in_as(current_user) + end + + it 'returns the users rating info' do + VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do + get(rating_info_v0_health_care_applications_path) + end + + expect(JSON.parse(response.body)['data']['attributes']).to eq( + { 'user_percent_of_disability' => 100 } + ) + end + end + describe 'GET healthcheck' do subject do get(healthcheck_v0_health_care_applications_path) diff --git a/spec/requests/swagger_spec.rb b/spec/requests/swagger_spec.rb index 6c614d4ad90..46498e0bc4a 100644 --- a/spec/requests/swagger_spec.rb +++ b/spec/requests/swagger_spec.rb @@ -755,6 +755,21 @@ json.delete('email') json.to_json end + let(:user) { build(:ch33_dd_user) } + let(:headers) do + { '_headers' => { 'Cookie' => sign_in(user, nil, true) } } + end + + it 'supports getting the disability rating' do + VCR.use_cassette('bgs/service/find_rating_data', VCR::MATCH_EVERYTHING) do + expect(subject).to validate( + :get, + '/v0/health_care_applications/rating_info', + 200, + headers + ) + end + end it 'supports getting the hca enrollment status' do expect(HealthCareApplication).to receive(:user_icn).and_return('123') diff --git a/spec/support/vcr_cassettes/bgs/service/find_rating_data.yml b/spec/support/vcr_cassettes/bgs/service/find_rating_data.yml new file mode 100644 index 00000000000..c39a5c22f9f --- /dev/null +++ b/spec/support/vcr_cassettes/bgs/service/find_rating_data.yml @@ -0,0 +1,193 @@ +--- +http_interactions: +- request: + method: get + uri: https://internal-dsva-vagov-dev-fwdproxy-1893365470.us-gov-west-1.elb.amazonaws.com:4447/RatingServiceBean/RatingService?WSDL + body: + encoding: US-ASCII + string: '' + headers: + Host: + - prepbepbenefits.vba.va.gov + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Sun, 16 Apr 2023 08:25:02 GMT + Server: + - Apache + X-Frame-Options: + - SAMEORIGIN + Transfer-Encoding: + - chunked + Content-Type: + - text/xml;charset=utf-8 + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: |- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + recorded_at: Sun, 16 Apr 2023 08:25:02 GMT +- request: + method: post + uri: https://internal-dsva-vagov-dev-fwdproxy-1893365470.us-gov-west-1.elb.amazonaws.com:4447/RatingServiceBean/RatingService + body: + encoding: UTF-8 + string: |- + + + VAgovAPI + + + 10.247.35.119 + 281 + VAgovAPI + 82836359962678900 + abraham lincoln Jr + + + 796104437 + headers: + Host: + - prepbepbenefits.vba.va.gov + Soapaction: + - '"findRatingData"' + Content-Type: + - text/xml;charset=UTF-8 + Content-Length: + - '993' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Sun, 16 Apr 2023 08:25:02 GMT + Server: + - Apache + X-Frame-Options: + - SAMEORIGIN + X-Oracle-Dms-Ecid: + - 36f1de07-0e57-4b5e-aeca-b5bb563ae797-000148e6 + X-Oracle-Dms-Rid: + - '0' + Transfer-Encoding: + - chunked + Content-Type: + - text/xml; charset=utf-8 + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: rO0ABXdTAB13ZWJsb2dpYy5hcHAuQ29ycG9yYXRlRGF0YUVBUgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTMuMy4wAAA=0SHAR + 9999Records found010120191231201810060102201901012005N100Hearing + Loss61006100-Hearing + loss12212018SVCCONNCTEDService + Connected1128271NPeacetime12212018N10mental + disorder9201Schizophrenia, + disorganized type12212018SVCCONNCTEDService + Connected112922812312018NPeacetime05012012Left + LowerN10Allergies + due to Hearing Loss5260Limitation + of flexion, knee12212018SVCCONNCTEDService + Connected1072414NVietnam + Era08012018N0Sarcoma + Soft-Tissue8540Soft + tissue sarcoma (neurogenic origin)12212018SVCCONNCTEDService + Connected1124345NVietnam + EraNTinnitus6260Tinnitus12212018NOTSVCCONNot + Service Connected1046370NTinnitusNDiabetes7913Diabetes + mellitus12212018NOTSVCCONNot + Service Connected1090859NTinnitusSHAR + 9999Records found1000SHAR + 9999Records found101012005AncillaryBasic + Eligibility under 38 USC Ch 3512212018SHAR + 9999Records found10SHAR + 9999Records found12212018134247K-1Entitled + to special monthly compensation under 38 U.S.C. 1114, subsection (k) and 38 + CFR 3.350(a) on + recorded_at: Sun, 16 Apr 2023 08:25:05 GMT +recorded_with: VCR 6.1.0