2026-06-28 14:59:06 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
2026-06-28 22:56:56 +03:30
|
|
|
import { useSearchParams } from 'next/navigation';
|
2026-06-28 14:59:06 +03:30
|
|
|
import { useTranslations } from 'next-intl';
|
2026-07-07 17:14:31 +03:30
|
|
|
import { MessageSquare } from 'lucide-react';
|
2026-06-28 16:46:42 +03:30
|
|
|
import { ToastStack } from '@/components/ui/shared/Toast';
|
|
|
|
|
import { formatApiErrorMessage } from '@/components/shared/formatApiError';
|
|
|
|
|
import { useAuth } from '@/lib/hooks/useAuth';
|
|
|
|
|
import { useToast } from '@/lib/hooks/useToast';
|
2026-07-07 17:14:31 +03:30
|
|
|
import { canEditCases, canEditTasks } from '@/components/shared/permissions';
|
|
|
|
|
import { Badge } from '@/components/ui/shared/Badge';
|
|
|
|
|
import { LabCaseCommentsPanel } from '@/components/ui/lab/LabCaseCommentsPanel';
|
2026-07-07 18:43:10 +03:30
|
|
|
import { CaseToothChartPanel } from '@/components/ui/lab/CaseToothChartPanel';
|
|
|
|
|
import { LabCaseAttachmentPreview } from '@/components/ui/lab/LabCaseAttachmentPreview';
|
2026-07-07 17:14:31 +03:30
|
|
|
import { labTaskStatusVariant } from '@/components/ui/lab/labTaskStatusDisplay';
|
2026-06-28 16:46:42 +03:30
|
|
|
import { casesApi } from '@/lib/api/cases';
|
2026-07-07 17:14:31 +03:30
|
|
|
import { tasksApi } from '@/lib/api/tasks';
|
2026-07-06 20:40:19 +03:30
|
|
|
import { treatmentCatalogApi } from '@/lib/api/treatment-catalog';
|
|
|
|
|
import { treatmentTypeLabelFromCatalog } from '@/components/ui/treatment/treatmentTypeDisplay';
|
2026-06-28 17:49:40 +03:30
|
|
|
import { Button } from '@/components/ui/shared/Button';
|
2026-06-28 22:56:56 +03:30
|
|
|
import { FORM_SELECT_CLASS } from '@/components/ui/shared/formSelectStyles';
|
2026-06-28 17:49:40 +03:30
|
|
|
import { SearchBar } from '@/components/ui/shared/SearchBar';
|
2026-07-06 20:40:19 +03:30
|
|
|
import type { TreatmentCatalogEntry } from '@/types/treatment-catalog';
|
2026-06-28 17:49:40 +03:30
|
|
|
import type {
|
|
|
|
|
CasesFilterOptions,
|
|
|
|
|
LabCaseDetail,
|
|
|
|
|
LabCaseListItem,
|
|
|
|
|
LabTaskStatus,
|
|
|
|
|
PaginatedLabCases,
|
|
|
|
|
} from '@/types/cases';
|
2026-07-07 15:31:09 +03:30
|
|
|
import {
|
|
|
|
|
formatToothList,
|
|
|
|
|
prosthesisTypeBadgeStyle,
|
|
|
|
|
} from '@/components/ui/treatment/prosthesisTypeDisplay';
|
2026-06-28 16:46:42 +03:30
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
const PAGE_SIZE = 20;
|
2026-06-28 22:56:56 +03:30
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
function formatPatientName(patient: { firstName: string; lastName: string }) {
|
|
|
|
|
return `${patient.firstName} ${patient.lastName}`.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatDateTime(value: string | null, locale: string) {
|
|
|
|
|
if (!value) return '—';
|
|
|
|
|
return new Intl.DateTimeFormat(locale, {
|
|
|
|
|
dateStyle: 'medium',
|
|
|
|
|
timeStyle: 'short',
|
|
|
|
|
}).format(new Date(value));
|
|
|
|
|
}
|
2026-06-28 14:59:06 +03:30
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
function TaskProgressBar({ completed, total }: { completed: number; total: number }) {
|
|
|
|
|
const pct = total > 0 ? Math.round((completed / total) * 100) : 0;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<div className="flex items-center justify-between text-xs text-text-muted">
|
|
|
|
|
<span>{completed}/{total}</span>
|
|
|
|
|
<span>{pct}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="h-1.5 rounded-full bg-border overflow-hidden">
|
|
|
|
|
<div
|
|
|
|
|
className="h-full rounded-full bg-primary transition-all duration-300"
|
|
|
|
|
style={{ width: `${pct}%` }}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-28 14:59:06 +03:30
|
|
|
export default function CasesPage() {
|
|
|
|
|
const t = useTranslations('cases');
|
2026-06-28 16:46:42 +03:30
|
|
|
const tTreatment = useTranslations('treatment');
|
|
|
|
|
const tCommon = useTranslations('common');
|
|
|
|
|
const { currentOrganization, user } = useAuth();
|
|
|
|
|
const toast = useToast();
|
2026-06-28 22:56:56 +03:30
|
|
|
const searchParams = useSearchParams();
|
2026-06-28 16:46:42 +03:30
|
|
|
|
|
|
|
|
const [search, setSearch] = useState('');
|
2026-06-28 17:49:40 +03:30
|
|
|
const [clinicId, setClinicId] = useState('');
|
|
|
|
|
const [treatmentType, setTreatmentType] = useState('');
|
|
|
|
|
const [sentFrom, setSentFrom] = useState('');
|
|
|
|
|
const [sentTo, setSentTo] = useState('');
|
|
|
|
|
const [page, setPage] = useState(1);
|
|
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
const [cases, setCases] = useState<LabCaseListItem[]>([]);
|
2026-06-28 17:49:40 +03:30
|
|
|
const [pagination, setPagination] = useState<PaginatedLabCases['pagination']>({
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
|
total: 0,
|
|
|
|
|
totalPages: 1,
|
|
|
|
|
});
|
|
|
|
|
const [filterOptions, setFilterOptions] = useState<CasesFilterOptions>({
|
|
|
|
|
clinics: [],
|
|
|
|
|
treatmentTypes: [],
|
|
|
|
|
});
|
2026-07-06 20:40:19 +03:30
|
|
|
const [treatmentCatalog, setTreatmentCatalog] = useState<TreatmentCatalogEntry[]>([]);
|
2026-06-28 17:49:40 +03:30
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
const [selectedCaseId, setSelectedCaseId] = useState<string | null>(null);
|
|
|
|
|
const [selectedCase, setSelectedCase] = useState<LabCaseDetail | null>(null);
|
|
|
|
|
const [loadingList, setLoadingList] = useState(false);
|
|
|
|
|
const [loadingDetail, setLoadingDetail] = useState(false);
|
|
|
|
|
const [updatingTaskId, setUpdatingTaskId] = useState<string | null>(null);
|
2026-07-07 17:14:31 +03:30
|
|
|
const [commentCount, setCommentCount] = useState(0);
|
2026-06-28 16:46:42 +03:30
|
|
|
|
2026-06-28 22:56:56 +03:30
|
|
|
const canEdit = canEditCases(currentOrganization);
|
2026-07-07 17:14:31 +03:30
|
|
|
const canEditComments = canEditTasks(currentOrganization);
|
2026-06-28 16:46:42 +03:30
|
|
|
const locale = user?.language ?? 'en';
|
|
|
|
|
|
|
|
|
|
const treatmentLabel = useCallback(
|
2026-07-06 20:40:19 +03:30
|
|
|
(type: string) => treatmentTypeLabelFromCatalog(type, treatmentCatalog),
|
|
|
|
|
[treatmentCatalog],
|
2026-06-28 16:46:42 +03:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const statusOptions: { value: LabTaskStatus; label: string }[] = useMemo(
|
|
|
|
|
() => [
|
|
|
|
|
{ value: 'IN_PROGRESS', label: t('statusInProgress') },
|
|
|
|
|
{ value: 'COMPLETED', label: t('statusCompleted') },
|
|
|
|
|
],
|
|
|
|
|
[t],
|
|
|
|
|
);
|
|
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
const hasActiveFilters = Boolean(
|
|
|
|
|
search.trim() || clinicId || treatmentType || sentFrom || sentTo,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const loadCases = async (params: {
|
|
|
|
|
q: string;
|
|
|
|
|
clinicOrganizationId: string;
|
|
|
|
|
treatmentType: string;
|
|
|
|
|
sentFrom: string;
|
|
|
|
|
sentTo: string;
|
|
|
|
|
page: number;
|
|
|
|
|
}) => {
|
2026-06-28 16:46:42 +03:30
|
|
|
setLoadingList(true);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
2026-06-28 17:49:40 +03:30
|
|
|
const response = await casesApi.list({
|
|
|
|
|
q: params.q.trim() || undefined,
|
|
|
|
|
clinicOrganizationId: params.clinicOrganizationId || undefined,
|
|
|
|
|
treatmentType: params.treatmentType || undefined,
|
|
|
|
|
sentFrom: params.sentFrom || undefined,
|
|
|
|
|
sentTo: params.sentTo || undefined,
|
|
|
|
|
page: params.page,
|
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
|
});
|
2026-06-28 16:46:42 +03:30
|
|
|
setCases(response.data.items);
|
2026-06-28 17:49:40 +03:30
|
|
|
setPagination(response.data.pagination);
|
2026-06-28 16:46:42 +03:30
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(formatApiErrorMessage(error, t('errorLoadList')));
|
|
|
|
|
} finally {
|
|
|
|
|
setLoadingList(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadDetail = async (caseId: string) => {
|
|
|
|
|
setLoadingDetail(true);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
|
|
|
|
const response = await casesApi.getOne(caseId);
|
|
|
|
|
setSelectedCase(response.data);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(formatApiErrorMessage(error, t('errorLoadDetail')));
|
|
|
|
|
setSelectedCase(null);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoadingDetail(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-06-28 17:49:40 +03:30
|
|
|
void casesApi.listFilterOptions().then((r) => setFilterOptions(r.data)).catch(() => {});
|
2026-07-06 20:40:19 +03:30
|
|
|
void treatmentCatalogApi.list().then((r) => setTreatmentCatalog(r.data)).catch(() => {});
|
2026-06-28 16:46:42 +03:30
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount-only initial fetch
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-06-28 22:56:56 +03:30
|
|
|
useEffect(() => {
|
|
|
|
|
const caseIdFromUrl = searchParams.get('caseId');
|
|
|
|
|
if (caseIdFromUrl) {
|
|
|
|
|
setSelectedCaseId(caseIdFromUrl);
|
|
|
|
|
}
|
|
|
|
|
}, [searchParams]);
|
|
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
useEffect(() => {
|
|
|
|
|
const timeout = setTimeout(() => {
|
2026-06-28 17:49:40 +03:30
|
|
|
void loadCases({
|
|
|
|
|
q: search,
|
|
|
|
|
clinicOrganizationId: clinicId,
|
|
|
|
|
treatmentType,
|
|
|
|
|
sentFrom,
|
|
|
|
|
sentTo,
|
|
|
|
|
page,
|
|
|
|
|
});
|
|
|
|
|
}, search ? 300 : 0);
|
2026-06-28 16:46:42 +03:30
|
|
|
return () => clearTimeout(timeout);
|
2026-06-28 17:49:40 +03:30
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- debounced search + filter reload
|
|
|
|
|
}, [search, clinicId, treatmentType, sentFrom, sentTo, page]);
|
2026-06-28 16:46:42 +03:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (selectedCaseId) {
|
|
|
|
|
void loadDetail(selectedCaseId);
|
2026-07-07 17:14:31 +03:30
|
|
|
void tasksApi
|
|
|
|
|
.listComments(selectedCaseId)
|
|
|
|
|
.then((r) => setCommentCount(r.data.length))
|
|
|
|
|
.catch(() => setCommentCount(0));
|
2026-06-28 16:46:42 +03:30
|
|
|
} else {
|
|
|
|
|
setSelectedCase(null);
|
2026-07-07 17:14:31 +03:30
|
|
|
setCommentCount(0);
|
2026-06-28 16:46:42 +03:30
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- reload when selection changes
|
|
|
|
|
}, [selectedCaseId]);
|
|
|
|
|
|
2026-07-07 17:14:31 +03:30
|
|
|
function scrollToComments() {
|
|
|
|
|
document.getElementById('case-comments')?.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 18:43:10 +03:30
|
|
|
const loadCaseAttachmentBlob = useCallback(
|
|
|
|
|
(caseId: string, attachmentId: string) => casesApi.getAttachmentFileBlob(caseId, attachmentId),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const latestCaseAttachment = useMemo(() => {
|
|
|
|
|
if (!selectedCase?.attachments.length) return null;
|
|
|
|
|
return [...selectedCase.attachments].sort(
|
|
|
|
|
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
|
|
|
|
|
)[0];
|
|
|
|
|
}, [selectedCase?.attachments]);
|
|
|
|
|
|
|
|
|
|
const caseProsthesisRows = useMemo(() => {
|
|
|
|
|
if (!selectedCase) return [];
|
|
|
|
|
if (selectedCase.toothProsthesis.length > 0) {
|
|
|
|
|
const byCode = new Map<string, string[]>();
|
|
|
|
|
for (const row of selectedCase.toothProsthesis) {
|
|
|
|
|
const key = row.prosthesisTypeCode;
|
|
|
|
|
const teeth = byCode.get(key) ?? [];
|
|
|
|
|
if (!teeth.includes(row.tooth)) teeth.push(row.tooth);
|
|
|
|
|
byCode.set(key, teeth);
|
|
|
|
|
}
|
|
|
|
|
return [...byCode.entries()].map(([prosthesisTypeCode, teeth]) => ({
|
|
|
|
|
prosthesisTypeCode,
|
|
|
|
|
teeth,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
return selectedCase.tasksByTooth.map((g) => ({
|
|
|
|
|
prosthesisTypeCode: g.prosthesisTypeCode,
|
|
|
|
|
teeth: g.teeth,
|
|
|
|
|
}));
|
|
|
|
|
}, [selectedCase]);
|
|
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
function clearFilters() {
|
|
|
|
|
setSearch('');
|
|
|
|
|
setClinicId('');
|
|
|
|
|
setTreatmentType('');
|
|
|
|
|
setSentFrom('');
|
|
|
|
|
setSentTo('');
|
|
|
|
|
setPage(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 15:31:09 +03:30
|
|
|
async function handleImportantToggle(taskId: string, isImportant: boolean) {
|
2026-06-28 16:46:42 +03:30
|
|
|
if (!selectedCaseId || !canEdit) return;
|
|
|
|
|
|
|
|
|
|
setUpdatingTaskId(taskId);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
2026-07-07 15:31:09 +03:30
|
|
|
await casesApi.setTaskImportant(selectedCaseId, taskId, isImportant);
|
2026-06-28 16:46:42 +03:30
|
|
|
await loadDetail(selectedCaseId);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(formatApiErrorMessage(error, t('errorUpdateTask')));
|
|
|
|
|
} finally {
|
|
|
|
|
setUpdatingTaskId(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-28 14:59:06 +03:30
|
|
|
|
2026-06-28 22:56:56 +03:30
|
|
|
const filterSelectClass = `${FORM_SELECT_CLASS} w-full rounded-md px-3 py-2`;
|
2026-06-28 17:49:40 +03:30
|
|
|
|
2026-06-28 14:59:06 +03:30
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
2026-06-28 16:46:42 +03:30
|
|
|
<div>
|
|
|
|
|
<h1 className="text-2xl font-semibold text-text-primary">{t('title')}</h1>
|
|
|
|
|
<p className="text-sm text-text-muted mt-1">{t('subtitle')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
<div className="grid gap-4 lg:grid-cols-[minmax(300px,380px)_1fr]">
|
|
|
|
|
<section className="rounded-lg border border-border bg-surface p-4 space-y-3 flex flex-col min-h-0">
|
|
|
|
|
<SearchBar
|
|
|
|
|
embedded
|
2026-06-28 16:46:42 +03:30
|
|
|
value={search}
|
2026-06-28 17:49:40 +03:30
|
|
|
onChange={(value) => {
|
|
|
|
|
setSearch(value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
2026-06-28 16:46:42 +03:30
|
|
|
placeholder={t('searchPlaceholder')}
|
|
|
|
|
/>
|
|
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
<div className="grid gap-2 sm:grid-cols-2">
|
|
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterClinic')}</span>
|
|
|
|
|
<select
|
|
|
|
|
value={clinicId}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setClinicId(e.target.value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
>
|
|
|
|
|
<option value="">{t('filterClinicAll')}</option>
|
|
|
|
|
{filterOptions.clinics.map((clinic) => (
|
|
|
|
|
<option key={clinic.id} value={clinic.id}>
|
|
|
|
|
{clinic.name}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
2026-06-28 16:46:42 +03:30
|
|
|
|
2026-06-28 17:49:40 +03:30
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterTreatmentType')}</span>
|
|
|
|
|
<select
|
|
|
|
|
value={treatmentType}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setTreatmentType(e.target.value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
>
|
|
|
|
|
<option value="">{t('filterTreatmentTypeAll')}</option>
|
|
|
|
|
{filterOptions.treatmentTypes.map((type) => (
|
|
|
|
|
<option key={type.code} value={type.code}>
|
|
|
|
|
{treatmentLabel(type.code)}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterSentFrom')}</span>
|
|
|
|
|
<input
|
|
|
|
|
type="date"
|
|
|
|
|
value={sentFrom}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSentFrom(e.target.value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterSentTo')}</span>
|
|
|
|
|
<input
|
|
|
|
|
type="date"
|
|
|
|
|
value={sentTo}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSentTo(e.target.value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{hasActiveFilters ? (
|
|
|
|
|
<Button variant="ghost" size="sm" onClick={clearFilters} className="self-start">
|
|
|
|
|
{t('clearFilters')}
|
|
|
|
|
</Button>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<div className="flex-1 min-h-0">
|
|
|
|
|
{loadingList ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{tCommon('loading')}</p>
|
|
|
|
|
) : cases.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{t('emptyList')}</p>
|
|
|
|
|
) : (
|
|
|
|
|
<ul className="space-y-2 max-h-[55vh] overflow-y-auto pr-1">
|
|
|
|
|
{cases.map((item) => {
|
|
|
|
|
const isActive = item.id === selectedCaseId;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<li key={item.id}>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setSelectedCaseId(item.id)}
|
|
|
|
|
className={`w-full rounded-md border px-3 py-2.5 text-left transition-colors ${
|
|
|
|
|
isActive
|
|
|
|
|
? 'border-primary bg-primary/5'
|
|
|
|
|
: 'border-border hover:border-primary/40'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="font-medium text-text-primary">
|
|
|
|
|
{formatPatientName(item.patient)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-text-muted mt-0.5">
|
|
|
|
|
{item.patient.mobile}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-text-muted mt-0.5">{item.clinic.name}</div>
|
|
|
|
|
<div className="text-xs text-text-muted mt-1">
|
|
|
|
|
{formatDateTime(item.sentAt, locale)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-text-muted mt-1 truncate">
|
|
|
|
|
{item.treatmentTypes.map(treatmentLabel).join(', ')}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mt-2">
|
|
|
|
|
<TaskProgressBar
|
|
|
|
|
completed={item.taskProgress.completed}
|
|
|
|
|
total={item.taskProgress.total}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{pagination.totalPages > 1 ? (
|
|
|
|
|
<div className="flex items-center justify-between gap-2 pt-2 border-t border-border">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
disabled={page <= 1 || loadingList}
|
|
|
|
|
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
|
|
|
|
>
|
|
|
|
|
{t('prevPage')}
|
|
|
|
|
</Button>
|
|
|
|
|
<span className="text-xs text-text-muted text-center">
|
|
|
|
|
{t('pageSummary', {
|
|
|
|
|
page: pagination.page,
|
|
|
|
|
totalPages: pagination.totalPages,
|
|
|
|
|
total: pagination.total,
|
|
|
|
|
})}
|
|
|
|
|
</span>
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
disabled={page >= pagination.totalPages || loadingList}
|
|
|
|
|
onClick={() => setPage((p) => p + 1)}
|
|
|
|
|
>
|
|
|
|
|
{t('nextPage')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
2026-06-28 16:46:42 +03:30
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section className="rounded-lg border border-border bg-surface p-4 min-h-[420px]">
|
|
|
|
|
{!selectedCaseId ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{t('selectCaseHint')}</p>
|
|
|
|
|
) : loadingDetail || !selectedCase ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{tCommon('loading')}</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<header className="space-y-1 border-b border-border pb-3">
|
2026-07-07 17:14:31 +03:30
|
|
|
<div className="flex flex-wrap items-start justify-between gap-2">
|
|
|
|
|
<h2 className="text-lg font-semibold text-text-primary">
|
|
|
|
|
{formatPatientName(selectedCase.patient)}
|
|
|
|
|
</h2>
|
|
|
|
|
<Button type="button" variant="outline" size="sm" onClick={scrollToComments}>
|
|
|
|
|
<MessageSquare className="h-4 w-4 me-1.5" />
|
|
|
|
|
{commentCount > 0
|
|
|
|
|
? t('commentsCount', { count: commentCount })
|
|
|
|
|
: t('showComments')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2026-06-28 17:49:40 +03:30
|
|
|
<p className="text-sm text-text-muted">
|
|
|
|
|
{t('patientMobile')}: {selectedCase.patient.mobile}
|
|
|
|
|
</p>
|
2026-06-28 16:46:42 +03:30
|
|
|
<p className="text-sm text-text-muted">
|
|
|
|
|
{t('fromClinic', { name: selectedCase.clinic.name })}
|
|
|
|
|
</p>
|
|
|
|
|
<p className="text-sm text-text-muted">
|
|
|
|
|
{t('sentAt', { date: formatDateTime(selectedCase.sentAt, locale) })}
|
|
|
|
|
</p>
|
2026-06-28 17:49:40 +03:30
|
|
|
<div className="pt-1 max-w-xs">
|
|
|
|
|
<p className="text-sm text-text-muted mb-1">
|
|
|
|
|
{t('taskProgressLabel', {
|
|
|
|
|
completed: selectedCase.taskProgress.completed,
|
|
|
|
|
total: selectedCase.taskProgress.total,
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
|
|
|
|
<TaskProgressBar
|
|
|
|
|
completed={selectedCase.taskProgress.completed}
|
|
|
|
|
total={selectedCase.taskProgress.total}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-06-28 16:46:42 +03:30
|
|
|
</header>
|
|
|
|
|
|
2026-07-07 18:43:10 +03:30
|
|
|
<div className="flex flex-wrap items-start gap-4">
|
|
|
|
|
<CaseToothChartPanel
|
|
|
|
|
details={selectedCase.details}
|
|
|
|
|
prosthesisRows={caseProsthesisRows}
|
|
|
|
|
scale={0.5}
|
|
|
|
|
className="min-w-0 flex-1"
|
|
|
|
|
/>
|
|
|
|
|
{latestCaseAttachment && selectedCaseId ? (
|
|
|
|
|
<div className="shrink-0 space-y-1">
|
|
|
|
|
<p className="text-xs font-medium text-text-secondary">{t('latestAttachment')}</p>
|
|
|
|
|
<LabCaseAttachmentPreview
|
|
|
|
|
caseId={selectedCaseId}
|
|
|
|
|
attachment={latestCaseAttachment}
|
|
|
|
|
loadBlob={loadCaseAttachmentBlob}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-28 16:46:42 +03:30
|
|
|
{selectedCase.details.length > 0 && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<h3 className="text-sm font-medium text-text-primary">{t('treatmentDetails')}</h3>
|
|
|
|
|
<ul className="space-y-2 text-sm">
|
|
|
|
|
{selectedCase.details.map((detail) => (
|
|
|
|
|
<li key={detail.id} className="rounded-md bg-background border border-border p-2">
|
|
|
|
|
<div className="font-medium">{treatmentLabel(detail.treatmentType)}</div>
|
|
|
|
|
<div className="text-text-muted">
|
|
|
|
|
{t('teethLabel')}: {detail.teeth.join(', ') || '—'}
|
|
|
|
|
</div>
|
|
|
|
|
{detail.comment ? (
|
|
|
|
|
<div className="text-text-muted mt-1">{detail.comment}</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
<h3 className="text-sm font-medium text-text-primary">{t('tasksByTooth')}</h3>
|
|
|
|
|
{selectedCase.tasksByTooth.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{t('noTasks')}</p>
|
|
|
|
|
) : (
|
2026-07-07 15:31:09 +03:30
|
|
|
selectedCase.tasksByTooth.map((group, groupIndex) => (
|
2026-06-28 16:46:42 +03:30
|
|
|
<div
|
2026-07-07 15:31:09 +03:30
|
|
|
key={`${group.treatmentDetailId}-${group.prosthesisTypeCode}`}
|
2026-06-28 16:46:42 +03:30
|
|
|
className="rounded-md border border-border p-3 space-y-2"
|
|
|
|
|
>
|
2026-07-07 15:31:09 +03:30
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
2026-07-07 18:43:10 +03:30
|
|
|
<Badge
|
|
|
|
|
truncate
|
|
|
|
|
title={group.prosthesisTypeLabel}
|
2026-07-07 15:31:09 +03:30
|
|
|
style={prosthesisTypeBadgeStyle(group.prosthesisTypeCode, groupIndex)}
|
|
|
|
|
>
|
|
|
|
|
{group.prosthesisTypeLabel}
|
2026-07-07 18:43:10 +03:30
|
|
|
</Badge>
|
2026-07-07 15:31:09 +03:30
|
|
|
<span className="text-sm font-medium text-text-primary">
|
|
|
|
|
{t('toothGroupTitle', {
|
|
|
|
|
teeth: formatToothList(group.teeth),
|
|
|
|
|
prosthesis: group.prosthesisTypeLabel,
|
|
|
|
|
})}
|
|
|
|
|
</span>
|
2026-06-28 16:46:42 +03:30
|
|
|
</div>
|
|
|
|
|
<ul className="space-y-2">
|
|
|
|
|
{group.tasks.map((task) => (
|
|
|
|
|
<li
|
|
|
|
|
key={task.id}
|
2026-07-07 15:31:09 +03:30
|
|
|
className="rounded bg-background p-2 text-sm space-y-1"
|
2026-06-28 16:46:42 +03:30
|
|
|
>
|
2026-07-07 15:31:09 +03:30
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
|
|
|
<span className="min-w-0 flex-1">
|
|
|
|
|
{task.stepOrder}. {task.stepLabel}
|
|
|
|
|
</span>
|
2026-07-07 17:14:31 +03:30
|
|
|
<Badge variant={labTaskStatusVariant(task.status)} fixedWidth={false}>
|
2026-07-07 15:31:09 +03:30
|
|
|
{statusOptions.find((opt) => opt.value === task.status)?.label ??
|
|
|
|
|
task.status}
|
|
|
|
|
</Badge>
|
|
|
|
|
{canEdit ? (
|
|
|
|
|
<label className="flex items-center gap-1.5 text-xs cursor-pointer shrink-0">
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
checked={task.isImportant}
|
|
|
|
|
disabled={updatingTaskId === task.id}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
void handleImportantToggle(task.id, e.target.checked)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
{t('importantLabel')}
|
|
|
|
|
</label>
|
|
|
|
|
) : task.isImportant ? (
|
|
|
|
|
<Badge variant="warning" fixedWidth={false}>
|
|
|
|
|
{t('importantLabel')}
|
|
|
|
|
</Badge>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-[11px] text-text-muted">
|
|
|
|
|
{task.lastStatusChangedBy
|
|
|
|
|
? t('lastUpdatedBy', { name: task.lastStatusChangedBy.name })
|
|
|
|
|
: t('lastUpdatedUnknown')}
|
|
|
|
|
{task.lastStatusChangedAt
|
|
|
|
|
? ` · ${formatDateTime(task.lastStatusChangedAt, locale)}`
|
|
|
|
|
: ''}
|
|
|
|
|
</p>
|
2026-06-28 16:46:42 +03:30
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-07 17:14:31 +03:30
|
|
|
|
|
|
|
|
{selectedCaseId ? (
|
|
|
|
|
<section id="case-comments" className="scroll-mt-4 border-t border-border pt-4">
|
|
|
|
|
<LabCaseCommentsPanel
|
|
|
|
|
caseId={selectedCaseId}
|
|
|
|
|
canPost={canEditComments}
|
|
|
|
|
canToggleVisibility={canEditComments}
|
|
|
|
|
loadComments={async () => {
|
|
|
|
|
const r = await tasksApi.listComments(selectedCaseId);
|
|
|
|
|
setCommentCount(r.data.length);
|
|
|
|
|
return r.data;
|
|
|
|
|
}}
|
|
|
|
|
onPost={async (body, visibleToClinic) => {
|
|
|
|
|
const r = await tasksApi.addComment(selectedCaseId, {
|
|
|
|
|
body,
|
|
|
|
|
visibleToClinic,
|
|
|
|
|
});
|
|
|
|
|
setCommentCount((n) => n + 1);
|
|
|
|
|
return r.data;
|
|
|
|
|
}}
|
|
|
|
|
onToggleVisibility={async (commentId, visible) => {
|
|
|
|
|
const r = await tasksApi.setCommentVisibility(commentId, visible);
|
|
|
|
|
return r.data;
|
|
|
|
|
}}
|
|
|
|
|
onError={toast.showError}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
) : null}
|
2026-06-28 16:46:42 +03:30
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<ToastStack {...toast.messages} />
|
2026-06-28 14:59:06 +03:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|