From b5b2e163c98f935aaaa10fa3377f9b9178d48436 Mon Sep 17 00:00:00 2001 From: ZenQuality Date: Sun, 17 May 2026 07:06:59 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20domain=20core=20=E2=80=94=20schemas,=20?= =?UTF-8?q?store,=20equine=20data,=20PDF=20roundtrip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase A — Domain & schemas (15 tests): - Zod schemas: ReportSchema, FindingSchema, PractitionerSchema, SeveritySchema - Types derived via z.infer (single source of truth) - newId() helper with optional prefix Phase B — Equine anatomy + pathology DB (7 tests): - 26 macro zones, axial subzones C1-7/T1-18/L1-6/S1-5 - 31 pathologies, each citing Merck Vet Manual, PubMed, IMAIOS or LCAO - Placeholder SVGs (lateral L/R + dorsal) with data-zone convention - Species registry: equine registered, 8 others remain stubs Phase C — Zustand store (8 tests): - Single source of truth with persist middleware (localStorage key osteo-report-draft) - Actions: hydrate, reset, toggleZone, addFinding, updateFinding, removeFinding, setConclusion/Recommendations/NextAppointment Phase H/I — PDF export + import roundtrip (2 tests): - A4 portrait, pdf-lib StandardFonts - Header (practitioner + animal), anatomy pages (per used view), findings table, conclusion/recommendations/RDV page, page footer with date+page# - Attachment: base64 data URI workaround (pdf-lib treats raw string as base64 input, and rejects cross-realm Uint8Array in jsdom tests) - Import: walks Catalog→Names→EmbeddedFiles→Names array→F stream; inflates via pako directly (bypasses pdf-lib's reference-equality FlateDecode check which fails across module realms in vitest); validates with ReportSchema Tooling: - Add pako 2.x + @types/pako (already transitive of pdf-lib) - Switch vitest 2 → 3 (already done in prior commit) - Add 8 test files (34 tests total green) --- .claude/tasks/IMPLEMENTATION-PLAN.md | 108 +++++++++ package-lock.json | 33 ++- package.json | 2 + public/species/equine/dorsal.svg | 22 ++ public/species/equine/lateral-left.svg | 24 ++ public/species/equine/lateral-right.svg | 24 ++ src/pdf/export.ts | 244 +++++++++++++++++++- src/pdf/import.ts | 102 +++++++- src/species/equine/anatomy.ts | 51 +++- src/species/equine/index.ts | 11 + src/species/equine/pathologies.ts | 294 +++++++++++++++++++++++- src/species/index.ts | 13 ++ src/state/reportStore.ts | 117 +++++++--- tests/unit/lib.id.test.ts | 20 ++ tests/unit/pdf.roundtrip.test.ts | 75 ++++++ tests/unit/schema.finding.test.ts | 53 +++++ tests/unit/schema.report.test.ts | 53 +++++ tests/unit/species.equine.test.ts | 65 ++++++ tests/unit/species.registry.test.ts | 19 ++ tests/unit/state.reportStore.test.ts | 94 ++++++++ 20 files changed, 1383 insertions(+), 41 deletions(-) create mode 100644 .claude/tasks/IMPLEMENTATION-PLAN.md create mode 100644 public/species/equine/dorsal.svg create mode 100644 public/species/equine/lateral-left.svg create mode 100644 public/species/equine/lateral-right.svg create mode 100644 src/species/equine/index.ts create mode 100644 src/species/index.ts create mode 100644 tests/unit/lib.id.test.ts create mode 100644 tests/unit/pdf.roundtrip.test.ts create mode 100644 tests/unit/schema.finding.test.ts create mode 100644 tests/unit/schema.report.test.ts create mode 100644 tests/unit/species.equine.test.ts create mode 100644 tests/unit/species.registry.test.ts create mode 100644 tests/unit/state.reportStore.test.ts diff --git a/.claude/tasks/IMPLEMENTATION-PLAN.md b/.claude/tasks/IMPLEMENTATION-PLAN.md new file mode 100644 index 00000000..2eae6a10 --- /dev/null +++ b/.claude/tasks/IMPLEMENTATION-PLAN.md @@ -0,0 +1,108 @@ +# Implementation Plan — Osteo Report V1 + +Granular tasks, TDD-first when behavior is testable. Each task targets one +coherent change. Tasks are ordered so that each unblocks the next. Estimate +≈ 2-5 min of agent work per task. + +Status legend: `[ ]` todo · `[~]` in progress · `[x]` done · `[s]` skipped. + +--- + +## Phase A — Domain & schemas (foundation, no UI) + +- [ ] **A1** Test: `tests/unit/schema.report.test.ts` — parse a valid sample Report; reject malformed (missing version, bad species, empty animal name); assert `z.infer` matches expected fields. +- [ ] **A2** Implement: flesh `src/schema/report.ts` (already drafted) — re-verify enum, required fields, defaults match test. +- [ ] **A3** Test: `tests/unit/schema.finding.test.ts` — severity enum, free pathology flag, linked zones default empty. +- [ ] **A4** Implement: `src/schema/finding.ts` cleanup (already drafted) + ensure default arrays don't break Zod transform. +- [ ] **A5** Test: `tests/unit/lib.id.test.ts` — `newId('finding')` returns `finding_…`, length, uniqueness over 1000 calls. +- [ ] **A6** Implement: confirm `src/lib/id.ts` passes. + +## Phase B — Equine anatomy data + +- [ ] **B1** Test: `tests/unit/species.equine.test.ts` — `EQUINE_ANATOMY.vertebralFormula` is `{ C7, T18, L6, S5 }`; zones include at least `neck`, `withers`, `thoracic-back`, `lumbar`, `sacrum`, `shoulder-l`, `shoulder-r`, `hip-l`, `hip-r`, `tail`. +- [ ] **B2** Implement: fill `src/species/equine/anatomy.ts` with ~20 macro zones, declare `views`, declare subzones for vertebral zones (T1-T18, C1-C7, L1-L6, S1-S5). +- [ ] **B3** Create placeholder SVGs `lateral-left.svg`, `lateral-right.svg`, `dorsal.svg` in `src/species/equine/` with at least 5 zones per view, conforming to convention (data-zone). +- [ ] **B4** Wire SVG imports via `vite-plugin-svgr` — type the import as React component. +- [ ] **B5** Test: `tests/unit/species.registry.test.ts` — `registerSpecies('equine', ...)` then `getSpecies('equine')` returns pack; `isSpeciesAvailable('chien')` is false. +- [ ] **B6** Implement: register equine pack at module load (`src/species/equine/index.ts`). +- [ ] **B7** Seed: `src/species/equine/pathologies.ts` — populate **30 pathologies** with sourced citations (Merck Vet Manual, IMAIOS, PubMed, equine clinical journals). Each entry: id, label FR, description, category, applicableZones, sources. +- [ ] **B8** Stub: empty `src/species//index.ts` so the registry import doesn't crash. Other species register `undefined` pack — selector marks them disabled. + +## Phase C — State store + +- [ ] **C1** Test: `tests/unit/state.reportStore.test.ts` — `hydrate(report)` sets all fields; `reset()` clears; `toggleZone('z1')` adds then removes; `addFinding(f)` pushes; `updateFinding(id, patch)` merges; `removeFinding(id)` removes; `setConclusion('x')` sets. +- [ ] **C2** Implement: full `reportStore` actions in `src/state/reportStore.ts` — typed via `z.infer`. Persist key `osteo-report-draft`. +- [ ] **C3** Add an `inferDraftFromStore` selector that builds a Report from current store state (used by export). +- [ ] **C4** Test: persist round-trip — write store, simulate page reload (clear in-memory state, re-create from localStorage), assert findings restored. + +## Phase D — Routes & navigation + +- [ ] **D1** Implement: `HomeRoute` UI — 2 large cards: "Nouveau bilan" → `/new`, "Importer un PDF" → file picker. Drag-drop overlay accepts only `.pdf`. +- [ ] **D2** Test: `tests/unit/HomeRoute.test.tsx` — render shows 2 CTAs; click "Nouveau bilan" navigates `/new` (use `MemoryRouter`). +- [ ] **D3** Implement: `NewReportRoute` form — species selector (9 options, 8 disabled badges), practitioner fields (fullName required + phone/email/address/SIRET optional), animal name + owner, sessionDate (default = today). React-hook-form + Zod resolver via `PractitionerSchema` & `ReportSchema.shape.animal`. +- [ ] **D4** Test: `tests/unit/NewReportRoute.test.tsx` — submit empty form shows validation errors; submitting valid form calls `store.hydrate(newReportSeed)` and navigates `/editor`. +- [ ] **D5** Implement: `EditorRoute` — `` + side panels (``, ``, ``, ``). + +## Phase E — Anatomy canvas + +- [ ] **E1** Implement: `AnatomyView` — renders one SVG (lateral L / R / dorsal). Attaches `onClick` to elements with `data-zone`. Highlights zones using `data-selected`, `data-linked` attributes synced with store state. +- [ ] **E2** Test: `tests/unit/AnatomyView.test.tsx` — render with mock SVG that has ``, click → store.toggleZone('z1') called. +- [ ] **E3** Implement: `AnatomyCanvas` — tabs for the 3 views, animate switch with motion. Persists current view in component state. +- [ ] **E4** Implement: `ZoneSelection` chip bar — shows current selection (zone labels), validate-button creates finding. +- [ ] **E5** Implement: `ZoomOverlay` modal — opens when user clicks "zoom" on a macro zone that has subzones. Uses `react-zoom-pan-pinch` inside the dialog. Click on subzone → store.addSubzoneSelection. + +## Phase F — Findings + +- [ ] **F1** Implement: `FindingEditor` — multi-select pathology list filtered by `applicableZones` from current selection. Free-text pathology input. Severity radio. Comment textarea. Linked-zones picker. +- [ ] **F2** Test: `tests/unit/FindingEditor.test.tsx` — selecting two zones from thoracic-back filters pathology list to entries containing that zone; adding a free pathology preserves it on save. +- [ ] **F3** Implement: `FindingPanel` list — shows existing findings (zones, pathologies, severity badge, comment preview); edit/delete actions. + +## Phase G — Conclusion + +- [ ] **G1** Implement: `ConclusionPanel` — textarea conclusion + textarea recommendations + optional date picker for nextAppointment. All wired to store. + +## Phase H — PDF export + +- [ ] **H1** Test: `tests/unit/pdf.export.test.ts` — `exportReport(sample, assets)` returns a Blob whose content starts with `%PDF-`; attachments include `report.json` with parsed content equal to input. +- [ ] **H2** Implement: `src/pdf/render/header.ts` — draw practitioner block + animal/owner/date heading on a page using pdf-lib StandardFonts. +- [ ] **H3** Implement: `src/pdf/render/anatomyPage.ts` — rasterize an SVG view with selected zones highlighted, embed PNG via `pdf.embedPng`. Use html2canvas alternative: serialize SVG with inline `