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 all 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 @@ -12,6 +12,7 @@

import static uk.gov.hmcts.reform.bsp.common.mapper.GenericMapper.getValueFromOcrDataFields;
import static uk.gov.hmcts.reform.bsp.common.utils.BulkScanCommonHelper.transformFormDateIntoCcdDate;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.Gender.NOT_GIVEN;
import static uk.gov.hmcts.reform.finrem.caseorchestration.service.bulkscan.transformation.mappers.ChildrenInfoMapper.Fields.COUNTRY;
import static uk.gov.hmcts.reform.finrem.caseorchestration.service.bulkscan.transformation.mappers.ChildrenInfoMapper.Fields.DOB;
import static uk.gov.hmcts.reform.finrem.caseorchestration.service.bulkscan.transformation.mappers.ChildrenInfoMapper.Fields.GENDER;
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 : NOT_GIVEN.getValue())
.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 @@ -8,6 +8,7 @@
import uk.gov.hmcts.reform.bsp.common.model.shared.in.InputScannedDoc;
import uk.gov.hmcts.reform.bsp.common.model.validation.out.OcrValidationResult;
import uk.gov.hmcts.reform.bsp.common.service.BulkScanFormValidator;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.Gender;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -19,7 +20,6 @@

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static uk.gov.hmcts.reform.bsp.common.model.validation.BulkScanValidationPatterns.CCD_EMAIL_REGEX;
import static uk.gov.hmcts.reform.bsp.common.model.validation.BulkScanValidationPatterns.CCD_PHONE_NUMBER_REGEX;
import static uk.gov.hmcts.reform.bsp.common.service.validation.PostcodeValidator.validatePostcode;
Expand Down Expand Up @@ -149,15 +149,17 @@ public class FormAValidator extends BulkScanFormValidator {
));
ALLOWED_VALUES_PER_FIELD.put(CHILD_SUPPORT_AGENCY_CALCULATION_MADE, asList(
"Yes",
"No",
EMPTY
"No"
));
ALLOWED_VALUES_PER_FIELD.put(AUTHORISATION_SIGNED_BY, asList(
"Applicant",
"Litigation Friend",
"Applicant's solicitor"
));
final List<String> genderEnum = asList("Male", "Female", EMPTY);
final List<String> genderEnum = asList(
Gender.MALE.getValue(),
Gender.FEMALE.getValue()
);
ALLOWED_VALUES_PER_FIELD.put(GENDER_CHILD_1, genderEnum);
ALLOWED_VALUES_PER_FIELD.put(GENDER_CHILD_2, genderEnum);
}
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 shouldTransformEmptyChildGenderIsNotGiven() {
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 @@ -224,6 +245,14 @@ public void shouldTransformAddressesWhenCitizensNotRepresented() {
);
}

@Test
public void childSupportAgencyCalculationMadeToNullWhenNotProvided() {
Map<String, Object> optionOneTransformedData = formAToCaseTransformer.transformIntoCaseData(createExceptionRecord(
singletonList(new OcrDataField("ChildSupportAgencyCalculationMade",
null))));
assertThat(optionOneTransformedData, hasEntry("ChildSupportAgencyCalculationMade", null));
}

@Test
public void shouldSetOrderForChildrenQuestion1ToYesIfOrderForChildrenFieldIsPopulated() {
Map<String, Object> optionOneTransformedData = formAToCaseTransformer.transformIntoCaseData(createExceptionRecord(
Expand Down Expand Up @@ -267,7 +296,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 +549,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
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,16 @@ public void shouldFailFieldsHavingInvalidValues() {
"to meet expenses incurred by a child in being educated or training for work",
"when either the child or the person with care of the child "
+ "or the absent parent of the child is not habitually resident in the United Kingdom"),
CHILD_SUPPORT_AGENCY_CALCULATION_MADE + " must be \"Yes\", \"No\" or left blank",
CHILD_SUPPORT_AGENCY_CALCULATION_MADE + " must be \"Yes\" or \"No\"",
mustBeOneOf(AUTHORISATION_SIGNED_BY,
"Applicant",
"Litigation Friend",
"Applicant's solicitor"),
AUTHORISATION_DATE + " must be a valid date",
DATE_OF_BIRTH_CHILD_1 + " must be a valid date",
DATE_OF_BIRTH_CHILD_2 + " must be a valid date",
GENDER_CHILD_1 + " must be \"Male\", \"Female\" or left blank",
GENDER_CHILD_2 + " must be \"Male\", \"Female\" or left blank",
GENDER_CHILD_1 + " must be \"Male\" or \"Female\"",
GENDER_CHILD_2 + " must be \"Male\" or \"Female\"",
mandatoryFieldIsMissing.apply(APPLICANT_ADDRESS_LINE_1),
mandatoryFieldIsMissing.apply(APPLICANT_ADDRESS_POSTCODE),
mandatoryFieldIsMissing.apply(RESPONDENT_ADDRESS_LINE_1),
Expand Down