Skip to content

Commit 7f29a03

Browse files
committed
fill and stamp PDF
1 parent ad5bdf8 commit 7f29a03

File tree

2 files changed

+40
-94
lines changed

2 files changed

+40
-94
lines changed

modules/simple_forms_api/app/services/simple_forms_api/form_remediation/form526_submission_remediation_data.rb

+39-94
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,48 @@
22

33
module SimpleFormsApi
44
module FormRemediation
5-
class Form526SubmissionRemediationData
6-
attr_reader :file_path, :submission, :attachments, :metadata
7-
8-
def initialize(id:, config:)
9-
@config = config
10-
11-
validate_input(id)
12-
fetch_submission(id)
13-
14-
@attachments = []
15-
@metadata = {}
16-
rescue => e
17-
config.handle_error("#{self.class.name} initialization failed", e)
5+
class Form0781
6+
def submission_date_stamps(timestamp)
7+
[
8+
{
9+
coords: [460, 710],
10+
text: 'Application Submitted:',
11+
page: 0,
12+
font_size: 12
13+
},
14+
{
15+
coords: [460, 690],
16+
text: timestamp.in_time_zone('UTC').strftime('%H:%M %Z %D'),
17+
page: 0,
18+
font_size: 12
19+
}
20+
]
21+
end
22+
23+
def desired_stamps
24+
[]
1825
end
26+
end
1927

28+
class Form526SubmissionRemediationData < SubmissionRemediationData
2029
def hydrate!
21-
form_number = fetch_submission_form_number
22-
form = build_form(form_number)
23-
filler = PdfFiller.new(form_number:, form:)
30+
form_content = JSON.parse(submission.form_to_json(Form526Submission::FORM_0781))['form0781a']
31+
submitted_claim_id = submission.submitted_claim_id
32+
submission_date = submission&.created_at
33+
form_content = form_content.merge(
34+
{ 'signatureDate' => submission_date&.in_time_zone('Central Time (US & Canada)') }
35+
)
36+
@file_path = PdfFill::Filler.fill_ancillary_form(
37+
form_content,
38+
submitted_claim_id,
39+
EVSS::DisabilityCompensationForm::SubmitForm0781::FORM_ID_0781A
40+
)
41+
SimpleFormsApi::PdfStamper.new(
42+
stamped_template_path: file_path,
43+
form: Form0781.new,
44+
timestamp: submission_date
45+
).stamp_pdf
2446

25-
handle_submission_data(filler, form, form_number)
2647
self
2748
rescue => e
2849
config.handle_error('Error hydrating submission', e)
@@ -32,84 +53,8 @@ def hydrate!
3253

3354
attr_reader :config
3455

35-
def validate_input(id)
36-
raise ArgumentError, "No #{config.id_type} was provided" unless id
37-
end
38-
3956
def fetch_submission(id)
40-
# TODO: Customize the below for Form 526
41-
#
42-
# form_submission_attempt = FormSubmissionAttempt.find_by(benefits_intake_uuid: id)
43-
# @submission = form_submission_attempt&.form_submission
44-
# validate_submission
45-
end
46-
47-
def validate_submission
48-
raise 'Submission was not found or invalid' unless submission&.latest_attempt&.send(config.id_type)
49-
raise "#{self.class} cannot be built: Only VFF forms are supported" unless valid_form?
50-
end
51-
52-
def fetch_submission_form_number
53-
valid_forms_map.fetch(submission.form_type)
54-
end
55-
56-
def build_form(form_number)
57-
form_class_name = "SimpleFormsApi::#{form_number.titleize.delete(' ')}"
58-
form_class = form_class_name.constantize
59-
form_class.new(form_data_hash).tap do |form|
60-
form.signature_date = submission.created_at.in_time_zone('America/Chicago')
61-
end
62-
rescue NameError => e
63-
config.handle_error("Form class not found for #{form_class_name}", e)
64-
end
65-
66-
def handle_submission_data(filler, form, form_number)
67-
@file_path = generate_pdf_file(filler)
68-
@metadata = validate_metadata(form)
69-
@attachments = process_attachments(form, form_number)
70-
end
71-
72-
def generate_pdf_file(filler)
73-
filler.generate(timestamp: submission.created_at)
74-
rescue => e
75-
config.handle_error('Error generating filled submission PDF', e)
76-
end
77-
78-
def validate_metadata(form)
79-
SimpleFormsApiSubmission::MetadataValidator.validate(
80-
form.metadata,
81-
zip_code_is_us_based: form.zip_code_is_us_based
82-
)
83-
rescue => e
84-
config.handle_error('Metadata validation failed', e)
85-
end
86-
87-
def process_attachments(form, form_number)
88-
case form_number
89-
when 'vba_40_0247', 'vba_40_10007'
90-
form.handle_attachments(file_path)
91-
[]
92-
when 'vba_20_10207'
93-
form.get_attachments
94-
else
95-
[]
96-
end
97-
rescue => e
98-
config.handle_error("Attachment handling failed for #{form_number}", e)
99-
end
100-
101-
def form_data_hash
102-
@form_data_hash ||= JSON.parse(submission.form_data)
103-
rescue JSON::ParserError => e
104-
config.handle_error('Error parsing form data', e)
105-
end
106-
107-
def valid_forms_map
108-
SimpleFormsApi::V1::UploadsController::FORM_NUMBER_MAP
109-
end
110-
111-
def valid_form?
112-
valid_forms_map.key?(submission.form_type)
57+
@submission = Form526Submission.find(id)
11358
end
11459
end
11560
end

modules/simple_forms_api/app/services/simple_forms_api/pdf_stamper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def pdftk
5151
end
5252

5353
def all_form_stamps
54+
byebug
5455
form ? form.desired_stamps + form.submission_date_stamps(timestamp) : []
5556
end
5657

0 commit comments

Comments
 (0)