Skip to content

Fix Fayda FAN false positive on adjacent date-of-birth dates - #1869

Open
BurningAXE wants to merge 1 commit into
release/2026.3.1from
bugfix/fayda-fan-date-false-positive
Open

BurningAXE wants to merge 1 commit into
release/2026.3.1from
bugfix/fayda-fan-date-false-positive

Conversation

@BurningAXE

@BurningAXE BurningAXE commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

JIRA ticket
Will be released in: 2026.3.1

Root cause analysis (for bugfixes only)

First known affected version: 2026.3.0 (Fayda support added in #1748)

  • Users reported that scanning a Fayda card sometimes fills the FAN field with two adjacent dates, e.g. 0702 1998 2005 1017 for a card whose date-of-birth line reads 07/02/1998 | 2005/10/17 (Gregorian | Ethiopian).
  • FaydaCardOcrReaderUseCase stripped all non-digit characters from each OCR line and then matched ^\d{16}$. The date-of-birth line contains exactly 16 digits once the / and | separators are removed, so it was accepted as a FAN.
  • OCR lines are sorted top to bottom and the date-of-birth line sits above the FAN, so whenever OCR read it, it won over the real FAN. On-device diagnostics confirmed the old logic would have returned 2512200020080831 from 25/12/2000 | 2008/08/31 in 6 of 8 frames.

Notable changes

  • Added FAN_OCR_PATTERN, which looks for 16 digits within an OCR line, and not part of a longer digit run. OCR sometimes splits the number, so up to 4 groups separated by single whitespace characters are allowed (e.g. 258094592481 5610). Date lines can't match: punctuation between digits isn't accepted, and the 6 groups of a date line whose separators OCR read as spaces (07 02 1998 2005 10 17) exceed the 4-group limit.
  • The FAN value is now extracted from the matched part only, so extra text OCR merges into the line (e.g. FAN 8642370540168134) is tolerated.
  • FAN_PATTERN (^\d{16}$) is unchanged. It is still used to validate manually entered or edited FANs in ExternalCredentialSearchViewModel.
  • Behaviour change: lines like 1234-5678-1234-5678 or 1234.5678.1234.5678 are no longer accepted by OCR. The card prints the FAN as one unbroken 16-digit number, so this was a false-positive risk rather than a supported format.

Testing guidance

  • Unit tests in FaydaCardOcrReaderUseCaseTest cover both reported date-of-birth lines, date lines with the | lost or the separators read as spaces by OCR, the FAN appearing below date lines, extra text on the FAN line, and rejected separators.
  • Manual: scan a Fayda card with an MFID project. The FAN field should show the number printed above the barcode, never the date-of-birth digits.

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

🤖 Generated with Claude Code

@cla-bot cla-bot Bot added the ... label Oct 19, 2026
@BurningAXE
BurningAXE force-pushed the bugfix/fayda-fan-date-false-positive branch from c11f840 to ff4050e Compare October 19, 2026 21:54
@BurningAXE
BurningAXE marked this pull request as ready for review October 20, 2026 11:00
@BurningAXE
BurningAXE requested review from a team, TristramN, alex-vt, alexandr-simprints, luhmirin-s, meladRaouf and ybourgery and a balanced review from Copilot and removed request for a team October 20, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approved

The focused matching change and regression coverage have no identified blocking issues; tests were inspected but not executed.

No open issues 🎉

What changed in this PR

Fixes Fayda OCR incorrectly accepting adjacent birth dates as a FAN, addressing a regression introduced with Fayda support.

Changes:

  • Restricts OCR matching to 16 digits across at most four whitespace-separated groups.
  • Extracts FANs from surrounding text while preserving manual validation.
  • Adds regression tests for date lines and accepted/rejected formats.
File Description
feature/​external-credential/​src/​test/​java/​com/​simprints/​feature/​externalcredential/​screens/​scanocr/​usecase/​FaydaCardOcrReaderUseCaseTest.kt Adds FAN extraction and date-rejection regression tests.
feature/​external-credential/​src/​main/​java/​com/​simprints/​feature/​externalcredential/​screens/​scanocr/​usecase/​FaydaCardOcrReaderUseCase.kt Replaces digit stripping with constrained OCR matching.

Review effort: Balanced

@meladRaouf

Copy link
Copy Markdown
Collaborator

@BurningAXE Please change the target branch to 2026.3.1 I have created it.

@BurningAXE
BurningAXE added this pull request to stack #1873 October 20, 2026 11:03
@BurningAXE
BurningAXE removed this pull request from stack #1873 October 20, 2026 11:19
@BurningAXE
BurningAXE changed the base branch from release/2026.3.0 to release/2026.3.1 October 20, 2026 11:20
@BurningAXE
BurningAXE added this pull request to stack #1874 October 20, 2026 11:22
"1234567812345A78", // letter in the middle
"1234-5678-1234-5678", // punctuation between digits
"1234.5678.1234.5678", // punctuation between digits
"1234 5678 1234 5678", // more than one whitespace between digits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be a realistic case from OCR? Maybe not all double spaces, but one of them could be.

The FAN reader stripped all non-digits from an OCR line before matching
16 digits, so the date-of-birth line "07/02/1998 | 2005/10/17" was read
as FAN 0702199820051017. Match 16 digits (optionally whitespace-separated)
within the line instead, rejecting punctuation between digits and longer
digit runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BurningAXE
BurningAXE force-pushed the bugfix/fayda-fan-date-false-positive branch from ff4050e to 3b87b16 Compare October 20, 2026 11:51
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants