Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFR-3127 child info mapper #1745

Merged
merged 20 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
public enum Gender {
MALE("Male"),
FEMALE("Female"),
NOT_GIVEN("notGiven"),
EMPTY("");
al-hmcts marked this conversation as resolved.
Show resolved Hide resolved
NOT_GIVEN("notGiven");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private static Map<String, String> formAExceptionRecordToCcdMap() {
// Section 1 - further details of application
exceptionRecordToCcdFieldsMap.put(OcrFieldName.ADDRESS_OF_PROPERTIES, "natureOfApplication3a");
exceptionRecordToCcdFieldsMap.put(OcrFieldName.MORTGAGE_DETAILS, "natureOfApplication3b");
exceptionRecordToCcdFieldsMap.put(OcrFieldName.ORDER_FOR_CHILDREN, NATURE_OF_APP_5B);
exceptionRecordToCcdFieldsMap.put(OcrFieldName.CHILD_SUPPORT_AGENCY_CALCULATION_MADE, "ChildSupportAgencyCalculationMade");
exceptionRecordToCcdFieldsMap.put(OcrFieldName.CHILD_SUPPORT_AGENCY_CALCULATION_REASON, "ChildSupportAgencyCalculationReason");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static uk.gov.hmcts.reform.bsp.common.mapper.GenericMapper.getValueFromOcrDataFields;
import static uk.gov.hmcts.reform.bsp.common.utils.BulkScanCommonHelper.transformFormDateIntoCcdDate;
Expand Down Expand Up @@ -46,10 +47,12 @@ private static ChildInfo mapChild(int index, List<OcrDataField> ocrDataFields) {
dob = transformFormDateIntoCcdDate("childInfo" + index + ".dateOfBirth", childsDob);
}

String gender = getValueOrEmptyString(index, ocrDataFields, GENDER);

return ChildInfo.builder()
.name(getValueOrEmptyString(index, ocrDataFields, NAME_OF_CHILD))
.dateOfBirth(dob)
.gender(getValueFromOcrDataFields(GENDER + index, ocrDataFields).orElse("notGiven"))
.gender(StringUtils.isNotBlank(gender) ? gender : "notGiven")
al-hmcts marked this conversation as resolved.
Show resolved Hide resolved
.relationshipToApplicant(getValueOrEmptyString(index, ocrDataFields, RELATION_TO_APPLICANT))
.relationshipToRespondent(getValueOrEmptyString(index, ocrDataFields, RELATION_TO_RESPONDENT))
.countryOfResidence(getValueOrEmptyString(index, ocrDataFields, COUNTRY))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,34 @@ public void shouldTransformFieldsAccordingly() {
hasEntry("authorisation2b", "I'm the CEO")
));

assertChildrenInfo(transformedCaseData);
assertGivenChildrenInfo(transformedCaseData);

assertThat(transformedCaseData.get("natureOfApplication2"), is(asList("Periodical Payment Order", "Pension Attachment Order")));
assertThat(transformedCaseData.get("dischargePeriodicalPaymentSubstituteFor"), is(asList("lumpSumOrder", "pensionSharingOrder")));
assertThat(transformedCaseData.get("natureOfApplication6"), is(singletonList("In addition to child support")));
}

@Test
public void shouldEmptyChildGenderIsNotGiven() {
ExceptionRecord incomingExceptionRecord = createExceptionRecord(asList(
new OcrDataField(OcrFieldName.NAME_CHILD_1, "Bilbo Baggins"),
new OcrDataField(OcrFieldName.GENDER_CHILD_1, ""),
new OcrDataField(OcrFieldName.DATE_OF_BIRTH_CHILD_1, "12/03/2000"),
new OcrDataField(OcrFieldName.RELATIONSHIP_TO_APPLICANT_CHILD_1, "son"),
new OcrDataField(OcrFieldName.RELATIONSHIP_TO_RESPONDENT_CHILD_1, "SON"),
new OcrDataField(OcrFieldName.COUNTRY_CHILD_1, "New Zeeland"),
new OcrDataField(OcrFieldName.NAME_CHILD_2, "Frodo Baggins"),
new OcrDataField(OcrFieldName.GENDER_CHILD_2, null),
new OcrDataField(OcrFieldName.DATE_OF_BIRTH_CHILD_2, "12/03/1895"),
new OcrDataField(OcrFieldName.RELATIONSHIP_TO_APPLICANT_CHILD_2, "daughter"),
new OcrDataField(OcrFieldName.RELATIONSHIP_TO_RESPONDENT_CHILD_2, "Daughter"),
new OcrDataField(OcrFieldName.COUNTRY_CHILD_2, "The Shire")));

Map<String, Object> transformedCaseData = formAToCaseTransformer.transformIntoCaseData(incomingExceptionRecord);

assertNotGivenChildrenInfo(transformedCaseData);
}

@Test
public void shouldNotReturnUnexpectedField() {
ExceptionRecord incomingExceptionRecord = createExceptionRecord(singletonList(
Expand Down Expand Up @@ -267,7 +288,7 @@ public void shouldNotSetOrderForChildrenQuestion1IfOrderForChildrenFieldIsNotPop
assertThat(transformedCaseData, allOf(
hasEntry(BULK_SCAN_CASE_REFERENCE, TEST_CASE_ID),
hasEntry(PAPER_APPLICATION, YES_VALUE),
hasEntry("natureOfApplication5b", ""),
not(hasEntry("natureOfApplication5b", "")),
not(hasKey("orderForChildrenQuestion1"))
));
}
Expand Down Expand Up @@ -520,13 +541,20 @@ private static ExceptionRecord createExceptionRecord(List<OcrDataField> ocrDataF
return ExceptionRecord.builder().id(TEST_CASE_ID).ocrDataFields(ocrDataFields).build();
}

private void assertChildrenInfo(Map<String, Object> transformedCaseData) {
private void assertGivenChildrenInfo(Map<String, Object> transformedCaseData) {
ComplexTypeCollection<ChildInfo> children = (ComplexTypeCollection<ChildInfo>) transformedCaseData.get("childrenInfo");

assertChild(children.getItem(0), asList("Johny Bravo", "2000-03-12", "Male", "son", "SON", "New Zeeland"));
assertChild(children.getItem(1), asList("Anne Shirley", "1895-03-12", "Female", "daughter", "Daughter", "Canada"));
}

private void assertNotGivenChildrenInfo(Map<String, Object> transformedCaseData) {
ComplexTypeCollection<ChildInfo> children = (ComplexTypeCollection<ChildInfo>) transformedCaseData.get("childrenInfo");

assertChild(children.getItem(0), asList("Bilbo Baggins", "2000-03-12", "notGiven", "son", "SON", "New Zeeland"));
assertChild(children.getItem(1), asList("Frodo Baggins", "1895-03-12", "notGiven", "daughter", "Daughter", "The Shire"));
}

private void assertChild(ChildInfo child, List<String> values) {
assertThat(child.getName(), is(values.get(0)));
assertThat(child.getDateOfBirth(), is(values.get(1)));
Expand Down