diff --git a/tdrs-backend/tdpservice/parsers/parse.py b/tdrs-backend/tdpservice/parsers/parse.py index 05c3da3ca..ac65dce5e 100644 --- a/tdrs-backend/tdpservice/parsers/parse.py +++ b/tdrs-backend/tdpservice/parsers/parse.py @@ -251,50 +251,6 @@ def manager_parse_line(line, schema_manager, generate_error, is_encrypted=False) ) ])] - -def get_schema_manager_options(program_type): - """Return the allowed schema options.""" - match program_type: - case 'TAN': - return { - 'A': { - 'T1': schema_defs.tanf.t1, - 'T2': schema_defs.tanf.t2, - 'T3': schema_defs.tanf.t3, - }, - 'C': { - 'T4': schema_defs.tanf.t4, - 'T5': schema_defs.tanf.t5, - }, - 'G': { - 'T6': schema_defs.tanf.t6, - }, - 'S': { - 'T7': schema_defs.tanf.t7, - }, - } - case 'SSP': - return { - 'A': { - 'M1': schema_defs.ssp.m1, - 'M2': schema_defs.ssp.m2, - 'M3': schema_defs.ssp.m3, - }, - 'C': { - # 'M4': schema_options.m4, - # 'M5': schema_options.m5, - }, - 'G': { - # 'M6': schema_options.m6, - }, - 'S': { - # 'M7': schema_options.m7, - }, - } - # case tribal? - return None - - def get_schema_manager(line, section, program_type): """Return the appropriate schema for the line.""" line_type = line[0:2] diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/header.py b/tdrs-backend/tdpservice/parsers/schema_defs/header.py index 96ede4754..deed0f416 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/header.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/header.py @@ -11,44 +11,162 @@ preparsing_validators=[ validators.hasLength( 23, - lambda value, length: f'Header length is {len(value)} but must be {length} characters.' + lambda value, length: f"Header length is {len(value)} but must be {length} characters.", ), - validators.startsWith('HEADER'), + validators.startsWith("HEADER"), ], postparsing_validators=[], fields=[ - Field(item="2", name='title', type='string', startIndex=0, endIndex=6, required=True, validators=[ - validators.matches('HEADER'), - ]), - Field(item="4", name='year', type='number', startIndex=6, endIndex=10, required=True, validators=[ - validators.isInLimits(2000, 2099) - ]), - Field(item="5", name='quarter', type='string', startIndex=10, endIndex=11, required=True, validators=[ - validators.oneOf(['1', '2', '3', '4']) - ]), - Field(item="6", name='type', type='string', startIndex=11, endIndex=12, required=True, validators=[ - validators.oneOf(['A', 'C', 'G', 'S']) - ]), - Field(item="1", name='state_fips', type='string', startIndex=12, endIndex=14, required=True, validators=[ - validators.oneOf(("01", "02", "04", "05", "06", "08", "09", "10", "11", "12", "13", "15", "16", "17", "18", - "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", - "34", "35", "36", "37", "38", "39", "40", "41", "42", "44", "45", "46", "47", "48", "49", - "50", "51", "53", "54", "55", "56", "66", "72", "78")) - ]), - Field(item="3", name='tribe_code', type='string', startIndex=14, endIndex=17, required=False, validators=[ - validators.isInStringRange(0, 999) - ]), - Field(item="7", name='program_type', type='string', startIndex=17, endIndex=20, required=True, validators=[ - validators.oneOf(['TAN', 'SSP']) - ]), - Field(item="8", name='edit', type='string', startIndex=20, endIndex=21, required=True, validators=[ - validators.oneOf(['1', '2']) - ]), - Field(item="9", name='encryption', type='string', startIndex=21, endIndex=22, required=False, validators=[ - validators.oneOf([' ', 'E']) - ]), - Field(item="10", name='update', type='string', startIndex=22, endIndex=23, required=True, validators=[ - validators.oneOf(['N', 'D', 'U']) - ]), + Field( + item="2", + name="title", + type="string", + startIndex=0, + endIndex=6, + required=True, + validators=[ + validators.matches("HEADER"), + ], + ), + Field( + item="4", + name="year", + type="number", + startIndex=6, + endIndex=10, + required=True, + validators=[validators.isInLimits(2000, 2099)], + ), + Field( + item="5", + name="quarter", + type="string", + startIndex=10, + endIndex=11, + required=True, + validators=[validators.oneOf(["1", "2", "3", "4"])], + ), + Field( + item="6", + name="type", + type="string", + startIndex=11, + endIndex=12, + required=True, + validators=[validators.oneOf(["A", "C", "G", "S"])], + ), + Field( + item="1", + name="state_fips", + type="string", + startIndex=12, + endIndex=14, + required=True, + validators=[ + validators.oneOf( + ( + "01", + "02", + "04", + "05", + "06", + "08", + "09", + "10", + "11", + "12", + "13", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + "32", + "33", + "34", + "35", + "36", + "37", + "38", + "39", + "40", + "41", + "42", + "44", + "45", + "46", + "47", + "48", + "49", + "50", + "51", + "53", + "54", + "55", + "56", + "66", + "72", + "78", + ) + ) + ], + ), + Field( + item="3", + name="tribe_code", + type="string", + startIndex=14, + endIndex=17, + required=False, + validators=[validators.isInStringRange(0, 999)], + ), + Field( + item="7", + name="program_type", + type="string", + startIndex=17, + endIndex=20, + required=True, + validators=[validators.oneOf(["TAN", "SSP"])], + ), + Field( + item="8", + name="edit", + type="string", + startIndex=20, + endIndex=21, + required=True, + validators=[validators.oneOf(["1", "2"])], + ), + Field( + item="9", + name="encryption", + type="string", + startIndex=21, + endIndex=22, + required=False, + validators=[validators.oneOf([" ", "E"])], + ), + Field( + item="10", + name="update", + type="string", + startIndex=22, + endIndex=23, + required=True, + validators=[validators.oneOf(["N", "D", "U"])], + ), ], ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/__init__.py b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/__init__.py index b3542bf07..31a2f6d6d 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/__init__.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/__init__.py @@ -2,8 +2,10 @@ from .m2 import m2 from .m3 import m3 from .m6 import m6 +from .m7 import m7 m1 = m1 m2 = m2 m3 = m3 m6 = m6 +m7 = m7 diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m1.py b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m1.py index 479a243cf..8f9d94697 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m1.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m1.py @@ -8,7 +8,7 @@ from tdpservice.search_indexes.models.ssp import SSP_M1 m1 = SchemaManager( - schemas=[ + schemas=[ RowSchema( model=SSP_M1, preparsing_validators=[ @@ -243,5 +243,5 @@ required=False, validators=[]), ] ) - ] - ) + ] +) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py index 58c99ccac..b45ccdf2c 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py @@ -10,7 +10,7 @@ m2 = SchemaManager( - schemas=[ + schemas=[ RowSchema( model=SSP_M2, preparsing_validators=[ @@ -364,5 +364,5 @@ ]), ], ) - ] - ) + ] +) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m3.py b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m3.py index 38e66ee35..beb975e58 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m3.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m3.py @@ -301,9 +301,4 @@ ] ) -m3 = SchemaManager( - schemas=[ - first_part_schema, - second_part_schema - ] -) +m3 = SchemaManager(schemas=[first_part_schema, second_part_schema]) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m7.py b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m7.py new file mode 100644 index 000000000..1fb1aa8fa --- /dev/null +++ b/tdrs-backend/tdpservice/parsers/schema_defs/ssp/m7.py @@ -0,0 +1,103 @@ +"""Schema for TANF T7 Row.""" + +from ...util import SchemaManager +from ...fields import Field, TransformField +from ...row_schema import RowSchema +from ...transforms import calendar_quarter_to_rpt_month_year +from ... import validators +from tdpservice.search_indexes.models.ssp import SSP_M7 + +schemas = [] + +validator_index = 7 +section_ind_index = 7 +stratum_index = 8 +families_index = 10 + +sub_item_labels = ["5A", "5B", "5C"] +families_item_numbers = [sub_item_labels[i % 3] for i in range(30)] + +for i in range(1, 31): + schemas.append( + RowSchema( + model=SSP_M7, + quiet_preparser_errors=i > 1, + preparsing_validators=[ + validators.hasLength(247), + validators.notEmpty(0, 7), + validators.notEmpty(validator_index, validator_index + 24), + ], + postparsing_validators=[], + fields=[ + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="2", + name="CALENDAR_QUARTER", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.quarterIsValid(), + ], + ), + TransformField( + transform_func=calendar_quarter_to_rpt_month_year((i - 1) % 3), + item="2A", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="3", + name="TDRS_SECTION_IND", + type="string", + startIndex=section_ind_index, + endIndex=section_ind_index + 1, + required=True, + validators=[validators.oneOf(["1", "2"])], + ), + Field( + item="4", + name="STRATUM", + type="string", + startIndex=stratum_index, + endIndex=stratum_index + 2, + required=True, + validators=[validators.isInStringRange(0, 99)], + ), + Field( + item=families_item_numbers[i - 1], + name="FAMILIES_MONTH", + type="number", + startIndex=families_index, + endIndex=families_index + 7, + required=True, + validators=[validators.isInLimits(0, 9999999)], + ), + ], + ) + ) + + index_offset = 0 if i % 3 != 0 else 24 + validator_index += index_offset + section_ind_index += index_offset + stratum_index += index_offset + families_index += 7 if i % 3 != 0 else 10 + +m7 = SchemaManager(schemas=schemas) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py index f31bc892c..4718db68e 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py @@ -7,258 +7,621 @@ from tdpservice.search_indexes.models.tanf import TANF_T1 -t1 = SchemaManager(schemas=[ - RowSchema( +t1 = SchemaManager( + schemas=[ + RowSchema( model=TANF_T1, preparsing_validators=[ - validators.hasLength(156), + validators.hasLength(156), ], postparsing_validators=[ - validators.if_then_validator( - condition_field='CASH_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='NBR_MONTHS', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='CC_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='CHILDREN_COVERED', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='CC_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='CC_NBR_MONTHS', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='TRANSP_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='TRANSP_NBR_MONTHS', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='TRANSITION_SERVICES_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='TRANSITION_NBR_MONTHS', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='OTHER_AMOUNT', condition_function=validators.isLargerThan(0), - result_field='OTHER_NBR_MONTHS', result_function=validators.isLargerThan(0), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='WORK_REQ_SANCTION', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='FAMILY_SANC_ADULT', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='SANC_TEEN_PARENT', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='NON_COOPERATION_CSE', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='FAILURE_TO_COMPLY', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='SANC_REDUCTION_AMT', condition_function=validators.isLargerThan(0), - result_field='OTHER_SANCTION', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='OTHER_TOTAL_REDUCTIONS', condition_function=validators.isLargerThan(0), - result_field='FAMILY_CAP', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='OTHER_TOTAL_REDUCTIONS', condition_function=validators.isLargerThan(0), - result_field='REDUCTIONS_ON_RECEIPTS', result_function=validators.oneOf((1, 2)), - ), - validators.if_then_validator( - condition_field='OTHER_TOTAL_REDUCTIONS', condition_function=validators.isLargerThan(0), - result_field='OTHER_NON_SANCTION', result_function=validators.oneOf((1, 2)), - ), - validators.sumIsLarger(("AMT_FOOD_STAMP_ASSISTANCE", "AMT_SUB_CC", "CASH_AMOUNT", "CC_AMOUNT", - "TRANSP_AMOUNT", "TRANSITION_SERVICES_AMOUNT", "OTHER_AMOUNT"), 0) + validators.if_then_validator( + condition_field="CASH_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="NBR_MONTHS", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="CC_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="CHILDREN_COVERED", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="CC_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="CC_NBR_MONTHS", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="TRANSP_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="TRANSP_NBR_MONTHS", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="TRANSITION_SERVICES_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="TRANSITION_NBR_MONTHS", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="OTHER_AMOUNT", + condition_function=validators.isLargerThan(0), + result_field="OTHER_NBR_MONTHS", + result_function=validators.isLargerThan(0), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="WORK_REQ_SANCTION", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="FAMILY_SANC_ADULT", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="SANC_TEEN_PARENT", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="NON_COOPERATION_CSE", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="FAILURE_TO_COMPLY", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="SANC_REDUCTION_AMT", + condition_function=validators.isLargerThan(0), + result_field="OTHER_SANCTION", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="OTHER_TOTAL_REDUCTIONS", + condition_function=validators.isLargerThan(0), + result_field="FAMILY_CAP", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="OTHER_TOTAL_REDUCTIONS", + condition_function=validators.isLargerThan(0), + result_field="REDUCTIONS_ON_RECEIPTS", + result_function=validators.oneOf((1, 2)), + ), + validators.if_then_validator( + condition_field="OTHER_TOTAL_REDUCTIONS", + condition_function=validators.isLargerThan(0), + result_field="OTHER_NON_SANCTION", + result_function=validators.oneOf((1, 2)), + ), + validators.sumIsLarger( + ( + "AMT_FOOD_STAMP_ASSISTANCE", + "AMT_SUB_CC", + "CASH_AMOUNT", + "CC_AMOUNT", + "TRANSP_AMOUNT", + "TRANSITION_SERVICES_AMOUNT", + "OTHER_AMOUNT", + ), + 0, + ), ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[ - validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid(), - ]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="2", name='COUNTY_FIPS_CODE', type='string', startIndex=19, endIndex=22, - required=True, validators=[ - validators.isNumber(), - ]), - Field(item="5", name='STRATUM', type='string', startIndex=22, endIndex=24, - required=False, validators=[ - validators.isInStringRange(0, 99), - ]), - Field(item="7", name='ZIP_CODE', type='string', startIndex=24, endIndex=29, - required=True, validators=[ - validators.isNumber(), - ]), - Field(item="8", name='FUNDING_STREAM', type='number', startIndex=29, endIndex=30, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="9", name='DISPOSITION', type='number', startIndex=30, endIndex=31, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="10", name='NEW_APPLICANT', type='number', startIndex=31, endIndex=32, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="11", name='NBR_FAMILY_MEMBERS', type='number', startIndex=32, endIndex=34, - required=True, validators=[ - validators.isLargerThan(0), - ]), - Field(item="12", name='FAMILY_TYPE', type='number', startIndex=34, endIndex=35, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="13", name='RECEIVES_SUB_HOUSING', type='number', startIndex=35, endIndex=36, - required=True, validators=[ - validators.isInLimits(1, 3), - ]), - Field(item="14", name='RECEIVES_MED_ASSISTANCE', type='number', startIndex=36, endIndex=37, - required=True, validators=[ - validators.isInLimits(1, 2), - ]), - Field(item="15", name='RECEIVES_FOOD_STAMPS', type='number', startIndex=37, endIndex=38, - required=False, validators=[ - validators.isInLimits(0, 2), - ]), - Field(item="16", name='AMT_FOOD_STAMP_ASSISTANCE', type='number', startIndex=38, endIndex=42, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="17", name='RECEIVES_SUB_CC', type='number', startIndex=42, endIndex=43, - required=False, validators=[ - validators.isInLimits(0, 3), - ]), - Field(item="18", name='AMT_SUB_CC', type='number', startIndex=43, endIndex=47, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="19", name='CHILD_SUPPORT_AMT', type='number', startIndex=47, endIndex=51, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="20", name='FAMILY_CASH_RESOURCES', type='number', startIndex=51, endIndex=55, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="21A", name='CASH_AMOUNT', type='number', startIndex=55, endIndex=59, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="21B", name='NBR_MONTHS', type='number', startIndex=59, endIndex=62, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="22A", name='CC_AMOUNT', type='number', startIndex=62, endIndex=66, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="22B", name='CHILDREN_COVERED', type='number', startIndex=66, endIndex=68, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="22C", name='CC_NBR_MONTHS', type='number', startIndex=68, endIndex=71, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="23A", name='TRANSP_AMOUNT', type='number', startIndex=71, endIndex=75, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="23B", name='TRANSP_NBR_MONTHS', type='number', startIndex=75, endIndex=78, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="24A", name='TRANSITION_SERVICES_AMOUNT', type='number', startIndex=78, endIndex=82, - required=False, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="24B", name='TRANSITION_NBR_MONTHS', type='number', startIndex=82, endIndex=85, - required=False, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="25A", name='OTHER_AMOUNT', type='number', startIndex=85, endIndex=89, - required=False, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="25B", name='OTHER_NBR_MONTHS', type='number', startIndex=89, endIndex=92, - required=False, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="26AI", name='SANC_REDUCTION_AMT', type='number', startIndex=92, endIndex=96, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="26AII", name='WORK_REQ_SANCTION', type='number', startIndex=96, endIndex=97, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26AIII", name='FAMILY_SANC_ADULT', type='number', startIndex=97, endIndex=98, - required=False, validators=[ - validators.oneOf([0, 1, 2]), - ]), - Field(item="26AIV", name='SANC_TEEN_PARENT', type='number', startIndex=98, endIndex=99, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26AV", name='NON_COOPERATION_CSE', type='number', startIndex=99, endIndex=100, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26AVI", name='FAILURE_TO_COMPLY', type='number', startIndex=100, endIndex=101, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26AVII", name='OTHER_SANCTION', type='number', startIndex=101, endIndex=102, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26B", name='RECOUPMENT_PRIOR_OVRPMT', type='number', startIndex=102, endIndex=106, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="26CI", name='OTHER_TOTAL_REDUCTIONS', type='number', startIndex=106, endIndex=110, - required=True, validators=[ - validators.isLargerThanOrEqualTo(0), - ]), - Field(item="26CII", name='FAMILY_CAP', type='number', startIndex=110, endIndex=111, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26CIII", name='REDUCTIONS_ON_RECEIPTS', type='number', startIndex=111, endIndex=112, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="26CIV", name='OTHER_NON_SANCTION', type='number', startIndex=112, endIndex=113, - required=True, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="27", name='WAIVER_EVAL_CONTROL_GRPS', type='string', startIndex=113, endIndex=114, - required=False, validators=[ - validators.or_validators(validators.matches('9'), validators.isEmpty()), - validators.isAlphaNumeric(), - ]), - Field(item="28", name='FAMILY_EXEMPT_TIME_LIMITS', type='number', startIndex=114, endIndex=116, - required=True, validators=[ - validators.oneOf([1, 2, 3, 4, - 6, 7, 8, 9]) - ]), - Field(item="29", name='FAMILY_NEW_CHILD', type='number', startIndex=116, endIndex=117, - required=False, validators=[ - validators.oneOf([1, 2]), - ]), - Field(item="-1", name='BLANK', type='string', startIndex=117, endIndex=156, required=False, - validators=[]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="2", + name="COUNTY_FIPS_CODE", + type="string", + startIndex=19, + endIndex=22, + required=True, + validators=[ + validators.isNumber(), + ], + ), + Field( + item="5", + name="STRATUM", + type="string", + startIndex=22, + endIndex=24, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="7", + name="ZIP_CODE", + type="string", + startIndex=24, + endIndex=29, + required=True, + validators=[ + validators.isNumber(), + ], + ), + Field( + item="8", + name="FUNDING_STREAM", + type="number", + startIndex=29, + endIndex=30, + required=True, + validators=[ + validators.isInLimits(1, 3), + ], + ), + Field( + item="9", + name="DISPOSITION", + type="number", + startIndex=30, + endIndex=31, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="10", + name="NEW_APPLICANT", + type="number", + startIndex=31, + endIndex=32, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="11", + name="NBR_FAMILY_MEMBERS", + type="number", + startIndex=32, + endIndex=34, + required=True, + validators=[ + validators.isLargerThan(0), + ], + ), + Field( + item="12", + name="FAMILY_TYPE", + type="number", + startIndex=34, + endIndex=35, + required=True, + validators=[ + validators.isInLimits(1, 3), + ], + ), + Field( + item="13", + name="RECEIVES_SUB_HOUSING", + type="number", + startIndex=35, + endIndex=36, + required=True, + validators=[ + validators.isInLimits(1, 3), + ], + ), + Field( + item="14", + name="RECEIVES_MED_ASSISTANCE", + type="number", + startIndex=36, + endIndex=37, + required=True, + validators=[ + validators.isInLimits(1, 2), + ], + ), + Field( + item="15", + name="RECEIVES_FOOD_STAMPS", + type="number", + startIndex=37, + endIndex=38, + required=False, + validators=[ + validators.isInLimits(0, 2), + ], + ), + Field( + item="16", + name="AMT_FOOD_STAMP_ASSISTANCE", + type="number", + startIndex=38, + endIndex=42, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="17", + name="RECEIVES_SUB_CC", + type="number", + startIndex=42, + endIndex=43, + required=False, + validators=[ + validators.isInLimits(0, 3), + ], + ), + Field( + item="18", + name="AMT_SUB_CC", + type="number", + startIndex=43, + endIndex=47, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="19", + name="CHILD_SUPPORT_AMT", + type="number", + startIndex=47, + endIndex=51, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="20", + name="FAMILY_CASH_RESOURCES", + type="number", + startIndex=51, + endIndex=55, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="21A", + name="CASH_AMOUNT", + type="number", + startIndex=55, + endIndex=59, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="21B", + name="NBR_MONTHS", + type="number", + startIndex=59, + endIndex=62, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="22A", + name="CC_AMOUNT", + type="number", + startIndex=62, + endIndex=66, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="22B", + name="CHILDREN_COVERED", + type="number", + startIndex=66, + endIndex=68, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="22C", + name="CC_NBR_MONTHS", + type="number", + startIndex=68, + endIndex=71, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="23A", + name="TRANSP_AMOUNT", + type="number", + startIndex=71, + endIndex=75, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="23B", + name="TRANSP_NBR_MONTHS", + type="number", + startIndex=75, + endIndex=78, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="24A", + name="TRANSITION_SERVICES_AMOUNT", + type="number", + startIndex=78, + endIndex=82, + required=False, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="24B", + name="TRANSITION_NBR_MONTHS", + type="number", + startIndex=82, + endIndex=85, + required=False, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="25A", + name="OTHER_AMOUNT", + type="number", + startIndex=85, + endIndex=89, + required=False, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="25B", + name="OTHER_NBR_MONTHS", + type="number", + startIndex=89, + endIndex=92, + required=False, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="26AI", + name="SANC_REDUCTION_AMT", + type="number", + startIndex=92, + endIndex=96, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="26AII", + name="WORK_REQ_SANCTION", + type="number", + startIndex=96, + endIndex=97, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26AIII", + name="FAMILY_SANC_ADULT", + type="number", + startIndex=97, + endIndex=98, + required=False, + validators=[ + validators.oneOf([0, 1, 2]), + ], + ), + Field( + item="26AIV", + name="SANC_TEEN_PARENT", + type="number", + startIndex=98, + endIndex=99, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26AV", + name="NON_COOPERATION_CSE", + type="number", + startIndex=99, + endIndex=100, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26AVI", + name="FAILURE_TO_COMPLY", + type="number", + startIndex=100, + endIndex=101, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26AVII", + name="OTHER_SANCTION", + type="number", + startIndex=101, + endIndex=102, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26B", + name="RECOUPMENT_PRIOR_OVRPMT", + type="number", + startIndex=102, + endIndex=106, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="26CI", + name="OTHER_TOTAL_REDUCTIONS", + type="number", + startIndex=106, + endIndex=110, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="26CII", + name="FAMILY_CAP", + type="number", + startIndex=110, + endIndex=111, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26CIII", + name="REDUCTIONS_ON_RECEIPTS", + type="number", + startIndex=111, + endIndex=112, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="26CIV", + name="OTHER_NON_SANCTION", + type="number", + startIndex=112, + endIndex=113, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="27", + name="WAIVER_EVAL_CONTROL_GRPS", + type="string", + startIndex=113, + endIndex=114, + required=False, + validators=[ + validators.or_validators( + validators.matches("9"), validators.isEmpty() + ), + validators.isAlphaNumeric(), + ], + ), + Field( + item="28", + name="FAMILY_EXEMPT_TIME_LIMITS", + type="number", + startIndex=114, + endIndex=116, + required=True, + validators=[validators.oneOf([1, 2, 3, 4, 6, 7, 8, 9])], + ), + Field( + item="29", + name="FAMILY_NEW_CHILD", + type="number", + startIndex=116, + endIndex=117, + required=False, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="-1", + name="BLANK", + type="string", + startIndex=117, + endIndex=156, + required=False, + validators=[], + ), ], - )] + ) + ] ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py index 1f2088b38..89cc794d8 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py @@ -9,235 +9,878 @@ from tdpservice.search_indexes.models.tanf import TANF_T2 -t2 = SchemaManager(schemas=[ - RowSchema( - model=TANF_T2, - preparsing_validators=[ - validators.hasLength(156), - ], - postparsing_validators=[ +t2 = SchemaManager( + schemas=[ + RowSchema( + model=TANF_T2, + preparsing_validators=[ + validators.hasLength(156), + ], + postparsing_validators=[ validators.validate__FAM_AFF__SSN(), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='SSN', result_function=validators.validateSSN(), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="SSN", + result_function=validators.validateSSN(), ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_HISPANIC', result_function=validators.isInLimits(1, 2), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_HISPANIC", + result_function=validators.isInLimits(1, 2), ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_AMER_INDIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_AMER_INDIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_ASIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_ASIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_BLACK', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_BLACK", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_HAWAIIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_HAWAIIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_WHITE', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_WHITE", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='MARITAL_STATUS', result_function=validators.isInLimits(1, 5), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="MARITAL_STATUS", + result_function=validators.isInLimits(1, 5), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 2), - result_field='PARENT_WITH_MINOR_CHILD', result_function=validators.isInLimits(1, 3), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 2), + result_field="PARENT_WITH_MINOR_CHILD", + result_function=validators.isInLimits(1, 3), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='EDUCATION_LEVEL', result_function=validators.or_validators( - validators.isInStringRange(0, 16), - validators.isInStringRange(98, 99) - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="EDUCATION_LEVEL", + result_function=validators.or_validators( + validators.isInStringRange(0, 16), + validators.isInStringRange(98, 99), ), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='CITIZENSHIP_STATUS', result_function=validators.oneOf((1, 2)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="CITIZENSHIP_STATUS", + result_function=validators.oneOf((1, 2)), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='COOPERATION_CHILD_SUPPORT', result_function=validators.oneOf((1, 2, 9)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="COOPERATION_CHILD_SUPPORT", + result_function=validators.oneOf((1, 2, 9)), + ), validators.validate__FAM_AFF__HOH__Fed_Time(), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='EMPLOYMENT_STATUS', result_function=validators.isInLimits(1, 3), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="EMPLOYMENT_STATUS", + result_function=validators.isInLimits(1, 3), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='WORK_ELIGIBLE_INDICATOR', result_function=validators.or_validators( - validators.isInStringRange(1, 9), - validators.oneOf(('11', '12')) - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="WORK_ELIGIBLE_INDICATOR", + result_function=validators.or_validators( + validators.isInStringRange(1, 9), validators.oneOf(("11", "12")) ), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='WORK_PART_STATUS', result_function=validators.oneOf(['01', '02', '05', '07', '09', - '15', '17', '18', '19', '99'] - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="WORK_PART_STATUS", + result_function=validators.oneOf( + ["01", "02", "05", "07", "09", "15", "17", "18", "19", "99"] ), + ), validators.if_then_validator( - condition_field='WORK_ELIGIBLE_INDICATOR', condition_function=validators.isInStringRange(1, 5), - result_field='WORK_PART_STATUS', result_function=validators.notMatches('99'), - ), + condition_field="WORK_ELIGIBLE_INDICATOR", + condition_function=validators.isInStringRange(1, 5), + result_field="WORK_PART_STATUS", + result_function=validators.notMatches("99"), + ), + ], + fields=[ + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="30", + name="FAMILY_AFFILIATION", + type="number", + startIndex=19, + endIndex=20, + required=True, + validators=[validators.oneOf([1, 2, 3, 5])], + ), + Field( + item="31", + name="NONCUSTODIAL_PARENT", + type="number", + startIndex=20, + endIndex=21, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="32", + name="DATE_OF_BIRTH", + type="number", + startIndex=21, + endIndex=29, + required=True, + validators=[ + validators.isLargerThan(0), + ], + ), + TransformField( + transform_func=tanf_ssn_decryption_func, + item="33", + name="SSN", + type="string", + startIndex=29, + endIndex=38, + required=True, + validators=[validators.validateSSN()], + is_encrypted=False, + ), + Field( + item="34A", + name="RACE_HISPANIC", + type="number", + startIndex=38, + endIndex=39, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="34B", + name="RACE_AMER_INDIAN", + type="number", + startIndex=39, + endIndex=40, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="34C", + name="RACE_ASIAN", + type="number", + startIndex=40, + endIndex=41, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="34D", + name="RACE_BLACK", + type="number", + startIndex=41, + endIndex=42, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="34E", + name="RACE_HAWAIIAN", + type="number", + startIndex=42, + endIndex=43, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="34F", + name="RACE_WHITE", + type="number", + startIndex=43, + endIndex=44, + required=False, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="35", + name="GENDER", + type="number", + startIndex=44, + endIndex=45, + required=True, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="36A", + name="FED_OASDI_PROGRAM", + type="number", + startIndex=45, + endIndex=46, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="36B", + name="FED_DISABILITY_STATUS", + type="number", + startIndex=46, + endIndex=47, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="36C", + name="DISABLED_TITLE_XIVAPDT", + type="string", + startIndex=47, + endIndex=48, + required=True, + validators=[ + validators.or_validators( + validators.oneOf(["1", "2"]), validators.isBlank() + ) + ], + ), + Field( + item="36D", + name="AID_AGED_BLIND", + type="number", + startIndex=48, + endIndex=49, + required=False, + validators=[ + validators.isLargerThanOrEqualTo(0), + ], + ), + Field( + item="36E", + name="RECEIVE_SSI", + type="number", + startIndex=49, + endIndex=50, + required=True, + validators=[ + validators.oneOf([1, 2]), + ], + ), + Field( + item="37", + name="MARITAL_STATUS", + type="number", + startIndex=50, + endIndex=51, + required=False, + validators=[ + validators.isInLimits(0, 5), + ], + ), + Field( + item="38", + name="RELATIONSHIP_HOH", + type="string", + startIndex=51, + endIndex=53, + required=True, + validators=[ + validators.isInStringRange(1, 10), + ], + ), + Field( + item="39", + name="PARENT_WITH_MINOR_CHILD", + type="number", + startIndex=53, + endIndex=54, + required=False, + validators=[ + validators.isInLimits(0, 3), + ], + ), + Field( + item="40", + name="NEEDS_PREGNANT_WOMAN", + type="number", + startIndex=54, + endIndex=55, + required=False, + validators=[ + validators.isInLimits(0, 9), + ], + ), + Field( + item="41", + name="EDUCATION_LEVEL", + type="string", + startIndex=55, + endIndex=57, + required=False, + validators=[ + validators.or_validators( + validators.isInStringRange(0, 16), + validators.isInStringRange(98, 99), + ) + ], + ), + Field( + item="42", + name="CITIZENSHIP_STATUS", + type="number", + startIndex=57, + endIndex=58, + required=False, + validators=[validators.oneOf([0, 1, 2, 9])], + ), + Field( + item="43", + name="COOPERATION_CHILD_SUPPORT", + type="number", + startIndex=58, + endIndex=59, + required=False, + validators=[ + validators.oneOf([0, 1, 2, 9]), + ], + ), + Field( + item="44", + name="MONTHS_FED_TIME_LIMIT", + type="string", + startIndex=59, + endIndex=62, + required=False, + validators=[ + validators.isInStringRange(0, 999), + ], + ), + Field( + item="45", + name="MONTHS_STATE_TIME_LIMIT", + type="string", + startIndex=62, + endIndex=64, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="46", + name="CURRENT_MONTH_STATE_EXEMPT", + type="number", + startIndex=64, + endIndex=65, + required=False, + validators=[ + validators.isInLimits(0, 9), + ], + ), + Field( + item="47", + name="EMPLOYMENT_STATUS", + type="number", + startIndex=65, + endIndex=66, + required=False, + validators=[ + validators.isInLimits(0, 3), + ], + ), + Field( + item="48", + name="WORK_ELIGIBLE_INDICATOR", + type="string", + startIndex=66, + endIndex=68, + required=True, + validators=[ + validators.or_validators( + validators.isInStringRange(0, 9), + validators.oneOf(("11", "12")), + ) + ], + ), + Field( + item="49", + name="WORK_PART_STATUS", + type="string", + startIndex=68, + endIndex=70, + required=False, + validators=[ + validators.oneOf( + [ + "01", + "02", + "05", + "07", + "09", + "15", + "16", + "17", + "18", + "19", + "99", + ] + ) + ], + ), + Field( + item="50", + name="UNSUB_EMPLOYMENT", + type="string", + startIndex=70, + endIndex=72, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="51", + name="SUB_PRIVATE_EMPLOYMENT", + type="string", + startIndex=72, + endIndex=74, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="52", + name="SUB_PUBLIC_EMPLOYMENT", + type="string", + startIndex=74, + endIndex=76, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="53A", + name="WORK_EXPERIENCE_HOP", + type="string", + startIndex=76, + endIndex=78, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="53B", + name="WORK_EXPERIENCE_EA", + type="string", + startIndex=78, + endIndex=80, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="53C", + name="WORK_EXPERIENCE_HOL", + type="string", + startIndex=80, + endIndex=82, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="54", + name="OJT", + type="string", + startIndex=82, + endIndex=84, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="55A", + name="JOB_SEARCH_HOP", + type="string", + startIndex=84, + endIndex=86, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="55B", + name="JOB_SEARCH_EA", + type="string", + startIndex=86, + endIndex=88, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="55C", + name="JOB_SEARCH_HOL", + type="string", + startIndex=88, + endIndex=90, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="56A", + name="COMM_SERVICES_HOP", + type="string", + startIndex=90, + endIndex=92, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="56B", + name="COMM_SERVICES_EA", + type="string", + startIndex=92, + endIndex=94, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="56C", + name="COMM_SERVICES_HOL", + type="string", + startIndex=94, + endIndex=96, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="57A", + name="VOCATIONAL_ED_TRAINING_HOP", + type="string", + startIndex=96, + endIndex=98, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="57B", + name="VOCATIONAL_ED_TRAINING_EA", + type="string", + startIndex=98, + endIndex=100, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="57C", + name="VOCATIONAL_ED_TRAINING_HOL", + type="string", + startIndex=100, + endIndex=102, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="58A", + name="JOB_SKILLS_TRAINING_HOP", + type="string", + startIndex=102, + endIndex=104, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="58B", + name="JOB_SKILLS_TRAINING_EA", + type="string", + startIndex=104, + endIndex=106, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="58C", + name="JOB_SKILLS_TRAINING_HOL", + type="string", + startIndex=106, + endIndex=108, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="59A", + name="ED_NO_HIGH_SCHOOL_DIPL_HOP", + type="string", + startIndex=108, + endIndex=110, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="59B", + name="ED_NO_HIGH_SCHOOL_DIPL_EA", + type="string", + startIndex=110, + endIndex=112, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="59C", + name="ED_NO_HIGH_SCHOOL_DIPL_HOL", + type="string", + startIndex=112, + endIndex=114, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="60A", + name="SCHOOL_ATTENDENCE_HOP", + type="string", + startIndex=114, + endIndex=116, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="60B", + name="SCHOOL_ATTENDENCE_EA", + type="string", + startIndex=116, + endIndex=118, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="60C", + name="SCHOOL_ATTENDENCE_HOL", + type="string", + startIndex=118, + endIndex=120, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="61A", + name="PROVIDE_CC_HOP", + type="string", + startIndex=120, + endIndex=122, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="61B", + name="PROVIDE_CC_EA", + type="string", + startIndex=122, + endIndex=124, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="61C", + name="PROVIDE_CC_HOL", + type="string", + startIndex=124, + endIndex=126, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="62", + name="OTHER_WORK_ACTIVITIES", + type="string", + startIndex=126, + endIndex=128, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="63", + name="DEEMED_HOURS_FOR_OVERALL", + type="string", + startIndex=128, + endIndex=130, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="64", + name="DEEMED_HOURS_FOR_TWO_PARENT", + type="string", + startIndex=130, + endIndex=132, + required=False, + validators=[ + validators.isInStringRange(0, 99), + ], + ), + Field( + item="65", + name="EARNED_INCOME", + type="string", + startIndex=132, + endIndex=136, + required=True, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), + Field( + item="66A", + name="UNEARNED_INCOME_TAX_CREDIT", + type="string", + startIndex=136, + endIndex=140, + required=False, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), + Field( + item="66B", + name="UNEARNED_SOCIAL_SECURITY", + type="string", + startIndex=140, + endIndex=144, + required=True, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), + Field( + item="66C", + name="UNEARNED_SSI", + type="string", + startIndex=144, + endIndex=148, + required=True, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), + Field( + item="66D", + name="UNEARNED_WORKERS_COMP", + type="string", + startIndex=148, + endIndex=152, + required=True, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), + Field( + item="66E", + name="OTHER_UNEARNED_INCOME", + type="string", + startIndex=152, + endIndex=156, + required=True, + validators=[ + validators.isInStringRange(0, 9999), + ], + ), ], - fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid(), - ]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="30", name='FAMILY_AFFILIATION', type='number', startIndex=19, endIndex=20, - required=True, validators=[validators.oneOf([1, 2, 3, 5])]), - Field(item="31", name='NONCUSTODIAL_PARENT', type='number', startIndex=20, endIndex=21, required=True, - validators=[validators.oneOf([1, 2])]), - Field(item="32", name='DATE_OF_BIRTH', type='number', startIndex=21, endIndex=29, required=True, - validators=[validators.isLargerThan(0),]), - TransformField(transform_func=tanf_ssn_decryption_func, item="33", name='SSN', type='string', startIndex=29, - endIndex=38, required=True, - validators=[validators.validateSSN()], is_encrypted=False), - Field(item="34A", name='RACE_HISPANIC', type='number', startIndex=38, endIndex=39, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="34B", name='RACE_AMER_INDIAN', type='number', startIndex=39, endIndex=40, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="34C", name='RACE_ASIAN', type='number', startIndex=40, endIndex=41, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="34D", name='RACE_BLACK', type='number', startIndex=41, endIndex=42, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="34E", name='RACE_HAWAIIAN', type='number', startIndex=42, endIndex=43, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="34F", name='RACE_WHITE', type='number', startIndex=43, endIndex=44, required=False, - validators=[validators.isInLimits(0, 2)]), - Field(item="35", name='GENDER', type='number', startIndex=44, endIndex=45, required=True, - validators=[validators.isLargerThanOrEqualTo(0),]), - Field(item="36A", name='FED_OASDI_PROGRAM', type='number', startIndex=45, endIndex=46, required=True, - validators=[validators.oneOf([1, 2])]), - Field(item="36B", name='FED_DISABILITY_STATUS', type='number', startIndex=46, endIndex=47, required=True, - validators=[validators.oneOf([1, 2])]), - Field(item="36C", name='DISABLED_TITLE_XIVAPDT', type='string', startIndex=47, endIndex=48, required=True, - validators=[validators.or_validators(validators.oneOf(["1", "2"]), validators.isBlank())]), - Field(item="36D", name='AID_AGED_BLIND', type='number', startIndex=48, endIndex=49, required=False, - validators=[validators.isLargerThanOrEqualTo(0),]), - Field(item="36E", name='RECEIVE_SSI', type='number', startIndex=49, endIndex=50, required=True, - validators=[validators.oneOf([1, 2]),]), - Field(item="37", name='MARITAL_STATUS', type='number', startIndex=50, endIndex=51, required=False, - validators=[validators.isInLimits(0, 5),]), - Field(item="38", name='RELATIONSHIP_HOH', type='string', startIndex=51, endIndex=53, required=True, - validators=[validators.isInStringRange(1, 10),]), - Field(item="39", name='PARENT_WITH_MINOR_CHILD', type='number', startIndex=53, endIndex=54, required=False, - validators=[validators.isInLimits(0, 3),]), - Field(item="40", name='NEEDS_PREGNANT_WOMAN', type='number', startIndex=54, endIndex=55, required=False, - validators=[validators.isInLimits(0, 9),]), - Field(item="41", name='EDUCATION_LEVEL', type='string', startIndex=55, endIndex=57, required=False, - validators=[validators.or_validators(validators.isInStringRange(0, 16), - validators.isInStringRange(98, 99) - )]), - Field(item="42", name='CITIZENSHIP_STATUS', type='number', startIndex=57, endIndex=58, required=False, - validators=[validators.oneOf([0, 1, 2, 9])]), - Field(item="43", name='COOPERATION_CHILD_SUPPORT', type='number', startIndex=58, endIndex=59, - required=False, validators=[validators.oneOf([0, 1, 2, 9]),]), - Field(item="44", name='MONTHS_FED_TIME_LIMIT', type='string', startIndex=59, endIndex=62, required=False, - validators=[validators.isInStringRange(0, 999),]), - Field(item="45", name='MONTHS_STATE_TIME_LIMIT', type='string', startIndex=62, endIndex=64, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="46", name='CURRENT_MONTH_STATE_EXEMPT', type='number', startIndex=64, endIndex=65, - required=False, validators=[validators.isInLimits(0, 9),]), - Field(item="47", name='EMPLOYMENT_STATUS', type='number', startIndex=65, endIndex=66, required=False, - validators=[validators.isInLimits(0, 3),]), - Field(item="48", name='WORK_ELIGIBLE_INDICATOR', type='string', startIndex=66, endIndex=68, required=True, - validators=[validators.or_validators(validators.isInStringRange(0, 9), - validators.oneOf(('11', '12')) - )]), - Field(item="49", name='WORK_PART_STATUS', type='string', startIndex=68, endIndex=70, required=False, - validators=[validators.oneOf(['01', '02', '05', '07', '09', '15', '16', '17', '18', '19', '99'])]), - Field(item="50", name='UNSUB_EMPLOYMENT', type='string', startIndex=70, endIndex=72, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="51", name='SUB_PRIVATE_EMPLOYMENT', type='string', startIndex=72, endIndex=74, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="52", name='SUB_PUBLIC_EMPLOYMENT', type='string', startIndex=74, endIndex=76, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="53A", name='WORK_EXPERIENCE_HOP', type='string', startIndex=76, endIndex=78, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="53B", name='WORK_EXPERIENCE_EA', type='string', startIndex=78, endIndex=80, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="53C", name='WORK_EXPERIENCE_HOL', type='string', startIndex=80, endIndex=82, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="54", name='OJT', type='string', startIndex=82, endIndex=84, required=False, validators=[ - validators.isInStringRange(0, 99), - ]), - Field(item="55A", name='JOB_SEARCH_HOP', type='string', startIndex=84, endIndex=86, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="55B", name='JOB_SEARCH_EA', type='string', startIndex=86, endIndex=88, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="55C", name='JOB_SEARCH_HOL', type='string', startIndex=88, endIndex=90, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="56A", name='COMM_SERVICES_HOP', type='string', startIndex=90, endIndex=92, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="56B", name='COMM_SERVICES_EA', type='string', startIndex=92, endIndex=94, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="56C", name='COMM_SERVICES_HOL', type='string', startIndex=94, endIndex=96, required=False, - validators=[validators.isInStringRange(0, 99),]), - Field(item="57A", name='VOCATIONAL_ED_TRAINING_HOP', type='string', startIndex=96, endIndex=98, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="57B", name='VOCATIONAL_ED_TRAINING_EA', type='string', startIndex=98, endIndex=100, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="57C", name='VOCATIONAL_ED_TRAINING_HOL', type='string', startIndex=100, endIndex=102, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="58A", name='JOB_SKILLS_TRAINING_HOP', type='string', startIndex=102, endIndex=104, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="58B", name='JOB_SKILLS_TRAINING_EA', type='string', startIndex=104, endIndex=106, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="58C", name='JOB_SKILLS_TRAINING_HOL', type='string', startIndex=106, endIndex=108, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="59A", name='ED_NO_HIGH_SCHOOL_DIPL_HOP', type='string', startIndex=108, endIndex=110, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="59B", name='ED_NO_HIGH_SCHOOL_DIPL_EA', type='string', startIndex=110, endIndex=112, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="59C", name='ED_NO_HIGH_SCHOOL_DIPL_HOL', type='string', startIndex=112, endIndex=114, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="60A", name='SCHOOL_ATTENDENCE_HOP', type='string', startIndex=114, endIndex=116, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="60B", name='SCHOOL_ATTENDENCE_EA', type='string', startIndex=116, endIndex=118, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="60C", name='SCHOOL_ATTENDENCE_HOL', type='string', startIndex=118, endIndex=120, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="61A", name='PROVIDE_CC_HOP', type='string', startIndex=120, endIndex=122, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="61B", name='PROVIDE_CC_EA', type='string', startIndex=122, endIndex=124, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="61C", name='PROVIDE_CC_HOL', type='string', startIndex=124, endIndex=126, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="62", name='OTHER_WORK_ACTIVITIES', type='string', startIndex=126, endIndex=128, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="63", name='DEEMED_HOURS_FOR_OVERALL', type='string', startIndex=128, endIndex=130, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="64", name='DEEMED_HOURS_FOR_TWO_PARENT', type='string', startIndex=130, endIndex=132, - required=False, validators=[validators.isInStringRange(0, 99),]), - Field(item="65", name='EARNED_INCOME', type='string', startIndex=132, endIndex=136, - required=True, validators=[validators.isInStringRange(0, 9999),]), - Field(item="66A", name='UNEARNED_INCOME_TAX_CREDIT', type='string', startIndex=136, endIndex=140, - required=False, validators=[validators.isInStringRange(0, 9999),]), - Field(item="66B", name='UNEARNED_SOCIAL_SECURITY', type='string', startIndex=140, endIndex=144, - required=True, validators=[validators.isInStringRange(0, 9999),]), - Field(item="66C", name='UNEARNED_SSI', type='string', startIndex=144, endIndex=148, required=True, - validators=[validators.isInStringRange(0, 9999),]), - Field(item="66D", name='UNEARNED_WORKERS_COMP', type='string', startIndex=148, endIndex=152, required=True, - validators=[validators.isInStringRange(0, 9999),]), - Field(item="66E", name='OTHER_UNEARNED_INCOME', type='string', startIndex=152, endIndex=156, required=True, - validators=[validators.isInStringRange(0, 9999),]), - ], - )] + ) + ] ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py index 66daa1e59..787828473 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t3.py @@ -16,124 +16,278 @@ ], postparsing_validators=[ validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='SSN', result_function=validators.validateSSN(), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="SSN", + result_function=validators.validateSSN(), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_HISPANIC', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_HISPANIC", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_AMER_INDIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_AMER_INDIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_ASIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_ASIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_BLACK', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_BLACK", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_HAWAIIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_HAWAIIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_WHITE', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_WHITE", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RELATIONSHIP_HOH', result_function=validators.isInStringRange(4, 9), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RELATIONSHIP_HOH", + result_function=validators.isInStringRange(4, 9), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='PARENT_MINOR_CHILD', result_function=validators.oneOf((2, 3)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="PARENT_MINOR_CHILD", + result_function=validators.oneOf((2, 3)), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='EDUCATION_LEVEL', result_function=validators.notMatches('99'), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="EDUCATION_LEVEL", + result_function=validators.notMatches("99"), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='CITIZENSHIP_STATUS', result_function=validators.oneOf((1, 2)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="CITIZENSHIP_STATUS", + result_function=validators.oneOf((1, 2)), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(2), - result_field='CITIZENSHIP_STATUS', result_function=validators.oneOf((1, 2, 9)), - ), - ], + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(2), + result_field="CITIZENSHIP_STATUS", + result_function=validators.oneOf((1, 2, 9)), + ), + ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="67", name='FAMILY_AFFILIATION', type='number', startIndex=19, endIndex=20, - required=True, validators=[ - validators.oneOf([1, 2, 4]) - ]), - Field(item="68", name='DATE_OF_BIRTH', type='number', startIndex=20, endIndex=28, - required=True, validators=[ - validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid(), - ]), - TransformField(transform_func=tanf_ssn_decryption_func, item="69", name='SSN', type='string', startIndex=28, - endIndex=37, required=True, validators=[validators.validateSSN()], - is_encrypted=False), - Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=37, endIndex=38, - required=False, validators=[validators.validateRace()]), - Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=38, endIndex=39, - required=False, validators=[validators.validateRace()]), - Field(item="70C", name='RACE_ASIAN', type='number', startIndex=39, endIndex=40, - required=False, validators=[validators.validateRace()]), - Field(item="70D", name='RACE_BLACK', type='number', startIndex=40, endIndex=41, - required=False, validators=[validators.validateRace()]), - Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=41, endIndex=42, - required=False, validators=[validators.validateRace()]), - Field(item="70F", name='RACE_WHITE', type='number', startIndex=42, endIndex=43, - required=False, validators=[validators.validateRace()]), - Field(item="71", name='GENDER', type='number', startIndex=43, endIndex=44, - required=True, validators=[ - validators.isInLimits(0, 9) - ]), - Field(item="72A", name='RECEIVE_NONSSA_BENEFITS', type='number', startIndex=44, endIndex=45, - required=True, validators=[ - validators.oneOf([1, 2]) - ]), - Field(item="72B", name='RECEIVE_SSI', type='number', startIndex=45, endIndex=46, - required=True, validators=[ - validators.oneOf([1, 2]) - ]), - Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=46, endIndex=48, - required=False, validators=[ - validators.isInStringRange(0, 10) - ]), - Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=48, endIndex=49, - required=False, validators=[ - validators.oneOf([0, 2, 3]) - ]), - Field(item="75", name='EDUCATION_LEVEL', type='string', startIndex=49, endIndex=51, - required=True, validators=[ - validators.or_validators( - validators.isInStringRange(0, 16), - validators.isInStringRange(98, 99) - ) - ]), - Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=51, endIndex=52, - required=False, validators=[ - validators.oneOf([0, 1, 2, 9]) - ]), - Field(item="77A", name='UNEARNED_SSI', type='string', startIndex=52, endIndex=56, - required=False, validators=[ - validators.isInStringRange(0, 9999) - ]), - Field(item="77B", name='OTHER_UNEARNED_INCOME', type='string', startIndex=56, endIndex=60, - required=False, validators=[ - validators.isInStringRange(0, 9999) - ]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="67", + name="FAMILY_AFFILIATION", + type="number", + startIndex=19, + endIndex=20, + required=True, + validators=[validators.oneOf([1, 2, 4])], + ), + Field( + item="68", + name="DATE_OF_BIRTH", + type="number", + startIndex=20, + endIndex=28, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + TransformField( + transform_func=tanf_ssn_decryption_func, + item="69", + name="SSN", + type="string", + startIndex=28, + endIndex=37, + required=True, + validators=[validators.validateSSN()], + is_encrypted=False, + ), + Field( + item="70A", + name="RACE_HISPANIC", + type="number", + startIndex=37, + endIndex=38, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70B", + name="RACE_AMER_INDIAN", + type="number", + startIndex=38, + endIndex=39, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70C", + name="RACE_ASIAN", + type="number", + startIndex=39, + endIndex=40, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70D", + name="RACE_BLACK", + type="number", + startIndex=40, + endIndex=41, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70E", + name="RACE_HAWAIIAN", + type="number", + startIndex=41, + endIndex=42, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70F", + name="RACE_WHITE", + type="number", + startIndex=42, + endIndex=43, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="71", + name="GENDER", + type="number", + startIndex=43, + endIndex=44, + required=True, + validators=[validators.isInLimits(0, 9)], + ), + Field( + item="72A", + name="RECEIVE_NONSSA_BENEFITS", + type="number", + startIndex=44, + endIndex=45, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="72B", + name="RECEIVE_SSI", + type="number", + startIndex=45, + endIndex=46, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="73", + name="RELATIONSHIP_HOH", + type="string", + startIndex=46, + endIndex=48, + required=False, + validators=[validators.isInStringRange(0, 10)], + ), + Field( + item="74", + name="PARENT_MINOR_CHILD", + type="number", + startIndex=48, + endIndex=49, + required=False, + validators=[validators.oneOf([0, 2, 3])], + ), + Field( + item="75", + name="EDUCATION_LEVEL", + type="string", + startIndex=49, + endIndex=51, + required=True, + validators=[ + validators.or_validators( + validators.isInStringRange(0, 16), + validators.isInStringRange(98, 99), + ) + ], + ), + Field( + item="76", + name="CITIZENSHIP_STATUS", + type="number", + startIndex=51, + endIndex=52, + required=False, + validators=[validators.oneOf([0, 1, 2, 9])], + ), + Field( + item="77A", + name="UNEARNED_SSI", + type="string", + startIndex=52, + endIndex=56, + required=False, + validators=[validators.isInStringRange(0, 9999)], + ), + Field( + item="77B", + name="OTHER_UNEARNED_INCOME", + type="string", + startIndex=56, + endIndex=60, + required=False, + validators=[validators.isInStringRange(0, 9999)], + ), ], ) @@ -145,130 +299,278 @@ ], postparsing_validators=[ validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='SSN', result_function=validators.validateSSN(), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="SSN", + result_function=validators.validateSSN(), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_HISPANIC', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_HISPANIC", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_AMER_INDIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_AMER_INDIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_ASIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_ASIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_BLACK', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_BLACK", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_HAWAIIAN', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_HAWAIIAN", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RACE_WHITE', result_function=validators.isInLimits(1, 2), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RACE_WHITE", + result_function=validators.isInLimits(1, 2), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='RELATIONSHIP_HOH', result_function=validators.isInStringRange(4, 9), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="RELATIONSHIP_HOH", + result_function=validators.isInStringRange(4, 9), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.oneOf((1, 2)), - result_field='PARENT_MINOR_CHILD', result_function=validators.oneOf((2, 3)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.oneOf((1, 2)), + result_field="PARENT_MINOR_CHILD", + result_function=validators.oneOf((2, 3)), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='EDUCATION_LEVEL', result_function=validators.notMatches('99'), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="EDUCATION_LEVEL", + result_function=validators.notMatches("99"), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='CITIZENSHIP_STATUS', result_function=validators.oneOf((1, 2)), - ), + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="CITIZENSHIP_STATUS", + result_function=validators.oneOf((1, 2)), + ), validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(2), - result_field='CITIZENSHIP_STATUS', result_function=validators.oneOf((1, 2, 9)), - ), - ], + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(2), + result_field="CITIZENSHIP_STATUS", + result_function=validators.oneOf((1, 2, 9)), + ), + ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="67", name='FAMILY_AFFILIATION', type='number', startIndex=60, endIndex=61, - required=True, validators=[ - validators.oneOf([1, 2, 4]) - ]), - Field(item="68", name='DATE_OF_BIRTH', type='number', startIndex=61, endIndex=69, - required=True, validators=[ - validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid(), - ]), - TransformField(transform_func=tanf_ssn_decryption_func, item="69", name='SSN', type='string', startIndex=69, - endIndex=78, required=True, validators=[validators.validateSSN()], - is_encrypted=False), - Field(item="70A", name='RACE_HISPANIC', type='number', startIndex=78, endIndex=79, - required=False, validators=[validators.validateRace()]), - Field(item="70B", name='RACE_AMER_INDIAN', type='number', startIndex=79, endIndex=80, - required=False, validators=[validators.validateRace()]), - Field(item="70C", name='RACE_ASIAN', type='number', startIndex=80, endIndex=81, - required=False, validators=[validators.validateRace()]), - Field(item="70D", name='RACE_BLACK', type='number', startIndex=81, endIndex=82, - required=False, validators=[validators.validateRace()]), - Field(item="70E", name='RACE_HAWAIIAN', type='number', startIndex=82, endIndex=83, - required=False, validators=[validators.validateRace()]), - Field(item="70F", name='RACE_WHITE', type='number', startIndex=83, endIndex=84, - required=False, validators=[validators.validateRace()]), - Field(item="71", name='GENDER', type='number', startIndex=84, endIndex=85, - required=True, validators=[ - validators.isInLimits(0, 9) - ]), - Field(item="72A", name='RECEIVE_NONSSA_BENEFITS', type='number', startIndex=85, endIndex=86, - required=True, validators=[ - validators.oneOf([1, 2]) - ]), - Field(item="72B", name='RECEIVE_SSI', type='number', startIndex=86, endIndex=87, - required=True, validators=[ - validators.oneOf([1, 2]) - ]), - Field(item="73", name='RELATIONSHIP_HOH', type='string', startIndex=87, endIndex=89, - required=False, validators=[ - validators.isInStringRange(0, 10) - ]), - Field(item="74", name='PARENT_MINOR_CHILD', type='number', startIndex=89, endIndex=90, - required=False, validators=[ - validators.oneOf([0, 2, 3]) - ]), - Field(item="75", name='EDUCATION_LEVEL', type='string', startIndex=90, endIndex=92, - required=True, validators=[ - validators.or_validators( - validators.isInStringRange(0, 16), - validators.oneOf(['98', '99']) - ) - ]), - Field(item="76", name='CITIZENSHIP_STATUS', type='number', startIndex=92, endIndex=93, - required=False, validators=[ - validators.oneOf([0, 1, 2, 9]) - ]), - Field(item="77A", name='UNEARNED_SSI', type='string', startIndex=93, endIndex=97, - required=False, validators=[ - validators.isInStringRange(0, 9999) - ]), - Field(item="77B", name='OTHER_UNEARNED_INCOME', type='string', startIndex=97, endIndex=101, - required=False, validators=[ - validators.isInStringRange(0, 9999) - ]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="67", + name="FAMILY_AFFILIATION", + type="number", + startIndex=60, + endIndex=61, + required=True, + validators=[validators.oneOf([1, 2, 4])], + ), + Field( + item="68", + name="DATE_OF_BIRTH", + type="number", + startIndex=61, + endIndex=69, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + TransformField( + transform_func=tanf_ssn_decryption_func, + item="69", + name="SSN", + type="string", + startIndex=69, + endIndex=78, + required=True, + validators=[validators.validateSSN()], + is_encrypted=False, + ), + Field( + item="70A", + name="RACE_HISPANIC", + type="number", + startIndex=78, + endIndex=79, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70B", + name="RACE_AMER_INDIAN", + type="number", + startIndex=79, + endIndex=80, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70C", + name="RACE_ASIAN", + type="number", + startIndex=80, + endIndex=81, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70D", + name="RACE_BLACK", + type="number", + startIndex=81, + endIndex=82, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70E", + name="RACE_HAWAIIAN", + type="number", + startIndex=82, + endIndex=83, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="70F", + name="RACE_WHITE", + type="number", + startIndex=83, + endIndex=84, + required=False, + validators=[validators.validateRace()], + ), + Field( + item="71", + name="GENDER", + type="number", + startIndex=84, + endIndex=85, + required=True, + validators=[validators.isInLimits(0, 9)], + ), + Field( + item="72A", + name="RECEIVE_NONSSA_BENEFITS", + type="number", + startIndex=85, + endIndex=86, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="72B", + name="RECEIVE_SSI", + type="number", + startIndex=86, + endIndex=87, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="73", + name="RELATIONSHIP_HOH", + type="string", + startIndex=87, + endIndex=89, + required=False, + validators=[validators.isInStringRange(0, 10)], + ), + Field( + item="74", + name="PARENT_MINOR_CHILD", + type="number", + startIndex=89, + endIndex=90, + required=False, + validators=[validators.oneOf([0, 2, 3])], + ), + Field( + item="75", + name="EDUCATION_LEVEL", + type="string", + startIndex=90, + endIndex=92, + required=True, + validators=[ + validators.or_validators( + validators.isInStringRange(0, 16), validators.oneOf(["98", "99"]) + ) + ], + ), + Field( + item="76", + name="CITIZENSHIP_STATUS", + type="number", + startIndex=92, + endIndex=93, + required=False, + validators=[validators.oneOf([0, 1, 2, 9])], + ), + Field( + item="77A", + name="UNEARNED_SSI", + type="string", + startIndex=93, + endIndex=97, + required=False, + validators=[validators.isInStringRange(0, 9999)], + ), + Field( + item="77B", + name="OTHER_UNEARNED_INCOME", + type="string", + startIndex=97, + endIndex=101, + required=False, + validators=[validators.isInStringRange(0, 9999)], + ), ], ) -t3 = SchemaManager( - schemas=[ - child_one, - child_two - ] -) +t3 = SchemaManager(schemas=[child_one, child_two]) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t4.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t4.py index d09aaa0cd..8ba5f7d39 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t4.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t4.py @@ -9,42 +9,139 @@ t4 = SchemaManager( - schemas=[ + schemas=[ RowSchema( - model=TANF_T4, - preparsing_validators=[ - validators.hasLength(71), - ], - postparsing_validators=[], - fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid()]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="2", name='COUNTY_FIPS_CODE', type='string', startIndex=19, endIndex=22, - required=True, validators=[validators.isInStringRange(1, 999)]), - Field(item="5", name='STRATUM', type='string', startIndex=22, endIndex=24, - required=True, validators=[validators.isInStringRange(0, 99)]), - Field(item="7", name='ZIP_CODE', type='string', startIndex=24, endIndex=29, - required=True, validators=[]), - Field(item="8", name='DISPOSITION', type='number', startIndex=29, endIndex=30, - required=True, validators=[validators.oneOf([1, 2])]), - Field(item="9", name='CLOSURE_REASON', type='string', startIndex=30, endIndex=32, - required=True, validators=[validators.or_validators(validators.isInStringRange(1, 19), - validators.matches("99"))]), - Field(item="10", name='REC_SUB_HOUSING', type='number', startIndex=32, endIndex=33, - required=True, validators=[validators.isInLimits(1, 3)]), - Field(item="11", name='REC_MED_ASSIST', type='number', startIndex=33, endIndex=34, - required=True, validators=[validators.isInLimits(1, 2)]), - Field(item="12", name='REC_FOOD_STAMPS', type='number', startIndex=34, endIndex=35, - required=True, validators=[validators.isInLimits(1, 2)]), - Field(item="13", name='REC_SUB_CC', type='number', startIndex=35, endIndex=36, - required=True, validators=[validators.isInLimits(1, 3)]), - Field(item="14", name='BLANK', type='string', startIndex=36, endIndex=71, required=False, validators=[]), - ], + model=TANF_T4, + preparsing_validators=[ + validators.hasLength(71), + ], + postparsing_validators=[], + fields=[ + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="2", + name="COUNTY_FIPS_CODE", + type="string", + startIndex=19, + endIndex=22, + required=True, + validators=[validators.isInStringRange(1, 999)], + ), + Field( + item="5", + name="STRATUM", + type="string", + startIndex=22, + endIndex=24, + required=True, + validators=[validators.isInStringRange(0, 99)], + ), + Field( + item="7", + name="ZIP_CODE", + type="string", + startIndex=24, + endIndex=29, + required=True, + validators=[], + ), + Field( + item="8", + name="DISPOSITION", + type="number", + startIndex=29, + endIndex=30, + required=True, + validators=[validators.oneOf([1, 2])], + ), + Field( + item="9", + name="CLOSURE_REASON", + type="string", + startIndex=30, + endIndex=32, + required=True, + validators=[ + validators.or_validators( + validators.isInStringRange(1, 19), validators.matches("99") + ) + ], + ), + Field( + item="10", + name="REC_SUB_HOUSING", + type="number", + startIndex=32, + endIndex=33, + required=True, + validators=[validators.isInLimits(1, 3)], + ), + Field( + item="11", + name="REC_MED_ASSIST", + type="number", + startIndex=33, + endIndex=34, + required=True, + validators=[validators.isInLimits(1, 2)], + ), + Field( + item="12", + name="REC_FOOD_STAMPS", + type="number", + startIndex=34, + endIndex=35, + required=True, + validators=[validators.isInLimits(1, 2)], + ), + Field( + item="13", + name="REC_SUB_CC", + type="number", + startIndex=35, + endIndex=36, + required=True, + validators=[validators.isInLimits(1, 3)], + ), + Field( + item="14", + name="BLANK", + type="string", + startIndex=36, + endIndex=71, + required=False, + validators=[], + ), + ], ) - ] - ) + ] +) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t5.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t5.py index 43c97225f..90047ec9a 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t5.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t5.py @@ -10,135 +10,374 @@ t5 = SchemaManager( - schemas=[ + schemas=[ RowSchema( - model=TANF_T5, - preparsing_validators=[ - validators.hasLength(71), - ], - postparsing_validators=[ - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='SSN', result_function=validators.validateSSN() - ), - validators.validate__FAM_AFF__SSN(), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_HISPANIC', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_AMER_INDIAN', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_ASIAN', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_BLACK', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_HAWAIIAN', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='RACE_WHITE', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='MARITAL_STATUS', result_function=validators.isInLimits(1, 5) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 2), - result_field='PARENT_MINOR_CHILD', result_function=validators.isInLimits(1, 3) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.isInLimits(1, 3), - result_field='EDUCATION_LEVEL', result_function=validators.or_validators( - validators.isInStringRange(1, 16), - validators.isInStringRange(98, 99) - ) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='CITIZENSHIP_STATUS', result_function=validators.isInLimits(1, 2) - ), - validators.validate__FAM_AFF__HOH__Count_Fed_Time(), - validators.if_then_validator( - condition_field='DATE_OF_BIRTH', condition_function=validators.olderThan(18), - result_field='REC_OASDI_INSURANCE', result_function=validators.isInLimits(1, 2) - ), - validators.if_then_validator( - condition_field='FAMILY_AFFILIATION', condition_function=validators.matches(1), - result_field='REC_FEDERAL_DISABILITY', result_function=validators.isInLimits(1, 2) - ), - ], - fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="4", name='RPT_MONTH_YEAR', type='number', startIndex=2, endIndex=8, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid()]), - Field(item="6", name='CASE_NUMBER', type='string', startIndex=8, endIndex=19, - required=True, validators=[validators.isAlphaNumeric()]), - Field(item="14", name='FAMILY_AFFILIATION', type='number', startIndex=19, endIndex=20, - required=True, validators=[validators.isInLimits(1, 5)]), - Field(item="15", name='DATE_OF_BIRTH', type='number', startIndex=20, endIndex=28, - required=True, validators=[validators.isLargerThan(0)]), - TransformField(transform_func=tanf_ssn_decryption_func, item="16", name='SSN', type='string', - startIndex=28, endIndex=37, required=True, validators=[validators.isNumber()], - is_encrypted=False), - Field(item="17A", name='RACE_HISPANIC', type='number', startIndex=37, endIndex=38, - required=True, validators=[validators.validateRace()]), - Field(item="17B", name='RACE_AMER_INDIAN', type='number', startIndex=38, endIndex=39, - required=True, validators=[validators.validateRace()]), - Field(item="17C", name='RACE_ASIAN', type='number', startIndex=39, endIndex=40, - required=True, validators=[validators.validateRace()]), - Field(item="17D", name='RACE_BLACK', type='number', startIndex=40, endIndex=41, - required=True, validators=[validators.validateRace()]), - Field(item="17E", name='RACE_HAWAIIAN', type='number', startIndex=41, endIndex=42, - required=True, validators=[validators.validateRace()]), - Field(item="17F", name='RACE_WHITE', type='number', startIndex=42, endIndex=43, - required=True, validators=[validators.validateRace()]), - Field(item="18", name='GENDER', type='number', startIndex=43, endIndex=44, - required=True, validators=[validators.isInLimits(0, 9)]), - Field(item="19A", name='REC_OASDI_INSURANCE', type='number', startIndex=44, endIndex=45, - required=True, validators=[validators.isInLimits(0, 2)]), - Field(item="19B", name='REC_FEDERAL_DISABILITY', type='number', startIndex=45, endIndex=46, - required=True, validators=[validators.isInLimits(1, 2)]), - Field(item="19C", name='REC_AID_TOTALLY_DISABLED', type='number', startIndex=46, endIndex=47, - required=True, validators=[validators.isInLimits(0, 2)]), - Field(item="19D", name='REC_AID_AGED_BLIND', type='number', startIndex=47, endIndex=48, - required=True, validators=[validators.isInLimits(0, 2)]), - Field(item="19E", name='REC_SSI', type='number', startIndex=48, endIndex=49, - required=True, validators=[validators.isInLimits(1, 2)]), - Field(item="20", name='MARITAL_STATUS', type='number', startIndex=49, endIndex=50, - required=True, validators=[validators.isInLimits(0, 5)]), - Field(item="21", name='RELATIONSHIP_HOH', type='string', startIndex=50, endIndex=52, - required=True, validators=[validators.isInStringRange(1, 10)]), - Field(item="22", name='PARENT_MINOR_CHILD', type='number', startIndex=52, endIndex=53, - required=True, validators=[validators.isInLimits(0, 2)]), - Field(item="23", name='NEEDS_OF_PREGNANT_WOMAN', type='number', startIndex=53, endIndex=54, - required=True, validators=[validators.isInLimits(0, 9)]), - Field(item="24", name='EDUCATION_LEVEL', type='string', startIndex=54, endIndex=56, - required=True, validators=[validators.or_validators(validators.isInStringRange(0, 16), - validators.isInStringRange(98, 99))]), - Field(item="25", name='CITIZENSHIP_STATUS', type='number', startIndex=56, endIndex=57, - required=True, validators=[validators.or_validators(validators.isInLimits(0, 2), - validators.matches(9))]), - Field(item="26", name='COUNTABLE_MONTH_FED_TIME', type='string', startIndex=57, endIndex=60, - required=True, validators=[validators.isInStringRange(0, 999)]), - Field(item="27", name='COUNTABLE_MONTHS_STATE_TRIBE', type='string', startIndex=60, endIndex=62, - required=True, validators=[validators.isInStringRange(0, 99)]), - Field(item="28", name='EMPLOYMENT_STATUS', type='number', startIndex=62, endIndex=63, - required=True, validators=[validators.isInLimits(0, 3)]), - Field(item="29", name='AMOUNT_EARNED_INCOME', type='string', startIndex=63, endIndex=67, - required=True, validators=[validators.isInStringRange(0, 9999)]), - Field(item="30", name='AMOUNT_UNEARNED_INCOME', type='string', startIndex=67, endIndex=71, - required=True, validators=[validators.isInStringRange(0, 9999)]), - ], + model=TANF_T5, + preparsing_validators=[ + validators.hasLength(71), + ], + postparsing_validators=[ + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="SSN", + result_function=validators.validateSSN(), + ), + validators.validate__FAM_AFF__SSN(), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_HISPANIC", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_AMER_INDIAN", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_ASIAN", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_BLACK", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_HAWAIIAN", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="RACE_WHITE", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="MARITAL_STATUS", + result_function=validators.isInLimits(1, 5), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 2), + result_field="PARENT_MINOR_CHILD", + result_function=validators.isInLimits(1, 3), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.isInLimits(1, 3), + result_field="EDUCATION_LEVEL", + result_function=validators.or_validators( + validators.isInStringRange(1, 16), + validators.isInStringRange(98, 99), + ), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="CITIZENSHIP_STATUS", + result_function=validators.isInLimits(1, 2), + ), + validators.validate__FAM_AFF__HOH__Count_Fed_Time(), + validators.if_then_validator( + condition_field="DATE_OF_BIRTH", + condition_function=validators.olderThan(18), + result_field="REC_OASDI_INSURANCE", + result_function=validators.isInLimits(1, 2), + ), + validators.if_then_validator( + condition_field="FAMILY_AFFILIATION", + condition_function=validators.matches(1), + result_field="REC_FEDERAL_DISABILITY", + result_function=validators.isInLimits(1, 2), + ), + ], + fields=[ + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=8, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="6", + name="CASE_NUMBER", + type="string", + startIndex=8, + endIndex=19, + required=True, + validators=[validators.isAlphaNumeric()], + ), + Field( + item="14", + name="FAMILY_AFFILIATION", + type="number", + startIndex=19, + endIndex=20, + required=True, + validators=[validators.isInLimits(1, 5)], + ), + Field( + item="15", + name="DATE_OF_BIRTH", + type="number", + startIndex=20, + endIndex=28, + required=True, + validators=[validators.isLargerThan(0)], + ), + TransformField( + transform_func=tanf_ssn_decryption_func, + item="16", + name="SSN", + type="string", + startIndex=28, + endIndex=37, + required=True, + validators=[validators.isNumber()], + is_encrypted=False, + ), + Field( + item="17A", + name="RACE_HISPANIC", + type="number", + startIndex=37, + endIndex=38, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="17B", + name="RACE_AMER_INDIAN", + type="number", + startIndex=38, + endIndex=39, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="17C", + name="RACE_ASIAN", + type="number", + startIndex=39, + endIndex=40, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="17D", + name="RACE_BLACK", + type="number", + startIndex=40, + endIndex=41, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="17E", + name="RACE_HAWAIIAN", + type="number", + startIndex=41, + endIndex=42, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="17F", + name="RACE_WHITE", + type="number", + startIndex=42, + endIndex=43, + required=True, + validators=[validators.validateRace()], + ), + Field( + item="18", + name="GENDER", + type="number", + startIndex=43, + endIndex=44, + required=True, + validators=[validators.isInLimits(0, 9)], + ), + Field( + item="19A", + name="REC_OASDI_INSURANCE", + type="number", + startIndex=44, + endIndex=45, + required=True, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="19B", + name="REC_FEDERAL_DISABILITY", + type="number", + startIndex=45, + endIndex=46, + required=True, + validators=[validators.isInLimits(1, 2)], + ), + Field( + item="19C", + name="REC_AID_TOTALLY_DISABLED", + type="number", + startIndex=46, + endIndex=47, + required=True, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="19D", + name="REC_AID_AGED_BLIND", + type="number", + startIndex=47, + endIndex=48, + required=True, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="19E", + name="REC_SSI", + type="number", + startIndex=48, + endIndex=49, + required=True, + validators=[validators.isInLimits(1, 2)], + ), + Field( + item="20", + name="MARITAL_STATUS", + type="number", + startIndex=49, + endIndex=50, + required=True, + validators=[validators.isInLimits(0, 5)], + ), + Field( + item="21", + name="RELATIONSHIP_HOH", + type="string", + startIndex=50, + endIndex=52, + required=True, + validators=[validators.isInStringRange(1, 10)], + ), + Field( + item="22", + name="PARENT_MINOR_CHILD", + type="number", + startIndex=52, + endIndex=53, + required=True, + validators=[validators.isInLimits(0, 2)], + ), + Field( + item="23", + name="NEEDS_OF_PREGNANT_WOMAN", + type="number", + startIndex=53, + endIndex=54, + required=True, + validators=[validators.isInLimits(0, 9)], + ), + Field( + item="24", + name="EDUCATION_LEVEL", + type="string", + startIndex=54, + endIndex=56, + required=True, + validators=[ + validators.or_validators( + validators.isInStringRange(0, 16), + validators.isInStringRange(98, 99), + ) + ], + ), + Field( + item="25", + name="CITIZENSHIP_STATUS", + type="number", + startIndex=56, + endIndex=57, + required=True, + validators=[ + validators.or_validators( + validators.isInLimits(0, 2), validators.matches(9) + ) + ], + ), + Field( + item="26", + name="COUNTABLE_MONTH_FED_TIME", + type="string", + startIndex=57, + endIndex=60, + required=True, + validators=[validators.isInStringRange(0, 999)], + ), + Field( + item="27", + name="COUNTABLE_MONTHS_STATE_TRIBE", + type="string", + startIndex=60, + endIndex=62, + required=True, + validators=[validators.isInStringRange(0, 99)], + ), + Field( + item="28", + name="EMPLOYMENT_STATUS", + type="number", + startIndex=62, + endIndex=63, + required=True, + validators=[validators.isInLimits(0, 3)], + ), + Field( + item="29", + name="AMOUNT_EARNED_INCOME", + type="string", + startIndex=63, + endIndex=67, + required=True, + validators=[validators.isInStringRange(0, 9999)], + ), + Field( + item="30", + name="AMOUNT_UNEARNED_INCOME", + type="string", + startIndex=67, + endIndex=71, + required=True, + validators=[validators.isInStringRange(0, 9999)], + ), + ], ) - ] + ] ) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py index 8140322c2..c99db03e0 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t6.py @@ -16,48 +16,183 @@ ], postparsing_validators=[ validators.sumIsEqual("NUM_APPLICATIONS", ["NUM_APPROVED", "NUM_DENIED"]), - validators.sumIsEqual("NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"]), - validators.sumIsEqual("NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"]), + validators.sumIsEqual( + "NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"] + ), + validators.sumIsEqual( + "NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"] + ), ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="3", name='CALENDAR_QUARTER', type='number', startIndex=2, endIndex=7, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.quarterIsValid()]), - TransformField(calendar_quarter_to_rpt_month_year(0), item="4", name='RPT_MONTH_YEAR', type='number', - startIndex=2, endIndex=7, required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid()]), - Field(item="4A", name='NUM_APPLICATIONS', type='number', startIndex=7, endIndex=15, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="5A", name='NUM_APPROVED', type='number', startIndex=31, endIndex=39, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="6A", name='NUM_DENIED', type='number', startIndex=55, endIndex=63, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="7A", name='ASSISTANCE', type='number', startIndex=79, endIndex=91, - required=True, validators=[validators.isInLimits(0, 999999999999)]), - Field(item="8A", name='NUM_FAMILIES', type='number', startIndex=115, endIndex=123, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="9A", name='NUM_2_PARENTS', type='number', startIndex=139, endIndex=147, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="10A", name='NUM_1_PARENTS', type='number', startIndex=163, endIndex=171, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="11A", name='NUM_NO_PARENTS', type='number', startIndex=187, endIndex=195, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="12A", name='NUM_RECIPIENTS', type='number', startIndex=211, endIndex=219, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="13A", name='NUM_ADULT_RECIPIENTS', type='number', startIndex=235, endIndex=243, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="14A", name='NUM_CHILD_RECIPIENTS', type='number', startIndex=259, endIndex=267, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="15A", name='NUM_NONCUSTODIALS', type='number', startIndex=283, endIndex=291, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="16A", name='NUM_BIRTHS', type='number', startIndex=307, endIndex=315, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="17A", name='NUM_OUTWEDLOCK_BIRTHS', type='number', startIndex=331, endIndex=339, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="18A", name='NUM_CLOSED_CASES', type='number', startIndex=355, endIndex=363, - required=True, validators=[validators.isInLimits(0, 99999999)]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="3", + name="CALENDAR_QUARTER", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.quarterIsValid(), + ], + ), + TransformField( + calendar_quarter_to_rpt_month_year(0), + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="4A", + name="NUM_APPLICATIONS", + type="number", + startIndex=7, + endIndex=15, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="5A", + name="NUM_APPROVED", + type="number", + startIndex=31, + endIndex=39, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="6A", + name="NUM_DENIED", + type="number", + startIndex=55, + endIndex=63, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="7A", + name="ASSISTANCE", + type="number", + startIndex=79, + endIndex=91, + required=True, + validators=[validators.isInLimits(0, 999999999999)], + ), + Field( + item="8A", + name="NUM_FAMILIES", + type="number", + startIndex=115, + endIndex=123, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="9A", + name="NUM_2_PARENTS", + type="number", + startIndex=139, + endIndex=147, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="10A", + name="NUM_1_PARENTS", + type="number", + startIndex=163, + endIndex=171, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="11A", + name="NUM_NO_PARENTS", + type="number", + startIndex=187, + endIndex=195, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="12A", + name="NUM_RECIPIENTS", + type="number", + startIndex=211, + endIndex=219, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="13A", + name="NUM_ADULT_RECIPIENTS", + type="number", + startIndex=235, + endIndex=243, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="14A", + name="NUM_CHILD_RECIPIENTS", + type="number", + startIndex=259, + endIndex=267, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="15A", + name="NUM_NONCUSTODIALS", + type="number", + startIndex=283, + endIndex=291, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="16A", + name="NUM_BIRTHS", + type="number", + startIndex=307, + endIndex=315, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="17A", + name="NUM_OUTWEDLOCK_BIRTHS", + type="number", + startIndex=331, + endIndex=339, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="18A", + name="NUM_CLOSED_CASES", + type="number", + startIndex=355, + endIndex=363, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), ], ) @@ -68,46 +203,177 @@ ], postparsing_validators=[ validators.sumIsEqual("NUM_APPLICATIONS", ["NUM_APPROVED", "NUM_DENIED"]), - validators.sumIsEqual("NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"]), - validators.sumIsEqual("NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"]), + validators.sumIsEqual( + "NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"] + ), + validators.sumIsEqual( + "NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"] + ), ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="3", name='CALENDAR_QUARTER', type='number', startIndex=2, endIndex=7, - required=True, validators=[]), - TransformField(calendar_quarter_to_rpt_month_year(1), item="4", name='RPT_MONTH_YEAR', type='number', - startIndex=2, endIndex=7, required=True, validators=[]), - Field(item="4B", name='NUM_APPLICATIONS', type='number', startIndex=15, endIndex=23, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="5B", name='NUM_APPROVED', type='number', startIndex=39, endIndex=47, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="6B", name='NUM_DENIED', type='number', startIndex=63, endIndex=71, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="7B", name='ASSISTANCE', type='number', startIndex=91, endIndex=103, - required=True, validators=[validators.isInLimits(0, 999999999999)]), - Field(item="8B", name='NUM_FAMILIES', type='number', startIndex=123, endIndex=131, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="9B", name='NUM_2_PARENTS', type='number', startIndex=147, endIndex=155, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="10B", name='NUM_1_PARENTS', type='number', startIndex=171, endIndex=179, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="11B", name='NUM_NO_PARENTS', type='number', startIndex=195, endIndex=203, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="12B", name='NUM_RECIPIENTS', type='number', startIndex=219, endIndex=227, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="13B", name='NUM_ADULT_RECIPIENTS', type='number', startIndex=243, endIndex=251, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="14B", name='NUM_CHILD_RECIPIENTS', type='number', startIndex=267, endIndex=275, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="15B", name='NUM_NONCUSTODIALS', type='number', startIndex=291, endIndex=299, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="16B", name='NUM_BIRTHS', type='number', startIndex=315, endIndex=323, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="17B", name='NUM_OUTWEDLOCK_BIRTHS', type='number', startIndex=339, endIndex=347, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="18B", name='NUM_CLOSED_CASES', type='number', startIndex=363, endIndex=371, - required=True, validators=[validators.isInLimits(0, 99999999)]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="3", + name="CALENDAR_QUARTER", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[], + ), + TransformField( + calendar_quarter_to_rpt_month_year(1), + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[], + ), + Field( + item="4B", + name="NUM_APPLICATIONS", + type="number", + startIndex=15, + endIndex=23, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="5B", + name="NUM_APPROVED", + type="number", + startIndex=39, + endIndex=47, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="6B", + name="NUM_DENIED", + type="number", + startIndex=63, + endIndex=71, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="7B", + name="ASSISTANCE", + type="number", + startIndex=91, + endIndex=103, + required=True, + validators=[validators.isInLimits(0, 999999999999)], + ), + Field( + item="8B", + name="NUM_FAMILIES", + type="number", + startIndex=123, + endIndex=131, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="9B", + name="NUM_2_PARENTS", + type="number", + startIndex=147, + endIndex=155, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="10B", + name="NUM_1_PARENTS", + type="number", + startIndex=171, + endIndex=179, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="11B", + name="NUM_NO_PARENTS", + type="number", + startIndex=195, + endIndex=203, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="12B", + name="NUM_RECIPIENTS", + type="number", + startIndex=219, + endIndex=227, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="13B", + name="NUM_ADULT_RECIPIENTS", + type="number", + startIndex=243, + endIndex=251, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="14B", + name="NUM_CHILD_RECIPIENTS", + type="number", + startIndex=267, + endIndex=275, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="15B", + name="NUM_NONCUSTODIALS", + type="number", + startIndex=291, + endIndex=299, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="16B", + name="NUM_BIRTHS", + type="number", + startIndex=315, + endIndex=323, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="17B", + name="NUM_OUTWEDLOCK_BIRTHS", + type="number", + startIndex=339, + endIndex=347, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="18B", + name="NUM_CLOSED_CASES", + type="number", + startIndex=363, + endIndex=371, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), ], ) @@ -118,54 +384,179 @@ ], postparsing_validators=[ validators.sumIsEqual("NUM_APPLICATIONS", ["NUM_APPROVED", "NUM_DENIED"]), - validators.sumIsEqual("NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"]), - validators.sumIsEqual("NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"]), + validators.sumIsEqual( + "NUM_FAMILIES", ["NUM_2_PARENTS", "NUM_1_PARENTS", "NUM_NO_PARENTS"] + ), + validators.sumIsEqual( + "NUM_RECIPIENTS", ["NUM_ADULT_RECIPIENTS", "NUM_CHILD_RECIPIENTS"] + ), ], fields=[ - Field(item="0", name='RecordType', type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="3", name='CALENDAR_QUARTER', type='number', startIndex=2, endIndex=7, - required=True, validators=[]), - TransformField(calendar_quarter_to_rpt_month_year(2), item="4", name='RPT_MONTH_YEAR', type='number', - startIndex=2, endIndex=7, required=True, validators=[]), - Field(item="4C", name='NUM_APPLICATIONS', type='number', startIndex=23, endIndex=31, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="5C", name='NUM_APPROVED', type='number', startIndex=47, endIndex=55, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="6C", name='NUM_DENIED', type='number', startIndex=71, endIndex=79, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="7C", name='ASSISTANCE', type='number', startIndex=103, endIndex=115, - required=True, validators=[validators.isInLimits(0, 999999999999)]), - Field(item="8C", name='NUM_FAMILIES', type='number', startIndex=131, endIndex=139, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="9C", name='NUM_2_PARENTS', type='number', startIndex=155, endIndex=163, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="10C", name='NUM_1_PARENTS', type='number', startIndex=179, endIndex=187, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="11C", name='NUM_NO_PARENTS', type='number', startIndex=203, endIndex=211, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="12C", name='NUM_RECIPIENTS', type='number', startIndex=227, endIndex=235, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="13C", name='NUM_ADULT_RECIPIENTS', type='number', startIndex=251, endIndex=259, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="14C", name='NUM_CHILD_RECIPIENTS', type='number', startIndex=275, endIndex=283, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="15C", name='NUM_NONCUSTODIALS', type='number', startIndex=299, endIndex=307, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="16C", name='NUM_BIRTHS', type='number', startIndex=323, endIndex=331, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="17C", name='NUM_OUTWEDLOCK_BIRTHS', type='number', startIndex=347, endIndex=355, - required=True, validators=[validators.isInLimits(0, 99999999)]), - Field(item="18C", name='NUM_CLOSED_CASES', type='number', startIndex=371, endIndex=379, - required=True, validators=[validators.isInLimits(0, 99999999)]), + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="3", + name="CALENDAR_QUARTER", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[], + ), + TransformField( + calendar_quarter_to_rpt_month_year(2), + item="4", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[], + ), + Field( + item="4C", + name="NUM_APPLICATIONS", + type="number", + startIndex=23, + endIndex=31, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="5C", + name="NUM_APPROVED", + type="number", + startIndex=47, + endIndex=55, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="6C", + name="NUM_DENIED", + type="number", + startIndex=71, + endIndex=79, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="7C", + name="ASSISTANCE", + type="number", + startIndex=103, + endIndex=115, + required=True, + validators=[validators.isInLimits(0, 999999999999)], + ), + Field( + item="8C", + name="NUM_FAMILIES", + type="number", + startIndex=131, + endIndex=139, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="9C", + name="NUM_2_PARENTS", + type="number", + startIndex=155, + endIndex=163, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="10C", + name="NUM_1_PARENTS", + type="number", + startIndex=179, + endIndex=187, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="11C", + name="NUM_NO_PARENTS", + type="number", + startIndex=203, + endIndex=211, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="12C", + name="NUM_RECIPIENTS", + type="number", + startIndex=227, + endIndex=235, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="13C", + name="NUM_ADULT_RECIPIENTS", + type="number", + startIndex=251, + endIndex=259, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="14C", + name="NUM_CHILD_RECIPIENTS", + type="number", + startIndex=275, + endIndex=283, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="15C", + name="NUM_NONCUSTODIALS", + type="number", + startIndex=299, + endIndex=307, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="16C", + name="NUM_BIRTHS", + type="number", + startIndex=323, + endIndex=331, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="17C", + name="NUM_OUTWEDLOCK_BIRTHS", + type="number", + startIndex=347, + endIndex=355, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), + Field( + item="18C", + name="NUM_CLOSED_CASES", + type="number", + startIndex=371, + endIndex=379, + required=True, + validators=[validators.isInLimits(0, 99999999)], + ), ], ) -t6 = SchemaManager( - schemas=[ - s1, - s2, - s3 - ] - ) +t6 = SchemaManager(schemas=[s1, s2, s3]) diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py index 2fcb4e0fd..199f4e525 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py @@ -15,45 +15,83 @@ families_index = 10 for i in range(1, 31): month_index = (i - 1) % 3 - sub_item_labels = ['A', 'B', 'C'] + sub_item_labels = ["A", "B", "C"] families_value_item_number = f"6{sub_item_labels[month_index]}" schemas.append( - RowSchema( - model=TANF_T7, - quiet_preparser_errors=i > 1, - preparsing_validators=[ - validators.notEmpty(0, 7), - validators.notEmpty(validator_index, validator_index + 24), - ], - postparsing_validators=[], - fields=[ - Field(item="0", name="RecordType", type='string', startIndex=0, endIndex=2, - required=True, validators=[]), - Field(item="3", name='CALENDAR_QUARTER', type='number', startIndex=2, endIndex=7, - required=True, validators=[validators.dateYearIsLargerThan(1998), - validators.quarterIsValid()]), - TransformField( - transform_func=calendar_quarter_to_rpt_month_year(month_index), - item="3A", - name='RPT_MONTH_YEAR', - type='number', - startIndex=2, - endIndex=7, - required=True, - validators=[ - validators.dateYearIsLargerThan(1998), - validators.dateMonthIsValid() - ] - ), - Field(item="4", name='TDRS_SECTION_IND', type='string', startIndex=section_ind_index, - endIndex=section_ind_index + 1, required=True, validators=[validators.oneOf(['1', '2'])]), - Field(item="5", name='STRATUM', type='string', startIndex=stratum_index, - endIndex=stratum_index + 2, required=True, validators=[validators.isInStringRange(1, 99)]), - Field(item=families_value_item_number, name='FAMILIES_MONTH', type='number', startIndex=families_index, - endIndex=families_index + 7, required=True, validators=[validators.isInLimits(0, 9999999)]), - ] - ) + RowSchema( + model=TANF_T7, + quiet_preparser_errors=i > 1, + preparsing_validators=[ + validators.hasLength(247), + validators.notEmpty(0, 7), + validators.notEmpty(validator_index, validator_index + 24), + ], + postparsing_validators=[], + fields=[ + Field( + item="0", + name="RecordType", + type="string", + startIndex=0, + endIndex=2, + required=True, + validators=[], + ), + Field( + item="3", + name="CALENDAR_QUARTER", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.quarterIsValid(), + ], + ), + TransformField( + transform_func=calendar_quarter_to_rpt_month_year(month_index), + item="3A", + name="RPT_MONTH_YEAR", + type="number", + startIndex=2, + endIndex=7, + required=True, + validators=[ + validators.dateYearIsLargerThan(1998), + validators.dateMonthIsValid(), + ], + ), + Field( + item="4", + name="TDRS_SECTION_IND", + type="string", + startIndex=section_ind_index, + endIndex=section_ind_index + 1, + required=True, + validators=[validators.oneOf(["1", "2"])], + ), + Field( + item="5", + name="STRATUM", + type="string", + startIndex=stratum_index, + endIndex=stratum_index + 2, + required=True, + validators=[validators.isInStringRange(1, 99)], + ), + Field( + item=families_value_item_number, + name="FAMILIES_MONTH", + type="number", + startIndex=families_index, + endIndex=families_index + 7, + required=True, + validators=[validators.isInLimits(0, 9999999)], + ), + ], + ) ) index_offset = 0 if i % 3 != 0 else 24 diff --git a/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py b/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py index 46a440508..d1ad29da7 100644 --- a/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py +++ b/tdrs-backend/tdpservice/parsers/schema_defs/trailer.py @@ -11,20 +11,38 @@ preparsing_validators=[ validators.hasLength( 23, - lambda value, length: f'Trailer length is {len(value)} but must be {length} characters.' + lambda value, length: f"Trailer length is {len(value)} but must be {length} characters.", ), - validators.startsWith('TRAILER') + validators.startsWith("TRAILER"), ], postparsing_validators=[], fields=[ - Field(item="1", name='title', type='string', startIndex=0, endIndex=7, required=True, validators=[ - validators.matches('TRAILER') - ]), - Field(item="2", name='record_count', type='number', startIndex=7, endIndex=14, required=True, validators=[ - validators.between(0, 9999999) - ]), - Field(item="-1", name='blank', type='string', startIndex=14, endIndex=23, required=False, validators=[ - validators.matches(' ') - ]), + Field( + item="1", + name="title", + type="string", + startIndex=0, + endIndex=7, + required=True, + validators=[validators.matches("TRAILER")], + ), + Field( + item="2", + name="record_count", + type="number", + startIndex=7, + endIndex=14, + required=True, + validators=[validators.between(0, 9999999)], + ), + Field( + item="-1", + name="blank", + type="string", + startIndex=14, + endIndex=23, + required=False, + validators=[validators.matches(" ")], + ), ], ) diff --git a/tdrs-backend/tdpservice/parsers/test/data/ADS.E2J.NDM4.MS24 b/tdrs-backend/tdpservice/parsers/test/data/ADS.E2J.NDM4.MS24 new file mode 100644 index 000000000..1393729b8 --- /dev/null +++ b/tdrs-backend/tdpservice/parsers/test/data/ADS.E2J.NDM4.MS24 @@ -0,0 +1,3 @@ +HEADER20184S24 SSP1 N +M720184101000176900013100001111102000074800007670000768103001335200139310014077200000120200011890001229 +TRAILER0000001 diff --git a/tdrs-backend/tdpservice/parsers/test/test_parse.py b/tdrs-backend/tdpservice/parsers/test/test_parse.py index 764de2990..305a0a721 100644 --- a/tdrs-backend/tdpservice/parsers/test/test_parse.py +++ b/tdrs-backend/tdpservice/parsers/test/test_parse.py @@ -5,7 +5,7 @@ from .. import parse from ..models import ParserError, ParserErrorCategoryChoices, DataFileSummary from tdpservice.search_indexes.models.tanf import TANF_T1, TANF_T2, TANF_T3, TANF_T4, TANF_T5, TANF_T6, TANF_T7 -from tdpservice.search_indexes.models.ssp import SSP_M1, SSP_M2, SSP_M3, SSP_M6 +from tdpservice.search_indexes.models.ssp import SSP_M1, SSP_M2, SSP_M3, SSP_M6, SSP_M7 from .factories import DataFileSummaryFactory from tdpservice.data_files.models import DataFile from .. import schema_defs, util @@ -909,6 +909,23 @@ def test_parse_tanf_section4_file(tanf_section4_file): assert first.FAMILIES_MONTH == 274 assert sixth.FAMILIES_MONTH == 499 +@pytest.fixture +def ssp_section4_file(stt_user, stt): + """Fixture for ADS.E2J.NDM4.MS24.""" + return util.create_test_datafile('ADS.E2J.NDM4.MS24', stt_user, stt, "SSP Stratum Data") + +@pytest.mark.django_db() +def test_parse_ssp_section4_file(ssp_section4_file): + """Test parsing SSP Section 4 submission.""" + parse.parse_datafile(ssp_section4_file) + + m7_objs = SSP_M7.objects.all().order_by('FAMILIES_MONTH') + + assert m7_objs.count() == 12 + + first = m7_objs.first() + assert first.RPT_MONTH_YEAR == 201810 + assert first.FAMILIES_MONTH == 748 @pytest.fixture def ssp_section3_file(stt_user, stt): diff --git a/tdrs-backend/tdpservice/parsers/util.py b/tdrs-backend/tdpservice/parsers/util.py index 6c7e4020a..3ee209607 100644 --- a/tdrs-backend/tdpservice/parsers/util.py +++ b/tdrs-backend/tdpservice/parsers/util.py @@ -161,8 +161,8 @@ def get_schema_options(program, section, query=None, model=None, model_name=None 'C': { 'section': DataFile.Section.SSP_CLOSED_CASE_DATA, 'models': { - # 'S4': schema_defs.ssp.m4, - # 'S5': schema_defs.ssp.m5, + # 'M4': schema_defs.ssp.m4, + # 'M5': schema_defs.ssp.m5, } }, 'G': { @@ -174,7 +174,7 @@ def get_schema_options(program, section, query=None, model=None, model_name=None 'S': { 'section': DataFile.Section.SSP_STRATUM_DATA, 'models': { - # 'S7': schema_defs.ssp.m7, + 'M7': schema_defs.ssp.m7, } } }, diff --git a/tdrs-backend/tdpservice/search_indexes/admin/__init__.py b/tdrs-backend/tdpservice/search_indexes/admin/__init__.py index 19ad02979..f9b99f7d9 100644 --- a/tdrs-backend/tdpservice/search_indexes/admin/__init__.py +++ b/tdrs-backend/tdpservice/search_indexes/admin/__init__.py @@ -14,3 +14,4 @@ admin.site.register(models.ssp.SSP_M2, ssp.SSP_M2Admin) admin.site.register(models.ssp.SSP_M3, ssp.SSP_M3Admin) admin.site.register(models.ssp.SSP_M6, ssp.SSP_M6Admin) +admin.site.register(models.ssp.SSP_M7, ssp.SSP_M7Admin) diff --git a/tdrs-backend/tdpservice/search_indexes/admin/ssp.py b/tdrs-backend/tdpservice/search_indexes/admin/ssp.py index d8e2088af..97112628d 100644 --- a/tdrs-backend/tdpservice/search_indexes/admin/ssp.py +++ b/tdrs-backend/tdpservice/search_indexes/admin/ssp.py @@ -55,7 +55,6 @@ class SSP_M3Admin(admin.ModelAdmin): 'RPT_MONTH_YEAR', ] - class SSP_M6Admin(admin.ModelAdmin): """ModelAdmin class for parsed M6 data files.""" @@ -71,3 +70,22 @@ class SSP_M6Admin(admin.ModelAdmin): CreationDateFilter, 'RPT_MONTH_YEAR' ] + +class SSP_M7Admin(admin.ModelAdmin): + """ModelAdmin class for parsed M7 data files.""" + + list_display = [ + 'RecordType', + 'CALENDAR_QUARTER', + 'RPT_MONTH_YEAR', + 'TDRS_SECTION_IND', + 'STRATUM', + 'FAMILIES_MONTH', + 'datafile', + ] + + list_filter = [ + 'CALENDAR_QUARTER', + CreationDateFilter, + 'RPT_MONTH_YEAR', + ] diff --git a/tdrs-backend/tdpservice/search_indexes/documents/ssp.py b/tdrs-backend/tdpservice/search_indexes/documents/ssp.py index d047acd0d..1f571101f 100644 --- a/tdrs-backend/tdpservice/search_indexes/documents/ssp.py +++ b/tdrs-backend/tdpservice/search_indexes/documents/ssp.py @@ -2,7 +2,7 @@ from django_elasticsearch_dsl import Document from django_elasticsearch_dsl.registries import registry -from ..models.ssp import SSP_M1, SSP_M2, SSP_M3, SSP_M6 +from ..models.ssp import SSP_M1, SSP_M2, SSP_M3, SSP_M6, SSP_M7 from .document_base import DocumentBase @@ -200,7 +200,6 @@ class Django: 'OTHER_UNEARNED_INCOME', ] - @registry.register_document class SSP_M6DataSubmissionDocument(DocumentBase, Document): """Elastic search model mapping for a parsed SSP M6 data file.""" @@ -233,3 +232,29 @@ class Django: 'AMT_ASSISTANCE', 'CLOSED_CASES', ] + +@registry.register_document +class SSP_M7DataSubmissionDocument(DocumentBase, Document): + """Elastic search model mapping for a parsed SSP M7 data file.""" + + class Index: + """ElasticSearch index generation settings.""" + + name = 'ssp_m7_submissions' + settings = { + 'number_of_shards': 1, + 'number_of_replicas': 0, + } + + class Django: + """Django model reference and field mapping.""" + + model = SSP_M7 + fields = [ + "RecordType", + "CALENDAR_QUARTER", + "RPT_MONTH_YEAR", + "TDRS_SECTION_IND", + "STRATUM", + "FAMILIES_MONTH", + ] diff --git a/tdrs-backend/tdpservice/search_indexes/migrations/0021_ssp_m7.py b/tdrs-backend/tdpservice/search_indexes/migrations/0021_ssp_m7.py new file mode 100644 index 000000000..acfaf91ad --- /dev/null +++ b/tdrs-backend/tdpservice/search_indexes/migrations/0021_ssp_m7.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.15 on 2023-10-19 14:24 + +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('data_files', '0012_datafile_s3_versioning_id'), + ('search_indexes', '0019_ssp_m6'), + ] + + operations = [ + migrations.CreateModel( + name='SSP_M7', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('RecordType', models.CharField(max_length=156, null=True)), + ('CALENDAR_QUARTER', models.IntegerField(blank=True, null=True)), + ('RPT_MONTH_YEAR', models.IntegerField(null=True)), + ('TDRS_SECTION_IND', models.CharField(max_length=1, null=True)), + ('STRATUM', models.CharField(max_length=2, null=True)), + ('FAMILIES_MONTH', models.IntegerField(null=True)), + ('datafile', models.ForeignKey(blank=True, help_text='The parent file from which this record was created.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='m7_parent', to='data_files.datafile')), + ], + ), + ] diff --git a/tdrs-backend/tdpservice/search_indexes/models/ssp.py b/tdrs-backend/tdpservice/search_indexes/models/ssp.py index 05c599c39..f362fb374 100644 --- a/tdrs-backend/tdpservice/search_indexes/models/ssp.py +++ b/tdrs-backend/tdpservice/search_indexes/models/ssp.py @@ -2,9 +2,7 @@ import uuid from django.db import models -from django.contrib.contenttypes.fields import GenericRelation from tdpservice.data_files.models import DataFile -from tdpservice.parsers.models import ParserError class SSP_M1(models.Model): @@ -24,7 +22,6 @@ class SSP_M1(models.Model): related_name='m1_parent' ) - error = GenericRelation(ParserError) RecordType = models.CharField(max_length=156, null=True, blank=False) RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False) CASE_NUMBER = models.CharField(max_length=11, null=True, blank=False) @@ -36,9 +33,7 @@ class SSP_M1(models.Model): ) STRATUM = models.CharField(max_length=2, null=True, blank=False) ZIP_CODE = models.CharField(max_length=5, null=True, blank=False) - # FUNDING_STREAM = models.IntegerField(null=True, blank=False) DISPOSITION = models.IntegerField(null=True, blank=False) - # NEW_APPLICANT = models.IntegerField(null=True, blank=False) NBR_FAMILY_MEMBERS = models.IntegerField(null=True, blank=False) FAMILY_TYPE = models.IntegerField(null=True, blank=False) TANF_ASST_IN_6MONTHS = models.IntegerField(null=True, blank=False) @@ -74,8 +69,6 @@ class SSP_M1(models.Model): REDUCTIONS_ON_RECEIPTS = models.IntegerField(null=True, blank=False) OTHER_NON_SANCTION = models.IntegerField(null=True, blank=False) WAIVER_EVAL_CONTROL_GRPS = models.IntegerField(null=True, blank=False) - # FAMILY_EXEMPT_TIME_LIMITS = models.IntegerField(null=True, blank=False) - # FAMILY_NEW_CHILD = models.IntegerField(null=True, blank=False) class SSP_M2(models.Model): @@ -95,7 +88,6 @@ class SSP_M2(models.Model): related_name='m2_parent' ) - error = GenericRelation(ParserError) RecordType = models.CharField(max_length=156, null=True, blank=False) RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False) CASE_NUMBER = models.CharField(max_length=11, null=True, blank=False) @@ -124,9 +116,6 @@ class SSP_M2(models.Model): EDUCATION_LEVEL = models.IntegerField(null=True, blank=False) CITIZENSHIP_STATUS = models.IntegerField(null=True, blank=False) COOPERATION_CHILD_SUPPORT = models.IntegerField(null=True, blank=False) - # months_fed_time_limit = models.FloatField(null=True, blank=False) - # months_state_time_limit = models.FloatField(null=True, blank=False) - # current_month_state_exempt = models.IntegerField(null=True, blank=False) EMPLOYMENT_STATUS = models.IntegerField(null=True, blank=False) WORK_ELIGIBLE_INDICATOR = models.IntegerField(null=True, blank=False) WORK_PART_STATUS = models.IntegerField(null=True, blank=False) @@ -186,7 +175,6 @@ class SSP_M3(models.Model): related_name='m3_parent' ) - error = GenericRelation(ParserError) RecordType = models.CharField(max_length=156, null=True, blank=False) RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False) CASE_NUMBER = models.CharField(max_length=11, null=True, blank=False) @@ -211,7 +199,6 @@ class SSP_M3(models.Model): UNEARNED_SSI = models.IntegerField(null=True, blank=False) OTHER_UNEARNED_INCOME = models.IntegerField(null=True, blank=False) - class SSP_M6(models.Model): """ Parsed record representing an M6 data submission. @@ -243,3 +230,31 @@ class SSP_M6(models.Model): NONCUSTODIALS = models.IntegerField(null=True, blank=True) AMT_ASSISTANCE = models.IntegerField(null=True, blank=True) CLOSED_CASES = models.IntegerField(null=True, blank=True) + +class SSP_M7(models.Model): + """ + Parsed record representing an SSP M3 data submission. + + Mapped to an elastic search index. + """ + + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + datafile = models.ForeignKey( + DataFile, + blank=True, + help_text='The parent file from which this record was created.', + null=True, + on_delete=models.CASCADE, + related_name='m7_parent' + ) + + RecordType = models.CharField(max_length=156, null=True, blank=False) + CALENDAR_QUARTER = models.IntegerField(null=True, blank=True) + RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False) + TDRS_SECTION_IND = models.CharField( + max_length=1, + null=True, + blank=False + ) + STRATUM = models.CharField(max_length=2, null=True, blank=False) + FAMILIES_MONTH = models.IntegerField(null=True, blank=False) diff --git a/tdrs-backend/tdpservice/search_indexes/models/tanf.py b/tdrs-backend/tdpservice/search_indexes/models/tanf.py index 9e31fffe2..f6ba10f29 100644 --- a/tdrs-backend/tdpservice/search_indexes/models/tanf.py +++ b/tdrs-backend/tdpservice/search_indexes/models/tanf.py @@ -2,9 +2,7 @@ import uuid from django.db import models -from django.contrib.contenttypes.fields import GenericRelation from tdpservice.data_files.models import DataFile -from tdpservice.parsers.models import ParserError class TANF_T1(models.Model): @@ -24,7 +22,6 @@ class TANF_T1(models.Model): related_name='t1_parent' ) - error = GenericRelation(ParserError) RecordType = models.CharField(max_length=156, null=True, blank=False) RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False) CASE_NUMBER = models.CharField(max_length=11, null=True, blank=False) diff --git a/tdrs-backend/tdpservice/search_indexes/test/test_model_mapping.py b/tdrs-backend/tdpservice/search_indexes/test/test_model_mapping.py index 15581d304..8386c5d48 100644 --- a/tdrs-backend/tdpservice/search_indexes/test/test_model_mapping.py +++ b/tdrs-backend/tdpservice/search_indexes/test/test_model_mapping.py @@ -350,9 +350,7 @@ def test_can_create_and_index_tanf_t7_submission(test_datafile): submission.CALENDAR_QUARTER = 1 submission.TDRS_SECTION_IND = '1' submission.STRATUM = '01' - submission.FAMILIES_MONTH_1 = 47655 - submission.FAMILIES_MONTH_2 = 81982 - submission.FAMILIES_MONTH_3 = 9999999 + submission.FAMILIES_MONTH = 47655 submission.save() @@ -579,7 +577,6 @@ def test_can_create_and_index_ssp_m3_submission(): assert response.hits.total.value == 1 - @pytest.mark.django_db def test_can_create_and_index_ssp_m6_submission(test_datafile): """SSP M6 submissions can be created and mapped.""" @@ -617,3 +614,30 @@ def test_can_create_and_index_ssp_m6_submission(test_datafile): response = search.execute() assert response.hits.total.value == 1 + +@pytest.mark.django_db +def test_can_create_and_index_ssp_m7_submission(test_datafile): + """SSP M7 submissions can be created and mapped.""" + record_num = fake.uuid4() + + submission = models.ssp.SSP_M7() + submission.datafile = test_datafile + submission.RecordType = record_num + submission.CALENDAR_YEAR = 2020 + submission.CALENDAR_QUARTER = 1 + submission.TDRS_SECTION_IND = '1' + submission.STRATUM = '01' + submission.FAMILIES_MONTH = 47655 + + submission.save() + + # No checks her because m7 records can't be parsed currently. + assert submission.id is not None + + search = documents.ssp.SSP_M7DataSubmissionDocument.search().query( + 'match', + RecordType=record_num + ) + response = search.execute() + + assert response.hits.total.value == 1 diff --git a/tdrs-backend/tdpservice/users/test/test_permissions.py b/tdrs-backend/tdpservice/users/test/test_permissions.py index d942fd0c8..404fdd9ae 100644 --- a/tdrs-backend/tdpservice/users/test/test_permissions.py +++ b/tdrs-backend/tdpservice/users/test/test_permissions.py @@ -126,6 +126,9 @@ def test_ofa_system_admin_permissions(ofa_system_admin): 'search_indexes.add_ssp_m6', 'search_indexes.view_ssp_m6', 'search_indexes.change_ssp_m6', + 'search_indexes.add_ssp_m7', + 'search_indexes.view_ssp_m7', + 'search_indexes.change_ssp_m7', } group_permissions = ofa_system_admin.get_group_permissions() assert group_permissions == expected_permissions