Skip to content

Commit

Permalink
79218 - Patient eligibility using VPG (#16173)
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-mccurdy authored Apr 10, 2024
1 parent 6c31e04 commit 4cbae8c
Show file tree
Hide file tree
Showing 13 changed files with 615 additions and 34 deletions.
12 changes: 6 additions & 6 deletions modules/mobile/spec/request/facility_eligibility_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
end

before do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_facility_102',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_facility_102',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_facility_103',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_facility_103',
match_requests_on: %i[method uri]) do
get '/mobile/v0/appointments/facility/eligibility', params:, headers: sis_headers
end
Expand Down Expand Up @@ -54,11 +54,11 @@
end

before do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_facility_100',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_facility_100',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_facility_101',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_facility_101',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_facility_102',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_facility_102',
match_requests_on: %i[method uri]) do
get '/mobile/v0/appointments/facility/eligibility', params:, headers: sis_headers
end
Expand Down Expand Up @@ -109,7 +109,7 @@
end

before do
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_bad_facility',
VCR.use_cassette('mobile/facility_eligibility/get_patient_appointment_metadata_vpg_bad_facility',
match_requests_on: %i[method uri]) do
get '/mobile/v0/appointments/facility/eligibility', params:, headers: sis_headers
end
Expand Down
30 changes: 23 additions & 7 deletions modules/vaos/app/services/vaos/v2/patients_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@ module VAOS
module V2
class PatientsService < VAOS::SessionService
def get_patient_appointment_metadata(clinic_service_id, facility_id, type)
with_monitoring do
response = if Flipper.enabled?(:va_online_scheduling_use_vpg) &&
Flipper.enabled?(:va_online_scheduling_enable_OH_eligibility)
get_patient_appointment_metadata_vpg(clinic_service_id, facility_id, type)
else
get_patient_appointment_metadata_vaos(clinic_service_id, facility_id, type)
end

OpenStruct.new(response.body.merge(id: SecureRandom.hex(2)))
end
end

private

def get_patient_appointment_metadata_vaos(clinic_service_id, facility_id, type)
params = {
clinicalServiceId: clinic_service_id,
facilityId: facility_id,
type:
}

with_monitoring do
response = perform(:get, url, params, headers)
OpenStruct.new(response.body.merge(id: SecureRandom.hex(2)))
end
perform(:get, "/vaos/v1/patients/#{user.icn}/eligibility", params, headers)
end

private
def get_patient_appointment_metadata_vpg(clinic_service_id, facility_id, type)
params = {
clinicalService: clinic_service_id,
location: facility_id,
type:
}

def url
"/vaos/v1/patients/#{user.icn}/eligibility"
perform(:get, "/vpg/v1/patients/#{user.icn}/eligibility", params, headers)
end
end
end
Expand Down
45 changes: 36 additions & 9 deletions modules/vaos/spec/request/v2/patients_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,42 @@
describe 'GET patient' do
let(:params) { { clinical_service_id: 'primaryCare', facility_id: '100', type: 'direct' } }

context 'patient appointment meta data' do
it 'successfully returns patient appointment metadata' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata',
match_requests_on: %i[method path query]) do
get '/vaos/v2/eligibility', params:, headers: inflection_header
expect(response).to have_http_status(:ok)
attributes = JSON.parse(response.body)['data']['attributes']
expect(attributes['eligible']).to be(false)
expect(response.body).to match_camelized_schema('vaos/v2/patient_appointment_metadata', { strict: false })
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_eligibility)
end

context 'patient appointment meta data' do
it 'successfully returns patient appointment metadata' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_vaos',
match_requests_on: %i[method path query]) do
get '/vaos/v2/eligibility', params:, headers: inflection_header
expect(response).to have_http_status(:ok)
attributes = JSON.parse(response.body)['data']['attributes']
expect(attributes['eligible']).to be(false)
expect(response.body).to match_camelized_schema('vaos/v2/patient_appointment_metadata', { strict: false })
end
end
end
end

context 'using VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_eligibility)
end

context 'patient appointment meta data' do
it 'successfully returns patient appointment metadata' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_vpg',
match_requests_on: %i[method path query]) do
get '/vaos/v2/eligibility', params:, headers: inflection_header
expect(response).to have_http_status(:ok)
attributes = JSON.parse(response.body)['data']['attributes']
expect(attributes['eligible']).to be(false)
expect(response.body).to match_camelized_schema('vaos/v2/patient_appointment_metadata', { strict: false })
end
end
end
end
Expand Down
71 changes: 59 additions & 12 deletions modules/vaos/spec/services/v2/patients_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,71 @@

describe '#index' do
context 'with an patient' do
it 'returns a patient' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata',
match_requests_on: %i[method path query]) do
response = subject.get_patient_appointment_metadata('primaryCare', '100', 'direct')
expect(response[:eligible]).to eq(false)
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_eligibility)
end

it 'returns a patient' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_vaos',
match_requests_on: %i[method path query]) do
response = subject.get_patient_appointment_metadata('primaryCare', '100', 'direct')
expect(response[:eligible]).to eq(false)

expect(response[:ineligibility_reasons][0][:coding][0][:code]).to eq('facility-cs-direct-disabled')
end
end
end

context 'using VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_eligibility)
end

it 'returns a patient' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_vpg',
match_requests_on: %i[method path query]) do
response = subject.get_patient_appointment_metadata('primaryCare', '100', 'direct')
expect(response[:eligible]).to eq(false)

expect(response[:ineligibility_reasons][0][:coding][0][:code]).to eq('facility-cs-direct-disabled')
expect(response[:ineligibility_reasons][0][:coding][0][:code]).to eq('facility-cs-direct-disabled')
end
end
end
end

context 'when the upstream server returns a 500' do
it 'raises a backend exception' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_500',
match_requests_on: %i[method path query]) do
expect { subject.get_patient_appointment_metadata('primaryCare', '100', 'direct') }.to raise_error(
Common::Exceptions::BackendServiceException
)
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_eligibility)
end

it 'raises a backend exception' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_500_vaos',
match_requests_on: %i[method path query]) do
expect { subject.get_patient_appointment_metadata('primaryCare', '100', 'direct') }.to raise_error(
Common::Exceptions::BackendServiceException
)
end
end
end

context 'using VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_eligibility)
end

it 'raises a backend exception' do
VCR.use_cassette('vaos/v2/patients/get_patient_appointment_metadata_500_vpg',
match_requests_on: %i[method path query]) do
expect { subject.get_patient_appointment_metadata('primaryCare', '100', 'direct') }.to raise_error(
Common::Exceptions::BackendServiceException
)
end
end
end
end
Expand Down

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

0 comments on commit 4cbae8c

Please sign in to comment.