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

bdex/80773: Toxic Exposure - [Lighthouse API] generatePdf hook up #16411

Merged
merged 10 commits into from
Apr 23, 2024
2 changes: 1 addition & 1 deletion lib/lighthouse/benefits_claims/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module BenefitsClaims
class Configuration < Common::Client::Configuration::REST
self.read_timeout = Settings.lighthouse.benefits_claims.timeout || 20

API_SCOPES = %w[system/claim.read system/claim.write].freeze
API_SCOPES = %w[system/claim.read system/claim.write system/526-pdf.override].freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified that staging and production Lighthouse benefits claims client ids can generate an auth token with these scopes listed
references: https://dsva.slack.com/archives/C02CQP3RFFX/p1713469011121339

CLAIMS_PATH = 'services/claims/v2/veterans'
TOKEN_PATH = 'oauth2/claims/system/v1/token'

Expand Down
42 changes: 33 additions & 9 deletions lib/lighthouse/benefits_claims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth
handle_error(e, lighthouse_client_id, endpoint)
end

# submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526
# submit form526 to Lighthouse API endpoint: /services/claims/v2/veterans/{veteranId}/526 or
# /services/claims/v2/veterans/{veteranId}/526/generatePdf
# @param [hash || Requests::Form526] body: a hash representing the form526
# attributes in the Lighthouse request schema
# @param [string] lighthouse_client_id: the lighthouse_client_id requested from Lighthouse
Expand All @@ -111,28 +112,31 @@ def create_intent_to_file(type, claimant_ssn, lighthouse_client_id = nil, lighth
# @option options [hash] :body_only only return the body from the request
# @option options [string] :aud_claim_url option to override the aud_claim_url for LH Veteran Verification APIs
# @option options [hash] :auth_params a hash to send in auth params to create the access token
# @option options [hash] :generate_pdf call the generatePdf endpoint to receive the 526 pdf
def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
endpoint = 'benefits_claims/form/526'
endpoint = '{icn}/526'
path = "#{@icn}/526"

if options[:generate_pdf].present?
path += '/generatePDF/minimum-validations'
endpoint += '/generatePDF/minimum-validations'
end

# if we're coming straight from the transformation service without
# making this a jsonapi request body first ({data: {type:, attributes}}),
# this will put it in the correct format for transmission

body = {
data: {
type: 'form/526',
attributes: body
}
}.as_json.deep_transform_keys { |k| k.camelize(:lower) }
body = build_request_body(body)

# Inflection settings force 'current_va_employee' to render as 'currentVAEmployee' in the above camelize() call
# Since Lighthouse needs 'currentVaEmployee', the following workaround renames it.
fix_current_va_employee(body)

json_body = remove_unicode_characters(body)

response = config.post(
path,
body,
json_body,
lighthouse_client_id, lighthouse_rsa_key_path, options
)

Expand All @@ -143,6 +147,26 @@ def submit526(body, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, o

private

def build_request_body(body)
{
data: {
type: 'form/526',
attributes: body
}
}.as_json.deep_transform_keys { |k| k.camelize(:lower) }
end

# this gsubbing is to fix an issue where the service that generates the 526PDF was failing due to
# unicoded carriage returns:
# i.e.: \n was throwing: "U+000A ('controlLF') is not available in the font Helvetica, encoding: WinAnsiEncoding"
def remove_unicode_characters(body)
body.to_json
.gsub('\\n', ' ')
.gsub('\\r', ' ')
.gsub('\\\\n', ' ')
.gsub('\\\\r', ' ')
end

def fix_current_va_employee(body)
if body.dig('data', 'attributes', 'veteranIdentification')&.select do |field|
field['currentVAEmployee']
Expand Down
Loading