Skip to content

Commit

Permalink
feat(vaos): add get_clinics method to batch retrieve clinic details (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmagdub authored Jun 7, 2023
1 parent 1a3f708 commit 7aba5ed
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
39 changes: 37 additions & 2 deletions modules/vaos/app/services/vaos/v2/mobile_facility_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class MobileFacilityService < VAOS::SessionService
def get_clinic(station_id:, clinic_id:)
params = { clinicIds: clinic_id }
parent_site_id = station_id[0, 3]
clinic_path = "/vaos/v1/locations/#{parent_site_id}/clinics"
with_monitoring do
response = perform(:get, clinic_path, params, headers)
response = perform(:get, clinic_url(parent_site_id), params, headers)
OpenStruct.new(response[:body][:data]&.first) # only one clinic is returned
end
end
Expand All @@ -37,6 +36,34 @@ def get_clinic_with_cache(station_id:, clinic_id:)
end
end

# Get clinic details for a given station and clinic ids from the VAOS Service
#
# @param station_id [String] The id of the station to get clinic details for
# @param clinic_ids [Array] A list of clinic ids to get details for
#
# @return [Array<OpenStruct>] - An array of OpenStruct objects containing clinic details
#
# @raise [Common::Exceptions::PrameterMissing] if station_id or clinic_ids are not provided
#
# @example
# ids = %w[16, 455]
# station_id = '983'
# clinics = VAOS::V2::MobileFacilityService.new.get_clinics(station_id, ids)
# or
# clinics = VAOS::V2::MobileFacilityService.new(session: session).get_clinics(station_id, 16, 455)
#
def get_clinics(station_id, *clinic_ids)
raise Common::Exceptions::ParameterMissing, 'station_id' if station_id.blank?
raise Common::Exceptions::ParameterMissing, 'clinic_ids' if bad_arg?(clinic_ids)

params = { clinicIds: clinic_ids.join(',') }
parent_site_id = station_id[0, 3]
with_monitoring do
response = perform(:get, clinic_url(parent_site_id), params, headers)
response.body[:data]&.map { |clinic| OpenStruct.new(clinic) }
end
end

# Retrieves facilities based on the provided parameters from the Mobile Facility Service.
#
# @param ids [String] a required parameter that contains a comma-separated list of facility IDs.
Expand Down Expand Up @@ -134,6 +161,10 @@ def deserialized_facilities(facility_list)
facility_list.map { |facility| OpenStruct.new(facility) }
end

def bad_arg?(arg)
(arg.length == 1 && arg[0].blank?) || arg.length.zero?
end

def pagination(pagination_params)
{
pagination: {
Expand All @@ -153,6 +184,10 @@ def page_params(pagination_params)
end
end

def clinic_url(station_id)
"/vaos/v1/locations/#{station_id}/clinics"
end

def scheduling_url
'/facilities/v2/scheduling/configurations'
end
Expand Down
54 changes: 53 additions & 1 deletion modules/vaos/spec/services/v2/mobile_facility_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
end
end

it "calls '#get_clinic' retrieving information from MFS" do
it "calls '#get_clinic' retrieving information from VAOS Service" do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
# rubocop:disable RSpec/SubjectStub
Expand Down Expand Up @@ -202,6 +202,58 @@
end
end

describe '#get_clinics' do
context 'when no station_id is passed in' do
it 'raises ParameterMissing exception' do
expect { subject.get_clinics(nil, 455) }.to raise_error(Common::Exceptions::ParameterMissing)
end
end

context 'when no clinic_ids are passed in' do
it 'raises ParameterMissing exception' do
expect { subject.get_clinics(983, nil) }.to raise_error(Common::Exceptions::ParameterMissing)
expect { subject.get_clinics(983, []) }.to raise_error(Common::Exceptions::ParameterMissing)
expect { subject.get_clinics(983) }.to raise_error(Common::Exceptions::ParameterMissing)
end
end

context 'with a station id and single clinic id' do
it 'returns the clinic information as the only item in an array' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
clinic = subject.get_clinics('983', '455')
expect(clinic.length).to eq(1)
expect(clinic[0][:station_id]).to eq('983')
expect(clinic[0][:id]).to eq('455')
end
end
end

context 'with a station id and multiple clinic ids as an array' do
it 'returns an array with the information of all the clinics' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinics_200',
match_requests_on: %i[method path query]) do
clinics = subject.get_clinics('983', %w[455 16])
expect(clinics.length).to eq(2)
expect(clinics[0][:id]).to eq('16')
expect(clinics[1][:id]).to eq('455')
end
end
end

context 'with a station id and multiple clinic ids as individual arguments' do
it 'returns an array with the information of all the clinics' do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinics_200',
match_requests_on: %i[method path query]) do
clinic = subject.get_clinics('983', '455', '16')
expect(clinic.size).to eq(2)
expect(clinic[0][:id]).to eq('16')
expect(clinic[1][:id]).to eq('455')
end
end
end
end

describe '#get_facility' do
context 'with a valid request' do
it 'returns a facility' do
Expand Down

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

0 comments on commit 7aba5ed

Please sign in to comment.