From 15390eca09d7adb62d7b8fbbf5de8de1b062e666 Mon Sep 17 00:00:00 2001 From: AJ Magdub Date: Wed, 7 Jun 2023 12:40:17 -0600 Subject: [PATCH] feat(vaos): add get_clinics method to batch retrieve clinic details (#12926) --- .../vaos/v2/mobile_facility_service.rb | 39 ++++++++++++- .../v2/mobile_facility_service_spec.rb | 54 +++++++++++++++++- .../get_clinics_200.yml | 57 +++++++++++++++++++ 3 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 spec/support/vcr_cassettes/vaos/v2/mobile_facility_service/get_clinics_200.yml diff --git a/modules/vaos/app/services/vaos/v2/mobile_facility_service.rb b/modules/vaos/app/services/vaos/v2/mobile_facility_service.rb index 18829fcd370..9be9d6c2a01 100644 --- a/modules/vaos/app/services/vaos/v2/mobile_facility_service.rb +++ b/modules/vaos/app/services/vaos/v2/mobile_facility_service.rb @@ -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 @@ -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] - 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. @@ -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: { @@ -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 diff --git a/modules/vaos/spec/services/v2/mobile_facility_service_spec.rb b/modules/vaos/spec/services/v2/mobile_facility_service_spec.rb index 757cc9eef8a..4050df48761 100644 --- a/modules/vaos/spec/services/v2/mobile_facility_service_spec.rb +++ b/modules/vaos/spec/services/v2/mobile_facility_service_spec.rb @@ -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 @@ -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 diff --git a/spec/support/vcr_cassettes/vaos/v2/mobile_facility_service/get_clinics_200.yml b/spec/support/vcr_cassettes/vaos/v2/mobile_facility_service/get_clinics_200.yml new file mode 100644 index 00000000000..7d3783588cc --- /dev/null +++ b/spec/support/vcr_cassettes/vaos/v2/mobile_facility_service/get_clinics_200.yml @@ -0,0 +1,57 @@ +--- +http_interactions: +- request: + method: get + uri: https://veteran.apps.va.gov/vaos/v1/locations/983/clinics?clinicIds=455,16 + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - Vets.gov Agent + Referer: + - https://review-instance.va.gov + X-Vamf-Jwt: + - stubbed_token + X-Request-Id: + - '' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Wed, 07 Jun 2023 15:08:03 GMT + Content-Type: + - application/json + Content-Length: + - '626' + Server: + - openresty + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Headers: + - x-vamf-jwt + Access-Control-Allow-Methods: + - GET,OPTIONS + Access-Control-Max-Age: + - '3600' + X-Envoy-Upstream-Service-Time: + - '7' + Strict-Transport-Security: + - max-age=16000000; includeSubDomains; preload; + body: + encoding: UTF-8 + string: '{"data":[{"vistaSite":983,"id":"16","serviceName":"CHY LAB OUTPATIENT","stationId":"983","stationName":"CHYSHR-Cheyenne + VA Medical Center","primaryStopCode":674,"primaryStopCodeName":"ADMIN PAT + ACTIVTIES (MASNONCT)","secondaryStopCode":108,"secondaryStopCodeName":"LABORATORY","futureBookingMaximumDays":365},{"vistaSite":983,"id":"455","serviceName":"CHY + PC CASSIDY","stationId":"983","stationName":"CHYSHR-Cheyenne VA Medical Center","primaryStopCode":323,"primaryStopCodeName":"PRIMARY + CARE/MEDICINE","secondaryStopCodeName":"*Missing*","patientDirectScheduling":true,"patientDisplay":true,"futureBookingMaximumDays":365}]}' + recorded_at: Wed, 07 Jun 2023 15:08:03 GMT +recorded_with: VCR 6.1.0