Skip to content

Commit

Permalink
forms_api: add central mail stamp and cleanup (#11966)
Browse files Browse the repository at this point in the history
* add central mail stamp

* create mapper for formid
  • Loading branch information
gmrabian authored Mar 6, 2023
1 parent 6efe679 commit 17ab064
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ class UploadsController < ApplicationController
skip_before_action :verify_authenticity_token
skip_after_action :set_csrf_header

FORM_NUMBER_MAP = {
'26-4555' => 'vba_26_4555',
'10-10D' => 'vha_10_10d'
}.freeze

def submit
filler = FormsApi::PdfFiller.new(form_number: params[:form_number], data: JSON.parse(params.to_json))
form_id = FORM_NUMBER_MAP[params[:form_number]]
filler = FormsApi::PdfFiller.new(form_number: form_id, data: JSON.parse(params.to_json))

file_path = filler.generate

central_mail_service = CentralMail::Service.new
filled_form = {
'metadata' => filler.metadata,
'document' => filler.to_faraday_upload(file_path, params[:form_number])
'document' => filler.to_faraday_upload(file_path, form_id)
}
response = central_mail_service.upload(filled_form)

Expand Down
16 changes: 8 additions & 8 deletions modules/forms_api/app/form_mappings/vba_26_4555.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
"F[0].Page_1[0].Date_Of_Birth[0]": "<%= data.dig('veteran', 'date_of_birth') %>",
"F[0].Page_1[0].JF03[0]": "<%= data.dig('veteran', 'email') %>",
"F[0].Page_1[0].JF04[0]": "<%= data.dig('veteran', 'address', 'street') %> <%= data.dig('veteran', 'address', 'city') %>, <%= data.dig('veteran', 'address', 'state') %> <%= data.dig('veteran', 'address', 'postal_code') %>",
"F[0].Page_1[0].JF05[0]": "<%= data.dig('previousSahApplication', 'previousSahApplicationAddress', 'street') %> <%= data.dig('previousSahApplication', 'previousSahApplicationAddress', 'city') %>, <%= data.dig('previousSahApplication', 'previousSahApplicationAddress', 'state') %> <%= data.dig('previousSahApplication', 'previousSahApplicationAddress', 'postal_code') %>",
"F[0].Page_1[0].JF06[0]": "<%= data.dig('previousHiApplication', 'previousHiApplicationAddress', 'street') %> <%= data.dig('previousHiApplication', 'previousHiApplicationAddress', 'city') %>, <%= data.dig('previousHiApplication', 'previousHiApplicationAddress', 'state') %> <%= data.dig('previousHiApplication', 'previousHiApplicationAddress', 'postal_code') %>",
"F[0].Page_1[0].JF07[0]": "<%= data.dig('livingSituation', 'careFacilityName') %> <%= data.dig('livingSituation', 'careFacilityAddress', 'street') %> <%= data.dig('livingSituation', 'careFacilityAddress', 'city') %>, <%= data.dig('livingSituation', 'careFacilityAddress', 'state') %> <%= data.dig('livingSituation', 'careFacilityAddress', 'postal_code') %>",
"F[0].Page_1[0].JF05[0]": "<%= data.dig('previous_sah_application', 'previous_sah_application_address', 'street') %> <%= data.dig('previous_sah_application', 'previous_sah_application_address', 'city') %>, <%= data.dig('previous_sah_application', 'previous_sah_application_address', 'state') %> <%= data.dig('previous_sah_application', 'previous_sah_application_address', 'postal_code') %>",
"F[0].Page_1[0].JF06[0]": "<%= data.dig('previous_hi_application', 'previous_hi_application_address', 'street') %> <%= data.dig('previous_hi_application', 'previous_hi_application_address', 'city') %>, <%= data.dig('previous_hi_application', 'previous_hi_application_address', 'state') %> <%= data.dig('previous_hi_application', 'previous_hi_application_address', 'postal_code') %>",
"F[0].Page_1[0].JF07[0]": "<%= data.dig('living_situation', 'care_facility_name') %> <%= data.dig('living_situation', 'care_facility_address', 'street') %> <%= data.dig('living_situation', 'care_facility_address', 'city') %>, <%= data.dig('living_situation', 'care_facility_address', 'state') %> <%= data.dig('living_situation', 'care_facility_address', 'postal_code') %>",
"F[0].Page_1[0].JF08[0]": "<%= data.dig('remarks') %>",

"F[0].Page_1[0].TELEPHONE01[0]": "<%= data.dig('veteran', 'home_phone') %>",
"F[0].Page_1[0].TELEPHONE02[0]": "<%= data.dig('veteran', 'home_phone') %>",
"F[0].Page_1[0].TELEPHONE03[0]": "<%= data.dig('veteran', 'mobile_phone') %>",

"F[0].Page_1[0].RadioButtonList[0]": "<%= data.dig('previousSahApplication', 'hasPreviousSahApplication') == true ? 1 : 2 %>",
"F[0].Page_1[0].RadioButtonList[1]": "<%= data.dig('previousHiApplication', 'hasPreviousHiApplication') == true ? 1 : 2 %>",
"F[0].Page_1[0].RadioButtonList[2]": "<%= data.dig('livingSituation', 'isInCareFacility') == true ? 1 : 2 %>",
"F[0].Page_1[0].RadioButtonList[0]": "<%= data.dig('previous_sah_application', 'has_previous_sah_application') == true ? 1 : 2 %>",
"F[0].Page_1[0].RadioButtonList[1]": "<%= data.dig('previous_hi_application', 'has_previous_hi_application') == true ? 1 : 2 %>",
"F[0].Page_1[0].RadioButtonList[2]": "<%= data.dig('living_situation', 'is_in_care_facility') == true ? 1 : 2 %>",

"F[0].Page_1[0].Date02[0]": "<%= data.dig('previousSahApplication', 'previousSahApplicationDate') %>",
"F[0].Page_1[0].Date03[0]": "<%= data.dig('previousHiApplication', 'previousHiApplicationDate') %>",
"F[0].Page_1[0].Date02[0]": "<%= data.dig('previous_sah_application', 'previous_sah_application_date') %>",
"F[0].Page_1[0].Date03[0]": "<%= data.dig('previous_hi_application', 'previous_hi_application_date') %>",
"F[0].Page_1[0].Date05[0]": "<%= 'todaysdate' %>",
"F[0].Page_1[0].Signature[0]": "<%= data.dig('veteran', 'full_name', 'first') %> <%= data.dig('veteran', 'full_name', 'middle') %>. <%= data.dig('veteran', 'full_name', 'last') %>"
}
4 changes: 1 addition & 3 deletions modules/forms_api/app/services/forms_api/pdf_filler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class PdfFiller

TEMPLATE_BASE = Rails.root.join('modules', 'forms_api', 'templates')

FORM_REQUIRES_STAMP = ['vba_26_4555'].freeze

attr_accessor :data, :form_number

def initialize(form_number:, data:)
Expand All @@ -24,7 +22,7 @@ def generate
generated_form_path = "tmp/#{form_number}-tmp.pdf"
pdftk = PdfForms.new(Settings.binaries.pdftk)
pdftk.fill_form(template_form_path, generated_form_path, mapped_data)
PdfStamper.stamp_pdf(generated_form_path, data) if FORM_REQUIRES_STAMP.include? form_number
PdfStamper.stamp_pdf(generated_form_path, data)
generated_form_path
end

Expand Down
20 changes: 15 additions & 5 deletions modules/forms_api/app/services/forms_api/pdf_stamper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@

module FormsApi
class PdfStamper
FORM_REQUIRES_STAMP = ['vba_26_4555'].freeze
SUBMISSION_TEXT = 'Signed electronically and submitted via VA.gov at '

def self.stamp_pdf(generated_form_path, data)
stamp_method = "stamp_#{data['form_number'].gsub('_', '')}"
send(stamp_method, generated_form_path, data)
if FORM_REQUIRES_STAMP.include? data['form_number']
stamp_method = "stamp_#{data['form_number'].gsub('_', '')}"
send(stamp_method, generated_form_path, data)
end
centrail_mail_stamper = CentralMail::DatestampPdf.new(generated_form_path)
current_time = Time.new.getlocal.strftime('%H:%M:%S')
stamp_text = SUBMISSION_TEXT + current_time
out_path = centrail_mail_stamper.run(text: stamp_text, x: 10, y: 10)
File.rename(out_path, generated_form_path)
end

def self.stamp_vba264555(generated_form_path, data)
desired_stamps = []
desired_stamps.append([73, 390]) if data['previousSahApplication']['hasPreviousSahApplication'] == false
desired_stamps.append([73, 355]) if data['previousHiApplication']['hasPreviousHiApplication'] == false
desired_stamps.append([73, 320]) if data['livingSituation']['isInCareFacility'] == false
desired_stamps.append([73, 390]) if data['previous_sah_application']['has_previous_sah_application'] == false
desired_stamps.append([73, 355]) if data['previous_hi_application']['has_previous_hi_application'] == false
desired_stamps.append([73, 320]) if data['living_situation']['is_in_care_facility'] == false
current_file_path = generated_form_path
desired_stamps.each do |x, y|
out_path = CentralMail::DatestampPdf.new(current_file_path).run(text: 'X', x: x, y: y, text_only: true)
Expand Down
2 changes: 1 addition & 1 deletion modules/forms_api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

FormsApi::Engine.routes.draw do
namespace :v1, defaults: { format: 'json' } do
post '/submit', to: 'uploads#submit'
post '/simple_forms', to: 'uploads#submit'
end
end
14 changes: 7 additions & 7 deletions modules/forms_api/spec/fixtures/form_json/vba_26_4555-min.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{
"form_number": "vba_26_4555",
"form_number": "26-4555",
"veteran": {
"full_name": {
"first": "Veteran",
Expand All @@ -16,13 +16,13 @@
"ssn": "222554444",
"home_phone": "9876543213"
},
"previousSahApplication": {
"hasPreviousSahApplication": false
"previous_sah_application": {
"has_previous_sah_application": false
},
"previousHiApplication": {
"hasPreviousHiApplication": false
"previous_hi_application": {
"has_previous_hi_application": false
},
"livingSituation": {
"isInCareFacility": false
"living_situation": {
"is_in_care_facility": false
}
}
26 changes: 13 additions & 13 deletions modules/forms_api/spec/fixtures/form_json/vba_26_4555.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{
"form_number": "vba_26_4555",
"form_number": "26-4555",
"veteran": {
"full_name": {
"first": "Veteran",
Expand All @@ -21,32 +21,32 @@
"mobile_phone": "9876543213",
"email": "veteran.surname@address.com"
},
"previousSahApplication": {
"hasPreviousSahApplication": true,
"previousSahApplicationDate": "2010-05-05",
"previousSahApplicationAddress": {
"previous_sah_application": {
"has_previous_sah_application": true,
"previous_sah_application_date": "2010-05-05",
"previous_sah_application_address": {
"country": "USA",
"street": "2 Second St",
"city": "Town",
"state": "LA",
"postal_code": "34251"
}
},
"previousHiApplication": {
"hasPreviousHiApplication": true,
"previousHiApplicationDate": "2013-06-06",
"previousHiApplicationAddress": {
"previous_hi_application": {
"has_previous_hi_application": true,
"previous_hi_application_date": "2013-06-06",
"previous_hi_application_address": {
"country": "USA",
"street": "3 Third Ave",
"city": "City",
"state": "NY",
"postal_code": "08712"
}
},
"livingSituation": {
"isInCareFacility": true,
"careFacilityName": "Top Care",
"careFacilityAddress": {
"living_situation": {
"is_in_care_facility": true,
"care_facility_name": "Top Care",
"care_facility_address": {
"country": "USA",
"street": "4 Final Rd",
"city": "Ville",
Expand Down
2 changes: 1 addition & 1 deletion modules/forms_api/spec/fixtures/form_json/vha_10_10d.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"form_number": "vha_10_10d",
"form_number": "10-10D",
"veteran": {
"date_of_birth": "1987-02-02",
"date_of_marriage": "2005-04-06",
Expand Down
4 changes: 2 additions & 2 deletions modules/forms_api/spec/requests/v1/uploads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'

RSpec.describe 'Dynamic forms uploader', type: :request do
describe '10-10d' do
describe 'form request' do
let(:client_stub) { instance_double(CentralMail::Service) }
let :multipart_request_matcher do
lambda do |r1, r2|
Expand All @@ -20,7 +20,7 @@ def self.test_submit_request(test_payload)
) do
fixture_path = Rails.root.join('modules', 'forms_api', 'spec', 'fixtures', 'form_json', test_payload)
data = JSON.parse(fixture_path.read)
post '/forms_api/v1/submit', params: data
post '/forms_api/v1/simple_forms', params: data
result = JSON.parse(response.body)
expect(result['status']).to eq('success')
end
Expand Down

0 comments on commit 17ab064

Please sign in to comment.