Skip to main content

sdac-validate-source-codes

Purpose

Validates funding source codes and federal-only funding rules for a cost report.

Tool type

Deterministic (rule-based)

Tool ID

sdac-validate-source-codes

Inputs

  • report_id (string)
  • record_ids (number[], optional): validate specific records

Outputs

  • success, passed
  • error_count, warning_count
  • errors, warnings, executed_rules

Example output

{
"success": true,
"passed": false,
"error_count": 1,
"warning_count": 1,
"errors": [
{
"rule_id": "SOURCE_CODE_FEDERAL_CLAIMED",
"row_number": 19,
"current_value": "4",
"message": "Federal-only source code has claimable costs.",
"severity": "ERROR"
}
],
"warnings": [
{
"rule_id": "SOURCE_CODE_INVALID_SEPARATOR",
"row_number": 22,
"current_value": "1;3",
"message": "Multiple source codes should be separated by comma, slash, or space.",
"severity": "WARNING"
}
],
"executed_rules": [
"SOURCE_CODE_FORMAT",
"SOURCE_CODE_FEDERAL_BACKOUT",
"SOURCE_CODE_ZERO_OR_BLANK"
]
}

Functional details

  • Validates single-digit or comma-delimited source codes.
  • Flags missing or malformed source codes.
  • Enforces federal-only backout rules when claimable amounts are present.

Implementation details

  • Loads records via loadPersonnelRecords(report_id, record_ids).
  • Parses source codes from SourceCodesParsed JSON or SourceCode fallback.
  • Enforces rule IDs: SOURCE_CODE_FORMAT, SOURCE_CODE_4_ONLY, SOURCE_CODE_MISSING, plus mixed funding warnings.
  • Flags federal-only rows when claimable salary or fringe is > 0.
  • Uses parseJsonArray() to normalize parsed codes before validation.
  • Tracks executed_rules in a Set and returns an array at completion.

Code Location: packages/domain-sdac/src/tools/validate-source-codes.tool.ts