Class: Lighthouse::PensionBenefitIntakeJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/lighthouse/pension_benefit_intake_job.rb

Defined Under Namespace

Classes: PensionBenefitIntakeError

Constant Summary collapse

FOREIGN_POSTALCODE =
'00000'

Instance Method Summary collapse

Instance Method Details

#check_success(response) ⇒ Object

Check benefits service upload_form response. On success send confirmation email.

Raises PensionBenefitIntakeError unless response.success?

Parameters:

  • response (Object)


112
113
114
115
116
117
118
119
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 112

def check_success(response)
  if response.success?
    Rails.logger.info('Lighthouse::PensionBenefitIntakeJob Succeeded!', { saved_claim_id: @claim.id })
    @claim.send_confirmation_email if @claim.respond_to?(:send_confirmation_email)
  else
    raise PensionBenefitIntakeError, response.to_s
  end
end

#cleanup_file_pathsObject

Delete temporary stamped PDF files for this instance.



122
123
124
125
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 122

def cleanup_file_paths
  Common::FileHelpers.delete_file_if_exists(@form_path) if @form_path
  @attachment_paths&.each { |p| Common::FileHelpers.delete_file_if_exists(p) }
end

#generate_form_metadata_lhHash

Generate form metadata to send in upload to Benefits Intake API

Returns:

  • (Hash)

See Also:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 92

def 
  form = @claim.parsed_form
  veteran_full_name = form['veteranFullName']
  address = form['claimantAddress'] || form['veteranAddress']

  {
    veteran_first_name: veteran_full_name['first'],
    veteran_last_name: veteran_full_name['last'],
    file_number: form['vaFileNumber'] || form['veteranSocialSecurityNumber'],
    zip: address['country'] == 'USA' ? address['postalCode'] : FOREIGN_POSTALCODE,
    doc_type: @claim.form_id,
    claim_date: @claim.created_at
  }
end

#perform(saved_claim_id) ⇒ Object

Process claim pdfs and upload to Benefits Intake API developer.va.gov/explore/api/benefits-intake/docs

On success send confirmation email Raises PensionBenefitIntakeError

Parameters:

  • saved_claim_id (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 32

def perform(saved_claim_id)
  @saved_claim_id = saved_claim_id
  @claim = SavedClaim::Pension.find(saved_claim_id)
  raise PensionBenefitIntakeError, "Unable to find SavedClaim::Pension #{saved_claim_id}" unless @claim

  @form_path = process_pdf(@claim.to_pdf)
  @attachment_paths = @claim.persistent_attachments.map { |pa| process_pdf(pa.to_pdf) }

  lighthouse_service = BenefitsIntakeService::Service.new(with_upload_location: true)
  Rails.logger.info({ message: 'PensionBenefitIntakeJob Attempt',
                      claim_id: @claim.id, uuid: lighthouse_service.uuid })

  response = lighthouse_service.upload_form(
    main_document: split_file_and_path(@form_path),
    attachments: @attachment_paths.map(&method(:split_file_and_path)),
    form_metadata: 
  )

  check_success(response)
rescue => e
  Rails.logger.warn('Lighthouse::PensionBenefitIntakeJob failed!',
                    { error: e.message })
  raise
ensure
  cleanup_file_paths
end

#process_pdf(pdf_path) ⇒ String

Create a temp stamped PDF, validate the PDF satisfies Benefits Intake specification

Raises PensionBenefitIntakeError if PDF is invalid

Parameters:

  • pdf_path (String)

Returns:

  • (String)

    path to temp stamped PDF

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 65

def process_pdf(pdf_path)
  stamped_path = CentralMail::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5)
  stamped_path = CentralMail::DatestampPdf.new(stamped_path).run(
    text: 'FDC Reviewed - va.gov Submission',
    x: 429,
    y: 770,
    text_only: true
  )

  response = BenefitsIntakeService::Service.new.validate_document(doc_path: stamped_path)
  raise PensionBenefitIntakeError, "Invalid Document: #{response}" unless response.success?

  stamped_path
end

#split_file_and_path(path) ⇒ Hash

Format doc path to send in upload to Benefits Intake API

Parameters:

  • path (String)

Returns:

  • (Hash)

    { file:, file_name: }



84
85
86
# File 'app/sidekiq/lighthouse/pension_benefit_intake_job.rb', line 84

def split_file_and_path(path)
  { file: path, file_name: path.split('/').last }
end