2026-07-12 21:08:29 +03:30
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
|
|
import { useSearchParams } from 'next/navigation';
|
|
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
import { getUserFacingError } from '@/components/shared/formatApiError';
|
|
|
|
|
import { useAuth } from '@/lib/hooks/useAuth';
|
|
|
|
|
import { useToast } from '@/lib/hooks/useToast';
|
|
|
|
|
import { canEditCases, canEditTasks } from '@/components/shared/permissions';
|
|
|
|
|
import { CaseDetailPanel, CaseTaskProgressBar } from '@/components/ui/lab/CaseDetailPanel';
|
2026-07-14 03:06:56 +03:30
|
|
|
import { LabCaseProsthesisGroupsList } from '@/components/ui/lab/LabCaseProsthesisGroupsList';
|
2026-07-12 21:08:29 +03:30
|
|
|
import { LabCaseCommentsPanel } from '@/components/ui/lab/LabCaseCommentsPanel';
|
|
|
|
|
import {
|
|
|
|
|
formatCaseDateTime,
|
|
|
|
|
formatPatientName,
|
|
|
|
|
} from '@/components/lab/caseDetailUtils';
|
2026-07-13 16:30:36 +03:30
|
|
|
import { LabCaseDueDateBadge } from '@/components/lab/LabCaseDueDateBadge';
|
2026-07-13 17:44:44 +03:30
|
|
|
import { notificationsApi } from '@/lib/api/notifications';
|
|
|
|
|
import { notifyTabBadgesChanged } from '@/lib/tabBadgeUtils';
|
2026-07-12 21:08:29 +03:30
|
|
|
import { casesApi } from '@/lib/api/cases';
|
|
|
|
|
import { tasksApi } from '@/lib/api/tasks';
|
2026-07-14 03:06:56 +03:30
|
|
|
import { prosthesisCatalogApi } from '@/lib/api/prosthesis-catalog';
|
2026-07-12 21:08:29 +03:30
|
|
|
import { treatmentCatalogApi } from '@/lib/api/treatment-catalog';
|
|
|
|
|
import { treatmentTypeLabelFromCatalog } from '@/components/shared/treatmentTypeDisplay';
|
2026-07-13 13:22:38 +03:30
|
|
|
import { Badge } from '@/components/ui/shared/Badge';
|
2026-07-12 21:08:29 +03:30
|
|
|
import { Button } from '@/components/ui/shared/Button';
|
|
|
|
|
import { MobileDetailBackButton } from '@/components/ui/shared/MobileDetailBackButton';
|
|
|
|
|
import { FORM_SELECT_CLASS } from '@/components/shared/formSelectStyles';
|
|
|
|
|
import { SearchBar } from '@/components/ui/shared/SearchBar';
|
2026-07-14 01:27:11 +03:30
|
|
|
import { AppDateInput } from '@/components/ui/shared/AppDateInput';
|
2026-07-14 03:06:56 +03:30
|
|
|
import type { ProsthesisCatalogEntry, TreatmentCatalogEntry } from '@/types/treatment-catalog';
|
2026-07-12 21:08:29 +03:30
|
|
|
import type {
|
2026-07-13 15:47:32 +03:30
|
|
|
AssignableTaskStaff,
|
2026-07-12 21:08:29 +03:30
|
|
|
CasesFilterOptions,
|
|
|
|
|
LabCaseDetail,
|
|
|
|
|
LabCaseListItem,
|
|
|
|
|
LabTaskStatus,
|
|
|
|
|
PaginatedLabCases,
|
|
|
|
|
} from '@/types/cases';
|
|
|
|
|
|
|
|
|
|
const PAGE_SIZE = 20;
|
|
|
|
|
|
|
|
|
|
export function CasesPage() {
|
|
|
|
|
const t = useTranslations('cases');
|
|
|
|
|
const tErrors = useTranslations('errors');
|
|
|
|
|
const tCommon = useTranslations('common');
|
|
|
|
|
const { currentOrganization, user } = useAuth();
|
|
|
|
|
const toast = useToast();
|
|
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
|
|
|
|
|
const [search, setSearch] = useState('');
|
|
|
|
|
const [clinicId, setClinicId] = useState('');
|
2026-07-14 03:06:56 +03:30
|
|
|
const [prosthesisTypeCode, setProsthesisTypeCode] = useState('');
|
2026-07-12 21:08:29 +03:30
|
|
|
const [sentFrom, setSentFrom] = useState('');
|
|
|
|
|
const [sentTo, setSentTo] = useState('');
|
|
|
|
|
const [page, setPage] = useState(1);
|
|
|
|
|
|
|
|
|
|
const [cases, setCases] = useState<LabCaseListItem[]>([]);
|
|
|
|
|
const [pagination, setPagination] = useState<PaginatedLabCases['pagination']>({
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
|
total: 0,
|
|
|
|
|
totalPages: 1,
|
|
|
|
|
});
|
|
|
|
|
const [filterOptions, setFilterOptions] = useState<CasesFilterOptions>({
|
|
|
|
|
clinics: [],
|
2026-07-14 03:06:56 +03:30
|
|
|
prosthesisTypes: [],
|
2026-07-12 21:08:29 +03:30
|
|
|
});
|
2026-07-14 03:06:56 +03:30
|
|
|
const [prosthesisCatalog, setProsthesisCatalog] = useState<ProsthesisCatalogEntry[]>([]);
|
2026-07-12 21:08:29 +03:30
|
|
|
const [treatmentCatalog, setTreatmentCatalog] = useState<TreatmentCatalogEntry[]>([]);
|
|
|
|
|
|
|
|
|
|
const [selectedCaseId, setSelectedCaseId] = useState<string | null>(null);
|
|
|
|
|
const [mobileDetailOpen, setMobileDetailOpen] = useState(false);
|
|
|
|
|
const [selectedCase, setSelectedCase] = useState<LabCaseDetail | null>(null);
|
|
|
|
|
const [loadingList, setLoadingList] = useState(false);
|
|
|
|
|
const [loadingDetail, setLoadingDetail] = useState(false);
|
|
|
|
|
const [updatingImportant, setUpdatingImportant] = useState(false);
|
2026-07-13 15:47:32 +03:30
|
|
|
const [assignableStaff, setAssignableStaff] = useState<AssignableTaskStaff[]>([]);
|
|
|
|
|
const [assigningTaskId, setAssigningTaskId] = useState<string | null>(null);
|
2026-07-12 21:08:29 +03:30
|
|
|
const [commentCount, setCommentCount] = useState(0);
|
|
|
|
|
|
|
|
|
|
const canEdit = canEditCases(currentOrganization);
|
|
|
|
|
const canEditComments = canEditTasks(currentOrganization);
|
|
|
|
|
const locale = user?.language ?? 'en';
|
|
|
|
|
|
2026-07-14 03:06:56 +03:30
|
|
|
const prosthesisLabel = useCallback(
|
|
|
|
|
(code: string) =>
|
|
|
|
|
prosthesisCatalog.find((entry) => entry.code === code)?.label ?? code,
|
|
|
|
|
[prosthesisCatalog],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const treatmentDetailLabel = useCallback(
|
2026-07-12 21:08:29 +03:30
|
|
|
(type: string) => treatmentTypeLabelFromCatalog(type, treatmentCatalog),
|
|
|
|
|
[treatmentCatalog],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const statusOptions: { value: LabTaskStatus; label: string }[] = useMemo(
|
|
|
|
|
() => [
|
|
|
|
|
{ value: 'IN_PROGRESS', label: t('statusInProgress') },
|
|
|
|
|
{ value: 'COMPLETED', label: t('statusCompleted') },
|
|
|
|
|
],
|
|
|
|
|
[t],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const hasActiveFilters = Boolean(
|
2026-07-14 03:06:56 +03:30
|
|
|
search.trim() || clinicId || prosthesisTypeCode || sentFrom || sentTo,
|
2026-07-12 21:08:29 +03:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const loadCases = async (params: {
|
|
|
|
|
q: string;
|
|
|
|
|
clinicOrganizationId: string;
|
2026-07-14 03:06:56 +03:30
|
|
|
prosthesisTypeCode: string;
|
2026-07-12 21:08:29 +03:30
|
|
|
sentFrom: string;
|
|
|
|
|
sentTo: string;
|
|
|
|
|
page: number;
|
|
|
|
|
}) => {
|
|
|
|
|
setLoadingList(true);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
|
|
|
|
const response = await casesApi.list({
|
|
|
|
|
q: params.q.trim() || undefined,
|
|
|
|
|
clinicOrganizationId: params.clinicOrganizationId || undefined,
|
2026-07-14 03:06:56 +03:30
|
|
|
prosthesisTypeCode: params.prosthesisTypeCode || undefined,
|
2026-07-12 21:08:29 +03:30
|
|
|
sentFrom: params.sentFrom || undefined,
|
|
|
|
|
sentTo: params.sentTo || undefined,
|
|
|
|
|
page: params.page,
|
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
|
});
|
|
|
|
|
setCases(response.data.items);
|
|
|
|
|
setPagination(response.data.pagination);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(getUserFacingError(error, tErrors, t('errorLoadList')));
|
|
|
|
|
} finally {
|
|
|
|
|
setLoadingList(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadDetail = async (caseId: string, options?: { silent?: boolean }) => {
|
|
|
|
|
if (!options?.silent) {
|
|
|
|
|
setLoadingDetail(true);
|
|
|
|
|
}
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
|
|
|
|
const response = await casesApi.getOne(caseId);
|
|
|
|
|
setSelectedCase(response.data);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(getUserFacingError(error, tErrors, t('errorLoadDetail')));
|
|
|
|
|
if (!options?.silent) {
|
|
|
|
|
setSelectedCase(null);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
if (!options?.silent) {
|
|
|
|
|
setLoadingDetail(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
void casesApi.listFilterOptions().then((r) => setFilterOptions(r.data)).catch(() => {});
|
2026-07-14 03:06:56 +03:30
|
|
|
void prosthesisCatalogApi.list().then((r) => setProsthesisCatalog(r.data)).catch(() => {});
|
2026-07-12 21:08:29 +03:30
|
|
|
void treatmentCatalogApi.list().then((r) => setTreatmentCatalog(r.data)).catch(() => {});
|
2026-07-13 15:47:32 +03:30
|
|
|
if (canEdit) {
|
|
|
|
|
void casesApi.listAssignableStaff().then((r) => setAssignableStaff(r.data)).catch(() => {});
|
|
|
|
|
}
|
2026-07-12 21:08:29 +03:30
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount-only initial fetch
|
2026-07-13 15:47:32 +03:30
|
|
|
}, [canEdit]);
|
2026-07-12 21:08:29 +03:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-07-13 22:53:23 +03:30
|
|
|
const clinicFromUrl = searchParams.get('clinicOrganizationId');
|
|
|
|
|
if (clinicFromUrl) {
|
|
|
|
|
setClinicId(clinicFromUrl);
|
|
|
|
|
}
|
2026-07-12 21:08:29 +03:30
|
|
|
}, [searchParams]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-07-14 03:06:56 +03:30
|
|
|
if (loadingList) return;
|
|
|
|
|
|
|
|
|
|
if (cases.length === 0) {
|
|
|
|
|
if (selectedCaseId !== null) {
|
|
|
|
|
setSelectedCaseId(null);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2026-07-12 21:08:29 +03:30
|
|
|
}
|
2026-07-14 03:06:56 +03:30
|
|
|
|
|
|
|
|
const urlCaseId = searchParams.get('caseId');
|
|
|
|
|
if (urlCaseId && cases.some((item) => item.id === urlCaseId)) {
|
|
|
|
|
if (selectedCaseId !== urlCaseId) {
|
|
|
|
|
setSelectedCaseId(urlCaseId);
|
|
|
|
|
setMobileDetailOpen(true);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selectedCaseId && cases.some((item) => item.id === selectedCaseId)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSelectedCaseId(cases[0].id);
|
|
|
|
|
}, [cases, loadingList, searchParams, selectedCaseId]);
|
2026-07-12 21:08:29 +03:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
|
void loadCases({
|
|
|
|
|
q: search,
|
|
|
|
|
clinicOrganizationId: clinicId,
|
2026-07-14 03:06:56 +03:30
|
|
|
prosthesisTypeCode,
|
2026-07-12 21:08:29 +03:30
|
|
|
sentFrom,
|
|
|
|
|
sentTo,
|
|
|
|
|
page,
|
|
|
|
|
});
|
|
|
|
|
}, search ? 300 : 0);
|
|
|
|
|
return () => clearTimeout(timeout);
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- debounced search + filter reload
|
2026-07-14 03:06:56 +03:30
|
|
|
}, [search, clinicId, prosthesisTypeCode, sentFrom, sentTo, page]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!selectedCaseId) {
|
|
|
|
|
setMobileDetailOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}, [selectedCaseId]);
|
2026-07-12 21:08:29 +03:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (selectedCaseId) {
|
|
|
|
|
void loadDetail(selectedCaseId);
|
2026-07-13 17:44:44 +03:30
|
|
|
void notificationsApi.markCaseRead(selectedCaseId).then(() => {
|
|
|
|
|
notifyTabBadgesChanged();
|
|
|
|
|
setCases((prev) =>
|
|
|
|
|
prev.map((item) =>
|
|
|
|
|
item.id === selectedCaseId ? { ...item, hasUnread: false } : item,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-07-12 21:08:29 +03:30
|
|
|
void tasksApi
|
|
|
|
|
.listComments(selectedCaseId)
|
|
|
|
|
.then((r) => setCommentCount(r.data.length))
|
|
|
|
|
.catch(() => setCommentCount(0));
|
|
|
|
|
} else {
|
|
|
|
|
setSelectedCase(null);
|
|
|
|
|
setCommentCount(0);
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- reload when selection changes
|
|
|
|
|
}, [selectedCaseId]);
|
|
|
|
|
|
|
|
|
|
function scrollToComments() {
|
|
|
|
|
document.getElementById('case-comments')?.scrollIntoView({ behavior: 'smooth' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const loadCaseAttachmentBlob = useCallback(
|
|
|
|
|
(caseId: string, attachmentId: string) => casesApi.getAttachmentFileBlob(caseId, attachmentId),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function clearFilters() {
|
|
|
|
|
setSearch('');
|
|
|
|
|
setClinicId('');
|
2026-07-14 03:06:56 +03:30
|
|
|
setProsthesisTypeCode('');
|
2026-07-12 21:08:29 +03:30
|
|
|
setSentFrom('');
|
|
|
|
|
setSentTo('');
|
|
|
|
|
setPage(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 15:47:32 +03:30
|
|
|
async function handleAssignTask(taskId: string, assigneeUserId: string | null) {
|
|
|
|
|
if (!selectedCaseId || !canEdit) return;
|
|
|
|
|
|
|
|
|
|
setAssigningTaskId(taskId);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
|
|
|
|
const response = await casesApi.assignTask(selectedCaseId, taskId, assigneeUserId);
|
|
|
|
|
setSelectedCase(response.data);
|
|
|
|
|
} catch (error: unknown) {
|
|
|
|
|
toast.showError(getUserFacingError(error, tErrors, t('errorAssignTask')));
|
|
|
|
|
} finally {
|
|
|
|
|
setAssigningTaskId(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 21:08:29 +03:30
|
|
|
async function handleCaseImportantToggle(isImportant: boolean) {
|
|
|
|
|
if (!selectedCaseId || !canEdit || !selectedCase) return;
|
|
|
|
|
|
|
|
|
|
const previousCase = selectedCase;
|
|
|
|
|
setSelectedCase({ ...selectedCase, isImportant });
|
|
|
|
|
|
|
|
|
|
setUpdatingImportant(true);
|
|
|
|
|
toast.setError('');
|
|
|
|
|
try {
|
|
|
|
|
const response = await casesApi.setCaseImportant(selectedCaseId, isImportant);
|
|
|
|
|
setSelectedCase(response.data);
|
2026-07-13 13:22:38 +03:30
|
|
|
setCases((prev) =>
|
|
|
|
|
prev.map((item) =>
|
|
|
|
|
item.id === selectedCaseId ? { ...item, isImportant: response.data.isImportant } : item,
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-07-13 17:44:44 +03:30
|
|
|
notifyTabBadgesChanged();
|
2026-07-12 21:08:29 +03:30
|
|
|
} catch (error: unknown) {
|
|
|
|
|
setSelectedCase(previousCase);
|
|
|
|
|
toast.showError(getUserFacingError(error, tErrors, t('errorUpdateTask')));
|
|
|
|
|
} finally {
|
|
|
|
|
setUpdatingImportant(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 01:27:11 +03:30
|
|
|
const filterSelectClass = `${FORM_SELECT_CLASS} w-full min-w-0 rounded-md py-1.5 text-xs sm:py-2 sm:text-sm`;
|
2026-07-12 21:08:29 +03:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="text-xl sm:text-2xl font-semibold text-text-primary">{t('title')}</h1>
|
|
|
|
|
<p className="text-sm text-text-muted mt-1">{t('subtitle')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-4 lg:grid-cols-[minmax(300px,380px)_1fr]">
|
|
|
|
|
<section
|
|
|
|
|
className={`rounded-lg border border-border bg-surface p-3 sm:p-4 space-y-3 flex flex-col min-h-0 ${
|
|
|
|
|
mobileDetailOpen && selectedCaseId ? 'hidden lg:flex' : 'flex'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<SearchBar
|
|
|
|
|
embedded
|
|
|
|
|
value={search}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
setSearch(value);
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
placeholder={t('searchPlaceholder')}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
<label className="space-y-1">
|
2026-07-14 03:06:56 +03:30
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterProsthesisType')}</span>
|
2026-07-12 21:08:29 +03:30
|
|
|
<select
|
2026-07-14 03:06:56 +03:30
|
|
|
value={prosthesisTypeCode}
|
2026-07-12 21:08:29 +03:30
|
|
|
onChange={(e) => {
|
2026-07-14 03:06:56 +03:30
|
|
|
setProsthesisTypeCode(e.target.value);
|
2026-07-12 21:08:29 +03:30
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
>
|
2026-07-14 03:06:56 +03:30
|
|
|
<option value="">{t('filterProsthesisTypeAll')}</option>
|
|
|
|
|
{filterOptions.prosthesisTypes.map((type) => (
|
2026-07-12 21:08:29 +03:30
|
|
|
<option key={type.code} value={type.code}>
|
2026-07-14 03:06:56 +03:30
|
|
|
{prosthesisLabel(type.code)}
|
2026-07-12 21:08:29 +03:30
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterSentFrom')}</span>
|
2026-07-14 01:27:11 +03:30
|
|
|
<AppDateInput
|
2026-07-12 21:08:29 +03:30
|
|
|
value={sentFrom}
|
2026-07-14 01:27:11 +03:30
|
|
|
onChange={(next) => {
|
|
|
|
|
setSentFrom(next);
|
2026-07-12 21:08:29 +03:30
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className={filterSelectClass}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="space-y-1">
|
|
|
|
|
<span className="text-xs font-medium text-text-muted">{t('filterSentTo')}</span>
|
2026-07-14 01:27:11 +03:30
|
|
|
<AppDateInput
|
2026-07-12 21:08:29 +03:30
|
|
|
value={sentTo}
|
2026-07-14 01:27:11 +03:30
|
|
|
onChange={(next) => {
|
|
|
|
|
setSentTo(next);
|
2026-07-12 21:08:29 +03:30
|
|
|
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);
|
|
|
|
|
setMobileDetailOpen(true);
|
|
|
|
|
}}
|
|
|
|
|
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'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2026-07-13 17:44:44 +03:30
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1.5">
|
|
|
|
|
<div className="font-medium text-text-primary">
|
|
|
|
|
{formatPatientName(item.patient)}
|
|
|
|
|
</div>
|
|
|
|
|
<LabCaseDueDateBadge
|
|
|
|
|
dueDate={item.dueDate}
|
|
|
|
|
locale={locale}
|
|
|
|
|
className="text-[10px]"
|
|
|
|
|
/>
|
|
|
|
|
{item.isImportant ? (
|
|
|
|
|
<Badge variant="warning" fixedWidth={false}>
|
|
|
|
|
{t('importantLabel')}
|
|
|
|
|
</Badge>
|
|
|
|
|
) : null}
|
2026-07-13 13:22:38 +03:30
|
|
|
</div>
|
2026-07-13 17:44:44 +03:30
|
|
|
{item.hasUnread ? (
|
|
|
|
|
<span
|
|
|
|
|
className="h-2 w-2 shrink-0 rounded-full bg-badge-warning-fg"
|
|
|
|
|
aria-label={t('unreadCase')}
|
|
|
|
|
/>
|
2026-07-13 13:22:38 +03:30
|
|
|
) : null}
|
2026-07-12 21:08:29 +03:30
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-text-muted mt-0.5">{item.clinic.name}</div>
|
2026-07-14 03:06:56 +03:30
|
|
|
<div className="mt-1">
|
|
|
|
|
<LabCaseProsthesisGroupsList
|
|
|
|
|
groups={item.prosthesisGroups}
|
|
|
|
|
prosthesisCatalog={prosthesisCatalog}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-[10px] text-text-muted mt-1">
|
2026-07-12 21:08:29 +03:30
|
|
|
{formatCaseDateTime(item.sentAt, locale)}
|
|
|
|
|
</div>
|
2026-07-14 03:06:56 +03:30
|
|
|
<div className="mt-1.5">
|
2026-07-12 21:08:29 +03:30
|
|
|
<CaseTaskProgressBar
|
|
|
|
|
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}
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section
|
|
|
|
|
className={`rounded-lg border border-border bg-surface p-3 sm:p-4 min-h-[320px] lg:min-h-[420px] ${
|
|
|
|
|
selectedCaseId && !mobileDetailOpen ? 'hidden lg:block' : ''
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{mobileDetailOpen && selectedCaseId ? (
|
|
|
|
|
<MobileDetailBackButton onClick={() => setMobileDetailOpen(false)} />
|
|
|
|
|
) : null}
|
2026-07-14 03:06:56 +03:30
|
|
|
{!selectedCaseId && !loadingList && cases.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{t('emptyList')}</p>
|
2026-07-12 21:08:29 +03:30
|
|
|
) : loadingDetail || !selectedCase ? (
|
|
|
|
|
<p className="text-sm text-text-muted">{tCommon('loading')}</p>
|
|
|
|
|
) : (
|
|
|
|
|
<CaseDetailPanel
|
|
|
|
|
labCase={selectedCase}
|
|
|
|
|
locale={locale}
|
2026-07-14 03:06:56 +03:30
|
|
|
treatmentLabel={treatmentDetailLabel}
|
2026-07-12 21:08:29 +03:30
|
|
|
statusOptions={statusOptions}
|
|
|
|
|
loadAttachmentBlob={loadCaseAttachmentBlob}
|
|
|
|
|
showCommentsButton
|
|
|
|
|
commentCount={commentCount}
|
|
|
|
|
onCommentsClick={scrollToComments}
|
|
|
|
|
canEditImportant={canEdit}
|
|
|
|
|
updatingImportant={updatingImportant}
|
|
|
|
|
onImportantChange={(checked) => void handleCaseImportantToggle(checked)}
|
2026-07-13 15:47:32 +03:30
|
|
|
assignableStaff={assignableStaff}
|
|
|
|
|
canAssignTasks={canEdit}
|
|
|
|
|
assigningTaskId={assigningTaskId}
|
|
|
|
|
onAssignTask={(taskId, assigneeUserId) =>
|
|
|
|
|
void handleAssignTask(taskId, assigneeUserId)
|
|
|
|
|
}
|
2026-07-12 21:08:29 +03:30
|
|
|
headerMetaLines={
|
|
|
|
|
<p className="text-sm text-text-muted">
|
|
|
|
|
{t('fromClinic', { name: selectedCase.clinic.name })}
|
|
|
|
|
</p>
|
|
|
|
|
}
|
|
|
|
|
commentsSection={
|
|
|
|
|
selectedCaseId ? (
|
|
|
|
|
<section id="case-comments" className="scroll-mt-4 border-t border-border pt-4">
|
|
|
|
|
<LabCaseCommentsPanel
|
|
|
|
|
caseId={selectedCaseId}
|
2026-07-17 12:30:43 +03:30
|
|
|
viewerSide="LAB"
|
2026-07-12 21:08:29 +03:30
|
|
|
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);
|
2026-07-13 17:44:44 +03:30
|
|
|
notifyTabBadgesChanged();
|
2026-07-12 21:08:29 +03:30
|
|
|
return r.data;
|
|
|
|
|
}}
|
|
|
|
|
onToggleVisibility={async (commentId, visible) => {
|
|
|
|
|
const r = await tasksApi.setCommentVisibility(commentId, visible);
|
|
|
|
|
return r.data;
|
|
|
|
|
}}
|
|
|
|
|
onError={toast.showError}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
) : null
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|