Skip to content

Commit

Permalink
Show correct address in review screen and PDF
Browse files Browse the repository at this point in the history
Co-authored-by: Ana Medrano <amedrano@codeforamerica.org>
  • Loading branch information
2 people authored and bseeger committed Mar 29, 2024
1 parent 1ef69ab commit 09bd8d1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 37 deletions.
7 changes: 2 additions & 5 deletions src/main/java/org/mdbenefits/app/inputs/MdBenefitsFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ public class MdBenefitsFlow extends FlowInputs {

private String mailingAddressZipCode;

// Verify Address
private String verifyAddress;

// Select Address
private String selectAddress;
// Verify Address & Select Address
private String useSuggestedAddress;

//Contact Info
@Pattern(regexp = "^\\(\\d{3}\\) \\d{3}-\\d{4}$", message = "{error.invalid-phone}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Map<String, SubmissionField> prepareSubmissionFields(Submission submissio
.reduce((e, c) -> e + "/" + c)
.get();

String applyingStatus = (String) inputData.get("isApplicantApplying");
String applyingStatus = (String) inputData.getOrDefault("isApplicantApplying", "no");
if (applyingStatus.equalsIgnoreCase("yes")) {

results.put("applicantDOB", new SingleField("applicantDOB", (String) dob, null));
Expand All @@ -51,36 +51,46 @@ public Map<String, SubmissionField> prepareSubmissionFields(Submission submissio
prepareCitizenshipStatus(inputData, results);

prepareRaceEthnicityInfo(inputData, results);

results.put("applicantMailingAddressFull",
new SingleField("applicantMailingAddressFull", formatMailingAddress(inputData), null));
}

results.put("applicantMailingAddressFull",
new SingleField("applicantMailingAddressFull", formatMailingAddress(inputData), null));

return results;
}

public String formatMailingAddress(Map<String, Object> inputData) {
String mailingAddressFull;
if (inputData.getOrDefault("sameAsHomeAddress", "false").equals("true")) {
mailingAddressFull = "";
} else {
if (inputData.get("mailingAddressStreetAddress2") != null) {
mailingAddressFull = String.format("%s, %s, %s, %s %s",
inputData.get("mailingAddressStreetAddress1"),
inputData.get("mailingAddressStreetAddress2"),
inputData.get("mailingAddressCity"),
inputData.get("mailingAddressState"),
inputData.get("mailingAddressZipCode")
);
} else {
mailingAddressFull = String.format("%s, %s, %s %s",
inputData.get("mailingAddressStreetAddress1"),
inputData.get("mailingAddressCity"),
inputData.get("mailingAddressState"),
inputData.get("mailingAddressZipCode")
);
return mailingAddressFull;
}

if (inputData.getOrDefault("useSuggestedAddress", "false").equals("true")) {
mailingAddressFull = String.format("%s, %s, %s %s",
inputData.get("mailingAddressStreetAddress1_validated"),
inputData.get("mailingAddressCity_validated"),
inputData.get("mailingAddressState_validated"),
inputData.get("mailingAddressZipCode_validated"));

return mailingAddressFull;
}

}
if (inputData.get("mailingAddressStreetAddress2") != null) {
mailingAddressFull = String.format("%s, %s, %s, %s %s",
inputData.get("mailingAddressStreetAddress1"),
inputData.get("mailingAddressStreetAddress2"),
inputData.get("mailingAddressCity"),
inputData.get("mailingAddressState"),
inputData.get("mailingAddressZipCode")
);
} else {
mailingAddressFull = String.format("%s, %s, %s %s",
inputData.get("mailingAddressStreetAddress1"),
inputData.get("mailingAddressCity"),
inputData.get("mailingAddressState"),
inputData.get("mailingAddressZipCode")
);
}
return mailingAddressFull;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.mdbenefits.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 java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.mdbenefits.app.data.enums.CitizenshipStatus;
import org.mdbenefits.app.data.enums.EthnicityType;
import org.mdbenefits.app.data.enums.RaceType;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HomeAddressPreparer implements SubmissionFieldPreparer {

@Override
public Map<String, SubmissionField> prepareSubmissionFields(Submission submission, PdfMap pdfMap) {
Map<String, SubmissionField> results = new HashMap<>();

Map<String, Object> inputData = submission.getInputData();

boolean useSuggestedAddress = Boolean.parseBoolean(
inputData.getOrDefault("useSuggestedAddress", "false").toString());

boolean homeAddressSameAsMailingAddress = Boolean.parseBoolean(
inputData.getOrDefault("sameAsHomeAddress", "false").toString());

List<String> homeAddressParts = List.of("homeAddressStreetAddress1", "homeAddressStreetAddress2",
"homeAddressCity", "homeAddressState", "homeAddressZipCode");

List<String> mailingAddressParts = List.of("mailingAddressStreetAddress1", "mailingAddressStreetAddress2",
"mailingAddressCity", "mailingAddressState", "mailingAddressZipCode");
// We only ever validate the mailing address so we need to replace the home address with the validated
// mailing address if they are the same
if (useSuggestedAddress && homeAddressSameAsMailingAddress) {
for (int i = 0; i < mailingAddressParts.size(); i++) {
String mailingAddressPart = mailingAddressParts.get(i);
if (inputData.containsKey(mailingAddressPart + "_validated")) {
results.put(homeAddressParts.get(i),
new SingleField(homeAddressParts.get(i), inputData.get(mailingAddressPart + "_validated").toString(), null));
}
}
}

return results;
}
}
23 changes: 14 additions & 9 deletions src/main/resources/templates/mdBenefitsFlow/contactInfoReview.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
<div class="spacing-above-15">
<p th:text="${fieldData.firstName} + ' ' + ${fieldData.lastName}"></p>
</div>
<hr class="spacing-below-35 spacing-above-20">
<hr class="spacing-below-35 spacing-above-10">
<b th:text="#{review-contact-info.birthdate}"></b>
<div class="spacing-above-10">
<p th:text="${T(org.mdbenefits.app.utils.SubmissionUtilities).getFormattedBirthdate(fieldData)}"></p>
</div>
<b th:text="#{review-contact-info.mailing-address}"></b>
<div class="spacing-above-10">
<p class="spacing-below-5" th:text="${fieldData.mailingAddressStreetAddress1}"></p>
<p class="spacing-below-5" th:text="${fieldData.mailingAddressStreetAddress2}"></p>
<p class="spacing-below-5"
th:text="${fieldData.mailingAddressCity} + ', ' + ${fieldData.mailingAddressState}"></p>
<p th:text="${fieldData.mailingAddressZipCode}"></p>
<div class="spacing-above-10" th:if="${fieldData.getOrDefault('useSuggestedAddress', 'false').equals('false')}">
<th:block th:text="${fieldData.mailingAddressStreetAddress1}"></th:block><br>
<div th:if="${fieldData.mailingAddressStreetAddress2 != null && !fieldData.mailingAddressStreetAddress2.trim().isEmpty()}">
<th:block th:text="${fieldData.mailingAddressStreetAddress2}"></th:block><br>
</div>
<th:block th:text="${fieldData.mailingAddressCity} + ', ' + ${fieldData.mailingAddressState}"></th:block><br>
<th:block th:text="${fieldData.mailingAddressZipCode}"></th:block><br>
</div>

<hr class="spacing-below-35 spacing-above-35">
<div class="spacing-above-15" th:if="${fieldData.getOrDefault('useSuggestedAddress', 'false').equals('true')}">
<th:block th:text="${fieldData.mailingAddressStreetAddress1_validated}"></th:block><br>
<th:block th:text="${fieldData.mailingAddressCity_validated} + ', ' + ${fieldData.mailingAddressState_validated}"></th:block><br>
<th:block th:text="${fieldData.mailingAddressZipCode_validated}"></th:block><br>
</div>
<hr class="spacing-below-25 spacing-above-25">
<div class="spacing-above-15">
<b th:text="#{review-contact-info.cell-phone-number}"></b>
<p class="spacing-below-5 spacing-above-10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<th:block th:replace="~{fragments/screens/addressSuggestionFound ::
addressSuggestionFound(
addressInputToCheck='mailingAddress',
inputName='selectAddress',
inputName='useSuggestedAddress',
header=#{verify-address.title},
notice=#{select-address.notice}
)}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<th:block th:replace="~{fragments/screens/addressSuggestionNotFound ::
addressSuggestionNotFound(
addressInputToCheck='mailingAddress',
inputName='verifyAddress',
inputName='useSuggestedAddress',
editAddressURL=${editURL},
header=#{verify-address.title},
notice=#{verify-address.notice}
Expand Down

0 comments on commit 09bd8d1

Please sign in to comment.