bugfix: Treatment detail auto-fill bug fixed.
This commit is contained in:
@@ -15,7 +15,6 @@ import { AppointmentsStrip } from '@/components/ui/treatment/AppointmentsStrip';
|
||||
import { NewTreatmentPatientPicker } from '@/components/ui/treatment/NewTreatmentPatientPicker';
|
||||
import { FdiToothChart } from '@/components/ui/treatment/FdiToothChart';
|
||||
import { LabCasesDispatchPanel } from '@/components/ui/treatment/LabCasesDispatchPanel';
|
||||
import { LabShipmentBlockedNotice } from '@/components/ui/treatment/LabShipmentBlockedNotice';
|
||||
import { LabDispatchAttentionPanel } from '@/components/ui/treatment/LabDispatchAttentionPanel';
|
||||
import { PastTreatmentsPanel } from '@/components/ui/treatment/PastTreatmentsPanel';
|
||||
import { TreatmentDetailsEditor } from '@/components/ui/treatment/TreatmentDetailsEditor';
|
||||
@@ -57,7 +56,11 @@ import {
|
||||
} from '@/components/treatment/toothSelectionGroups';
|
||||
import type { LabDispatchAttentionItem } from '@/components/treatment/labDispatchAttention';
|
||||
import { collectLabDispatchAttention } from '@/components/treatment/labDispatchAttention';
|
||||
import { loadLabDispatchDefaults, rememberLastLab } from '@/components/treatment/labDispatchDefaults';
|
||||
import {
|
||||
loadRecentLabIds,
|
||||
MAX_RECENT_LABS,
|
||||
rememberRecentLab,
|
||||
} from '@/components/treatment/labDispatchDefaults';
|
||||
import { canEditTreatment, canViewTreatment, canAccessDashboardRoute } from '@/components/shared/permissions';
|
||||
import { scrollWithinMainScrollContainer } from '@/components/shared/scrollWithinMain';
|
||||
import { useMarkTabReadOnVisit, useTabBadgeCounts } from '@/lib/hooks/useTabBadgeCounts';
|
||||
@@ -735,7 +738,7 @@ export function TreatmentWorkspace({
|
||||
mapped.length > 0
|
||||
? mapped
|
||||
: options?.seedBlankIfEmpty
|
||||
? [newDetail(defaultTreatmentTypeForAppointment(undefined, treatmentCatalog))]
|
||||
? [newDetail()]
|
||||
: [];
|
||||
setDetails(nextDetails);
|
||||
setActiveDetailId((prev) => {
|
||||
@@ -750,7 +753,7 @@ export function TreatmentWorkspace({
|
||||
setActiveLabCaseId(mappedLabCases[0]?.clientId ?? null);
|
||||
setOrganizationSearch('');
|
||||
setSaveStatus('idle');
|
||||
}, [treatmentCatalog]);
|
||||
}, []);
|
||||
|
||||
const selectedTeethSet = useMemo(() => new Set(activeDetail?.teeth ?? []), [activeDetail?.teeth]);
|
||||
const connectedSelectedTeeth = useMemo(
|
||||
@@ -803,6 +806,7 @@ export function TreatmentWorkspace({
|
||||
useEffect(() => {
|
||||
setShowWholeTreatmentPlan(false);
|
||||
rangeAnchorRef.current = null;
|
||||
setOrganizationSearch('');
|
||||
const pending = pendingEntryStepRef.current;
|
||||
pendingEntryStepRef.current = null;
|
||||
setEntryStep(pending ?? 'treatment');
|
||||
@@ -910,11 +914,11 @@ export function TreatmentWorkspace({
|
||||
setLabDependentCodes(
|
||||
new Set(catalogResponse.data.filter((entry) => entry.labDependent).map((entry) => entry.code)),
|
||||
);
|
||||
const lastLabId = loadLabDispatchDefaults(currentOrganization?.id).lastLabId;
|
||||
if (lastLabId && orgsResponse.data.some((o) => o.id === lastLabId && o.active)) {
|
||||
setRecentOrganizationIds((prev) =>
|
||||
prev.includes(lastLabId) ? prev : [lastLabId, ...prev].slice(0, 10),
|
||||
);
|
||||
const recentIds = loadRecentLabIds(currentOrganization?.id).filter((id) =>
|
||||
orgsResponse.data.some((o) => o.id === id && o.active),
|
||||
);
|
||||
if (recentIds.length > 0) {
|
||||
setRecentOrganizationIds(recentIds);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (!cancelled) {
|
||||
@@ -1959,14 +1963,9 @@ export function TreatmentWorkspace({
|
||||
return;
|
||||
}
|
||||
|
||||
const lastLabId = loadLabDispatchDefaults(currentOrganization?.id).lastLabId;
|
||||
const lastLabStillActive = lastLabId
|
||||
? orgs.some((o) => o.id === lastLabId && o.active)
|
||||
: false;
|
||||
const next: LabCaseDraft = {
|
||||
...newLabCaseDraft(),
|
||||
detailClientId: shouldIncludeActive ? activeDetailId : null,
|
||||
destinationOrganizationId: lastLabStillActive ? lastLabId! : null,
|
||||
attachmentIds: activeDetail?.attachmentMetas.map((a) => a.id) ?? [],
|
||||
};
|
||||
const updatedLabCases = [...cleaned, next];
|
||||
@@ -1982,11 +1981,9 @@ export function TreatmentWorkspace({
|
||||
}, [
|
||||
activeDetailId,
|
||||
canEditTreatmentForDay,
|
||||
currentOrganization?.id,
|
||||
details,
|
||||
labCaseDrafts,
|
||||
labDependentCodes,
|
||||
orgs,
|
||||
persistDraft,
|
||||
persistLabCases,
|
||||
selectedAppointment,
|
||||
@@ -2106,8 +2103,8 @@ export function TreatmentWorkspace({
|
||||
|
||||
setRecentOrganizationIds((prev) => {
|
||||
const orgId = labCase.destinationOrganizationId!;
|
||||
rememberLastLab(currentOrganization?.id, orgId);
|
||||
return [orgId, ...prev.filter((id) => id !== orgId)].slice(0, 10);
|
||||
rememberRecentLab(currentOrganization?.id, orgId);
|
||||
return [orgId, ...prev.filter((id) => id !== orgId)].slice(0, MAX_RECENT_LABS);
|
||||
});
|
||||
showSuccess(t('successCaseSent'));
|
||||
notifyTabBadgesChanged();
|
||||
@@ -2345,10 +2342,8 @@ export function TreatmentWorkspace({
|
||||
canEdit={canEdit}
|
||||
saveStatus={saveStatus}
|
||||
uploadBusy={uploadBusyDetailId === activeDetailId}
|
||||
onAddDetail={() => {
|
||||
const next = newDetail(
|
||||
defaultTreatmentTypeForAppointment(selectedAppointment?.purpose, treatmentCatalog),
|
||||
);
|
||||
onAddDetail={(initialType) => {
|
||||
const next = newDetail(initialType);
|
||||
setDetails((prev) => [...prev, next]);
|
||||
setActiveDetailId(next.clientId);
|
||||
setEntryStep('treatment');
|
||||
@@ -2587,7 +2582,6 @@ export function TreatmentWorkspace({
|
||||
|
||||
{entryStep === 'lab' ? (
|
||||
<div ref={labPanelRef} className="space-y-3">
|
||||
{showLabShipmentBlocked ? <LabShipmentBlockedNotice /> : null}
|
||||
{showLabDispatchPanel ? (
|
||||
<LabCasesDispatchPanel
|
||||
details={details}
|
||||
@@ -2595,7 +2589,6 @@ export function TreatmentWorkspace({
|
||||
labCases={labCaseDrafts}
|
||||
labDependentCodes={labDependentCodes}
|
||||
treatmentCatalog={treatmentCatalog}
|
||||
clinicOrganizationId={currentOrganization?.id}
|
||||
labCaseSummary={activeLabCaseSummary}
|
||||
locale={locale}
|
||||
onLabCaseSummaryChange={handleLabCaseSummaryChange}
|
||||
@@ -2613,27 +2606,13 @@ export function TreatmentWorkspace({
|
||||
organizationSearch={organizationSearch}
|
||||
onOrganizationSearchChange={setOrganizationSearch}
|
||||
recentOrganizationIds={recentOrganizationIds}
|
||||
onRecentOrganizationPick={(orgId) => {
|
||||
setLabCaseDrafts((prev) => {
|
||||
const targetId =
|
||||
activeLabCaseId ??
|
||||
prev.find((lc) => !lc.sentAt && lc.detailClientId === activeDetailId)
|
||||
?.clientId;
|
||||
if (!targetId) return prev;
|
||||
return prev.map((lc) =>
|
||||
lc.clientId === targetId && !lc.sentAt
|
||||
? { ...lc, destinationOrganizationId: orgId }
|
||||
: lc,
|
||||
);
|
||||
});
|
||||
}}
|
||||
sendBusyId={sendBusyId}
|
||||
onSendLabCase={(lc, comment) => handleSendLabCase(lc, comment)}
|
||||
onCommentError={showError}
|
||||
canInviteLab={canAccessOrganizations}
|
||||
onInviteLab={() => router.push('/organizations?action=invite-lab')}
|
||||
/>
|
||||
) : (
|
||||
) : showLabShipmentBlocked ? null : (
|
||||
<p className="text-sm text-text-muted surface-card p-4">
|
||||
{t('entryStepLabUnavailable')}
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user