Skip to content

Commit

Permalink
Adding home expenses
Browse files Browse the repository at this point in the history
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
sree-cfa committed Dec 21, 2023
1 parent a70be16 commit df21753
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ public class LaDigitalAssister extends FlowInputs {

private String outOfStateBenefitsRecipients;

private String receivedOutOfStateBenefits;

// SNAP
private String buyPrepareMealsSeparateIndicator;

Expand Down
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;
}
}
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;
}
}

This file was deleted.

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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public SsnPreparer(StringEncryptor stringEncryptor) {
encryptor = stringEncryptor;
}

private StringEncryptor getEncryptor() {
return encryptor;
}

@Override
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) {
Map<String, SubmissionField> results = new HashMap<>();
Expand All @@ -41,7 +37,7 @@ public Map<String, SubmissionField> prepareSubmissionFields(Submission submissio
for (Map<String, Object> hhmember : householdMembers) {
encryptedSSN = (String) hhmember.get(ENCRYPTED_SSNS_INPUT_NAME);
String decryptedSSN = encryptor.decrypt(encryptedSSN);
results.put("ssns_" + i, new SingleField("ssns_" + i, decryptedSSN, null));
results.put("ssns" + i, new SingleField("ssns", decryptedSSN, i));
i++;
}
}
Expand Down
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;
}
}
14 changes: 12 additions & 2 deletions src/main/java/org/ladocuploader/app/utils/SubmissionUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.*;

import static formflow.library.inputs.FieldNameMarkers.DYNAMIC_FIELD_MARKER;
import static java.util.Collections.emptyList;
import static org.ladocuploader.app.utils.Parish.ORLEANS;

public class SubmissionUtilities {
Expand Down Expand Up @@ -119,7 +120,7 @@ public static boolean inExperimentGroup(String groupName, Submission submission)
return groupName.equals(submission.getInputData().get("experimentGroup"));
}

public static String householdMemberFullName(Map<String, String> householdMember) {
public static String householdMemberFullName(Map<String, Object> householdMember) {
return householdMember.get("householdMemberFirstName") + " " + householdMember.get("householdMemberLastName");
}

Expand All @@ -132,14 +133,23 @@ public static List<String> getHouseholdMemberNames(Submission submission) {
ArrayList<String> names = new ArrayList<>();

var applicantName = submission.getInputData().get("firstName") + " " + submission.getInputData().get("lastName");
var householdMembers = (List<Map<String, String>>) submission.getInputData().getOrDefault("household", new ArrayList<HashMap<String, Object>>());
var householdMembers = (List<Map<String, Object>>) submission.getInputData().getOrDefault("household", new ArrayList<HashMap<String, Object>>());

names.add(applicantName);
householdMembers.forEach(hh -> names.add(householdMemberFullName(hh)));

return names;
}

public static String getHouseholdMemberFullnameByUUID(String uuid, Map<String, Object> inputData) {
var members = (List<Map<String, Object>>) inputData.getOrDefault("household", emptyList());
for (var member : members) {
if (uuid.equals(member.get("uuid"))) {
return householdMemberFullName(member);
}
}
return "%s %s".formatted(inputData.get("firstName"), inputData.get("lastName"));
}
public static ArrayList<HashMap<String, Object>> getHouseholdIncomeReviewItems(Submission submission) {
var applicantFullName = submission.getInputData().getOrDefault("firstName", "") + " " + submission.getInputData().getOrDefault("lastName", "");
var notYetShownNames = getHouseholdMemberNames(submission);
Expand Down
Loading

0 comments on commit df21753

Please sign in to comment.