41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import type { LabCaseDetail } from '@/types/cases';
|
|
import type { CaseToothChartProsthesisRow } from '@/components/ui/lab/CaseToothChartPanel';
|
|
|
|
export function formatPatientName(patient: { firstName: string; lastName: string }) {
|
|
return `${patient.firstName} ${patient.lastName}`.trim();
|
|
}
|
|
|
|
export function formatCaseDateTime(value: string | null, locale: string) {
|
|
if (!value) return '—';
|
|
return new Intl.DateTimeFormat(locale, {
|
|
dateStyle: 'medium',
|
|
timeStyle: 'short',
|
|
}).format(new Date(value));
|
|
}
|
|
|
|
export function buildCaseProsthesisRows(labCase: LabCaseDetail): CaseToothChartProsthesisRow[] {
|
|
if (labCase.toothProsthesis.length > 0) {
|
|
const byCode = new Map<string, string[]>();
|
|
for (const row of labCase.toothProsthesis) {
|
|
const teeth = byCode.get(row.prosthesisTypeCode) ?? [];
|
|
if (!teeth.includes(row.tooth)) teeth.push(row.tooth);
|
|
byCode.set(row.prosthesisTypeCode, teeth);
|
|
}
|
|
return [...byCode.entries()].map(([prosthesisTypeCode, teeth]) => ({
|
|
prosthesisTypeCode,
|
|
teeth,
|
|
}));
|
|
}
|
|
return labCase.tasksByTooth.map((g) => ({
|
|
prosthesisTypeCode: g.prosthesisTypeCode,
|
|
teeth: g.teeth,
|
|
}));
|
|
}
|
|
|
|
export function latestCaseAttachment(labCase: LabCaseDetail) {
|
|
if (!labCase.attachments.length) return null;
|
|
return [...labCase.attachments].sort(
|
|
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
|
|
)[0];
|
|
}
|