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

Adapt FormRemediation for 526 #21348

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ flipper:
github_organization: department-of-veterans-affairs
github_team: <%= ENV['flipper__github_team'] %>
mute_logs: <%= ENV['flipper__mute_logs'] %>
form0781_remediation:
aws:
bucket: <%= ENV['evidence_remediation__aws__bucket'] %>
region: us-gov-west-1
form1095_b:
s3:
aws_access_key_id: <%= ENV['form1095_b__s3__aws_access_key_id'] %>
Expand Down
4 changes: 4 additions & 0 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ flipper:
github_organization: ~
github_team: ~
mute_logs: false
form0781_remediation:
aws:
bucket: ~
region: ~
form1095_b:
s3:
aws_access_key_id: ~
Expand Down
4 changes: 4 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ flipper:
github_organization: organization
github_team: 0
mute_logs: false
form0781_remediation:
aws:
bucket: ~
region: ~
form1095_b:
s3:
aws_access_key_id: ~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'simple_forms_api/form_remediation/configuration/base'

module SimpleFormsApi
module FormRemediation
module Configuration
class Form0781Config < Base
def submission_archive_class
SimpleFormsApi::FormRemediation::Form526SubmissionArchive
end

def remediation_data_class
SimpleFormsApi::FormRemediation::Form0781SubmissionRemediationData
end

def temp_directory_path
Rails.root.join("tmp/#{SecureRandom.hex}-archive").to_s
end

def s3_settings
Settings.form0781_remediation.aws
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

module SimpleFormsApi
module FormRemediation
class Form0781
def submission_date_stamps(timestamp)
[
{
coords: [460, 710],
text: 'Application Submitted:',
page: 0,
font_size: 12
},
{
coords: [460, 690],
text: timestamp.in_time_zone('UTC').strftime('%H:%M %Z %D'),
page: 0,
font_size: 12
}
]
end

def desired_stamps
[]
end
end

class Form0781SubmissionRemediationData < SubmissionRemediationData
def hydrate!
Copy link
Contributor

Choose a reason for hiding this comment

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

Would any of the logic in hydrate! benefit from an async job? Is Form0781SubmissionRemediationData.new(submission).hydrate! used in a request flow at all? If so, it might benefit from a background job potentially

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It all gets kicked off from a invocation to SimpleFormsApi::FormRemediation::Jobs::ArchiveBatchProcessingJob, which is a Sidekiq job. Do you recommend another job triggered by the first job?

Copy link
Contributor Author

@Thrillberg Thrillberg Mar 27, 2025

Choose a reason for hiding this comment

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

This PR is basically plugging in custom pieces to the pattern established in the form remediation work (README here)

form_content = JSON.parse(submission.form_to_json(Form526Submission::FORM_0781))['form0781a']
submitted_claim_id = submission.submitted_claim_id
submission_date = submission&.created_at
form_content = form_content.merge(
{ 'signatureDate' => submission_date&.in_time_zone('Central Time (US & Canada)') }
)
@file_path = PdfFill::Filler.fill_ancillary_form(
form_content,
submitted_claim_id,
EVSS::DisabilityCompensationForm::SubmitForm0781::FORM_ID_0781A
)
SimpleFormsApi::PdfStamper.new(
stamped_template_path: file_path,
form: Form0781.new,
timestamp: submission_date
).stamp_pdf

self
rescue => e
config.handle_error('Error hydrating submission', e)
end

private

attr_reader :config

def fetch_submission(id)
@submission = Form526Submission.find(id)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module SimpleFormsApi
module FormRemediation
class Form526SubmissionArchive < SubmissionArchive
def hydrate_submission_data
raise "No #{config.id_type} was provided" unless id

built_submission = config.remediation_data_class.new(id:, config:).hydrate!

initialize_data(
attachments: built_submission.attachments,
file_path: built_submission.file_path,
id: built_submission.submission.id,
metadata: built_submission.metadata,
submission: built_submission.submission,
type: archive_type
)
end

private

def submission_file_name
@submission_file_name ||= unique_file_name('526', id)
end

def manifest_entry
[
submission.created_at,
'526',
id
]
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'simple_forms_api/form_remediation/configuration/form_0781_config'
require_relative '../../app/services/simple_forms_api/form_remediation/jobs/archive_batch_processing_job'

# Invoke this as follows:
# Passing just form526_submission_ids (will use default type):
# bundle exec rails simple_forms_api:remediate_0781_submissions[123 456]

def validate_input!(form526_submission_ids)
raise Common::Exceptions::ParameterMissing, 'form526_submission_ids' unless form526_submission_ids&.any?
end

namespace :simple_forms_api do
desc 'Kick off the ArchiveBatchProcessingJob to archive 0781 submissions to S3 and print presigned URLs'
task :remediate_0781_submissions, %i[form526_submission_ids] => :environment do |_, args|
form526_submission_ids = args[:form526_submission_ids].to_s.split(/[,\s]+/)
type = :remediation

begin
validate_input!(form526_submission_ids)

Rails.logger.info(
"Starting ArchiveBatchProcessingJob for form 526 ids: #{form526_submission_ids.join(', ')} using type: #{type}"
)

# Call the service object synchronously and get the presigned URLs
config = SimpleFormsApi::FormRemediation::Configuration::Form0781Config.new
job = SimpleFormsApi::FormRemediation::Jobs::ArchiveBatchProcessingJob.new
job.perform(ids: form526_submission_ids, config:, type: type.to_sym)

Rails.logger.info('Task successfully completed.')
rescue Common::Exceptions::ParameterMissing => e
raise e
rescue => e
Rails.logger.error("Error occurred while archiving submissions: #{e.message}")
puts 'An error occurred. Check logs for more details.'
end
end
end
Loading