Skip to content

Commit

Permalink
Added logic to handle cross validation for AWARD_REF and REF_NUMBER u…
Browse files Browse the repository at this point in the history
…niqueness
  • Loading branch information
sambodeme committed Aug 14, 2023
1 parent f4db871 commit d7bb657
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from .errors import (
err_award_ref_repeat_reference,
)
from collections import defaultdict


def award_ref_and_references_uniqueness(sac_dict, *_args, **_kwargs):
"""
Ensure the REFERENCE numbers uniqueness for a given AWARD in findings.
"""

all_sections = sac_dict.get("sf_sac_sections", {})
findings_uniform_guidance_section = (
all_sections.get("findings_uniform_guidance") or {}
)
findings_uniform_guidance = findings_uniform_guidance_section.get(
"findings_uniform_guidance_entries", []
)

ref_numbers = defaultdict(set)
duplicate_ref_number = defaultdict(set)
errors = []

for finding in findings_uniform_guidance:
award_ref = finding["program"]["award_reference"]
ref_number = finding["findings"]["reference_number"]
if ref_number in ref_numbers[award_ref]:
duplicate_ref_number[award_ref].add(ref_number)
ref_numbers[award_ref].add(ref_number)

for award_ref, ref_nums in duplicate_ref_number.items():
for ref_num in ref_nums:
errors.append(
{
"error": err_award_ref_repeat_reference(
award_ref,
ref_num,
)
}
)

return errors
4 changes: 4 additions & 0 deletions backend/audit/cross_validation/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ def err_missing_tribal_data_sharing_consent():
"As a tribal organization, you must complete the data "
"sharing consent statement before submitting your audit."
)


def err_award_ref_repeat_reference(award_ref, ref_number):
return f"Award {award_ref} repeats reference {ref_number}. The reference {ref_number} should only appear once for award {award_ref}."

0 comments on commit d7bb657

Please sign in to comment.