Skip to content

Commit

Permalink
2501 intake add rd and u validations to new workbook vals (#2561)
Browse files Browse the repository at this point in the history
* #2501 Updated ALN pattern

* #2501 Added logic to check ALN pattern and to check if additional award identification is present

* Apply suggestions from code review

* Update backend/audit/intakelib/checks/runners.py

---------

Co-authored-by: Dan Swick <[email protected]>
  • Loading branch information
sambodeme and danswick authored Oct 19, 2023
1 parent e9d5bfe commit 87e9c62
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 3 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import logging
import re
from audit.intakelib.intermediate_representation import (
get_range_values_by_name,
get_range_by_name,
)
from .check_aln_three_digit_extension_pattern import (
REGEX_RD_EXTENSION,
REGEX_U_EXTENSION,
)
from .util import get_message, build_cell_error_tuple

logger = logging.getLogger(__name__)


# DESCRIPTION
# Additional award identification should be present if the ALN three digit extension is RD#, or U##
def additional_award_identification(ir):
extension = get_range_values_by_name(ir, "three_digit_extension")
additional = get_range_values_by_name(ir, "additional_award_identification")
errors = []
patterns = [REGEX_RD_EXTENSION, REGEX_U_EXTENSION]
for index, (ext, add) in enumerate(zip(extension, additional)):
if any(re.match(pattern, ext) for pattern in patterns) and not add:
errors.append(
build_cell_error_tuple(
ir,
get_range_by_name(ir, "additional_award_identification"),
index,
get_message("check_additional_award_identification_present"),
)
)

return errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging
import re
from audit.intakelib.intermediate_representation import (
get_range_values_by_name,
get_range_by_name,
)
from .util import get_message, build_cell_error_tuple

logger = logging.getLogger(__name__)

# A version of these regexes also exists in Base.libsonnet
REGEX_RD_EXTENSION = r"^RD[0-9]?$"
REGEX_THREE_DIGIT_EXTENSION = r"^[0-9]{3}[A-Za-z]{0,1}$"
REGEX_U_EXTENSION = r"^U[0-9]{2}$"


# DESCRIPTION
# The three digit extension should follow one of these formats: ###, RD#, or U##, where # represents a number
def aln_three_digit_extension(ir):
extension = get_range_values_by_name(ir, "three_digit_extension")
errors = []
# Define regex patterns
patterns = [REGEX_RD_EXTENSION, REGEX_THREE_DIGIT_EXTENSION, REGEX_U_EXTENSION]
for index, ext in enumerate(extension):
# Check if ext is None or does not match any of the regex patterns
if not ext:
errors.append(
build_cell_error_tuple(
ir,
get_range_by_name(ir, "three_digit_extension"),
index,
get_message("check_aln_three_digit_extension_missing"),
)
)
elif not any(re.match(pattern, ext) for pattern in patterns):
errors.append(
build_cell_error_tuple(
ir,
get_range_by_name(ir, "three_digit_extension"),
index,
get_message("check_aln_three_digit_extension_invalid"),
)
)

return errors
3 changes: 3 additions & 0 deletions backend/audit/intakelib/checks/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"check_passthrough_name_when_no_direct_n_and_empty_number": "When the award is direct, passthrough number must be empty",
"check_findings_grid_validation": "The combination of findings <b>{}</b> is not a valid combination under Uniform Guidance",
"check_eins_are_not_empty": "EIN cannot be empty",
"check_aln_three_digit_extension_missing": "Missing ALN (CFDA) three digit extension",
"check_aln_three_digit_extension_invalid": "The three digit extension should follow one of these formats: ###, RD#, or U##, where # represents a number",
"check_additional_award_identification_present": "Missing additional award identification",
"check_federal_program_total": "Federal program total is {}, but should be {}",
"check_cluster_total": "This cluster total is {}, but should be {}",
"check_total_amount_expended": "Total amount expended is {}, but should be {}",
Expand Down
6 changes: 6 additions & 0 deletions backend/audit/intakelib/checks/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
from .check_federal_award_passed_always_present import (
federal_award_passed_always_present,
)
from .check_aln_three_digit_extension_pattern import aln_three_digit_extension
from .check_additional_award_identification_present import (
additional_award_identification,
)
from .check_federal_program_total import federal_program_total_is_correct
from .check_cluster_total import cluster_total_is_correct
from .check_total_amount_expended import total_amount_expended_is_correct
Expand Down Expand Up @@ -69,6 +73,8 @@
no_major_program_no_type,
all_unique_award_numbers,
sequential_award_numbers,
aln_three_digit_extension,
additional_award_identification,
federal_program_total_is_correct,
cluster_total_is_correct,
total_amount_expended_is_correct,
Expand Down
4 changes: 2 additions & 2 deletions backend/schemas/output/sections/FederalAwards.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
"if": {
"properties": {
"three_digit_extension": {
"pattern": "^(RD|U[0-9]{2})$",
"pattern": "^(RD[0-9]?|U[0-9]{2})$",
"type": "string"
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@
"type": "string"
},
"three_digit_extension": {
"pattern": "^(RD|[0-9]{3}[A-Za-z]{0,1}|U[0-9]{2})$",
"pattern": "^(RD[0-9]?|[0-9]{3}[A-Za-z]{0,1}|U[0-9]{2})$",
"type": "string"
}
},
Expand Down
3 changes: 2 additions & 1 deletion backend/schemas/source/base/Base.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ local Meta = {
};

local REGEX_ALN_PREFIX = '^([0-9]{2})$';
local REGEX_RD_EXTENSION = 'RD';
# A python version of these regexes also exists in intakelib
local REGEX_RD_EXTENSION = 'RD[0-9]?';
local REGEX_THREE_DIGIT_EXTENSION = '[0-9]{3}[A-Za-z]{0,1}';
local REGEX_U_EXTENSION = 'U[0-9]{2}';
local REGEX_NUMBER = '[0-9]+';
Expand Down

0 comments on commit 87e9c62

Please sign in to comment.