feat(backend): assemble resolved extraction from voice intents
Composes the tooth, span, prosthesis, catalog and date resolvers into the payload the review sheet renders. Connected spans expand: "a bridge from 14 to 16" selects 15, which was never spoken. Overlapping spans merge into one bridge, group teeth sort along the arch (16-15-14, and 11 beside 21 across the midline), and a span collapsing to a single tooth degrades to a single group without losing that tooth — there is no such thing as a one-tooth bridge. A cross-arch span is impossible and is reported rather than guessed at. Prosthesis expands a default across the selection then applies per-tooth overrides, because "همه زیرکونیا، ۲۶ پیافام" is how clinicians actually speak. Completeness is computed here so an unshippable map surfaces at review rather than failing later at dispatch. Everything the model names is checked against the catalog we supplied it, and anything rejected is reported rather than dropped — a hallucinated lab id must not look identical to "no lab was spoken", since silence and a wrong lab lead to very different corrective actions. Also fixed, from review of this commit: - an empty prosthesis object no longer fabricates an "incomplete, cannot ship" warning on a plain restoration - an override naming a tooth outside the selection now reports tooth_not_selected rather than malformed; the clinician was understood, the tooth just is not on this detail - a due object with no `kind` is treated as no deadline rather than a blank "heard but lost" row; an unrecognised kind is still flagged, and named Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
areArchNeighbors,
|
||||
sortInArchOrder,
|
||||
FDI_TOOTH_IDS,
|
||||
isFdiTooth,
|
||||
sameArch,
|
||||
@@ -122,4 +123,22 @@ describe('FDI geometry', () => {
|
||||
expect(teethBetweenInclusive('99', '14')).toBeNull();
|
||||
});
|
||||
});
|
||||
describe('sortInArchOrder', () => {
|
||||
it('sorts along the arch rather than lexically', () => {
|
||||
expect(sortInArchOrder(['14', '16', '15'])).toEqual(['16', '15', '14']);
|
||||
});
|
||||
|
||||
it('places 11 beside 21 across the midline', () => {
|
||||
expect(sortInArchOrder(['21', '11', '12'])).toEqual(['12', '11', '21']);
|
||||
});
|
||||
|
||||
it('is a no-op for an empty or single-tooth list', () => {
|
||||
expect(sortInArchOrder([])).toEqual([]);
|
||||
expect(sortInArchOrder(['14'])).toEqual(['14']);
|
||||
});
|
||||
|
||||
it('does not drop teeth it cannot place', () => {
|
||||
expect(sortInArchOrder(['99', '14']).sort()).toEqual(['14', '99']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -118,3 +118,18 @@ export function toFdi(
|
||||
const code = `${quadrant}${position}`;
|
||||
return FDI_TOOTH_IDS.has(code) ? code : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort teeth along the arch, not lexically — a bridge reads 16-15-14, and 11 sits beside
|
||||
* 21 across the midline. Teeth from another arch (or unknown) sort to the end, stably.
|
||||
*/
|
||||
export function sortInArchOrder(teeth: readonly string[]): string[] {
|
||||
if (teeth.length === 0) return [];
|
||||
const arch = teeth.map((t) => archOrder(t)).find((a) => a !== null) ?? null;
|
||||
if (!arch) return [...teeth];
|
||||
const indexOf = (tooth: string) => {
|
||||
const i = arch.indexOf(tooth);
|
||||
return i === -1 ? Number.MAX_SAFE_INTEGER : i;
|
||||
};
|
||||
return [...teeth].sort((a, b) => indexOf(a) - indexOf(b));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user