Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get claims by date endpoint, add appt > claim association logic #18868

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

module TravelPay
class ClaimAssociationService
## @params
# appointments: [VAOS::Appointment]
# start_date: string ('2024-01-01T12:45:00Z')
# end_date: string ('2024-02-01T12:45:00Z')
#
# @returns
# appointments: [VAOS::Appointment + associatedTravelPayClaim (string)]

def associate_appointments_to_claims(params = {})
# We need to associate an existing claim to a VAOS appointment, matching on date-time & facility
#
# So there will be a 1:1 claimID > appt association
#
# Will return a new array:
#
# VAOS::Appointment
# + if date-time & facility match
# associatedTravelPayClaim => claimId (string)

appointments = []
# Get claims for the specified date range
raw_claims = service.get_claims_by_date_range(
{ 'start_date' => params['start_date'],
'end_date' => params['end_date'] }
)

# TODO: figure out how to append an error message to appt if claims call fails

# map over the appointments list and the raw_claims and match dates
params['appointments']['data'].each do |appt|
raw_claims[:data].each do |cl|
# Match the exact date-time of the appointment
if !cl['appointmentDateTime'].nil? &&
(DateTime.parse(cl['appointmentDateTime']).to_s == DateTime.parse(appt['start']).to_s)

# match the facility
# cl['facilityName'] == appt['facilityName']
# Add the new attribute "associatedTravelPayClaim" => claim ID to the appt hash
appt['associatedTravelPayClaim'] = cl
break
else
# if no claims match, append.... something?
appt['associatedTravelPayClaim'] = {
'metadata' => 'No claim found for this appointment' # Appt team requested a string to this effect, actual string TBD

Check failure on line 48 in modules/travel_pay/app/services/travel_pay/claim_association_service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineLength: Line is too long. [130/120]
}
end
end
appointments.push(appt)
end
appointments
end

private

def service
auth_manager = TravelPay::AuthManager.new(Settings.travel_pay.client_number, @current_user)
TravelPay::ClaimsService.new(auth_manager)
end
end
end
31 changes: 31 additions & 0 deletions modules/travel_pay/app/services/travel_pay/claims_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ def get_claims(veis_token, btsss_token)
end
end

##
# HTTP GET call to the BTSSS 'claims/search-by-appointment-date' endpoint
# API responds with travel pay claims including status for the specified date-range
#
# @params {
# startDate: string ('2024-01-01T12:45:34.465Z') (Required)
# endDate: string ('2024-01-01T12:45:34.465Z') (Required)
# pageNumber: int
# pageSize: int
# sortField: string
# sortDirection: string
# }
# @return [TravelPay::Claim]
#
def get_claims_by_date(veis_token, btsss_token, params = {})
btsss_url = Settings.travel_pay.base_url
correlation_id = SecureRandom.uuid
Rails.logger.debug(message: 'Correlation ID', correlation_id:)

url_params = params.transform_keys { |k| k.to_s.camelize(:lower) }

connection(server_url: btsss_url)
# URL subject to change once v1.2 is available (proposed endpoint: '/search')
.get("/api/v1.1/claims/search-by-appointment-date?#{url_params.to_query}") do |req|
req.headers['Authorization'] = "Bearer #{veis_token}"
req.headers['BTSSS-Access-Token'] = btsss_token
req.headers['X-Correlation-ID'] = correlation_id
req.headers.merge!(claim_headers)
end
end

##
# HTTP POST call to the BTSSS 'claims' endpoint
# API responds with a new travel pay claim ID
Expand Down
25 changes: 25 additions & 0 deletions modules/travel_pay/app/services/travel_pay/claims_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ def get_claims(params = {})
}
end

def get_claims_by_date_range(params = {})
if params['start_date'] && params['end_date']
DateTime.parse(params['start_date'].to_s) && DateTime.parse(params['end_date'].to_s)
else
raise ArgumentError,
message: "Both start and end dates are required, got #{params['start_date']}-#{params['end_date']}."
end

@auth_manager.authorize => { veis_token:, btsss_token: }
faraday_response = client.get_claims_by_date(veis_token, btsss_token, params)
raw_claims = faraday_response.body['data'].deep_dup

{
data: raw_claims.map do |sc|
sc['claimStatus'] = sc['claimStatus'].underscore.titleize
sc
end
}
rescue Date::Error => e
Rails.logger.debug(message:
"#{e}. Invalid date(s) provided (given: #{params['start_date']} & #{params['end_date']}).")
raise ArgumentError,
message: "#{e}. Invalid date(s) provided (given: #{params['start_date']} & #{params['end_date']})."
end

def get_claim_by_id(claim_id)
# ensure claim ID is the right format, allowing any version
uuid_all_version_format = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[89ABCD][0-9A-F]{3}-[0-9A-F]{12}$/i
Expand Down
Loading
Loading