Bufdir Field Validation Service
Component Detail
Description
Evaluates each field in the assembled report preview against three rule classes: completeness (non-empty), threshold compliance (value meets minimum required by Bufdir guidelines), and anomaly detection (value deviates significantly from the prior-period equivalent). Returns a structured list of validation issues with severity, field key, and human-readable explanation.
bufdir-field-validation-service
Summaries
The Bufdir Field Validation Service protects the organization from submitting inaccurate or incomplete government reports by automatically detecting three categories of problems before submission: missing required data, values that fall below Bufdir-mandated minimums, and figures that deviate anomalously from the same period in the prior year. Catching these issues early — before a coordinator finalizes a report — prevents costly re-submissions, avoids scrutiny from government reviewers, and builds confidence in the accuracy of the organization's reported activity data. The anomaly detection capability in particular adds significant operational value by surfacing potential data entry errors or unexpected activity drops that coordinators might otherwise miss, supporting both data integrity and organizational accountability.
The Bufdir Field Validation Service has medium complexity and depends on the `bufdir-preview-repository` for prior-period data access, making it a second-tier deliverable in the report preview feature track. The three validation rule classes — completeness, threshold compliance, and anomaly detection — should be implemented and tested incrementally, with completeness being the simplest and anomaly detection requiring the most careful specification with stakeholders. Threshold rules must be sourced from official Bufdir documentation and kept in a maintainable configuration structure, as they may change across reporting years. A key project risk is that anomaly detection thresholds need domain expert input to be meaningful; scheduling a workshop with coordinators early can prevent late-stage rework.
Ensure QA plans include edge cases such as first-period reports (no prior data available) and fields explicitly permitted to be zero.
The Bufdir Field Validation Service is a shared-context service component that operates on an assembled report preview model and returns a structured list of typed validation issues. `validateReport(reportPreviewModel)` is the primary entry point, iterating all fields and delegating to `validateField(fieldKey, value, priorValue)` for per-field rule evaluation. The service depends on `bufdir-preview-repository` to resolve prior-period values for anomaly comparison — this dependency should be injected to enable unit testing with mock data. `getIssuesForSection(sectionId)` enables section-level UI rendering of issue counts, while `hasBlockingIssues()` gates the submission action.
Issues should carry a structured shape including `severity` (blocking | warning), `fieldKey`, `sectionId`, and a human-readable `message`. Anomaly detection logic should use a configurable percentage-deviation threshold rather than hardcoded constants to support future tuning without code changes.
Responsibilities
- Check all required fields for non-empty values
- Apply minimum-threshold rules per field as defined in Bufdir guidelines
- Compare current values against prior-period values to detect anomalies
- Return prioritised validation issues with field location and description
Interfaces
validateReport(reportPreviewModel)
validateField(fieldKey, value, priorValue)
getIssuesForSection(sectionId)
hasBlockingIssues()
getIssueSeverity(issueId)
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (1)
Data entities managed by this component