improvment: Case sheets now show comments. wet milling removed from PFM crown workflow pipeline.

This commit is contained in:
2026-10-02 19:54:31 +03:30
parent 686297000d
commit f59951ef97
7 changed files with 249 additions and 31 deletions

View File

@@ -213,7 +213,6 @@ export const PROSTHESIS_TYPES: ProsthesisTypeSeed[] = [
crown('pfm_crown', 1, [
...SCAN_DESIGN,
'printer_metal',
'milling_wet',
'sinter',
'build_up_crown',
'stain',

View File

@@ -0,0 +1,27 @@
-- 20261001234000 added Metal Print to PFM crown and left Wet milling in place.
-- This runs after that mapping (and after its row-count check) so staging and
-- production both end with Metal Print only. Other types still use wet milling.
DELETE FROM "prosthesis_type_steps" AS step
USING "prosthesis_types" AS type, "lab_workflow_steps" AS workflow
WHERE step."prosthesisTypeId" = type."id"
AND step."labWorkflowStepId" = workflow."id"
AND type."code" = 'pfm_crown'
AND workflow."code" = 'milling_wet';
-- Cases already generated from the doubled pipeline still list both steps.
-- Drop the extra in-progress wet-milling task only when Metal Print is on the
-- same section. Completed, historical, and outsourced wet-milling tasks stay.
DELETE FROM "lab_case_tasks" AS wet
USING "lab_case_tasks" AS metal
WHERE wet."workflowStepCode" = 'milling_wet'
AND wet."prosthesisTypeCode" = 'pfm_crown'
AND wet."roundId" IS NULL
AND wet."status" = 'IN_PROGRESS'
AND wet."outsourcedToLabCaseId" IS NULL
AND wet."parentTaskId" IS NULL
AND metal."labCaseId" = wet."labCaseId"
AND metal."sourceKey" = wet."sourceKey"
AND metal."tooth" = wet."tooth"
AND metal."prosthesisTypeCode" = wet."prosthesisTypeCode"
AND metal."workflowStepCode" = 'printer_metal'
AND metal."roundId" IS NULL;

View File

@@ -182,16 +182,17 @@ describe('generateLabCaseTasks', () => {
});
expect(pipeline.map((row) => row.workflowStepCode)).toEqual(rowStepCodes(pfmSteps));
expect(pipeline.map((row) => row.workflowStepCode)).toEqual(
expect.arrayContaining(['printer_metal', 'build_up_crown', 'milling_wet']),
expect.arrayContaining(['printer_metal', 'build_up_crown']),
);
const pipelineCodes = pipeline.map((row) => row.workflowStepCode);
expect(pipelineCodes).not.toContain('milling_wet');
expect(pipelineCodes).not.toContain('model_design');
expect(pipelineCodes).not.toContain('model_create');
expect(pipelineCodes.indexOf('design')).toBeLessThan(
pipelineCodes.indexOf('printer_metal'),
);
expect(pipelineCodes.indexOf('printer_metal')).toBeLessThan(
pipelineCodes.indexOf('milling_wet'),
pipelineCodes.indexOf('sinter'),
);
expect(lineLevel.map((row) => row.workflowStepCode)).toEqual([
'intraoral_scan',

View File

@@ -8,6 +8,7 @@ import {
CaseSheetPrintLayout,
type CaseSheetLabels,
type CaseSheetOrientation,
type CaseSheetPrintedComment,
} from '@/components/ui/lab/CaseSheetPrintLayout';
import type { LabCaseDetail } from '@/types/cases';
import type { ProsthesisCatalogEntry } from '@/types/treatment-catalog';
@@ -18,10 +19,22 @@ type DownloadCaseSheetPdfArgs = {
messages: AbstractIntlMessages;
labels: CaseSheetLabels;
prosthesisCatalog: readonly ProsthesisCatalogEntry[];
notes?: readonly string[];
comments?: readonly CaseSheetPrintedComment[];
fileName?: string;
orientation?: CaseSheetOrientation;
};
function printFontFamily(locale: string): string {
if (locale !== 'fa' || typeof document === 'undefined') {
return 'system-ui, -apple-system, "Segoe UI", sans-serif';
}
const style = getComputedStyle(document.documentElement);
const vazir = style.getPropertyValue('--font-vazirmatn').trim();
const noto = style.getPropertyValue('--font-noto-sans-arabic').trim();
return [vazir, noto, 'Tahoma', '"Segoe UI"', 'sans-serif'].filter(Boolean).join(', ');
}
function waitForPaint(): Promise<void> {
return new Promise((resolve) => {
requestAnimationFrame(() => {
@@ -43,6 +56,8 @@ export async function downloadCaseSheetPdf({
messages,
labels,
prosthesisCatalog,
notes = [],
comments = [],
fileName,
orientation = 'portrait',
}: DownloadCaseSheetPdfArgs): Promise<void> {
@@ -64,6 +79,9 @@ export async function downloadCaseSheetPdf({
labels,
prosthesisCatalog,
orientation,
notes,
comments,
fontFamily: printFontFamily(locale),
}),
}),
);
@@ -84,9 +102,11 @@ export async function downloadCaseSheetPdf({
scrollY: -window.scrollY,
// Drop app stylesheets so parsers never see lab()/oklch() from Tailwind.
onclone: (clonedDoc) => {
clonedDoc
.querySelectorAll('style, link[rel="stylesheet"]')
.forEach((node) => node.remove());
clonedDoc.querySelectorAll('style, link[rel="stylesheet"]').forEach((node) => {
const css = node instanceof HTMLStyleElement ? (node.textContent ?? '') : '';
if (css.includes('@font-face') && !/oklch\(|\blab\(/i.test(css)) return;
node.remove();
});
// Brand mark viewBoxes are thousands of units. Without an explicit
// pixel size, html2canvas lays them out huge and pads the page.
clonedDoc.querySelectorAll('[data-case-sheet-lockup]').forEach((node) => {

View File

@@ -28,6 +28,7 @@ import {
} from '@/components/lab/caseDetailUtils';
import { downloadCaseSheetPdf } from '@/components/lab/caseSheetPdf';
import type { CaseSheetOrientation } from '@/components/ui/lab/CaseSheetPrintLayout';
import { caseCommentsApi } from '@/lib/api/case-comments';
import { ConnectedSelectionBadge } from '@/components/ui/treatment/ConnectedSelectionBadge';
import { useToast } from '@/lib/hooks/useToast';
import { formatAppMoney } from '@/lib/i18n/format';
@@ -45,6 +46,19 @@ import type {
} from '@/types/cases';
import type { ProsthesisCatalogEntry } from '@/types/treatment-catalog';
function caseSheetLineNotes(labCase: LabCaseDetail): string[] {
const raw = [labCase.detail?.comment, ...(labCase.lines ?? []).map((line) => line.comment)];
const seen = new Set<string>();
const notes: string[] = [];
for (const value of raw) {
const text = value?.trim();
if (!text || seen.has(text)) continue;
seen.add(text);
notes.push(text);
}
return notes;
}
function CurrentRoundTaskStatus({
task,
statusOptions,
@@ -241,6 +255,7 @@ export function CaseDetailPanel({
}: CaseDetailPanelProps) {
const t = useTranslations('cases');
const tTreatment = useTranslations('treatment');
const tComments = useTranslations('caseComments');
const intlLocale = useLocale();
const messages = useMessages();
const toast = useToast();
@@ -298,12 +313,28 @@ export function CaseDetailPanel({
setSheetMenuOpen(false);
setDownloadingPdf(true);
try {
const listed = await caseCommentsApi.list(labCase.id);
const comments = [...listed.data]
.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
.map((comment) => ({
id: comment.id,
body: comment.body,
createdAt: comment.createdAt,
authorLabel: [
comment.authorSide === 'LAB' ? tComments('labAuthor') : tComments('clinicAuthor'),
comment.authorName?.trim() || null,
]
.filter(Boolean)
.join(' · '),
}));
await downloadCaseSheetPdf({
labCase,
locale: intlLocale,
messages,
prosthesisCatalog,
orientation,
notes: caseSheetLineNotes(labCase),
comments,
labels: {
title: t('caseSheetTitle'),
orderNumber: t('caseSheetOrderNumber'),

View File

@@ -348,10 +348,11 @@ function ArchCaption({
textAlign: 'center',
fontSize: 11,
fontWeight: 600,
textTransform: 'uppercase',
lineHeight: '13px',
color: color ?? PLAIN_CAPTION,
...(rtl ? { direction: 'rtl' as const } : { letterSpacing: '0.04em' }),
...(rtl
? { direction: 'rtl' as const, letterSpacing: 'normal' as const, textTransform: 'none' as const }
: { letterSpacing: '0.04em', textTransform: 'uppercase' as const }),
}}
>
{label}

View File

@@ -42,6 +42,13 @@ export type CaseSheetLabels = {
walkIn: string;
};
export type CaseSheetPrintedComment = {
id: string;
body: string;
authorLabel: string;
createdAt: string;
};
export type CaseSheetOrientation = 'portrait' | 'landscape';
type CaseSheetPrintLayoutProps = {
@@ -50,6 +57,10 @@ type CaseSheetPrintLayoutProps = {
labels: CaseSheetLabels;
prosthesisCatalog: readonly ProsthesisCatalogEntry[];
orientation?: CaseSheetOrientation;
/** Line notes plus the comment thread shown under the case. */
notes?: readonly string[];
comments?: readonly CaseSheetPrintedComment[];
fontFamily?: string;
};
const PAGE_SIZE: Record<CaseSheetOrientation, { width: number; height: number }> = {
@@ -57,18 +68,53 @@ const PAGE_SIZE: Record<CaseSheetOrientation, { width: number; height: number }>
landscape: { width: 1123, height: 794 },
};
/** Uppercase tracking on Latin labels. Farsi omits letter-spacing: html2canvas then draws each letter alone and Persian stops joining. */
/**
* Uppercase tracking on Latin labels.
* Farsi keeps normal spacing and no text-transform: html2canvas then draws each
* letter alone and Persian stops joining.
*/
function printLabelStyle(rtl: boolean) {
return {
color: '#64748b',
fontSize: 11,
fontWeight: 600,
textTransform: 'uppercase' as const,
...(rtl ? {} : { letterSpacing: '0.04em' as const }),
...(rtl
? {
direction: 'rtl' as const,
letterSpacing: 'normal' as const,
textTransform: 'none' as const,
}
: { letterSpacing: '0.04em' as const, textTransform: 'uppercase' as const }),
};
}
function printHeadingStyle(rtl: boolean) {
return {
margin: 0,
fontSize: 15,
fontWeight: 600,
lineHeight: '18px',
...(rtl
? {
direction: 'rtl' as const,
letterSpacing: 'normal' as const,
textTransform: 'none' as const,
}
: {}),
};
}
const body = { color: '#0f172a', fontSize: 13, lineHeight: '16px' };
const rule = { borderTop: '1px solid #cbd5e1', marginTop: 8, paddingTop: 6 };
/** Extra drop so Farsi descenders clear the rule. Latin layouts stay put. */
const FA_RULE_DROP = 6;
function printRule(rtl: boolean) {
return {
borderTop: '1px solid #cbd5e1',
marginTop: rtl ? 8 + FA_RULE_DROP : 8,
paddingTop: 6,
};
}
/**
* Off-screen A4 layout for PDF capture.
@@ -80,6 +126,9 @@ export function CaseSheetPrintLayout({
labels,
prosthesisCatalog,
orientation = 'portrait',
notes = [],
comments = [],
fontFamily,
}: CaseSheetPrintLayoutProps) {
const prosthesisRows = buildCaseProsthesisRows(labCase, prosthesisCatalog);
const connectedTeeth = buildCaseConnectedTeeth(labCase);
@@ -93,19 +142,28 @@ export function CaseSheetPrintLayout({
const contentWidth = page.width - 48;
const chartFitWidth = Math.round(page.width * 0.85);
const rtl = locale === 'fa';
const printFont =
fontFamily ??
(rtl
? 'Tahoma, "Segoe UI", sans-serif'
: 'system-ui, -apple-system, "Segoe UI", sans-serif');
const joinedNotes = notes.map((note) => note.trim()).filter(Boolean);
return (
<div
data-case-sheet-root
dir="ltr"
style={{
boxSizing: 'border-box',
width: page.width,
padding: '0 24px 8px',
padding: rtl ? '0 24px 20px' : '0 24px 8px',
backgroundColor: '#ffffff',
color: '#0f172a',
fontFamily: 'system-ui, -apple-system, Segoe UI, sans-serif',
fontFamily: printFont,
fontSize: '13px',
lineHeight: '16px',
direction: 'ltr',
...(rtl ? { letterSpacing: 'normal' as const } : {}),
}}
>
<header
@@ -114,10 +172,27 @@ export function CaseSheetPrintLayout({
alignItems: 'center',
gap: 12,
borderBottom: '1px solid #cbd5e1',
paddingBottom: 8,
paddingBottom: rtl ? 8 + FA_RULE_DROP : 8,
}}
>
<div style={{ margin: 0, minWidth: 0, flex: 1, fontSize: 24, fontWeight: 600, lineHeight: '28px' }}>
<div
style={{
margin: 0,
minWidth: 0,
flex: 1,
fontSize: 24,
fontWeight: 600,
lineHeight: '28px',
...(rtl
? {
direction: 'rtl' as const,
letterSpacing: 'normal' as const,
textAlign: 'left' as const,
textTransform: 'none' as const,
}
: {}),
}}
>
{labels.title}
</div>
<div
@@ -173,7 +248,7 @@ export function CaseSheetPrintLayout({
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
gap: 12,
...rule,
...printRule(rtl),
}}
>
<PartyBlock label={labels.sender} title={labCase.clinic.name} rtl={rtl} />
@@ -186,8 +261,8 @@ export function CaseSheetPrintLayout({
/>
</section>
<h2 style={{ margin: '8px 0 0', fontSize: 15, fontWeight: 600, lineHeight: '18px' }}>{labels.toothChart}</h2>
<section style={rule}>
<h2 style={{ ...printHeadingStyle(rtl), marginTop: 8 }}>{labels.toothChart}</h2>
<section style={{ ...printRule(rtl), direction: 'ltr' }}>
<CaseSheetFdiChart
connectedTeeth={connectedTeeth}
prosthesisRows={prosthesisRows}
@@ -196,8 +271,8 @@ export function CaseSheetPrintLayout({
/>
</section>
<section style={rule}>
<h2 style={{ margin: 0, fontSize: 15, fontWeight: 600 }}>{labels.prosthesis}</h2>
<section style={printRule(rtl)}>
<h2 style={printHeadingStyle(rtl)}>{labels.prosthesis}</h2>
<div style={{ marginTop: 10 }}>
{prosthesisRows.length === 0 ? (
<div style={{ color: '#64748b', fontSize: 13, lineHeight: '16px' }}>—</div>
@@ -212,23 +287,58 @@ export function CaseSheetPrintLayout({
catalog={prosthesisCatalog}
connectedLabel={row.connected ? labels.connected : null}
rtl={rtl}
fontFamily={printFont}
/>
))
)}
</div>
</section>
<section style={rule}>
<h2 style={{ margin: 0, fontSize: 15, fontWeight: 600 }}>{labels.comments}</h2>
<p style={{ ...body, margin: '4px 0 0', whiteSpace: 'pre-wrap' }}>
{labCase.detail?.comment?.trim() || labels.noComments}
</p>
<section
style={{
...printRule(rtl),
...(rtl ? { direction: 'rtl' as const, paddingBottom: 8 } : {}),
}}
>
<h2 style={printHeadingStyle(rtl)}>{labels.comments}</h2>
{joinedNotes.length === 0 && comments.length === 0 ? (
<p style={{ ...body, margin: '4px 0 0', letterSpacing: 'normal' }}>{labels.noComments}</p>
) : (
<div style={{ marginTop: 4 }}>
{joinedNotes.map((note) => (
<p
key={note}
style={{ ...body, margin: '4px 0 0', whiteSpace: 'pre-wrap', letterSpacing: 'normal' }}
>
{note}
</p>
))}
{comments.map((comment) => (
<div key={comment.id} style={{ marginTop: 8, letterSpacing: 'normal' }}>
<p
style={{
margin: 0,
fontSize: 11,
fontWeight: 600,
color: '#64748b',
letterSpacing: 'normal',
textTransform: 'none',
}}
>
{comment.authorLabel} · {formatCaseDateTime(comment.createdAt, locale)}
</p>
<p style={{ ...body, margin: '2px 0 0', whiteSpace: 'pre-wrap', letterSpacing: 'normal' }}>
{comment.body}
</p>
</div>
))}
</div>
)}
</section>
</div>
);
}
const PRINT_FONT = 'system-ui, Segoe UI, sans-serif';
const BOX_HEIGHT = 28;
type PrintRun = {
@@ -248,6 +358,7 @@ function ProsthesisPrintBox({
code,
catalog,
connectedLabel,
fontFamily,
rtl,
}: {
width: number;
@@ -256,6 +367,7 @@ function ProsthesisPrintBox({
code: string;
catalog: readonly ProsthesisCatalogEntry[];
connectedLabel: string | null;
fontFamily: string;
rtl: boolean;
}) {
const tTreatment = useTranslations('treatment');
@@ -348,7 +460,7 @@ function ProsthesisPrintBox({
y={BOX_HEIGHT / 2}
textAnchor="start"
dominantBaseline="central"
fontFamily={PRINT_FONT}
fontFamily={fontFamily}
fontSize={13}
style={
rtl
@@ -378,7 +490,16 @@ function MetaBlock({ label, value, rtl }: { label: string; value: string; rtl: b
return (
<div>
<p style={{ ...printLabelStyle(rtl), margin: 0 }}>{label}</p>
<p style={{ ...body, margin: '2px 0 0', fontWeight: 500 }}>{value}</p>
<p
style={{
...body,
margin: '2px 0 0',
fontWeight: 500,
...(rtl ? { direction: 'rtl' as const, letterSpacing: 'normal' as const } : {}),
}}
>
{value}
</p>
</div>
);
}
@@ -397,9 +518,27 @@ function PartyBlock({
return (
<div>
<p style={{ ...printLabelStyle(rtl), margin: 0 }}>{label}</p>
<p style={{ margin: '4px 0 0', fontSize: 15, fontWeight: 600 }}>{title}</p>
<p
style={{
margin: '4px 0 0',
fontSize: 15,
fontWeight: 600,
...(rtl ? { direction: 'rtl' as const, letterSpacing: 'normal' as const } : {}),
}}
>
{title}
</p>
{subtitle ? (
<p style={{ margin: '2px 0 0', fontSize: 12, color: '#475569' }}>{subtitle}</p>
<p
style={{
margin: '2px 0 0',
fontSize: 12,
color: '#475569',
...(rtl ? { direction: 'rtl' as const, letterSpacing: 'normal' as const } : {}),
}}
>
{subtitle}
</p>
) : null}
</div>
);