Skip to content

Commit

Permalink
Create appointments using VPG (#16409)
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-mccurdy authored Apr 22, 2024
1 parent a9a4f7a commit bce3813
Show file tree
Hide file tree
Showing 16 changed files with 1,209 additions and 153 deletions.
188 changes: 153 additions & 35 deletions modules/mobile/spec/request/appointments_create_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,70 +61,188 @@
end

context 'when feature flag is on and user has access' do
it 'returns created' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:created)
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_requests)
end

it 'returns created' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:created)
end
end
end
end

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

it 'returns created' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M_vpg',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:created)
end
end
end
end
end
end

it 'clears the cache' do
expect(Mobile::V0::Appointment).to receive(:clear_cache).once
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_requests)
end

VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: va_proposed_request_body, headers: sis_headers
it 'clears the cache' do
expect(Mobile::V0::Appointment).to receive(:clear_cache).once

VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: va_proposed_request_body, headers: sis_headers
end
end

it 'returns a descriptive 400 error when given invalid params' do
VCR.use_cassette('mobile/appointments/post_appointments_400', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors'][0]['status']).to eq('400')
expect(JSON.parse(response.body)['errors'][0]['detail']).to eq(
'the patientIcn must match the ICN in the request URI'
)
end
end
end

it 'returns a descriptive 400 error when given invalid params' do
VCR.use_cassette('mobile/appointments/post_appointments_400', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors'][0]['status']).to eq('400')
expect(JSON.parse(response.body)['errors'][0]['detail']).to eq(
'the patientIcn must match the ICN in the request URI'
)
context 'using VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_requests)
end

it 'clears the cache' do
expect(Mobile::V0::Appointment).to receive(:clear_cache).once

VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200_vpg',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: va_proposed_request_body, headers: sis_headers
end
end

it 'returns a descriptive 400 error when given invalid params' do
VCR.use_cassette('mobile/appointments/post_appointments_400_vpg', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:bad_request)
expect(JSON.parse(response.body)['errors'][0]['status']).to eq('400')
expect(JSON.parse(response.body)['errors'][0]['detail']).to eq(
'the patientIcn must match the ICN in the request URI'
)
end
end
end

context 'for CC facility' do
it 'creates the cc appointment' do
VCR.use_cassette('mobile/appointments/post_appointments_cc_200_2222022', match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: community_cares_request_body, headers: sis_headers
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
context 'for VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_requests)
end

it 'creates the cc appointment' do
VCR.use_cassette('mobile/appointments/post_appointments_cc_200_2222022', match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: community_cares_request_body, headers: sis_headers
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end
end
end

context 'for VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_requests)
end

it 'creates the cc appointment' do
VCR.use_cassette('mobile/appointments/post_appointments_cc_200_2222022_vpg',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: community_cares_request_body, headers: sis_headers
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end
end
end
end

context 'for va facility' do
it 'creates the va appointment - proposed' do
VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
context 'using VAOS' do
before do
Flipper.disable(:va_online_scheduling_use_vpg)
Flipper.disable(:va_online_scheduling_enable_OH_requests)
end

it 'creates the va appointment - proposed' do
VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers

expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end

it 'creates the va appointment - booked' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end
end
end

it 'creates the va appointment - booked' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
context 'using VPG' do
before do
Flipper.enable(:va_online_scheduling_use_vpg)
Flipper.enable(:va_online_scheduling_enable_OH_requests)
end

it 'creates the va appointment - proposed' do
VCR.use_cassette('mobile/appointments/post_appointments_va_proposed_clinic_200_vpg',
match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers

expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end

it 'creates the va appointment - booked' do
VCR.use_cassette('mobile/appointments/post_appointments_va_booked_200_JACQUELINE_M_vpg',
match_requests_on: %i[method uri]) do
VCR.use_cassette('mobile/appointments/VAOS_v2/get_facilities_200', match_requests_on: %i[method uri]) do
post '/mobile/v0/appointment', params: {}, headers: sis_headers
expect(response).to have_http_status(:created)
expect(json_body_for(response)).to match_camelized_schema('vaos/v2/appointment', { strict: false })
end
end
end
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion modules/vaos/app/services/vaos/v2/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AppointmentsService < VAOS::SessionService
AVS_FLIPPER = :va_online_scheduling_after_visit_summary
ORACLE_HEALTH_CANCELLATIONS = :va_online_scheduling_enable_OH_cancellations
APPOINTMENTS_USE_VPG = :va_online_scheduling_use_vpg
APPOINTMENTS_ENABLE_OH_REQUESTS = :va_online_scheduling_enable_OH_requests

# rubocop:disable Metrics/MethodLength
def get_appointments(start_date, end_date, statuses = nil, pagination_params = {})
Expand Down Expand Up @@ -92,7 +93,12 @@ def post_appointment(request_object_body)
params = VAOS::V2::AppointmentForm.new(user, request_object_body).params.with_indifferent_access
params.compact_blank!
with_monitoring do
response = perform(:post, appointments_base_path, params, headers)
response = if Flipper.enabled?(APPOINTMENTS_USE_VPG, user) &&
Flipper.enabled?(APPOINTMENTS_ENABLE_OH_REQUESTS)
perform(:post, "/vpg/v1/patients/#{user.icn}/appointments", params, headers)
else
perform(:post, appointments_base_path, params, headers)
end
convert_appointment_time(response.body)
OpenStruct.new(response.body)
rescue Common::Exceptions::BackendServiceException => e
Expand Down
Loading

0 comments on commit bce3813

Please sign in to comment.