Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

2695 field spaces #2704

Merged
merged 26 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f94c1ff
- Added support to fields that can allow blanks as valid fields
elipe17 Sep 13, 2023
8a12d79
- Updating blank fields to not be required
elipe17 Sep 15, 2023
5ede638
- Fix lint errors
elipe17 Sep 15, 2023
49b148d
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Sep 18, 2023
780a6c7
- updating fields to be required until guidance comes out on what is …
elipe17 Sep 20, 2023
0750677
- ADding None check
elipe17 Sep 20, 2023
c63ba74
- Error checking
elipe17 Sep 20, 2023
6f32a02
- Updated to run field validators even if field is empty but is allow…
elipe17 Sep 21, 2023
870c01d
- Switching back to numIsBlank
elipe17 Sep 21, 2023
c66fd8a
-Adding back numIsBlank
elipe17 Sep 21, 2023
ca0b22c
- adding isNone since empty string fields are also None
elipe17 Sep 21, 2023
45644e6
- Added all missing fields to test file
elipe17 Sep 21, 2023
ccb80fc
- Updating test
elipe17 Sep 21, 2023
265d498
- Fix lint errors
elipe17 Sep 21, 2023
78f108b
- Re-added missing fields
elipe17 Sep 25, 2023
2d96c9b
- Updated tests
elipe17 Sep 25, 2023
dfefa46
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Sep 25, 2023
22d3fa5
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Oct 2, 2023
6817519
- Fixing errors from merge
elipe17 Oct 2, 2023
18c987a
- Removed extra flag
elipe17 Oct 3, 2023
88cc777
- Fixed failing tests
elipe17 Oct 4, 2023
f444601
- Fix lint
elipe17 Oct 4, 2023
374ff3c
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Oct 10, 2023
c6aba84
- Removing unnused validator
elipe17 Oct 10, 2023
ce8521d
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Oct 13, 2023
9a53a06
Merge branch 'develop' into 2695-field-spaces
andrew-jameson Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tdrs-backend/tdpservice/parsers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def parse_value(self, line):
class TransformField(Field):
"""Represents a field that requires some transformation before serializing."""

def __init__(self, transform_func, item, name, type, startIndex, endIndex, required=True, validators=[], **kwargs):
def __init__(self, transform_func, item, name, type, startIndex, endIndex, required=True,
validators=[], **kwargs):
super().__init__(item, name, type, startIndex, endIndex, required, validators)
self.transform_func = transform_func
self.kwargs = kwargs
Expand Down
4 changes: 3 additions & 1 deletion tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def run_field_validators(self, instance, generate_error):
else:
value = getattr(instance, field.name, None)

if field.required and not value_is_empty(value, field.endIndex-field.startIndex):
is_empty = value_is_empty(value, field.endIndex-field.startIndex)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value_is_empty doesn't test for 0-filled strings, which i think is fine but worth calling out since we have other 'space'-fill operators (@ and #). the end result currently is

'000' -> 0
' ' -> None
'###' -> None
'@@@' -> None

maybe a possibility is to add 0-fills to value_is_empty so that 0 becomes None for non-required fields, but i think this could cause side effects with actual 0 values we want to preserve. moreover, i think you're currently meeting the requirements as i understand them - treat 0 as 0 but allow for space-filling as well - space filling just results in a slightly different result.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I didn't think we wanted to add zero fill to the value_is_empty function since there are so many fields across the schemas that expect zero as a valid value. I will point Alex at this as well to make sure everything is good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ADPennington can you verify that this is the logic we want in these situations?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand how we are using "#" and "@" but im seeing the expected behavior @elipe17 @jtimpe

should_validate = not field.required and not is_empty
if (field.required and not is_empty) or should_validate:
for validator in field.validators:
validator_is_valid, validator_error = validator(value)
is_valid = False if not validator_is_valid else is_valid
Expand Down
20 changes: 10 additions & 10 deletions tdrs-backend/tdpservice/parsers/schema_defs/tanf/t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
validators.isNumber(),
]),
Field(item="5", name='STRATUM', type='string', startIndex=22, endIndex=24,
required=True, validators=[
required=False, validators=[
validators.isInStringRange(0, 99),
]),
Field(item="7", name='ZIP_CODE', type='string', startIndex=24, endIndex=29,
Expand Down Expand Up @@ -128,15 +128,15 @@
validators.isInLimits(1, 2),
]),
Field(item="15", name='RECEIVES_FOOD_STAMPS', type='number', startIndex=37, endIndex=38,
required=True, validators=[
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=True, validators=[
required=False, validators=[
validators.isInLimits(0, 3),
]),
Field(item="18", name='AMT_SUB_CC', type='number', startIndex=43, endIndex=47,
Expand Down Expand Up @@ -180,19 +180,19 @@
validators.isLargerThanOrEqualTo(0),
]),
Field(item="24A", name='TRANSITION_SERVICES_AMOUNT', type='number', startIndex=78, endIndex=82,
required=True, validators=[
required=False, validators=[
validators.isLargerThanOrEqualTo(0),
]),
Field(item="24B", name='TRANSITION_NBR_MONTHS', type='number', startIndex=82, endIndex=85,
required=True, validators=[
required=False, validators=[
validators.isLargerThanOrEqualTo(0),
]),
Field(item="25A", name='OTHER_AMOUNT', type='number', startIndex=85, endIndex=89,
required=True, validators=[
required=False, validators=[
validators.isLargerThanOrEqualTo(0),
]),
Field(item="25B", name='OTHER_NBR_MONTHS', type='number', startIndex=89, endIndex=92,
required=True, validators=[
required=False, validators=[
validators.isLargerThanOrEqualTo(0),
]),
Field(item="26AI", name='SANC_REDUCTION_AMT', type='number', startIndex=92, endIndex=96,
Expand All @@ -204,7 +204,7 @@
validators.oneOf([1, 2]),
]),
Field(item="26AIII", name='FAMILY_SANC_ADULT', type='number', startIndex=97, endIndex=98,
required=True, validators=[
required=False, validators=[
validators.oneOf([0, 1, 2]),
]),
Field(item="26AIV", name='SANC_TEEN_PARENT', type='number', startIndex=98, endIndex=99,
Expand Down Expand Up @@ -244,7 +244,7 @@
validators.oneOf([1, 2]),
]),
Field(item="27", name='WAIVER_EVAL_CONTROL_GRPS', type='string', startIndex=113, endIndex=114,
required=True, validators=[
required=False, validators=[
validators.or_validators(validators.matches('9'), validators.isEmpty()),
validators.isAlphaNumeric(),
]),
Expand All @@ -254,7 +254,7 @@
6, 7, 8, 9])
]),
Field(item="29", name='FAMILY_NEW_CHILD', type='number', startIndex=116, endIndex=117,
required=True, validators=[
required=False, validators=[
validators.oneOf([1, 2]),
]),
Field(item="-1", name='BLANK', type='string', startIndex=117, endIndex=156, required=False,
Expand Down
74 changes: 37 additions & 37 deletions tdrs-backend/tdpservice/parsers/schema_defs/tanf/t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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),]),
Expand All @@ -129,66 +129,66 @@
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
validators=[validators.oneOf([0, 1, 2, 9]),]),
Field(item="44", name='MONTHS_FED_TIME_LIMIT', type='string', startIndex=59, endIndex=62, required=True,
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=True,
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=True, validators=[validators.isInLimits(0, 9),]),
Field(item="47", name='EMPLOYMENT_STATUS', type='number', startIndex=65, endIndex=66, required=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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=True, validators=[
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=True,
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=True,
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=True,
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=True,
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=True,
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=True,
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),]),
Expand Down Expand Up @@ -227,16 +227,16 @@
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=False, validators=[validators.isInStringRange(0, 9999),]),
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=False, validators=[validators.isInStringRange(0, 9999),]),
Field(item="66C", name='UNEARNED_SSI', type='string', startIndex=144, endIndex=148, required=False,
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=False,
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=False,
Field(item="66E", name='OTHER_UNEARNED_INCOME', type='string', startIndex=152, endIndex=156, required=True,
validators=[validators.isInStringRange(0, 9999),]),
],
)]
Expand Down
Loading
Loading