improvement: Case Sheet PDF type, landscape QR, and filename.

Upscale print type without widening the layout, pad the header so the landscape QR is not clipped, and name downloads case-sheet-{orderNumber}.pdf using the printed external code when set.
This commit is contained in:
2026-10-15 18:47:29 +03:30
parent 3a851fb11f
commit 5b17aa4115
8 changed files with 130 additions and 61 deletions

View File

@@ -15,7 +15,7 @@ alwaysApply: false
- **Outsource** (`POST /cases/:id/outsource`, label `cases.sendCase`): one linked lab, checked in-progress prosthesis-job steps, one `LAB_OUTSOURCE` child case. The child stores the sending lab as `referringClinicName` and clears dentist and partner clinic. Those parent steps leave Tasks until the child completes them (written back with no actor). Sender detail shows only that direct lab. The sender chart stays the full plan; the child chart is the selected jobs plus pontics on that bridge. Recall before any of those steps is completed. Received child cases have Outsource, not Start, Delete, or Edit. Case-level steps stay on the owning lab. Child `sourceKey` is the child case id. When two selected steps share tooth, prosthesis type, and workflow step, `outsourceChildSourceKey` uses `childId:parentSourceKey` so the current-round unique index accepts both. `dedupeToothJobs` includes `sourceKey`.
- **Share link:** QR + URL when the case is sent **or** a lab-origin case is started; token API + focus page — see `.cursor/skills/lab-case-share-link/SKILL.md`.
- **One plan:** a live case has one prosthesis plan. Clinic send still uses `treatmentDetailId` as `sourceKey`. Lab-origin cases use the case id. Outsource children use the child case id, or `childId:parentSourceKey` when two selected steps would collide (see Outsource). `LabCaseLine` is gone. Detail and New case use `UnderlineTabs`: Details, Files, Messages. Files and Messages show unread counts (`LabCaseSectionReadState`); opening Details does not clear them. `ATTACHMENT_ADDED` is not a sidebar badge. Origin is one combobox of linked clinics and labs, or a typed name. Dentist/Technician stays optional. Arch jobs (`UA`/`LA`) highlight the read-only FDI chart.
- **Case Sheet PDF:** same layout for portrait and landscape (Download PDF menu). One A4 page, scaled to fit — the chart is never split. Header is a flex row: current organization name (one line, 48px line box so html2canvas does not clip the glyphs), Nudentic lockup aligned with that text, share QR at 88px inside a 96px frame with `fill` off (a stretched SVG is dropped by html2canvas; not a table cell). The page stays LTR in every locale. On `fa`, the org name is a shrink-wrapped `inline-block` (`direction: ltr` unless the name itself contains Arabic script) with `letter-spacing` and `word-spacing` `0px` — a full-width RTL box gaps Latin words. Party and meta values use `printRtlValueStyle` (Arabic script stays RTL; Latin stays LTR and right-aligned). `FA_RULE_DROP` (6px) clears Persian descenders. `onclone` must not overwrite the name span’s direction. Print ink is `prosthesisTypePrintColorFromCatalog` (heaviest family swatch). Prosthesis rows are SVG boxes. Chart is 85% of the page width with capped glyph height, shared upper column widths, outline-only unselected teeth, root vs crown fills, a larger gap under the upper caption, and matching tooth/number/midline gaps on both arches. Bridge marks match the FDI chart: 10px `#009cae` dots on the column boundary in the tooth-to-number gap. `onclone` sizes the lockup SVGs and the organization-name line box. Hex inline styles only. Optional `externalCode` replaces the order number.
- **Case Sheet PDF:** same layout for portrait and landscape (Download PDF menu). One A4 page, scaled to fit — the chart is never split. Header is a flex row: current organization name (one line, 56px line box so html2canvas does not clip the 28px glyphs), Nudentic lockup aligned with that text, share QR at 88px inside a 96px frame with `fill` off (a stretched SVG is dropped by html2canvas; not a table cell). Print root top padding is 16px portrait / 24px landscape so the QR is not clipped; `html2canvas` `scrollY` is 0. The page stays LTR in every locale. On `fa`, the org name is a shrink-wrapped `inline-block` (`direction: ltr` unless the name itself contains Arabic script) with `letter-spacing` and `word-spacing` `0px` — a full-width RTL box gaps Latin words. Party and meta values use `printRtlValueStyle` (Arabic script stays RTL; Latin stays LTR and right-aligned). Section rules keep a 12px gap and 8px padding so the line clears the values; `FA_RULE_DROP` (6px) clears Persian descenders. `onclone` must not overwrite the name span’s direction. Print ink is `prosthesisTypePrintColorFromCatalog` (heaviest family swatch). Prosthesis rows are SVG boxes. Chart is 85% of the page width with capped glyph height, shared upper column widths, outline-only unselected teeth, root vs crown fills, a larger gap under the upper caption, and matching tooth/number/midline gaps on both arches. Bridge marks match the FDI chart: 10px `#009cae` dots on the column boundary in the tooth-to-number gap. `onclone` sizes the lockup SVGs and the organization-name line box. Hex inline styles only. Optional `externalCode` replaces the printed order number and the `case-sheet-{orderNumber}.pdf` filename.
- **Detail chrome:** **Mark as important** is centered in the header on `lg`. Below that, the header is one compact stack: name and the same QR thumb as desktop (`w-24 sm:w-32`) on the first row, mobile/from/date on one wrapping line, the progress bar without a separate “tasks completed” sentence, important and billed on one row, and Edit / Outsource / Get PDF sharing one row (`responsiveFill`). External code sits under the progress bar in the start column, same width as the bar; billed price is under important on `lg`. Get PDF and Add files are primary `CaseLifecycleButton`s with no icon, the same width as Outsource from `lg` up. **Add case** is a full-width `px-6 py-3 text-base` split (label + mic) matching New treatment and Add detail voice. There is no Comments button, and opening Messages does not scroll the page. File cards: name at the start and checkbox at the end, then a clipped preview, then size over date at the start with the View/Download menu centered at the end. Remove is on that menu (`DELETE /cases/:id/attachments/:attachmentId`, confirm first). An in-progress upload is its own card with a progress bar. The sent-date line reads “Outsource {date}”.
- **Attachments:** no size cap. One file per request, streamed with `orgDiskStorage` (not memory). The client has no axios timeout. The upload queue sits with the toast, so leaving Files or Cases does not cancel it and does not refetch the case; the open case patches from the response. A draft flushes once, then keeps the new file id so autosave does not unlink it. Nginx `/api` uses `client_max_body_size 0`, `send_timeout 3600s`, and `proxy_request_buffering off`. JSON bodies stay on the Express limit; only multipart is unlimited. Production must recreate nginx from the SSL template. Staging also needs the Windows host nginx reloaded. Do not set `Content-Type: multipart/form-data` by hand.
- **Drafts rail:** unstarted lab-origin cases sit in a collapsed `TreatmentRailSection`; expands on click or **Add case**. Main list is received + started cases (`drafts=exclude` / `drafts=only`), newest first by `listedAt` (`LAB_CASE_LIST_ORDER_BY`; trigger `lab_cases_listed_at_sync` = `COALESCE(startedAt, sentAt)`). Never `orderBy startedAt, sentAt` and never a `GENERATED ALWAYS` `listedAt`.

View File

@@ -55,7 +55,7 @@ List item shape: `prosthesisGroups: { prosthesisTypeCode, teeth[], ponticTeeth?
## Case Sheet PDF
**Entry:** Get PDF on `CaseDetailPanel` (primary, same width as Outsource, no icon) — menu chooses portrait or landscape. Organization name uses a 48px line box so the glyphs are not clipped. The page stays LTR in every locale. On the Persian sheet that name is a shrink-wrapped `inline-block` (`data-case-sheet-org-text`, `direction: ltr` unless the name itself contains Arabic script, `letter-spacing` and `word-spacing` `0px`) so html2canvas does not stretch the words across the header column. Party and meta values use `printRtlValueStyle`: Arabic script stays RTL; Latin stays LTR, isolated, and right-aligned under the Persian label. `FA_RULE_DROP` (6px) is the only extra rule margin, so Persian descenders clear the line.
**Entry:** Get PDF on `CaseDetailPanel` (primary, same width as Outsource, no icon) — menu chooses portrait or landscape. Organization name uses a 56px line box so the 28px glyphs are not clipped. The print root has top padding (16px portrait, 24px landscape) so the header QR is not clipped at the page edge. `html2canvas` uses `scrollY: 0` (the host is `position: fixed`). The page stays LTR in every locale. On the Persian sheet that name is a shrink-wrapped `inline-block` (`data-case-sheet-org-text`, `direction: ltr` unless the name itself contains Arabic script, `letter-spacing` and `word-spacing` `0px`) so html2canvas does not stretch the words across the header column. Party and meta values use `printRtlValueStyle`: Arabic script stays RTL; Latin stays LTR, isolated, and right-aligned under the Persian label. Section rules use a 12px gap and 8px padding so the line clears the values; `FA_RULE_DROP` (6px) is the only extra margin, for Persian descenders.
**Builder:** [`caseSheetPdf.ts`](frontend/src/components/lab/caseSheetPdf.ts) → off-screen [`CaseSheetPrintLayout.tsx`](frontend/src/components/ui/lab/CaseSheetPrintLayout.tsx) wrapped in `NextIntlClientProvider` → `html2canvas` → `jspdf` A4 (ISO √2 — prints cleanly onto A3–A6).
### html2canvas + Tailwind v4 (required)
@@ -72,12 +72,12 @@ Stock `html2canvas` **cannot** parse `lab()` / `oklch()` from app CSS. Do **not*
### Layout conventions
- Portrait and landscape use this same tree; only the page pixel size changes. One A4 page, scaled to fit — never slice the canvas.
- Header is a **flex** row: title at the start, Nudentic lockup centered, share QR at the end (same row when there is no QR). The QR is `LabCaseShareQrCode` `fill={false}` inside the padded frame. Do not put that SVG in a table cell — html2canvas then paints an empty box.
- Header is a **flex** row: title at the start, Nudentic lockup centered, share QR at the end (same row when there is no QR). The QR is `LabCaseShareQrCode` `fill={false}` inside the padded frame. Do not put that SVG in a table cell — html2canvas then paints an empty box. Print-root top padding (16px portrait, 24px landscape) keeps the QR off the page edge.
- Sections: meta → parties → **Tooth Chart** heading *above* the horizontal rule → chart → **Prosthesis** rows (SVG rect + text, so the border stays on the label; the chart stays above a long job list) → Comments.
- Prosthesis print ink and selected teeth use the heaviest family swatch (`prosthesisTypePrintColorFromCatalog`), not `prosthesisTypeLabelColorFromCatalog`. Persian print labels and values use `letter-spacing` and `word-spacing` `0px` (not `normal`). Positive letter-spacing makes html2canvas draw each letter alone, so the script stops joining. A full-width `direction: rtl` box also inserts gaps between Latin words — keep RTL only on text that itself contains Arabic script. Prosthesis SVG text is anchored on the inline start for the locale (`fa` starts at the right padding with `direction: rtl`).
- Chart is [`CaseSheetFdiChart`](frontend/src/components/ui/lab/CaseSheetFdiChart.tsx): realistic FDI paths, hex fills, always-on Upper/Lower arch captions. An arch-level job (`UA`/`LA`) boxes that arch with a light tint and a border in the same swatch. Unselected teeth are outline only; a root prosthesis colors the root and a crown prosthesis colors the crown. Width is 85% of the page; glyph height stays capped; both arches share the upper column widths. The upper caption has a larger gap above the teeth. Tooth-to-number and number-to-midline gaps match on both arches. A bridge is the chart’s read-only mark: a 10px `#009cae` dot on the column boundary in that tooth-to-number gap, plus a primary line across a middle tooth.
- Connected badge: bold + underline inside the prosthesis SVG, with a gap (`dx`) before the word so it does not sit on the job text.
- Order number: `externalCode.trim()` when set, else short case id (`id` without hyphens, first 8, uppercased).
- Order number: `externalCode.trim()` when set, else short case id (`id` without hyphens, first 8, uppercased). Download name is `case-sheet-{orderNumber}.pdf` (`caseSheetPdfFileName`); filesystem-unsafe characters in the code are replaced with `-`.
- Share QR when `shareUrl` present.
### API

View File

@@ -72,7 +72,7 @@ frontend/src/
**Lab Tasks tab:** Newest case first (`listedAt`); grouping only for date sort; filters include completed step, origin, due date, assignment, and prosthesis. New tasks are plan-scoped: one scan → prosthesis sections → optional Model design/creation (when any type has `requiresModelSteps`) → packing/shipping. `lineCount` stays 1. `__line__` tasks are independently completable and non-outsourceable; historical `__case__` scan keeps whole-case fan-out. Same-type exclusive steps coalesce across matching teeth; duplicate non-model steps for stacked types become `typeA+typeB` sections. Pontics fold into connected crown/indirect sections. Task identity includes source, first tooth, section type, and workflow code because one section may produce different tooth sets across steps. Job titles use `ProsthesisJobLineLabel`; task assignment is in Cases; only assignee/unassigned pool can update status in Tasks. `CASE_COMPLETED` drives inbox/tab badges only after all case tasks finish. See `.cursor/skills/lab-tasks/SKILL.md`.
**Lab Cases tab:** Filter by **prosthesis type** (not treatment type); auto-select newest case on open; list **10 per page**; left rail list fills column height (`flex-1 overflow-y-auto`). Unstarted lab-origin **drafts** sit in a collapsed expandable rail section (opens on click or **Add case**); received + started cases list below, newest first by send or start time (`listedAt`, same key as Tasks). List cards use `LabCaseProsthesisGroupsList` (colored type + teeth, shared with Treatment rail) plus **From clinic** / **Generated** / **From lab** origin badges. Job titles use `ProsthesisJobLineLabel` the same as Treatment/Tasks (`13 · Pontic - 14 · PFZ Crown`; no category; indirect keeps Inlay · Layered ceramic). Deep link: `?caseId=`, `?clinicOrganizationId=`. **Share link:** QR + URL on sent cases **and** started lab-origin cases (attachment left, QR right); opens `/lab-case/[token]` focus page. **Case Sheet PDF:** same portrait/landscape layout, one A4 page (`jspdf`/`html2canvas`, scaled to fit); realistic FDI chart; hex-only print layout; share QR stays in the flex header; optional `externalCode` replaces order number. The page stays LTR; on Persian sheets the org name is shrink-wrapped (RTL only when the name itself is Arabic script) and labels use `0px` letter-spacing. Lab-origin Start has no clinic send and notifies the linked org once (`PARTNER_CASE_CREATED`, share link); generated-case comments have no visibility toggle. A lab-to-lab case uses the eye button so the sending lab can see that comment. Comments use Cases **or** Tasks permission. Unstarted generated drafts can be deleted (`DELETE /cases/:id`). **Edit** (`POST /cases/:id/stop`) returns a started generated case to that drafts rail: completed steps and the previous prosthesis plan stay as history, in-progress steps are dropped, and the case can be edited and started again. Open outsources with no finished step are cancelled; a finished outsourced step blocks Edit. **Outsource** gives selected in-progress prosthesis steps to one linked lab as a child case. Child `sourceKey` stays the child case id unless two selected steps share tooth, type, and workflow (`childId:parentSourceKey`). The child shows only that sending lab (no original clinic or dentist). Those steps leave Tasks until that lab completes them, and only the sending lab sees that direct handoff. The sender chart stays the full plan; the receiver chart is the selected jobs plus pontics on that bridge. **Live:** inbox Socket.IO → `notifyTabBadgesChanged()` soft-refreshes list + selected detail (no remount). A file upload emits `case-section.changed` on that socket (no inbox card) so Files and Messages unread counts refresh the same way. **Add case** is a full-width split button with the lab mic. One file can be removed from its card menu. An upload keeps running after leaving Files or Cases; the open case adds the file from the upload response without another fetch. Attachments have no size cap; production must recreate nginx from the SSL template or `/api` stays at 50MB. See `.cursor/skills/lab-cases/SKILL.md` and `.cursor/skills/lab-case-share-link/SKILL.md`.
**Lab Cases tab:** Filter by **prosthesis type** (not treatment type); auto-select newest case on open; list **10 per page**; left rail list fills column height (`flex-1 overflow-y-auto`). Unstarted lab-origin **drafts** sit in a collapsed expandable rail section (opens on click or **Add case**); received + started cases list below, newest first by send or start time (`listedAt`, same key as Tasks). List cards use `LabCaseProsthesisGroupsList` (colored type + teeth, shared with Treatment rail) plus **From clinic** / **Generated** / **From lab** origin badges. Job titles use `ProsthesisJobLineLabel` the same as Treatment/Tasks (`13 · Pontic - 14 · PFZ Crown`; no category; indirect keeps Inlay · Layered ceramic). Deep link: `?caseId=`, `?clinicOrganizationId=`. **Share link:** QR + URL on sent cases **and** started lab-origin cases (attachment left, QR right); opens `/lab-case/[token]` focus page. **Case Sheet PDF:** same portrait/landscape layout, one A4 page (`jspdf`/`html2canvas`, scaled to fit); realistic FDI chart; hex-only print layout; share QR stays in the flex header; optional `externalCode` replaces the printed order number and the `case-sheet-{orderNumber}.pdf` filename. The page stays LTR; on Persian sheets the org name is shrink-wrapped (RTL only when the name itself is Arabic script) and labels use `0px` letter-spacing. Lab-origin Start has no clinic send and notifies the linked org once (`PARTNER_CASE_CREATED`, share link); generated-case comments have no visibility toggle. A lab-to-lab case uses the eye button so the sending lab can see that comment. Comments use Cases **or** Tasks permission. Unstarted generated drafts can be deleted (`DELETE /cases/:id`). **Edit** (`POST /cases/:id/stop`) returns a started generated case to that drafts rail: completed steps and the previous prosthesis plan stay as history, in-progress steps are dropped, and the case can be edited and started again. Open outsources with no finished step are cancelled; a finished outsourced step blocks Edit. **Outsource** gives selected in-progress prosthesis steps to one linked lab as a child case. Child `sourceKey` stays the child case id unless two selected steps share tooth, type, and workflow (`childId:parentSourceKey`). The child shows only that sending lab (no original clinic or dentist). Those steps leave Tasks until that lab completes them, and only the sending lab sees that direct handoff. The sender chart stays the full plan; the receiver chart is the selected jobs plus pontics on that bridge. **Live:** inbox Socket.IO → `notifyTabBadgesChanged()` soft-refreshes list + selected detail (no remount). A file upload emits `case-section.changed` on that socket (no inbox card) so Files and Messages unread counts refresh the same way. **Add case** is a full-width split button with the lab mic. One file can be removed from its card menu. An upload keeps running after leaving Files or Cases; the open case adds the file from the upload response without another fetch. Attachments have no size cap; production must recreate nginx from the SSL template or `/api` stays at 50MB. See `.cursor/skills/lab-cases/SKILL.md` and `.cursor/skills/lab-case-share-link/SKILL.md`.
**Lab case share link (quick ref):**
- Token on first ship **or** lab-origin Start → `/{locale}/lab-case/{token}` after login. Editing a generated case keeps that token. The page reads the current round and the live patient/clinic snapshots. Cases, Treatment lab dispatch, and the Case Sheet QR all use this URL.

View File

@@ -1,5 +1,10 @@
import { describe, expect, it } from 'vitest';
import { formatPatientMobile, formatPatientName } from './caseDetailUtils';
import {
caseSheetOrderNumber,
caseSheetPdfFileName,
formatPatientMobile,
formatPatientName,
} from './caseDetailUtils';
const SENTINEL_MOBILE = '__walkin__:83c493d2-fbbc-4b0f-b8bc-1442305cfb2f';
@@ -48,3 +53,35 @@ describe('formatPatientMobile', () => {
);
});
});
describe('caseSheetOrderNumber', () => {
it('uses the trimmed external code when set', () => {
expect(
caseSheetOrderNumber({ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', externalCode: ' EXO-123 ' }),
).toBe('EXO-123');
});
it('falls back to the short uppercased case id', () => {
expect(caseSheetOrderNumber({ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' })).toBe('A1B2C3D4');
});
});
describe('caseSheetPdfFileName', () => {
it('prefixes the printed external code', () => {
expect(
caseSheetPdfFileName({ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', externalCode: 'EXO-123' }),
).toBe('case-sheet-EXO-123.pdf');
});
it('replaces filesystem-unsafe characters in the code', () => {
expect(
caseSheetPdfFileName({ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', externalCode: 'EXO/12:3' }),
).toBe('case-sheet-EXO-12-3.pdf');
});
it('uses the short case id when there is no external code', () => {
expect(caseSheetPdfFileName({ id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' })).toBe(
'case-sheet-A1B2C3D4.pdf',
);
});
});

View File

@@ -122,3 +122,25 @@ export function latestCaseAttachment(labCase: LabCaseDetail) {
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
)[0];
}
const CASE_SHEET_UNSAFE_FILENAME = /[/\\:*?"<>|]/g;
/** Printed order number: external code when set, else short case id. */
export function caseSheetOrderNumber(labCase: {
id: string;
externalCode?: string | null;
}): string {
const external = labCase.externalCode?.trim();
if (external) return external;
return labCase.id.replace(/-/g, '').slice(0, 8).toUpperCase();
}
/** Download name uses the same order number as the printed sheet. */
export function caseSheetPdfFileName(labCase: {
id: string;
externalCode?: string | null;
}): string {
const order = caseSheetOrderNumber(labCase).replace(CASE_SHEET_UNSAFE_FILENAME, '-').trim();
const fallback = labCase.id.replace(/-/g, '').slice(0, 8).toUpperCase();
return `case-sheet-${order || fallback}.pdf`;
}

View File

@@ -10,6 +10,7 @@ import {
type CaseSheetOrientation,
type CaseSheetPrintedComment,
} from '@/components/ui/lab/CaseSheetPrintLayout';
import { caseSheetPdfFileName } from '@/components/lab/caseDetailUtils';
import type { LabCaseDetail } from '@/types/cases';
import type { ProsthesisCatalogEntry } from '@/types/treatment-catalog';
@@ -102,7 +103,7 @@ export async function downloadCaseSheetPdf({
useCORS: true,
logging: false,
scrollX: 0,
scrollY: -window.scrollY,
scrollY: 0,
// Drop app stylesheets so parsers never see lab()/oklch() from Tailwind.
onclone: (clonedDoc) => {
clonedDoc.querySelectorAll('style, link[rel="stylesheet"]').forEach((node) => {
@@ -117,8 +118,8 @@ export async function downloadCaseSheetPdf({
node.style.display = 'flex';
node.style.alignItems = 'center';
node.style.justifyContent = 'flex-start';
node.style.height = '48px';
node.style.lineHeight = '48px';
node.style.height = '56px';
node.style.lineHeight = '56px';
node.style.overflow = 'hidden';
node.style.direction = 'ltr';
node.style.letterSpacing = '0px';
@@ -128,7 +129,7 @@ export async function downloadCaseSheetPdf({
text.style.display = 'inline-block';
text.style.maxWidth = '100%';
text.style.overflow = 'visible';
text.style.lineHeight = '48px';
text.style.lineHeight = '56px';
text.style.paddingTop = '0';
text.style.paddingBottom = '0';
text.style.letterSpacing = '0px';
@@ -138,8 +139,8 @@ export async function downloadCaseSheetPdf({
});
clonedDoc.querySelectorAll('[data-case-sheet-lockup]').forEach((node) => {
if (!(node instanceof HTMLElement)) return;
node.style.height = '28px';
node.style.lineHeight = '28px';
node.style.height = '32px';
node.style.lineHeight = '32px';
node.style.overflow = 'hidden';
});
clonedDoc.querySelectorAll('[data-case-sheet-lockup] svg').forEach((node) => {
@@ -148,7 +149,7 @@ export async function downloadCaseSheetPdf({
const vbW = parts[2];
const vbH = parts[3];
if (!vbW || !vbH) return;
const height = 22;
const height = 26;
const width = Math.max(1, Math.round(height * (vbW / vbH)));
node.setAttribute('width', String(width));
node.setAttribute('height', String(height));
@@ -181,9 +182,7 @@ export async function downloadCaseSheetPdf({
const x = margin + (usableWidth - drawWidth) / 2;
pdf.addImage(imgData, 'PNG', x, margin, drawWidth, drawHeight);
const safeName =
fileName ??
`case-sheet-${labCase.id.replace(/-/g, '').slice(0, 8)}.pdf`;
const safeName = fileName ?? caseSheetPdfFileName(labCase);
pdf.save(safeName);
} finally {
root.unmount();

View File

@@ -346,9 +346,9 @@ function ArchCaption({
style={{
margin: 0,
textAlign: 'center',
fontSize: 11,
fontSize: 14,
fontWeight: 600,
lineHeight: '13px',
lineHeight: '16px',
color: color ?? PLAIN_CAPTION,
...(rtl
? { direction: 'rtl' as const, letterSpacing: 'normal' as const, textTransform: 'none' as const }
@@ -391,7 +391,7 @@ function NumberRow({
columnWidths: readonly number[];
}) {
const width = columnWidths.reduce((sum, column) => sum + column, 0);
const height = 12;
const height = 16;
let cursor = 0;
return (
<svg
@@ -414,7 +414,7 @@ function NumberRow({
dominantBaseline="central"
fill={NUMBER_INK}
fontFamily="system-ui, Segoe UI, sans-serif"
fontSize={11}
fontSize={14}
fontWeight={600}
>
{fdi}

View File

@@ -6,6 +6,7 @@ import { LabCaseShareQrCode } from '@/components/ui/lab/LabCaseShareQrCode';
import {
buildCaseConnectedTeeth,
buildCaseProsthesisRows,
caseSheetOrderNumber,
formatCaseDateTime,
formatPatientMobile,
formatPatientName,
@@ -77,8 +78,9 @@ const PAGE_SIZE: Record<CaseSheetOrientation, { width: number; height: number }>
function printLabelStyle(rtl: boolean) {
return {
color: '#64748b',
fontSize: 11,
fontSize: 14,
fontWeight: 600,
lineHeight: '18px',
...(rtl
? {
direction: 'rtl' as const,
@@ -94,9 +96,9 @@ function printLabelStyle(rtl: boolean) {
function printHeadingStyle(rtl: boolean) {
return {
margin: 0,
fontSize: 15,
fontSize: 20,
fontWeight: 600,
lineHeight: '18px',
lineHeight: '26px',
...(rtl
? {
direction: 'rtl' as const,
@@ -108,9 +110,11 @@ function printHeadingStyle(rtl: boolean) {
: {}),
};
}
const body = { color: '#0f172a', fontSize: 13, lineHeight: '16px' };
const body = { color: '#0f172a', fontSize: 17, lineHeight: '22px' };
/** Extra drop so Farsi descenders clear the rule. Latin layouts stay put. */
/** Gap above a section rule so the line sits clear of the values above it. */
const RULE_GAP = 12;
/** Extra drop so Farsi descenders clear the rule. */
const FA_RULE_DROP = 6;
const ARABIC_SCRIPT = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF]/;
@@ -134,8 +138,8 @@ function printRtlValueStyle(value: string) {
function printRule(rtl: boolean) {
return {
borderTop: '1px solid #cbd5e1',
marginTop: rtl ? 8 + FA_RULE_DROP : 8,
paddingTop: 6,
marginTop: rtl ? RULE_GAP + FA_RULE_DROP : RULE_GAP,
paddingTop: 8,
};
}
@@ -159,8 +163,7 @@ export function CaseSheetPrintLayout({
const labName =
labCase.sends[0]?.organizationName ??
(labCase.sends.map((s) => s.organizationName).filter(Boolean).join(', ') || '—');
const fallbackOrder = labCase.id.replace(/-/g, '').slice(0, 8).toUpperCase();
const orderNumber = labCase.externalCode?.trim() || fallbackOrder;
const orderNumber = caseSheetOrderNumber(labCase);
const orderDate = labCase.sentAt ?? labCase.startedAt ?? null;
const page = PAGE_SIZE[orientation];
const contentWidth = page.width - 48;
@@ -180,12 +183,15 @@ export function CaseSheetPrintLayout({
style={{
boxSizing: 'border-box',
width: page.width,
padding: rtl ? '0 24px 20px' : '0 24px 8px',
paddingTop: orientation === 'landscape' ? 24 : 16,
paddingRight: 24,
paddingBottom: rtl ? 20 : 8,
paddingLeft: 24,
backgroundColor: '#ffffff',
color: '#0f172a',
fontFamily: printFont,
fontSize: '13px',
lineHeight: '16px',
fontSize: '17px',
lineHeight: '22px',
direction: 'ltr',
...(rtl ? { letterSpacing: '0px' as const, wordSpacing: '0px' as const } : {}),
}}
@@ -196,7 +202,7 @@ export function CaseSheetPrintLayout({
alignItems: 'center',
gap: 12,
borderBottom: '1px solid #cbd5e1',
paddingBottom: rtl ? 8 + FA_RULE_DROP : 8,
paddingBottom: rtl ? RULE_GAP + FA_RULE_DROP : RULE_GAP,
}}
>
<div
@@ -209,13 +215,13 @@ export function CaseSheetPrintLayout({
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-start',
// Taller than the 22px glyphs. html2canvas clips the bottoms of
// letters when this box is only as tall as the lockup (28px).
height: 48,
// Taller than the 28px glyphs. html2canvas clips the bottoms of
// letters when this box is only as tall as the lockup (32px).
height: 56,
overflow: 'hidden',
fontSize: 22,
fontSize: 28,
fontWeight: 600,
lineHeight: '48px',
lineHeight: '56px',
direction: 'ltr',
letterSpacing: '0px',
wordSpacing: '0px',
@@ -227,7 +233,7 @@ export function CaseSheetPrintLayout({
display: 'inline-block',
maxWidth: '100%',
overflow: 'visible',
lineHeight: '48px',
lineHeight: '56px',
whiteSpace: 'nowrap',
verticalAlign: 'middle',
letterSpacing: '0px',
@@ -247,13 +253,13 @@ export function CaseSheetPrintLayout({
style={{
flexShrink: 0,
alignSelf: 'center',
height: 28,
height: 32,
color: '#0f172a',
fontSize: 22,
lineHeight: '28px',
fontSize: 26,
lineHeight: '32px',
}}
>
<BrandLockup style={{ display: 'inline-flex', alignItems: 'center', height: 28, verticalAlign: 'middle' }} />
<BrandLockup style={{ display: 'inline-flex', alignItems: 'center', height: 32, verticalAlign: 'middle' }} />
</div>
<div style={{ flex: 1, display: 'flex', justifyContent: 'flex-end', minWidth: 0 }}>
{labCase.shareUrl ? (
@@ -286,8 +292,9 @@ export function CaseSheetPrintLayout({
style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
alignItems: 'start',
gap: 12,
marginTop: 8,
marginTop: RULE_GAP,
}}
>
<MetaBlock label={labels.orderNumber} value={orderNumber} rtl={rtl} />
@@ -299,6 +306,7 @@ export function CaseSheetPrintLayout({
style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
alignItems: 'start',
gap: 12,
...printRule(rtl),
}}
@@ -313,7 +321,7 @@ export function CaseSheetPrintLayout({
/>
</section>
<h2 style={{ ...printHeadingStyle(rtl), marginTop: 8 }}>{labels.toothChart}</h2>
<h2 style={{ ...printHeadingStyle(rtl), marginTop: RULE_GAP }}>{labels.toothChart}</h2>
<section style={{ ...printRule(rtl), direction: 'ltr' }}>
<CaseSheetFdiChart
connectedTeeth={connectedTeeth}
@@ -325,9 +333,9 @@ export function CaseSheetPrintLayout({
<section style={printRule(rtl)}>
<h2 style={printHeadingStyle(rtl)}>{labels.prosthesis}</h2>
<div style={{ marginTop: 10 }}>
<div style={{ marginTop: 8 }}>
{prosthesisRows.length === 0 ? (
<div style={{ color: '#64748b', fontSize: 13, lineHeight: '16px' }}>—</div>
<div style={{ color: '#64748b', fontSize: 17, lineHeight: '22px' }}>—</div>
) : (
prosthesisRows.map((row) => (
<ProsthesisPrintBox
@@ -366,12 +374,13 @@ export function CaseSheetPrintLayout({
</p>
))}
{comments.map((comment) => (
<div key={comment.id} style={{ marginTop: 8, letterSpacing: 'normal' }}>
<div key={comment.id} style={{ marginTop: 6, letterSpacing: 'normal' }}>
<p
style={{
margin: 0,
fontSize: 11,
fontSize: 14,
fontWeight: 600,
lineHeight: '18px',
color: '#64748b',
letterSpacing: 'normal',
textTransform: 'none',
@@ -391,7 +400,7 @@ export function CaseSheetPrintLayout({
);
}
const BOX_HEIGHT = 28;
const BOX_HEIGHT = 40;
type PrintRun = {
text: string;
@@ -440,7 +449,7 @@ function ProsthesisPrintBox({
text: prosthesisJobLineSeparator(previous.kind),
fill: '#64748b',
weight: 400,
size: 13,
size: 18,
});
}
if (segment.kind === 'teeth') {
@@ -449,19 +458,19 @@ function ProsthesisPrintBox({
text: segment.text,
fill: typeCode ? prosthesisTypePrintColorFromCatalog(typeCode, catalog) : '#0f172a',
weight: 600,
size: 13,
size: 18,
});
} else if (segment.kind === 'pontic') {
runs.push({
text: segment.text,
fill: prosthesisTypePrintColorFromCatalog(PONTIC_CODE, catalog),
weight: 500,
size: 13,
size: 18,
});
} else {
splitProsthesisGroupCode(segment.code).forEach((part, partIndex) => {
if (partIndex > 0) {
runs.push({ text: ' + ', fill: '#64748b', weight: 400, size: 13 });
runs.push({ text: ' + ', fill: '#64748b', weight: 400, size: 18 });
}
const path = prosthesisJobPathParts(part, catalog, tr);
const fill = prosthesisTypePrintColorFromCatalog(part, catalog);
@@ -470,10 +479,10 @@ function ProsthesisPrintBox({
text: `${path.ancestors.join(PROSTHESIS_JOB_PATH_SEP)}${PROSTHESIS_JOB_PATH_SEP}`,
fill,
weight: 400,
size: 13,
size: 18,
});
}
runs.push({ text: path.leaf, fill, weight: 600, size: 13 });
runs.push({ text: path.leaf, fill, weight: 600, size: 18 });
});
}
});
@@ -482,7 +491,7 @@ function ProsthesisPrintBox({
text: connectedLabel.toUpperCase(),
fill: '#334155',
weight: 700,
size: 11,
size: 14,
underline: true,
dx: rtl ? -16 : 16,
});
@@ -513,7 +522,7 @@ function ProsthesisPrintBox({
textAnchor="start"
dominantBaseline="central"
fontFamily={fontFamily}
fontSize={13}
fontSize={18}
style={
rtl
? { direction: 'rtl', unicodeBidi: 'embed' }
@@ -572,9 +581,10 @@ function PartyBlock({
<p style={{ ...printLabelStyle(rtl), margin: 0 }}>{label}</p>
<p
style={{
margin: '4px 0 0',
fontSize: 15,
margin: '2px 0 0',
fontSize: 20,
fontWeight: 600,
lineHeight: '26px',
...(rtl ? printRtlValueStyle(title) : {}),
}}
>
@@ -584,7 +594,8 @@ function PartyBlock({
<p
style={{
margin: '2px 0 0',
fontSize: 12,
fontSize: 15,
lineHeight: '20px',
color: '#475569',
...(rtl ? printRtlValueStyle(subtitle) : {}),
}}