Skip to content

Commit

Permalink
VAOS Appointment Service Category Logging (#11869)
Browse files Browse the repository at this point in the history
*service category logging
  • Loading branch information
cferris32 authored Feb 24, 2023
1 parent 95e5c23 commit 275e8e0
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 2 deletions.
19 changes: 19 additions & 0 deletions modules/vaos/app/services/vaos/v2/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module VAOS
module V2
class AppointmentsService < VAOS::SessionService
DIRECT_SCHEDULE_ERROR_KEY = 'DirectScheduleError'
VAOS_SERVICE_CATEGORY_KEY = 'VAOSServiceCategory'

def get_appointments(start_date, end_date, statuses = nil, pagination_params = {})
params = date_params(start_date, end_date)
Expand All @@ -17,6 +18,9 @@ def get_appointments(start_date, end_date, statuses = nil, pagination_params = {

with_monitoring do
response = perform(:get, appointments_base_url, params, headers)
response.body[:data].each do |appt|
process_service_category(appt)
end
{
data: deserialized_appointments(response.body[:data]),
meta: pagination(pagination_params).merge(partial_errors(response))
Expand All @@ -37,6 +41,7 @@ def post_appointment(request_object_body)
params.compact_blank!
with_monitoring do
response = perform(:post, appointments_base_url, params, headers)
process_service_category(response.body)
OpenStruct.new(response.body)
rescue Common::Exceptions::BackendServiceException => e
log_direct_schedule_submission_errors(e) if params[:status] == 'booked'
Expand Down Expand Up @@ -67,6 +72,20 @@ def ds_error_details(e)
}
end

def process_service_category(appt)
appt[:service_category]&.each do |category_el|
category_el&.[](:coding)&.each do |coding_el|
service_category_data = coding_el&.[](:code)
log_service_category(service_category_data)
end
end
end

def log_service_category(service_category_data)
service_category_log_entry = { VAOS_SERVICE_CATEGORY_KEY => service_category_data }
Rails.logger.info('VAOS appointment service category', service_category_log_entry.to_json)
end

def deserialized_appointments(appointment_list)
return [] unless appointment_list

Expand Down
17 changes: 16 additions & 1 deletion modules/vaos/spec/services/v2/appointment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
let(:end_date) { Time.zone.parse('2022-07-03T04:00:00.000Z') }
let(:start_date2) { Time.zone.parse('2022-01-01T19:25:00Z') }
let(:end_date2) { Time.zone.parse('2022-12-01T19:45:00Z') }
let(:start_date3) { Time.zone.parse('2022-04-01T19:25:00Z') }
let(:end_date3) { Time.zone.parse('2023-03-01T19:45:00Z') }
let(:id) { '202006031600983000030800000000000000' }
let(:appointment_id) { 123 }

Expand Down Expand Up @@ -38,8 +40,11 @@
it 'returns the created appointment - va - booked' do
VCR.use_cassette('vaos/v2/appointments/post_appointments_va_booked_200_JACQUELINE_M',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(Rails.logger).to have_received(:info).with('VAOS appointment service category',
any_args).at_least(:once)
end
end

Expand All @@ -52,7 +57,6 @@
end
end

# TODO: Verify CC request details
context 'when cc appointment create request is valid' do
it 'returns the created appointment - cc - proposed' do
VCR.use_cassette('vaos/v2/appointments/post_appointments_cc_200_2222022',
Expand Down Expand Up @@ -106,6 +110,17 @@
expect(response[:data].size).to eq(395)
end
end

it 'logs the service categories of the returned appointments' do
VCR.use_cassette('vaos/v2/appointments/get_appointments_200_and_log_service_category',
match_requests_on: %i[method path query], tag: :force_utf8) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.get_appointments(start_date3, end_date3)
expect(response[:data].size).to eq(163)
expect(Rails.logger).to have_received(:info).with('VAOS appointment service category',
any_args).at_least(:once)
end
end
end

context 'when requesting a list of appointments given a date range and single status' do
Expand Down
Loading

0 comments on commit 275e8e0

Please sign in to comment.