generated from codeforamerica/form-flow-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding student expenses and clean up updating ssn pdf mapping Add pregnancy details Adding out of state benefits mapper Adding mappings for special situations where theres a list of names Adding income mapper
- Loading branch information
Showing
18 changed files
with
582 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/org/ladocuploader/app/preparers/HouseholdExpensesPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
@Component | ||
@Slf4j | ||
public class HouseholdExpensesPreparer implements SubmissionFieldPreparer { | ||
private static final Map<String, String> EXPENSES = new HashMap<>(); | ||
|
||
static { | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Rent", "Rent"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Mortgage", "Mortgage"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Homeowner's Insurance", "Homeowner's Insurance"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Property Tax", "Property Tax"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Condominium Fees", "Condo Fees"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Lot Rental", "Lot Rental"); | ||
EXPENSES.put("householdHomeExpenseAmount_wildcard_Flood Insurance", "Flood Insurance"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Electricity", "Electricity"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Water", "Water"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Phone/Cell Phone", "Phone/Cell Phone"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Garbage", "Garbage"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Sewer", "Sewer"); | ||
EXPENSES.put("householdUtilitiesExpenseAmount_wildcard_Cooking Fuel", "Gas"); | ||
} | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> results = new HashMap<>(); | ||
|
||
var householdUtilities = (List) submission.getInputData().getOrDefault("householdUtilitiesExpenses[]", emptyList()); | ||
var householdExpenses = (List) submission.getInputData().getOrDefault("householdHomeExpenses[]", emptyList()); | ||
if (!householdExpenses.isEmpty() || !householdUtilities.isEmpty()) { | ||
List<String> sortedExpenses = EXPENSES.keySet().stream().sorted().toList(); | ||
int i = 1; | ||
for (String expense : sortedExpenses) { | ||
var expenseInput = submission.getInputData().get(expense); | ||
if (expenseInput != null) { | ||
results.put("householdExpensesType" + i, new SingleField("householdExpensesType", EXPENSES.get(expense), i)); | ||
results.put("householdExpensesAmount" + i, new SingleField("householdExpensesAmount", (String) expenseInput, i)); | ||
results.put("householdExpensesFreq" + i, new SingleField("householdExpensesFreq", "Monthly", i)); | ||
i++; | ||
} | ||
} | ||
|
||
// Heating or A/C | ||
results.put("heatingOrCoolingInd", new SingleField("heatingOrCoolingInd", Boolean.toString(householdUtilities.contains("Heating") || householdUtilities.contains("Cooling")), null)); | ||
|
||
// Check for "Other" - theres only one spot for this in the PDF so just combine them | ||
var totalOtherAmount = 0.0; | ||
try { | ||
var expensesOther = submission.getInputData().get("expensesOther"); | ||
if (expensesOther != null) { | ||
totalOtherAmount += Double.parseDouble((String) expensesOther); | ||
} | ||
var expensesUtilitiesOther = submission.getInputData().get("expensesUtilitiesOther"); | ||
if (expensesUtilitiesOther != null) { | ||
totalOtherAmount += Double.parseDouble((String) expensesUtilitiesOther); | ||
} | ||
} catch (NumberFormatException e) { | ||
log.warn("Could not parse amount", e); | ||
} | ||
|
||
if (totalOtherAmount > 0) { | ||
results.put("Other", new SingleField("Other", "Yes", null)); | ||
|
||
results.put("householdExpensesType_" + i, new SingleField("householdExpensesType_" + i, "Other", null)); | ||
results.put("householdExpensesAmount_" + i, new SingleField("householdExpensesAmount_" + i, Double.toString(totalOtherAmount), null)); | ||
results.put("householdExpensesFreq_" + i, new SingleField("householdExpensesFreq_" + i, "Monthly", null)); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/org/ladocuploader/app/preparers/IncomeDetailsPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import org.ladocuploader.app.utils.IncomeCalculator; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class IncomeDetailsPreparer implements SubmissionFieldPreparer { | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> results = new HashMap<>(); | ||
|
||
var income = (List<Map<String, Object>>) submission.getInputData().get("income"); | ||
if (income != null) { | ||
int nonSelfEmploymentIdx = 1; | ||
int selfEmploymentIdx = 1; | ||
for (int i = 0; i < income.size(); i++) { | ||
Map<String, Object> incomeDetails = income.get(i); | ||
|
||
boolean isSelfEmployed = Boolean.parseBoolean((String) incomeDetails.getOrDefault("selfEmployed", "false")); | ||
var employeeName = incomeDetails.get("householdMemberJobAdd"); | ||
var employerName = incomeDetails.get("employerName"); | ||
var hoursPerWeek = incomeDetails.get("hoursPerWeek"); | ||
|
||
if (isSelfEmployed) { | ||
var monthlyIncome = IncomeCalculator.futureIncomeForJob(incomeDetails); | ||
results.put("selfEmploymentName" + i, new SingleField("selfEmploymentName", (String) employeeName, selfEmploymentIdx)); | ||
results.put("selfEmploymentDesc" + i, new SingleField("selfEmploymentDesc", (String) employerName, selfEmploymentIdx)); | ||
results.put("selfEmploymentMonthlyIncome" + i, new SingleField("selfEmploymentMonthlyIncome", Double.toString(monthlyIncome), selfEmploymentIdx)); | ||
results.put("selfEmploymentHoursPerWeek" + i, new SingleField("selfEmploymentHoursPerWeek", (String) hoursPerWeek, selfEmploymentIdx)); | ||
selfEmploymentIdx++; | ||
} else { | ||
var payPeriod = incomeDetails.get("payPeriod"); | ||
var hourlyWage = incomeDetails.get("hourlyWage"); | ||
results.put("employeeName" + i, new SingleField("employeeName", (String) employeeName, nonSelfEmploymentIdx)); | ||
results.put("employerName" + i, new SingleField("employerName", (String) employerName, nonSelfEmploymentIdx)); | ||
results.put("employmentPayFreq" + i, new SingleField("employmentPayFreq", (String) payPeriod, nonSelfEmploymentIdx)); | ||
results.put("employeeHoursPerWeek" + i, new SingleField("employeeHoursPerWeek", (String) hoursPerWeek, nonSelfEmploymentIdx)); | ||
results.put("employeeHourlyWage" + i, new SingleField("employeeHourlyWage", (String) hourlyWage, nonSelfEmploymentIdx)); | ||
nonSelfEmploymentIdx++; | ||
} | ||
} | ||
} | ||
return results; | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/main/java/org/ladocuploader/app/preparers/PlaceholderPreparer.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/main/java/org/ladocuploader/app/preparers/PregnancyDueDatePreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import org.apache.logging.log4j.util.Strings; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.ladocuploader.app.utils.SubmissionUtilities.getHouseholdMemberFullnameByUUID; | ||
|
||
@Component | ||
public class PregnancyDueDatePreparer implements SubmissionFieldPreparer { | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> result = new HashMap<>(); | ||
var pregnancies = (List) submission.getInputData().getOrDefault("pregnancies[]", emptyList()); | ||
if (!pregnancies.isEmpty()) { | ||
List<String> pregnantMemberNames = new ArrayList<>(); | ||
List<String> pregnantMemberDueDates = new ArrayList<>(); | ||
for (var uuid : pregnancies) { | ||
var day = submission.getInputData().get("dayPregnancyDueDate_wildcard_%s".formatted(uuid)); | ||
var year = submission.getInputData().get("yearPregnancyDueDate_wildcard_%s".formatted(uuid)); | ||
var month = submission.getInputData().get("monthPregnancyDueDate_wildcard_%s".formatted(uuid)); | ||
pregnantMemberDueDates.add("%s/%s/%s".formatted(month, day, year)); | ||
|
||
var pregnantMemberName = getHouseholdMemberFullnameByUUID((String) uuid, submission.getInputData()); | ||
pregnantMemberNames.add(pregnantMemberName); | ||
} | ||
result.put("pregnantMemberNames", new SingleField("pregnantMemberNames", Strings.join(pregnantMemberNames, ','), null)); | ||
result.put("pregnantMemberDueDates", new SingleField("pregnantMemberDueDates", Strings.join(pregnantMemberDueDates, ','), null)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/org/ladocuploader/app/preparers/SpecialSituationsPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import org.apache.logging.log4j.util.Strings; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.ladocuploader.app.utils.SubmissionUtilities.householdMemberFullName; | ||
|
||
@Component | ||
public class SpecialSituationsPreparer implements SubmissionFieldPreparer { | ||
|
||
private static final List<String> INPUTS = List.of( | ||
"outOfStateBenefitsRecipients", | ||
"veterans", | ||
"fostersAgedOut", | ||
"preparesFood"); | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> result = new HashMap<>(); | ||
|
||
Map<String, List<String>> inputToNames = new HashMap<>(); | ||
Map<String, List<String>> inputToUUIDs = new HashMap<>(); | ||
for (String input : INPUTS) { | ||
List inputValue = (List) submission.getInputData().getOrDefault(input + "[]", emptyList()); | ||
inputToUUIDs.put(input, inputValue); | ||
inputToNames.put(input, new ArrayList<>()); | ||
} | ||
|
||
var members = (List<Map<String, Object>>) submission.getInputData().get("household"); | ||
if (members != null) { | ||
for (var member : members) { | ||
var uuid = (String) member.get("uuid"); | ||
var memberName = householdMemberFullName(member); | ||
|
||
for (String input : INPUTS) { | ||
if (inputToUUIDs.get(input).contains(uuid)) { | ||
inputToNames.get(input).add(memberName); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Check single-member household and format fields | ||
for (String input : INPUTS) { | ||
List<String> names = inputToNames.get(input); | ||
if (inputToUUIDs.get(input).contains("you")) { | ||
names.add("%s %s".formatted(submission.getInputData().get("firstName"), submission.getInputData().get("lastName"))); | ||
} | ||
if (!names.isEmpty()) { | ||
result.put(input + "Names", new SingleField(input + "Names", Strings.join(names, ','), null)); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/org/ladocuploader/app/preparers/StudentDetailsPreparer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.ladocuploader.app.preparers; | ||
|
||
import formflow.library.data.Submission; | ||
import formflow.library.pdf.PdfMap; | ||
import formflow.library.pdf.SingleField; | ||
import formflow.library.pdf.SubmissionField; | ||
import formflow.library.pdf.SubmissionFieldPreparer; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static formflow.library.inputs.FieldNameMarkers.DYNAMIC_FIELD_MARKER; | ||
import static java.util.Collections.emptyList; | ||
import static org.ladocuploader.app.utils.SubmissionUtilities.getHouseholdMemberFullnameByUUID; | ||
|
||
@Component | ||
public class StudentDetailsPreparer implements SubmissionFieldPreparer { | ||
|
||
@Override | ||
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) { | ||
Map<String, SubmissionField> result = new HashMap<>(); | ||
var students = (List) submission.getInputData().getOrDefault("students[]", emptyList()); | ||
if (!students.isEmpty()) { | ||
var i = 1; | ||
for (var studentUUID : students) { | ||
var studentName = getHouseholdMemberFullnameByUUID((String) studentUUID, submission.getInputData()); | ||
var schoolName = (String) submission.getInputData().get("schoolName%s%s".formatted(DYNAMIC_FIELD_MARKER, studentUUID)); | ||
var attendance = (String) submission.getInputData().get("schoolEnrollmentLevel%s%s".formatted(DYNAMIC_FIELD_MARKER, studentUUID)); | ||
|
||
result.put("studentName" + i, new SingleField("studentName", studentName, i)); | ||
result.put("schoolName" + i, new SingleField("schoolName", schoolName, i)); | ||
result.put("attendance" + i, new SingleField("attendance", attendance, i)); | ||
i++; | ||
} | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.