Skip to content

Commit

Permalink
Merge branch 'master' into API-41368-remove-bgs-ext-okcomputer
Browse files Browse the repository at this point in the history
  • Loading branch information
mchristiansonVA authored Dec 2, 2024
2 parents da5c1c3 + 929ee51 commit 440f577
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 122 deletions.
32 changes: 16 additions & 16 deletions modules/claims_api/app/swagger/claims_api/v1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3045,7 +3045,7 @@
"example": "DOMESTIC"
},
"state": {
"description": "State Veteran resides in.",
"description": "State or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down Expand Up @@ -3197,7 +3197,7 @@
"type": "string"
},
"state": {
"description": "New state Veteran resides in.",
"description": "New state or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down Expand Up @@ -5303,7 +5303,7 @@
"example": "DOMESTIC"
},
"state": {
"description": "State Veteran resides in.",
"description": "State or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down Expand Up @@ -5455,7 +5455,7 @@
"type": "string"
},
"state": {
"description": "New state Veteran resides in.",
"description": "New state or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down Expand Up @@ -8953,14 +8953,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -9093,14 +9093,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -9229,14 +9229,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -10821,14 +10821,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -10961,14 +10961,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -11097,14 +11097,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down
12 changes: 6 additions & 6 deletions modules/claims_api/config/schemas/v1/2122.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -170,14 +170,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down Expand Up @@ -292,14 +292,14 @@
"example": "Portland"
},
"state": {
"description": "State for the address.",
"description": "State or province for the address.",
"type": "string",
"example": "OR"
},
"country": {
"description": "Country of the address.",
"type": "string",
"example": "USA"
"example": "US"
},
"zipFirstFive": {
"description": "Zipcode (First 5 digits) of the address.",
Expand Down
4 changes: 2 additions & 2 deletions modules/claims_api/config/schemas/v1/526.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"example": "DOMESTIC"
},
"state": {
"description": "State Veteran resides in.",
"description": "State or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down Expand Up @@ -250,7 +250,7 @@
"type": "string"
},
"state": {
"description": "New state Veteran resides in.",
"description": "New state or province Veteran resides in.",
"type": "string",
"pattern": "^[a-z,A-Z]{2}$",
"example": "OR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ClaimAssociationService
def initialize(user)
@user = user
end

# We need to associate an existing claim to a VAOS appointment, matching on date-time
#
# There will be a 1:1 claimID > appt association
Expand All @@ -16,7 +17,7 @@ def initialize(user)
# metadata => {
# status => int (http status code, i.e. 200)
# success => boolean
# message => string ('No claim for this appt' | 'Claim service is unavailable')
# message => string ('Data retrieved successfully' | 'Claim service is unavailable')
# }
# claim => TravelPay::Claim (if a claim matches)
# }
Expand All @@ -30,52 +31,79 @@ def initialize(user)
# appointments: [VAOS::Appointment + travelPayClaim]

def associate_appointments_to_claims(params = {})
raw_claims = service.get_claims_by_date_range(
{ 'start_date' => params['start_date'],
'end_date' => params['end_date'] }
)
if raw_claims
append_claims(params['appointments'], raw_claims[:data], raw_claims[:metadata])
else
append_error(params['appointments'], { 'status' => 503,
'success' => false,
'message' => 'Travel Pay service unavailable.' })
validate_date_params(params['start_date'], params['end_date'])

auth_manager.authorize => { veis_token:, btsss_token: }
faraday_response = client.get_claims_by_date(veis_token, btsss_token,
{ 'start_date' => params['start_date'],
'end_date' => params['end_date'] })

if faraday_response.status == 200
raw_claims = faraday_response.body['data'].deep_dup

data = raw_claims&.map do |sc|
sc['claimStatus'] = sc['claimStatus'].underscore.titleize
sc
end

append_claims(params['appointments'],
data,
build_metadata(faraday_response.body))

end
rescue => e
append_error(params['appointments'],
rescue_errors(e))
end

def associate_single_appointment_to_claim(params = {})
appt = params['appointment']
# Because we only receive a single date/time but the external endpoint requires 2 dates
# in this case both start and end dates are the same
validate_date_params(appt['start'], appt['start'])

raw_claim = service.get_claims_by_date_range(
{ 'start_date' => appt['start'],
'end_date' => appt['start'] }
)
if raw_claim
append_single_claim(appt, raw_claim)
else
appt['travelPayClaim'] = {
'metadata' => { 'status' => 503,
'success' => false,
'message' => 'Travel Pay service unavailable.' }
}
appt
end
auth_manager.authorize => { veis_token:, btsss_token: }
faraday_response = client.get_claims_by_date(veis_token, btsss_token,
{ 'start_date' => appt['start'], 'end_date' => appt['start'] })

claim_data = faraday_response.body['data']&.dig(0)
appt['travelPayClaim'] = {}
appt['travelPayClaim']['metadata'] = build_metadata(faraday_response.body)
appt['travelPayClaim']['claim'] = claim_data if claim_data

appt
rescue => e
appt['travelPayClaim'] = {
'metadata' => rescue_errors(e)
}
appt
end

private

def append_single_claim(appt, claim_response)
appt['travelPayClaim'] = if claim_response[:data].count
{
'metadata' => claim_response[:metadata],
'claim' => claim_response[:data][0]
}
else
{
'metadata' => claim_response[:metadata]
}
end
appt
def rescue_errors(e) # rubocop:disable Metrics/MethodLength
if e.is_a?(ArgumentError)
Rails.logger.error(message: e.message.to_s)
{
'status' => 400,
'message' => e.message.to_s,
'success' => false
}
elsif e.is_a?(Common::Exceptions::BackendServiceException)
Rails.logger.error(message: "#{e}, #{e.original_body}")
{
'status' => e.original_status,
'message' => e.original_body['message'],
'success' => false
}
else
Rails.logger.error(message: "An unknown error occured: #{e}")
{
'status' => 520, # Unknown error code
'message' => "An unknown error occured: #{e}",
'success' => false
}
end
end

def append_claims(appts, claims, metadata)
Expand Down Expand Up @@ -112,9 +140,30 @@ def append_error(appts, metadata)
appointments
end

def service
auth_manager = TravelPay::AuthManager.new(Settings.travel_pay.client_number, @user)
TravelPay::ClaimsService.new(auth_manager)
def build_metadata(faraday_response_body)
{ 'status' => faraday_response_body['statusCode'],
'success' => faraday_response_body['success'],
'message' => faraday_response_body['message'] }
end

def validate_date_params(start_date, end_date)
if start_date && end_date
DateTime.parse(start_date.to_s) && DateTime.parse(end_date.to_s)
else
raise ArgumentError,
message: "Both start and end dates are required, got #{start_date}-#{end_date}."
end
rescue Date::Error => e
raise ArgumentError,
message: "#{e}. Invalid date(s) provided (given: #{start_date} & #{end_date})."
end

def auth_manager
@auth_manager ||= TravelPay::AuthManager.new(Settings.travel_pay.client_number, @user)
end

def client
TravelPay::ClaimsClient.new
end
end
end
Loading

0 comments on commit 440f577

Please sign in to comment.