fix(frontend): stop the remembered prosthesis default rewriting the map

Dictating "12 روکش PFM, 13 روکش PFZ" previewed correctly and then landed in
the form as PFM on both teeth.

The stored data was never wrong — the dev database holds 12 → pfm_crown and
13 → pfz_crown with selectionGroupIds matching the detail's groups exactly,
and a page reload renders it correctly. The damage was live client state:
the dispatch panel's "last type used for this lab" default rebuilt the
*entire* map from one code, so a single row reading as unfilled destroyed
every type already set.

Two changes:

- It fills blanks now, and leaves every entry that already carries a type
  alone. The bulk "apply to all" select only pre-sets itself when the fill
  really did cover every tooth, instead of claiming one type while the rows
  below disagree.
- A lab case created by confirming a voice result is exempt from the
  default entirely. The review sheet is a contract: topping the case up
  with a type for a tooth the preview never showed makes the confirmation
  step a lie about what it was going to fill.

The exemption is tracked in workspace state rather than on LabCaseDraft
because a draft field is dropped by mapLabCaseDraftFromApi on the first
server round-trip — exactly the window this failure lives in.

isProsthesisMapComplete is deliberately untouched: its strict
selectionGroupId match succeeds on the real data, so loosening it would
have been a blind change to a working path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-21 17:16:46 +08:00
parent e48eeb18c4
commit 5d8393c1eb
3 changed files with 87 additions and 3 deletions

View File

@@ -417,6 +417,16 @@ export function TreatmentWorkspace({
const [details, setDetails] = useState<TreatmentDetailDraft[]>(() => [newDetail()]);
const [labCaseDrafts, setLabCaseDrafts] = useState<LabCaseDraft[]>([]);
/**
* Lab cases created by confirming a voice result.
*
* Kept here rather than as a field on LabCaseDraft on purpose: a draft field is dropped
* by mapLabCaseDraftFromApi on the first server round-trip, which is exactly the window
* where the dispatch panel's remembered-prosthesis default would fire.
*/
const [voiceConfirmedLabCaseIds, setVoiceConfirmedLabCaseIds] = useState<ReadonlySet<string>>(
() => new Set<string>(),
);
const [activeDetailId, setActiveDetailId] = useState<string>(() => details[0].clientId);
const [activeLabCaseId, setActiveLabCaseId] = useState<string | null>(null);
const [savedSnapshot, setSavedSnapshot] = useState<string | null>(null);
@@ -1985,6 +1995,9 @@ export function TreatmentWorkspace({
}
const updatedLabCases = [...labCaseDrafts, draft];
setLabCaseDrafts(updatedLabCases);
// The sheet already showed the clinician exactly what this case would contain, so
// the dispatch panel must not top it up with a remembered default afterwards.
setVoiceConfirmedLabCaseIds((prev) => new Set(prev).add(draft.clientId));
// Every other path that creates a lab draft persists it immediately, and the
// autosave effect only watches `details`. Left in state alone, the destination
@@ -2745,6 +2758,7 @@ export function TreatmentWorkspace({
}
}}
activeLabCaseId={activeLabCaseId}
previewConfirmedCaseIds={voiceConfirmedLabCaseIds}
onLabCasesChange={handleLabCasesChange}
disabled={!canEditTreatmentForDay}
canEdit={canEdit}