Merge branch 'master' into feature/ci-cd
This commit is contained in:
@@ -683,7 +683,9 @@
|
||||
"selectedPatient": "Selected patient",
|
||||
"purposeLabel": "Purpose:",
|
||||
"loadingAppointments": "Loading appointments…",
|
||||
"selectDayWithAppointment": "Select a day with at least one appointment.",
|
||||
"selectDayWithAppointment": "Search for a patient or select a visit from the day strip.",
|
||||
"noTreatmentFoundTitle": "No treatment found",
|
||||
"noTreatmentFoundBody": "There is no treatment or visit for {name} yet. You can add one with the {action} button in the rail.",
|
||||
"confirmDiscard": "You have unsaved changes. Discard them and continue?",
|
||||
"errorChooseOrg": "Choose at least one active organization to send this case.",
|
||||
"successCaseSent": "Case sent to selected organizations.",
|
||||
@@ -707,6 +709,8 @@
|
||||
"walkIn": "Walk-in",
|
||||
"newTreatment": "New treatment",
|
||||
"newTreatmentPatientPrompt": "Who is this visit for?",
|
||||
"newTreatmentUseCurrent": "Use {name}",
|
||||
"newTreatmentUseCurrentHint": "Start a new visit for the patient already open on this page.",
|
||||
"walkInPickerHint": "No named patient — always available, no search needed.",
|
||||
"errorCreateTreatment": "Could not create treatment.",
|
||||
"deleteEmptyTreatment": "Delete empty treatment",
|
||||
@@ -717,6 +721,7 @@
|
||||
"detailsTitle": "Treatment details",
|
||||
"addDetail": "Add detail",
|
||||
"confirmRemoveDetail": "Remove this treatment detail?",
|
||||
"confirmRemoveLastDetail": "This is the last detail. Removing it leaves the plan empty until you add another. Continue?",
|
||||
"removeDetailAria": "Remove detail {n}",
|
||||
"detailLabel": "Detail {n}",
|
||||
"detailSentBadge": "sent",
|
||||
|
||||
@@ -684,7 +684,9 @@
|
||||
"selectedPatient": "بیمار انتخاب شده",
|
||||
"purposeLabel": "هدف:",
|
||||
"loadingAppointments": "در حال بارگذاری نوبتها...",
|
||||
"selectDayWithAppointment": "روزی را انتخاب کنید که حداقل یک نوبت داشته باشد.",
|
||||
"selectDayWithAppointment": "برای بیمار جستجو کنید یا یک ویزیت را از نوار روز انتخاب کنید.",
|
||||
"noTreatmentFoundTitle": "درمانی یافت نشد",
|
||||
"noTreatmentFoundBody": "هنوز درمان یا ویزیتی برای {name} ثبت نشده است. میتوانید با دکمه {action} در نوار کناری یکی اضافه کنید.",
|
||||
"confirmDiscard": "تغییرات ذخیرهنشده دارید. آنها را کنار بگذارید و ادامه دهید؟",
|
||||
"errorChooseOrg": "حداقل یک سازمان فعال را برای ارسال این پرونده انتخاب کنید.",
|
||||
"successCaseSent": "پرونده به سازمانهای انتخاب شده ارسال شد.",
|
||||
@@ -708,6 +710,8 @@
|
||||
"walkIn": "بدون نوبت (مراجع)",
|
||||
"newTreatment": "درمان جدید",
|
||||
"newTreatmentPatientPrompt": "این ویزیت برای چه کسی است؟",
|
||||
"newTreatmentUseCurrent": "استفاده از {name}",
|
||||
"newTreatmentUseCurrentHint": "ویزیت جدیدی برای بیماری که همین حالا در این صفحه باز است شروع کنید.",
|
||||
"walkInPickerHint": "بیمار نامدار نیست — همیشه در دسترس است و نیازی به جستجو ندارد.",
|
||||
"errorCreateTreatment": "ایجاد درمان ممکن نشد.",
|
||||
"deleteEmptyTreatment": "حذف درمان خالی",
|
||||
@@ -718,6 +722,7 @@
|
||||
"detailsTitle": "جزئیات درمان",
|
||||
"addDetail": "افزودن جزئیات",
|
||||
"confirmRemoveDetail": "این جزئیات درمان حذف شود؟",
|
||||
"confirmRemoveLastDetail": "این آخرین جزئیات است. با حذف آن برنامه خالی میماند تا جزئیات جدیدی اضافه کنید. ادامه میدهید؟",
|
||||
"removeDetailAria": "حذف جزئیات {n}",
|
||||
"detailLabel": "جزئیات {n}",
|
||||
"detailSentBadge": "ارسالشده",
|
||||
|
||||
@@ -683,7 +683,9 @@
|
||||
"selectedPatient": "Geselecteerde patiënt",
|
||||
"purposeLabel": "Doel:",
|
||||
"loadingAppointments": "Afspraken laden...",
|
||||
"selectDayWithAppointment": "Selecteer een dag met ten minste één afspraak.",
|
||||
"selectDayWithAppointment": "Zoek een patiënt of kies een bezoek uit de dagstrook.",
|
||||
"noTreatmentFoundTitle": "Geen behandeling gevonden",
|
||||
"noTreatmentFoundBody": "Er is nog geen behandeling of bezoek voor {name}. U kunt er een toevoegen met de knop {action} in de zijbalk.",
|
||||
"confirmDiscard": "U heeft niet-opgeslagen wijzigingen. Wilt u deze negeren en doorgaan?",
|
||||
"errorChooseOrg": "Kies ten minste één actieve organisatie om deze case te verzenden.",
|
||||
"successCaseSent": "Case verzonden naar geselecteerde organisaties.",
|
||||
@@ -707,6 +709,8 @@
|
||||
"walkIn": "Inloop",
|
||||
"newTreatment": "Nieuwe behandeling",
|
||||
"newTreatmentPatientPrompt": "Voor wie is dit bezoek?",
|
||||
"newTreatmentUseCurrent": "{name} gebruiken",
|
||||
"newTreatmentUseCurrentHint": "Start een nieuw bezoek voor de patiënt die al op deze pagina openstaat.",
|
||||
"walkInPickerHint": "Geen benoemde patiënt — altijd beschikbaar, zonder zoeken.",
|
||||
"errorCreateTreatment": "Behandeling aanmaken is mislukt.",
|
||||
"deleteEmptyTreatment": "Lege behandeling verwijderen",
|
||||
@@ -717,6 +721,7 @@
|
||||
"detailsTitle": "Behandeldetails",
|
||||
"addDetail": "Detail toevoegen",
|
||||
"confirmRemoveDetail": "Dit behandelingsdetail verwijderen?",
|
||||
"confirmRemoveLastDetail": "Dit is het laatste detail. Als u het verwijdert, blijft het plan leeg tot u een nieuw detail toevoegt. Doorgaan?",
|
||||
"removeDetailAria": "Detail {n} verwijderen",
|
||||
"detailLabel": "Detail {n}",
|
||||
"detailSentBadge": "verzonden",
|
||||
|
||||
@@ -12,3 +12,10 @@ export type DayStripItem = {
|
||||
subtitle: string;
|
||||
canDelete?: boolean;
|
||||
};
|
||||
|
||||
/** Unscheduled card banner: first line’s type only. Empty / missing type → no color. */
|
||||
export function unscheduledStripColorCode(
|
||||
details: readonly { treatmentType?: string | null }[],
|
||||
): string {
|
||||
return details[0]?.treatmentType?.trim() ?? '';
|
||||
}
|
||||
|
||||
@@ -1,73 +1,60 @@
|
||||
const STORAGE_PREFIX = 'dyolink.labDispatchDefaults.';
|
||||
|
||||
export type LabDispatchDefaults = {
|
||||
lastLabId: string | null;
|
||||
lastProsthesisByLab: Record<string, string>;
|
||||
};
|
||||
|
||||
const EMPTY: LabDispatchDefaults = {
|
||||
lastLabId: null,
|
||||
lastProsthesisByLab: {},
|
||||
};
|
||||
/** Chips under lab search — last destinations this clinic actually sent a case to. */
|
||||
export const MAX_RECENT_LABS = 3;
|
||||
|
||||
function storageKey(clinicOrganizationId: string): string {
|
||||
return `${STORAGE_PREFIX}${clinicOrganizationId}`;
|
||||
}
|
||||
|
||||
export function loadLabDispatchDefaults(clinicOrganizationId: string | null | undefined): LabDispatchDefaults {
|
||||
if (!clinicOrganizationId || typeof window === 'undefined') return EMPTY;
|
||||
function uniqueIds(ids: string[]): string[] {
|
||||
const out: string[] = [];
|
||||
for (const id of ids) {
|
||||
if (id && !out.includes(id)) out.push(id);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function loadRecentLabIds(clinicOrganizationId: string | null | undefined): string[] {
|
||||
if (!clinicOrganizationId || typeof window === 'undefined') return [];
|
||||
try {
|
||||
const raw = window.localStorage.getItem(storageKey(clinicOrganizationId));
|
||||
if (!raw) return EMPTY;
|
||||
const parsed = JSON.parse(raw) as Partial<LabDispatchDefaults>;
|
||||
return {
|
||||
lastLabId: typeof parsed.lastLabId === 'string' ? parsed.lastLabId : null,
|
||||
lastProsthesisByLab:
|
||||
parsed.lastProsthesisByLab && typeof parsed.lastProsthesisByLab === 'object'
|
||||
? parsed.lastProsthesisByLab
|
||||
: {},
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as {
|
||||
recentLabIds?: unknown;
|
||||
lastLabId?: unknown;
|
||||
};
|
||||
const fromList = Array.isArray(parsed.recentLabIds)
|
||||
? parsed.recentLabIds.filter((id): id is string => typeof id === 'string')
|
||||
: [];
|
||||
// Older builds stored a single lastLabId used as an auto-selected default.
|
||||
const fromLegacy = typeof parsed.lastLabId === 'string' ? [parsed.lastLabId] : [];
|
||||
return uniqueIds([...fromList, ...fromLegacy]).slice(0, MAX_RECENT_LABS);
|
||||
} catch {
|
||||
return EMPTY;
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function writeDefaults(clinicOrganizationId: string, next: LabDispatchDefaults): void {
|
||||
function writeRecentLabIds(clinicOrganizationId: string, recentLabIds: string[]): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
try {
|
||||
window.localStorage.setItem(storageKey(clinicOrganizationId), JSON.stringify(next));
|
||||
window.localStorage.setItem(
|
||||
storageKey(clinicOrganizationId),
|
||||
JSON.stringify({ recentLabIds }),
|
||||
);
|
||||
} catch {
|
||||
// Ignore quota / private-mode failures.
|
||||
}
|
||||
}
|
||||
|
||||
export function rememberLastLab(clinicOrganizationId: string | null | undefined, labId: string): void {
|
||||
if (!clinicOrganizationId || !labId) return;
|
||||
const current = loadLabDispatchDefaults(clinicOrganizationId);
|
||||
writeDefaults(clinicOrganizationId, { ...current, lastLabId: labId });
|
||||
}
|
||||
|
||||
export function rememberLastProsthesisType(
|
||||
/** Record a lab after a successful send — suggestion chips only, never a form default. */
|
||||
export function rememberRecentLab(
|
||||
clinicOrganizationId: string | null | undefined,
|
||||
labId: string,
|
||||
prosthesisTypeCode: string,
|
||||
): void {
|
||||
if (!clinicOrganizationId || !labId || !prosthesisTypeCode) return;
|
||||
const current = loadLabDispatchDefaults(clinicOrganizationId);
|
||||
writeDefaults(clinicOrganizationId, {
|
||||
...current,
|
||||
lastLabId: labId,
|
||||
lastProsthesisByLab: {
|
||||
...current.lastProsthesisByLab,
|
||||
[labId]: prosthesisTypeCode,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function lastProsthesisTypeForLab(
|
||||
clinicOrganizationId: string | null | undefined,
|
||||
labId: string | null | undefined,
|
||||
): string | null {
|
||||
if (!clinicOrganizationId || !labId) return null;
|
||||
return loadLabDispatchDefaults(clinicOrganizationId).lastProsthesisByLab[labId] ?? null;
|
||||
if (!clinicOrganizationId || !labId) return;
|
||||
writeRecentLabIds(
|
||||
clinicOrganizationId,
|
||||
uniqueIds([labId, ...loadRecentLabIds(clinicOrganizationId)]).slice(0, MAX_RECENT_LABS),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@ const TOOTH_NUMBER_GAP = 'mt-1';
|
||||
const REALISTIC_NUMBER_GAP = '2mm';
|
||||
/** Tight interproximal gap between tooth columns. */
|
||||
const TOOTH_GAP = 'gap-x-px';
|
||||
/**
|
||||
* Centers a mark on the inline-end edge of a tooth column (between this tooth
|
||||
* and the next in flex order). Logical `end` + 0-width flex stays correct in LTR and RTL.
|
||||
*/
|
||||
const EDGE_MARK_ANCHOR =
|
||||
'absolute inset-y-0 end-0 z-10 w-0 flex items-center justify-center';
|
||||
|
||||
function quadrantMirrored(fdi: FdiToothId): boolean {
|
||||
const q = fdi[0];
|
||||
@@ -285,40 +291,42 @@ export function FdiToothChart({
|
||||
/>
|
||||
) : null}
|
||||
{renderEdge ? (
|
||||
linkInteractive ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isDisabled}
|
||||
title={linked ? t('toothUnlinkHint') : t('toothLinkHint')}
|
||||
aria-label={
|
||||
linked
|
||||
? t('toothUnlinkAria', { a: fdi, b: next! })
|
||||
: t('toothLinkAria', { a: fdi, b: next! })
|
||||
}
|
||||
aria-pressed={linked}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onToggleLink?.(fdi, next!);
|
||||
}}
|
||||
className={`
|
||||
absolute right-0 z-10 translate-x-1/2 h-3.5 w-3.5 rounded-full border-2 transition-colors
|
||||
focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50
|
||||
${
|
||||
<div className={EDGE_MARK_ANCHOR}>
|
||||
{linkInteractive ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isDisabled}
|
||||
title={linked ? t('toothUnlinkHint') : t('toothLinkHint')}
|
||||
aria-label={
|
||||
linked
|
||||
? 'border-primary bg-primary shadow-sm'
|
||||
: 'border-primary bg-background-secondary hover:bg-primary/15'
|
||||
? t('toothUnlinkAria', { a: fdi, b: next! })
|
||||
: t('toothLinkAria', { a: fdi, b: next! })
|
||||
}
|
||||
${isDisabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}
|
||||
`}
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className="absolute right-0 z-10 translate-x-1/2 h-2.5 w-2.5 rounded-full bg-primary shadow-sm"
|
||||
title={t('toothConnectedHint')}
|
||||
aria-hidden
|
||||
/>
|
||||
)
|
||||
aria-pressed={linked}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onToggleLink?.(fdi, next!);
|
||||
}}
|
||||
className={`
|
||||
h-3.5 w-3.5 shrink-0 rounded-full border-2 transition-colors
|
||||
focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50
|
||||
${
|
||||
linked
|
||||
? 'border-primary bg-primary shadow-sm'
|
||||
: 'border-primary bg-background-secondary hover:bg-primary/15'
|
||||
}
|
||||
${isDisabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}
|
||||
`}
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-full bg-primary shadow-sm"
|
||||
title={t('toothConnectedHint')}
|
||||
aria-hidden
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Button } from '@/components/ui/shared/Button';
|
||||
import { Checkbox } from '@/components/ui/shared/Checkbox';
|
||||
@@ -16,12 +16,6 @@ import { LabCaseTrackerCard } from '@/components/ui/treatment/LabCaseTrackerCard
|
||||
import { treatmentTypeLabelFromCatalog } from '@/components/shared/treatmentTypeDisplay';
|
||||
import { treatmentsApi } from '@/lib/api/treatments';
|
||||
import { prosthesisCatalogApi } from '@/lib/api/prosthesis-catalog';
|
||||
import {
|
||||
lastProsthesisTypeForLab,
|
||||
loadLabDispatchDefaults,
|
||||
rememberLastLab,
|
||||
rememberLastProsthesisType,
|
||||
} from '@/components/treatment/labDispatchDefaults';
|
||||
import type { ProsthesisCatalogEntry, TreatmentCatalogEntry } from '@/types/treatment-catalog';
|
||||
import type { LabCaseDraft, LinkedOrganizationOption, TreatmentDetailDraft } from '@/types/treatment';
|
||||
import type { PatientLabCaseSummary } from '@/types/lab-case-activity';
|
||||
@@ -34,7 +28,6 @@ interface LabCasesDispatchPanelProps {
|
||||
labCases: LabCaseDraft[];
|
||||
labDependentCodes: Set<string>;
|
||||
treatmentCatalog: TreatmentCatalogEntry[];
|
||||
clinicOrganizationId?: string | null;
|
||||
labCaseSummary?: PatientLabCaseSummary | null;
|
||||
locale: string;
|
||||
onLabCaseSummaryChange?: (summary: PatientLabCaseSummary) => void;
|
||||
@@ -48,7 +41,6 @@ interface LabCasesDispatchPanelProps {
|
||||
organizationSearch: string;
|
||||
onOrganizationSearchChange: (value: string) => void;
|
||||
recentOrganizationIds: string[];
|
||||
onRecentOrganizationPick: (orgId: string) => void;
|
||||
canInviteLab?: boolean;
|
||||
onInviteLab?: () => void;
|
||||
sendBusyId: string | null;
|
||||
@@ -124,7 +116,6 @@ export function LabCasesDispatchPanel({
|
||||
labCases,
|
||||
labDependentCodes,
|
||||
treatmentCatalog,
|
||||
clinicOrganizationId,
|
||||
labCaseSummary,
|
||||
locale,
|
||||
onLabCaseSummaryChange,
|
||||
@@ -138,7 +129,6 @@ export function LabCasesDispatchPanel({
|
||||
organizationSearch,
|
||||
onOrganizationSearchChange,
|
||||
recentOrganizationIds,
|
||||
onRecentOrganizationPick,
|
||||
canInviteLab = false,
|
||||
onInviteLab,
|
||||
sendBusyId,
|
||||
@@ -150,7 +140,6 @@ export function LabCasesDispatchPanel({
|
||||
const [prosthesisOptions, setProsthesisOptions] = useState<ProsthesisCatalogEntry[]>([]);
|
||||
const [applyAllProsthesis, setApplyAllProsthesis] = useState('');
|
||||
const [pendingComment, setPendingComment] = useState('');
|
||||
const autoFilledCaseRef = useRef<string | null>(null);
|
||||
const hasTrackerSummary = Boolean(labCaseSummary && labCaseSummary.labCaseId);
|
||||
|
||||
const activeLinkedOrganizations = orgs.filter((o) => o.active);
|
||||
@@ -168,7 +157,14 @@ export function LabCasesDispatchPanel({
|
||||
|
||||
const activeLabCase =
|
||||
labCaseForActiveDetail ??
|
||||
(activeLabCaseId ? labCases.find((lc) => lc.clientId === activeLabCaseId) : null);
|
||||
(activeLabCaseId
|
||||
? labCases.find(
|
||||
(lc) =>
|
||||
lc.clientId === activeLabCaseId &&
|
||||
(lc.detailClientId == null || lc.detailClientId === activeDetailId),
|
||||
)
|
||||
: null) ??
|
||||
null;
|
||||
|
||||
const sent = Boolean(activeLabCase?.sentAt);
|
||||
const activeDetailNumber = details.findIndex((d) => d.clientId === activeDetailId) + 1;
|
||||
@@ -208,6 +204,7 @@ export function LabCasesDispatchPanel({
|
||||
|
||||
useEffect(() => {
|
||||
setPendingComment('');
|
||||
setApplyAllProsthesis('');
|
||||
}, [activeLabCase?.clientId]);
|
||||
|
||||
function updateActiveLabCase(patch: Partial<LabCaseDraft>) {
|
||||
@@ -226,45 +223,6 @@ export function LabCasesDispatchPanel({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- only sync newly uploaded files
|
||||
}, [activeDetail?.attachmentMetas, activeLabCase?.clientId, sent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeLabCase || sent || activeLabCase.destinationOrganizationId) return;
|
||||
const lastLabId = loadLabDispatchDefaults(clinicOrganizationId).lastLabId;
|
||||
const lastLab = lastLabId
|
||||
? activeLinkedOrganizations.find((o) => o.id === lastLabId)
|
||||
: undefined;
|
||||
if (!lastLab) return;
|
||||
updateActiveLabCase({ destinationOrganizationId: lastLab.id, toothProsthesis: [] });
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activeLabCase?.clientId, clinicOrganizationId, sent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeLabCase || sent) return;
|
||||
if (!activeLabCase.destinationOrganizationId) return;
|
||||
if (prosthesisOptions.length === 0 || prosthesisRows.length === 0) return;
|
||||
const fillKey = `${activeLabCase.clientId}:${prosthesisRows.length}`;
|
||||
if (autoFilledCaseRef.current === fillKey) return;
|
||||
if (isProsthesisMapComplete(activeLabCase, prosthesisRows)) {
|
||||
autoFilledCaseRef.current = fillKey;
|
||||
return;
|
||||
}
|
||||
const lastCode = lastProsthesisTypeForLab(
|
||||
clinicOrganizationId,
|
||||
activeLabCase.destinationOrganizationId,
|
||||
);
|
||||
if (!lastCode || !prosthesisOptions.some((opt) => opt.code === lastCode)) return;
|
||||
autoFilledCaseRef.current = fillKey;
|
||||
setApplyAllProsthesis(lastCode);
|
||||
updateActiveLabCase({ toothProsthesis: toothProsthesisForRows(prosthesisRows, lastCode) });
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
activeLabCase?.clientId,
|
||||
activeLabCase?.destinationOrganizationId,
|
||||
clinicOrganizationId,
|
||||
prosthesisOptions,
|
||||
prosthesisRows.length,
|
||||
sent,
|
||||
]);
|
||||
|
||||
if (!activeDetail || !isLabDependentDetail) {
|
||||
return null;
|
||||
}
|
||||
@@ -287,25 +245,11 @@ export function LabCasesDispatchPanel({
|
||||
]
|
||||
: rest;
|
||||
updateActiveLabCase({ toothProsthesis: next });
|
||||
if (prosthesisTypeCode && activeLabCase.destinationOrganizationId) {
|
||||
rememberLastProsthesisType(
|
||||
clinicOrganizationId,
|
||||
activeLabCase.destinationOrganizationId,
|
||||
prosthesisTypeCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function applyProsthesisToAll(code: string) {
|
||||
if (!activeLabCase || !code) return;
|
||||
updateActiveLabCase({ toothProsthesis: toothProsthesisForRows(prosthesisRows, code) });
|
||||
if (activeLabCase.destinationOrganizationId) {
|
||||
rememberLastProsthesisType(
|
||||
clinicOrganizationId,
|
||||
activeLabCase.destinationOrganizationId,
|
||||
code,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAttachmentInActiveLabCase(attachmentId: string, checked: boolean) {
|
||||
@@ -317,13 +261,11 @@ export function LabCasesDispatchPanel({
|
||||
}
|
||||
|
||||
function handleSelectOrganization(org: LinkedOrganizationOption) {
|
||||
autoFilledCaseRef.current = null;
|
||||
updateActiveLabCase({
|
||||
destinationOrganizationId: org.id,
|
||||
toothProsthesis: [],
|
||||
});
|
||||
setApplyAllProsthesis('');
|
||||
rememberLastLab(clinicOrganizationId, org.id);
|
||||
}
|
||||
|
||||
const caseFullyComplete = isLabCaseCompleted(activeLabCase?.taskProgress);
|
||||
@@ -463,10 +405,7 @@ export function LabCasesDispatchPanel({
|
||||
key={o.id}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => {
|
||||
handleSelectOrganization(o);
|
||||
onRecentOrganizationPick(o.id);
|
||||
}}
|
||||
onClick={() => handleSelectOrganization(o)}
|
||||
className="text-xs rounded-[var(--radius-sm)] border border-border/70 px-2 py-1 text-text-secondary hover:text-text-primary hover:border-border focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/35 disabled:opacity-50"
|
||||
>
|
||||
{o.name}
|
||||
@@ -615,26 +554,7 @@ export function LabCasesDispatchPanel({
|
||||
!prosthesisComplete
|
||||
}
|
||||
isLoading={sendBusyId === activeLabCase.clientId}
|
||||
onClick={() => {
|
||||
if (activeLabCase.destinationOrganizationId) {
|
||||
rememberLastLab(clinicOrganizationId, activeLabCase.destinationOrganizationId);
|
||||
const codes = [
|
||||
...new Set(
|
||||
activeLabCase.toothProsthesis
|
||||
.map((tp) => tp.prosthesisTypeCode)
|
||||
.filter(Boolean),
|
||||
),
|
||||
];
|
||||
if (codes.length === 1) {
|
||||
rememberLastProsthesisType(
|
||||
clinicOrganizationId,
|
||||
activeLabCase.destinationOrganizationId,
|
||||
codes[0],
|
||||
);
|
||||
}
|
||||
}
|
||||
return onSendLabCase(activeLabCase, pendingComment.trim());
|
||||
}}
|
||||
onClick={() => onSendLabCase(activeLabCase, pendingComment.trim())}
|
||||
>
|
||||
{t('sendToLab')}
|
||||
</Button>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { AlertCircle } from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
export function LabShipmentBlockedNotice() {
|
||||
const t = useTranslations('treatment');
|
||||
|
||||
return (
|
||||
<div className="surface-card p-4 border border-amber-500/35 bg-amber-500/5">
|
||||
<div className="flex items-start gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-amber-600 dark:text-amber-400 shrink-0 mt-0.5 icon-flat" />
|
||||
<div className="min-w-0 space-y-1">
|
||||
<h3 className="text-sm font-semibold text-text-primary">{t('labShipmentBlockedTitle')}</h3>
|
||||
<p className="text-xs text-text-muted">{t('labShipmentBlockedBody')}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,19 +4,45 @@ import { useTranslations } from 'next-intl';
|
||||
import { Button } from '@/components/ui/shared/Button';
|
||||
import { PatientSearchCombobox } from '@/components/ui/patient/PatientSearchCombobox';
|
||||
import { usePatientSearchQuery } from '@/lib/hooks/usePatientSearchQuery';
|
||||
import { formatMobileForDisplay } from '@/lib/phone';
|
||||
import type { Patient } from '@/types/patient';
|
||||
|
||||
const pickerChoiceClass =
|
||||
'w-full rounded-[var(--radius-md)] border border-primary/40 bg-primary-soft px-3 py-2 text-start transition-colors hover:border-primary disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/45';
|
||||
|
||||
interface NewTreatmentPatientPickerProps {
|
||||
creating?: boolean;
|
||||
currentPatient?: {
|
||||
id: string;
|
||||
displayName: string;
|
||||
mobile?: string | null;
|
||||
email?: string | null;
|
||||
} | null;
|
||||
onSelectWalkIn: () => void | Promise<void>;
|
||||
onSelectPatient: (patient: Patient) => void | Promise<void>;
|
||||
onSelectCurrentPatient?: () => void | Promise<void>;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
function contactLine(
|
||||
patient: { mobile?: string | null; email?: string | null },
|
||||
fallback: string,
|
||||
): string {
|
||||
const mobile = patient.mobile?.trim()
|
||||
? formatMobileForDisplay(patient.mobile.trim())
|
||||
: '';
|
||||
if (mobile) return mobile;
|
||||
const email = patient.email?.trim();
|
||||
if (email) return email;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function NewTreatmentPatientPicker({
|
||||
creating = false,
|
||||
currentPatient = null,
|
||||
onSelectWalkIn,
|
||||
onSelectPatient,
|
||||
onSelectCurrentPatient,
|
||||
onCancel,
|
||||
}: NewTreatmentPatientPickerProps) {
|
||||
const t = useTranslations('treatment');
|
||||
@@ -31,11 +57,25 @@ export function NewTreatmentPatientPicker({
|
||||
type="button"
|
||||
disabled={creating}
|
||||
onClick={() => void onSelectWalkIn()}
|
||||
className="w-full rounded-[var(--radius-md)] border border-primary/40 bg-primary-soft px-3 py-2 text-start transition-colors hover:border-primary disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/45"
|
||||
className={pickerChoiceClass}
|
||||
>
|
||||
<p className="text-sm font-medium text-text-primary">{t('walkIn')}</p>
|
||||
<p className="text-xs text-text-muted mt-0.5">{t('walkInPickerHint')}</p>
|
||||
</button>
|
||||
{currentPatient && onSelectCurrentPatient ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={creating}
|
||||
onClick={() => void onSelectCurrentPatient()}
|
||||
aria-label={t('newTreatmentUseCurrent', { name: currentPatient.displayName })}
|
||||
className={pickerChoiceClass}
|
||||
>
|
||||
<p className="text-sm font-medium text-text-primary break-words">{currentPatient.displayName}</p>
|
||||
<p className="text-xs text-text-muted mt-0.5 break-words">
|
||||
{contactLine(currentPatient, t('newTreatmentUseCurrentHint'))}
|
||||
</p>
|
||||
</button>
|
||||
) : null}
|
||||
<PatientSearchCombobox
|
||||
search={search}
|
||||
onSearchChange={setSearch}
|
||||
|
||||
@@ -203,12 +203,12 @@ export function TreatmentDetailsEditor({
|
||||
|
||||
{stepper && activeDetail ? <div className="pt-1">{stepper}</div> : null}
|
||||
|
||||
{activeDetail && showMissingTeethLabBlock ? (
|
||||
<p className={labBlockedBannerClass}>{t('labShipmentBlockedBody')}</p>
|
||||
) : null}
|
||||
|
||||
{showFields && activeDetail ? (
|
||||
<div className="space-y-3">
|
||||
{showMissingTeethLabBlock && (
|
||||
<p className={labBlockedBannerClass}>{t('labShipmentBlockedBody')}</p>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 sm:items-end">
|
||||
<Dropdown
|
||||
label={t('treatmentType')}
|
||||
@@ -268,6 +268,8 @@ export function TreatmentDetailsEditor({
|
||||
|
||||
{footer ? <div className="pt-1">{footer}</div> : null}
|
||||
</div>
|
||||
) : showFields && !activeDetail ? (
|
||||
<p className="text-sm text-text-muted">{t('noDetails')}</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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';
|
||||
@@ -33,7 +32,7 @@ import { prosthesisCatalogApi } from '@/lib/api/prosthesis-catalog';
|
||||
import { treatmentsApi } from '@/lib/api/treatments';
|
||||
import { notificationsApi } from '@/lib/api/notifications';
|
||||
import { pickAutoAppointment } from '@/components/shared/treatmentSelection';
|
||||
import type { DayStripItem } from '@/components/treatment/dayStrip';
|
||||
import { unscheduledStripColorCode, type DayStripItem } from '@/components/treatment/dayStrip';
|
||||
import {
|
||||
areDetailsPersistable,
|
||||
defaultTreatmentTypeForAppointment,
|
||||
@@ -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';
|
||||
@@ -203,6 +206,7 @@ function mapAppointment(record: AppointmentRecord): TreatmentAppointment {
|
||||
patientId: record.patientId,
|
||||
patientFirstName: record.patient.firstName,
|
||||
patientLastName: record.patient.lastName,
|
||||
patientMobile: record.patient.mobile,
|
||||
providerUserId: record.providerUserId,
|
||||
startAt: record.startAt,
|
||||
endAt: record.endAt,
|
||||
@@ -383,10 +387,12 @@ export function TreatmentWorkspace({
|
||||
const [unreadLabCasesLoading, setUnreadLabCasesLoading] = useState(false);
|
||||
const [labCasesScope, setLabCasesScope] = useState<TreatmentLabCasesScope>('patient');
|
||||
const [selectedRailLabCaseId, setSelectedRailLabCaseId] = useState<string | null>(null);
|
||||
const [searchedPatient, setSearchedPatient] = useState<Pick<
|
||||
Patient,
|
||||
'id' | 'firstName' | 'lastName'
|
||||
> | null>(null);
|
||||
const [searchedPatient, setSearchedPatient] = useState<
|
||||
(Pick<Patient, 'id' | 'firstName' | 'lastName'> & {
|
||||
mobile?: string | null;
|
||||
email?: string | null;
|
||||
}) | null
|
||||
>(null);
|
||||
const [patientSearchBusy, setPatientSearchBusy] = useState(false);
|
||||
const [newTreatmentPickerOpen, setNewTreatmentPickerOpen] = useState(false);
|
||||
const [creatingStandalone, setCreatingStandalone] = useState(false);
|
||||
@@ -499,6 +505,8 @@ export function TreatmentWorkspace({
|
||||
id: selectedAppointment.patientId,
|
||||
firstName: selectedAppointment.patientFirstName,
|
||||
lastName: selectedAppointment.patientLastName,
|
||||
mobile: selectedAppointment.patientMobile ?? null,
|
||||
email: null,
|
||||
purpose: selectedAppointment.purpose,
|
||||
isWalkIn: false,
|
||||
};
|
||||
@@ -509,6 +517,8 @@ export function TreatmentWorkspace({
|
||||
id: selectedStandalone.patientId,
|
||||
firstName: isWalkIn ? walkInLabel : (selectedStandalone.patient?.firstName ?? ''),
|
||||
lastName: isWalkIn ? '' : (selectedStandalone.patient?.lastName ?? ''),
|
||||
mobile: isWalkIn ? null : (selectedStandalone.patient?.mobile ?? null),
|
||||
email: isWalkIn ? null : (selectedStandalone.patient?.email ?? null),
|
||||
purpose: selectedStandalone.details[0]?.treatmentType,
|
||||
isWalkIn,
|
||||
};
|
||||
@@ -518,7 +528,9 @@ export function TreatmentWorkspace({
|
||||
id: searchedPatient.id,
|
||||
firstName: searchedPatient.firstName,
|
||||
lastName: searchedPatient.lastName,
|
||||
purpose: undefined as string | undefined,
|
||||
mobile: searchedPatient.mobile ?? null,
|
||||
email: searchedPatient.email ?? null,
|
||||
purpose: undefined,
|
||||
isWalkIn: false,
|
||||
};
|
||||
}
|
||||
@@ -529,6 +541,23 @@ export function TreatmentWorkspace({
|
||||
const activePatientName = activePatient
|
||||
? `${activePatient.firstName} ${activePatient.lastName}`.trim()
|
||||
: null;
|
||||
const namedActivePatient =
|
||||
activePatient && !activePatient.isWalkIn && activePatient.id
|
||||
? {
|
||||
id: activePatient.id,
|
||||
displayName: activePatientName ?? '',
|
||||
mobile: activePatient.mobile ?? null,
|
||||
email: activePatient.email ?? null,
|
||||
}
|
||||
: null;
|
||||
const searchedWithoutLiveVisit = Boolean(searchedPatient) && !hasLiveContext;
|
||||
const showSearchedPatientLoading =
|
||||
searchedWithoutLiveVisit && (patientSearchBusy || historyLoading);
|
||||
const showNoTreatmentFound =
|
||||
searchedWithoutLiveVisit &&
|
||||
!patientSearchBusy &&
|
||||
!historyLoading &&
|
||||
history.length === 0;
|
||||
|
||||
const unreadUpdatesCount = unreadLabCases.length;
|
||||
const otherPatientsUnreadCount = useMemo(
|
||||
@@ -600,8 +629,8 @@ export function TreatmentWorkspace({
|
||||
setStandaloneTreatments((prev) => {
|
||||
const current = prev.find((row) => row.id === selectedStandaloneId);
|
||||
if (!current) return prev;
|
||||
const prevColor = current.details.find((d) => d.treatmentType?.trim())?.treatmentType?.trim() ?? '';
|
||||
const nextColor = nextDetails.find((d) => d.treatmentType?.trim())?.treatmentType?.trim() ?? '';
|
||||
const prevColor = unscheduledStripColorCode(current.details);
|
||||
const nextColor = unscheduledStripColorCode(nextDetails);
|
||||
if (
|
||||
prevColor === nextColor &&
|
||||
areUnscheduledDetailsStripDeletable(current.details) ===
|
||||
@@ -632,8 +661,7 @@ export function TreatmentWorkspace({
|
||||
const sourceDetails = tr.id === selectedStandaloneId && !draftHydratingRef.current
|
||||
? details
|
||||
: tr.details;
|
||||
const typedDetail = sourceDetails.find((d) => Boolean(d.treatmentType?.trim()));
|
||||
const colorCode = typedDetail?.treatmentType?.trim() ?? '';
|
||||
const colorCode = unscheduledStripColorCode(sourceDetails);
|
||||
return {
|
||||
kind: 'unscheduled' as const,
|
||||
id: tr.id,
|
||||
@@ -735,7 +763,7 @@ export function TreatmentWorkspace({
|
||||
mapped.length > 0
|
||||
? mapped
|
||||
: options?.seedBlankIfEmpty
|
||||
? [newDetail(defaultTreatmentTypeForAppointment(undefined, treatmentCatalog))]
|
||||
? [newDetail()]
|
||||
: [];
|
||||
setDetails(nextDetails);
|
||||
setActiveDetailId((prev) => {
|
||||
@@ -750,7 +778,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 +831,7 @@ export function TreatmentWorkspace({
|
||||
useEffect(() => {
|
||||
setShowWholeTreatmentPlan(false);
|
||||
rangeAnchorRef.current = null;
|
||||
setOrganizationSearch('');
|
||||
const pending = pendingEntryStepRef.current;
|
||||
pendingEntryStepRef.current = null;
|
||||
setEntryStep(pending ?? 'treatment');
|
||||
@@ -910,11 +939,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) {
|
||||
@@ -1549,24 +1578,51 @@ export function TreatmentWorkspace({
|
||||
return;
|
||||
}
|
||||
|
||||
const ok = await flushDraftSave();
|
||||
if (!ok) return;
|
||||
|
||||
setPatientSearchBusy(true);
|
||||
setSearchedPatient({
|
||||
id: patient.id,
|
||||
firstName: patient.firstName,
|
||||
lastName: patient.lastName,
|
||||
});
|
||||
try {
|
||||
const response = await treatmentsApi.listPatientHistory(patient.id, 1);
|
||||
const latest = response.data[0];
|
||||
if (latest) {
|
||||
const ok = await loadTreatmentIntoWorkspace(latest);
|
||||
if (!ok) {
|
||||
setSearchedPatient(null);
|
||||
const stripAppointment = appointments.find((row) => row.patientId === patient.id);
|
||||
const stripStandalone = standaloneTreatments.find(
|
||||
(row) => row.patientId === patient.id && !row.patient?.isWalkIn,
|
||||
);
|
||||
if (stripAppointment || stripStandalone) {
|
||||
draftHydratingRef.current = true;
|
||||
resetToLiveContext();
|
||||
setSearchedPatient(null);
|
||||
setNewTreatmentPickerOpen(false);
|
||||
setSelectionLocked(true);
|
||||
if (stripAppointment) {
|
||||
setSelectedAppointmentId(stripAppointment.id);
|
||||
setSelectedStandaloneId(null);
|
||||
} else if (stripStandalone) {
|
||||
setSelectedAppointmentId(null);
|
||||
setSelectedStandaloneId(stripStandalone.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
await refreshHistory(patient.id);
|
||||
setSearchedPatient({
|
||||
id: patient.id,
|
||||
firstName: patient.firstName,
|
||||
lastName: patient.lastName,
|
||||
mobile: patient.mobile,
|
||||
email: patient.email,
|
||||
});
|
||||
resetToLiveContext();
|
||||
setNewTreatmentPickerOpen(false);
|
||||
setSelectedAppointmentId(null);
|
||||
setSelectedStandaloneId(null);
|
||||
setSelectionLocked(true);
|
||||
setHistory([]);
|
||||
setHistoryLoading(true);
|
||||
|
||||
const response = await treatmentsApi.listPatientHistory(patient.id, 1);
|
||||
const latest = response.data[0];
|
||||
if (latest) {
|
||||
await loadTreatmentIntoWorkspace(latest);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
showError(getUserFacingError(error, tErrors, t('errorLoadHistory')));
|
||||
setSearchedPatient(null);
|
||||
@@ -1580,8 +1636,11 @@ export function TreatmentWorkspace({
|
||||
selectedStandalone?.patientId,
|
||||
searchedPatient?.id,
|
||||
hasLiveContext,
|
||||
flushDraftSave,
|
||||
appointments,
|
||||
standaloneTreatments,
|
||||
resetToLiveContext,
|
||||
loadTreatmentIntoWorkspace,
|
||||
refreshHistory,
|
||||
showError,
|
||||
t,
|
||||
tErrors,
|
||||
@@ -1883,7 +1942,9 @@ export function TreatmentWorkspace({
|
||||
if (idx < 0) return;
|
||||
const target = details[idx];
|
||||
if (!target || isDetailLocked(target)) return;
|
||||
if (!window.confirm(t('confirmRemoveDetail'))) return;
|
||||
if (!window.confirm(
|
||||
details.length <= 1 ? t('confirmRemoveLastDetail') : t('confirmRemoveDetail'),
|
||||
)) return;
|
||||
|
||||
const nextDetails = details.filter((d) => d.clientId !== detailClientId);
|
||||
const nextActive =
|
||||
@@ -1959,14 +2020,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 +2038,9 @@ export function TreatmentWorkspace({
|
||||
}, [
|
||||
activeDetailId,
|
||||
canEditTreatmentForDay,
|
||||
currentOrganization?.id,
|
||||
details,
|
||||
labCaseDrafts,
|
||||
labDependentCodes,
|
||||
orgs,
|
||||
persistDraft,
|
||||
persistLabCases,
|
||||
selectedAppointment,
|
||||
@@ -2106,8 +2160,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();
|
||||
@@ -2148,11 +2202,24 @@ export function TreatmentWorkspace({
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<header className="space-y-1">
|
||||
<h1 className="text-xl sm:text-2xl font-semibold text-text-primary">{t('title')}</h1>
|
||||
{!canEdit ? (
|
||||
<p className="text-sm text-text-secondary">{t('subtitleReadOnly')}</p>
|
||||
) : null}
|
||||
<header className="flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4">
|
||||
<div className="min-w-0 shrink-0">
|
||||
<h1 className="text-xl sm:text-2xl font-semibold text-text-primary">{t('title')}</h1>
|
||||
{!canEdit ? (
|
||||
<p className="text-sm text-text-secondary mt-1">{t('subtitleReadOnly')}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<PatientSearchCombobox
|
||||
search={patientSearch}
|
||||
onSearchChange={setPatientSearch}
|
||||
patients={patientSearchResults}
|
||||
loading={patientSearchLoading || patientSearchBusy}
|
||||
onSelectPatient={handleSelectSearchedPatient}
|
||||
placeholder={tPatients('searchPlaceholder')}
|
||||
emptyResultsMessage={tPatients('noResults')}
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<AppointmentsStrip
|
||||
@@ -2183,15 +2250,6 @@ export function TreatmentWorkspace({
|
||||
<div className="treatment-layout-grid grid grid-cols-1 xl:grid-cols-[minmax(300px,380px)_minmax(0,1fr)] gap-4 items-start">
|
||||
<div className="space-y-3 min-w-0 xl:max-w-[380px]">
|
||||
<div className="surface-card p-3 space-y-3">
|
||||
<PatientSearchCombobox
|
||||
search={patientSearch}
|
||||
onSearchChange={setPatientSearch}
|
||||
patients={patientSearchResults}
|
||||
loading={patientSearchLoading || patientSearchBusy}
|
||||
onSelectPatient={handleSelectSearchedPatient}
|
||||
placeholder={tPatients('searchPlaceholder')}
|
||||
emptyResultsMessage={tPatients('noResults')}
|
||||
/>
|
||||
{canEdit && !isViewingPastDay ? (
|
||||
<div className="space-y-2">
|
||||
<Button
|
||||
@@ -2206,10 +2264,16 @@ export function TreatmentWorkspace({
|
||||
{newTreatmentPickerOpen ? (
|
||||
<NewTreatmentPatientPicker
|
||||
creating={creatingStandalone}
|
||||
currentPatient={namedActivePatient}
|
||||
onSelectWalkIn={() => createStandaloneTreatment({ walkIn: true })}
|
||||
onSelectPatient={(patient) =>
|
||||
createStandaloneTreatment({ patientId: patient.id })
|
||||
}
|
||||
onSelectCurrentPatient={
|
||||
namedActivePatient
|
||||
? () => createStandaloneTreatment({ patientId: namedActivePatient.id })
|
||||
: undefined
|
||||
}
|
||||
onCancel={() => setNewTreatmentPickerOpen(false)}
|
||||
/>
|
||||
) : null}
|
||||
@@ -2217,8 +2281,14 @@ export function TreatmentWorkspace({
|
||||
) : null}
|
||||
|
||||
{activePatient ? (
|
||||
<div className="space-y-0.5 border-t border-border/60 pt-3">
|
||||
<p className="text-[10px] uppercase tracking-wide text-text-muted">{t('selectedPatient')}</p>
|
||||
<div
|
||||
className={`space-y-0.5 ${
|
||||
canEdit && !isViewingPastDay ? 'border-t border-border/60 pt-3' : ''
|
||||
}`}
|
||||
>
|
||||
<p className="text-[10px] uppercase tracking-wide text-text-muted">
|
||||
{t('selectedPatient')}
|
||||
</p>
|
||||
<p className="text-base font-semibold text-text-primary">{activePatientName}</p>
|
||||
{activePatient.purpose ? (
|
||||
<p className="text-[11px] text-text-secondary">
|
||||
@@ -2230,7 +2300,11 @@ export function TreatmentWorkspace({
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-text-muted border-t border-border/60 pt-3">
|
||||
<p
|
||||
className={`text-sm text-text-muted ${
|
||||
canEdit && !isViewingPastDay ? 'border-t border-border/60 pt-3' : ''
|
||||
}`}
|
||||
>
|
||||
{apptsLoading ? t('loadingAppointments') : t('selectDayWithAppointment')}
|
||||
</p>
|
||||
)}
|
||||
@@ -2333,6 +2407,24 @@ export function TreatmentWorkspace({
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 min-w-0 w-full">
|
||||
{showSearchedPatientLoading ? (
|
||||
<div className="surface-card p-6">
|
||||
<p className="text-sm text-text-muted">{t('loading')}</p>
|
||||
</div>
|
||||
) : showNoTreatmentFound ? (
|
||||
<div className="surface-card w-full p-6 space-y-3">
|
||||
<h2 className="text-lg font-semibold text-text-primary">
|
||||
{t('noTreatmentFoundTitle')}
|
||||
</h2>
|
||||
<p className="text-sm text-text-secondary">
|
||||
{t('noTreatmentFoundBody', {
|
||||
name: activePatientName ?? '',
|
||||
action: t('newTreatment'),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<TreatmentDetailsEditor
|
||||
details={details}
|
||||
activeDetailId={activeDetailId}
|
||||
@@ -2346,9 +2438,14 @@ export function TreatmentWorkspace({
|
||||
saveStatus={saveStatus}
|
||||
uploadBusy={uploadBusyDetailId === activeDetailId}
|
||||
onAddDetail={() => {
|
||||
const next = newDetail(
|
||||
defaultTreatmentTypeForAppointment(selectedAppointment?.purpose, treatmentCatalog),
|
||||
);
|
||||
const seedFromAppointment =
|
||||
details.length === 0 && selectedAppointment
|
||||
? defaultTreatmentTypeForAppointment(
|
||||
selectedAppointment.purpose,
|
||||
treatmentCatalog,
|
||||
)
|
||||
: undefined;
|
||||
const next = newDetail(seedFromAppointment);
|
||||
setDetails((prev) => [...prev, next]);
|
||||
setActiveDetailId(next.clientId);
|
||||
setEntryStep('treatment');
|
||||
@@ -2587,7 +2684,6 @@ export function TreatmentWorkspace({
|
||||
|
||||
{entryStep === 'lab' ? (
|
||||
<div ref={labPanelRef} className="space-y-3">
|
||||
{showLabShipmentBlocked ? <LabShipmentBlockedNotice /> : null}
|
||||
{showLabDispatchPanel ? (
|
||||
<LabCasesDispatchPanel
|
||||
details={details}
|
||||
@@ -2595,7 +2691,6 @@ export function TreatmentWorkspace({
|
||||
labCases={labCaseDrafts}
|
||||
labDependentCodes={labDependentCodes}
|
||||
treatmentCatalog={treatmentCatalog}
|
||||
clinicOrganizationId={currentOrganization?.id}
|
||||
labCaseSummary={activeLabCaseSummary}
|
||||
locale={locale}
|
||||
onLabCaseSummaryChange={handleLabCaseSummaryChange}
|
||||
@@ -2613,33 +2708,21 @@ 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>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface TreatmentAppointment {
|
||||
patientId: string;
|
||||
patientFirstName: string;
|
||||
patientLastName: string;
|
||||
patientMobile?: string | null;
|
||||
providerUserId: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
@@ -139,6 +140,8 @@ export interface PastTreatment {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
isWalkIn: boolean;
|
||||
mobile?: string | null;
|
||||
email?: string | null;
|
||||
} | null;
|
||||
details: PastTreatmentDetail[];
|
||||
labCases: PastLabCase[];
|
||||
|
||||
Reference in New Issue
Block a user