fix(backend): read a tooth code whatever script its digits are in
The extraction model transcribes Persian speech, so it can hand back "۲۶" in Persian digits or "2 6" from a digit-by-digit dictation. Both were compared literally against /^[1-8][1-8]$/, missed, and fell through to the positional branch with no quadrant — where the tooth was reported as "not understood". The clinician loses a tooth and is told the words were the problem. normalizeFdiCode() now runs at both the branch choice and the final validation, so the two cannot disagree. toLatinDigits moves out of jalali.ts into common/digits.ts: it was exported but unused in production, and a tooth module reaching into the calendar module would read as an accident. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
31
backend/src/common/digits.spec.ts
Normal file
31
backend/src/common/digits.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { toLatinDigits } from './digits';
|
||||
|
||||
/**
|
||||
* Exercised by the voice pipeline on two untrusted inputs: spoken dates, and the tooth
|
||||
* code the extraction model echoes back — a Persian-digit "۲۶" that fails to normalise
|
||||
* costs the clinician a tooth, silently.
|
||||
*/
|
||||
describe('toLatinDigits', () => {
|
||||
it('normalises Persian digits and leaves everything else alone', () => {
|
||||
expect(
|
||||
toLatinDigits('\u06F1\u06F4\u06F0\u06F4/\u06F0\u06F7/\u06F2\u06F5'),
|
||||
).toBe('1404/07/25');
|
||||
expect(toLatinDigits('1404/07/25')).toBe('1404/07/25');
|
||||
expect(toLatinDigits('\u062F\u0646\u062F\u0627\u0646 \u06F1\u06F4')).toBe(
|
||||
'\u062F\u0646\u062F\u0627\u0646 14',
|
||||
);
|
||||
});
|
||||
|
||||
it('also normalises the Arabic-Indic block, which ASR output can carry', () => {
|
||||
// U+0660..U+0669, distinct code points from the Persian U+06F0..U+06F9 block.
|
||||
expect(
|
||||
toLatinDigits('\u0661\u0664\u0660\u0664/\u0660\u0667/\u0662\u0665'),
|
||||
).toBe('1404/07/25');
|
||||
});
|
||||
|
||||
it('normalises a transcript that mixes both blocks with ASCII', () => {
|
||||
expect(toLatinDigits('\u06F1\u06F4 and \u0661\u0665 and 16')).toBe(
|
||||
'14 and 15 and 16',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user