Skip to content

Commit

Permalink
update to return single appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
liztownd committed Sep 23, 2024
1 parent a9cb4fd commit e568e1a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
36 changes: 28 additions & 8 deletions modules/travel_pay/app/services/travel_pay/appointments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,49 @@

module TravelPay
class AppointmentsService
def get_appointments_by_date(veis_token, btsss_token, params = {})
##
# gets all appointments and finds the singular BTSSS appointment that matches the provided datetime
# @params: datetime string ('2024-01-01T12:45:34.465Z')
#
# @return {
# 'id' => 'string',
# 'appointmentSource' => 'string',
# 'appointmentDateTime' => 'string',
# 'appointmentName' => 'string',
# 'appointmentType' => 'string',
# 'facilityName' => 'string',
# 'serviceConnectedDisability' => int,
# 'currentStatus' => 'string',
# 'appointmentStatus' => 'string',
# 'externalAppointmentId' => 'string',
# 'associatedClaimId' => string,
# 'associatedClaimNumber' => string,
# 'isCompleted' => boolean,
# }
#
#
def get_appointment_by_date_time(veis_token, btsss_token, params = {})
faraday_response = client.get_all_appointments(veis_token, btsss_token, { 'excludeWithClaims' => true })
raw_appointments = faraday_response.body['data'].deep_dup

appointments = filter_by_date(params['appt_datetime'], raw_appointments)
appointment = find_by_date_time(params['appt_datetime'], raw_appointments)

{
data: appointments || []
data: appointment
}
end

private

def filter_by_date(date_string, appointments)
def find_by_date_time(date_string, appointments)
if date_string.present?

appointments.filter do |appointment|
appointment['appointmentDateTime'].nil? &&
date_string == appointment['appointmentDateTime']
appointments.find do |appt|
date_string == appt['appointmentDateTime']
end
end
rescue Date::Error => e
Rails.logger.debug(message: "#{e}. Unable to find appointments with date (given: #{date_string}).")
Rails.logger.debug(message: "#{e}. Unable to find appointment with provided date-time (given: #{date_string}).")
end

def client
Expand Down
29 changes: 15 additions & 14 deletions modules/travel_pay/spec/services/appointments_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

describe TravelPay::AppointmentsService do
context 'get_appointments_by_date' do
context 'get_appointment_by_date_time' do
let(:user) { build(:user) }
let(:appointments_data) do
{
Expand Down Expand Up @@ -56,7 +56,7 @@
{
'id' => 'uuid4',
'appointmentSource' => 'API',
'appointmentDateTime' => '2024-02-11T16:45:34.465Z',
'appointmentDateTime' => nil,
'appointmentName' => 'string',
'appointmentType' => 'EnvironmentalHealth',
'facilityName' => 'Cheyenne VA Medical Center',
Expand Down Expand Up @@ -86,28 +86,29 @@
.and_return(appointments_response)
end

context 'filter by appt date' do
it 'returns appointments that match appt date if specified' do
context 'find by appt date-time' do
it 'returns the BTSSS appointment that matches appt date' do
date_string = '2024-01-01T12:45:34.465Z'
service = TravelPay::AppointmentsService.new
appts = service.get_appointments_by_date(*tokens, { 'appt_datetime' => '2024-01-01T12:45:34.465Z' })
appt = service.get_appointment_by_date_time(*tokens, { 'appt_datetime' => date_string })

expect(appts.count).to equal(1)
expect(appt[:data]['appointmentDateTime']).to eq(date_string)
end

it 'returns 0 appointments if appt date does not match' do
it 'returns nil if appt date does not match' do
service = TravelPay::AppointmentsService.new
appts = service.get_appointments_by_date(*tokens, { 'appt_datetime' => '1700-01-01T12:45:34.465Z' })
appt = service.get_appointment_by_date_time(*tokens, { 'appt_datetime' => '1700-01-01T12:45:34.465Z' })

expect(appts[:data].count).to equal(0)
expect(appt[:data]).to equal(nil)
end

it 'returns 0 appointments if appt date is invalid' do
it 'returns nil if appt date is invalid' do
service = TravelPay::AppointmentsService.new
appts = service.get_appointments_by_date(*tokens, { 'appt_datetime' => 'banana' })
appts_empty_date = service.get_appointments_by_date(*tokens, { 'appt_datetime' => '' })
appt = service.get_appointment_by_date_time(*tokens, { 'appt_datetime' => 'banana' })
appt_empty_date = service.get_appointment_by_date_time(*tokens, { 'appt_datetime' => '' })

expect(appts[:data].count).to equal(0)
expect(appts_empty_date[:data].count).to equal(0)
expect(appt[:data]).to equal(nil)
expect(appt_empty_date[:data]).to equal(nil)
end
end
end
Expand Down

0 comments on commit e568e1a

Please sign in to comment.