feat(editor): findings tree picker + scope disclaimer + PDF render

Replaces the flat PathologyPicker with FindingsTreePicker — breadcrumb
navigation, drill into intermediate categories, toggle leaves, optional
vet-referral badge, optional description rendering. One picker per zone
that has a catalog entry; zones without a tree fall back to the free-text
input (renamed FreeTextFindingInput to match the new vocabulary).

EditorRoute now loads SpeciesFindings instead of a Pathology[] and shows
the scope_disclaimer once per session via a sessionStorage flag so the
practitioner is reminded of the legal perimeter the first time.

PDF observationPage renders findings via the snapshotted FR label and
prefixes ⚠ on vet-referral items, keeping the existing layout pipeline
intact (LRN-007/008/009 still apply).

Also drops the unused Toast and ZoneTooltip stubs, refreshes the
CLAUDE.md folder map, and adds a FindingsTreePicker test covering
navigation, leaf toggle, vet-referral flag, and back-out.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 03:49:11 +02:00
1 parent d08d773d74
commit b67f4cd82b
12 files changed
+473 -186

No files matched your search

-3
View File
@@ -1,3 +0,0 @@
export default function ZoneTooltip() {
return <div>ZoneTooltip placeholder</div>
}
@@ -0,0 +1,208 @@
import { useMemo, useState } from 'react'
import type {
FindingNode,
ZoneFindings,
} from '@/domain/schema/findings'
import type { Finding } from '@/domain/schema/observation'
import Button from '@/components/ui/Button'
export interface FindingsTreePickerProps {
zoneId: string
tree: ZoneFindings
selected: Finding[]
onChange: (next: Finding[]) => void
}
function isLeaf(node: FindingNode): boolean {
return !node.children || node.children.length === 0
}
function samePath(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false
for (let i = 0; i < a.length; i += 1) {
if (a[i] !== b[i]) return false
}
return true
}
function findNode(
categories: FindingNode[],
path: string[],
): FindingNode | undefined {
let nodes: FindingNode[] = categories
let node: FindingNode | undefined
for (const segment of path) {
node = nodes.find((n) => n.id === segment)
if (!node) return undefined
nodes = node.children ?? []
}
return node
}
export default function FindingsTreePicker({
zoneId,
tree,
selected,
onChange,
}: FindingsTreePickerProps) {
const [path, setPath] = useState<string[]>([])
const currentNodes = useMemo<FindingNode[]>(() => {
if (path.length === 0) return tree.categories
const node = findNode(tree.categories, path)
return node?.children ?? []
}, [tree, path])
const focusedNode = useMemo(
() => (path.length === 0 ? undefined : findNode(tree.categories, path)),
[tree, path],
)
const breadcrumb = useMemo<{ label: string; depth: number }[]>(() => {
const crumbs: { label: string; depth: number }[] = [
{ label: tree.name_fr, depth: 0 },
]
let nodes: FindingNode[] = tree.categories
path.forEach((seg, i) => {
const n = nodes.find((x) => x.id === seg)
if (n) {
crumbs.push({ label: n.name_fr, depth: i + 1 })
nodes = n.children ?? []
}
})
return crumbs
}, [tree, path])
function isLeafSelected(leafPath: string[]): boolean {
return selected.some(
(f) => f.zoneId === zoneId && samePath(f.path, leafPath),
)
}
function toggleLeaf(leafPath: string[], leaf: FindingNode) {
if (isLeafSelected(leafPath)) {
onChange(
selected.filter(
(f) => !(f.zoneId === zoneId && samePath(f.path, leafPath)),
),
)
return
}
const next: Finding = {
zoneId,
path: leafPath,
labelFrSnapshot: leaf.name_fr,
labelEnSnapshot: leaf.name_en,
}
if (leaf.requires_vet_referral) next.requiresVetReferral = true
onChange([...selected, next])
}
return (
<div className="space-y-2">
<div className="flex flex-wrap items-center gap-1 text-xs text-[var(--color-ink-muted)]">
{breadcrumb.map((c, i) => {
const isLast = i === breadcrumb.length - 1
return (
<span key={`${c.label}-${i}`} className="flex items-center gap-1">
<button
type="button"
onClick={() => setPath(path.slice(0, c.depth))}
disabled={isLast}
className={
isLast
? 'text-[var(--color-ink)] font-medium'
: 'underline text-[var(--color-accent-strong)]'
}
>
{c.label}
</button>
{!isLast && <span aria-hidden="true">›</span>}
</span>
)
})}
</div>
{focusedNode?.description_fr && (
<p className="text-xs italic text-[var(--color-ink-muted)]">
{focusedNode.description_fr}
</p>
)}
{path.length > 0 && (
<Button
size="sm"
variant="ghost"
onClick={() => setPath(path.slice(0, -1))}
aria-label="Retour au niveau précédent"
>
← Retour
</Button>
)}
<ul className="space-y-1.5 max-h-64 overflow-auto pr-1">
{currentNodes.length === 0 ? (
<li className="text-sm text-[var(--color-ink-muted)]">
Aucune option disponible à ce niveau.
</li>
) : (
currentNodes.map((node) => {
const nodePath = [...path, node.id]
if (isLeaf(node)) {
const checked = isLeafSelected(nodePath)
return (
<li key={node.id}>
<label className="flex items-start gap-2 cursor-pointer">
<input
type="checkbox"
checked={checked}
onChange={() => toggleLeaf(nodePath, node)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={node.name_fr}
/>
<div className="flex-1">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{node.name_fr}
</span>
{node.requires_vet_referral && (
<span
title="Référer au vétérinaire"
aria-label="Référer au vétérinaire"
className="text-[var(--color-danger)]"
>
⚠
</span>
)}
</div>
{node.description_fr && (
<div className="text-xs text-[var(--color-ink-muted)]">
{node.description_fr}
</div>
)}
</div>
</label>
</li>
)
}
return (
<li key={node.id}>
<button
type="button"
onClick={() => setPath(nodePath)}
className="flex items-center justify-between w-full text-left text-sm px-2 py-1.5 rounded hover:bg-[var(--color-surface-strong)] text-[var(--color-ink)]"
aria-label={`Ouvrir ${node.name_fr}`}
>
<span>{node.name_fr}</span>
<span aria-hidden="true" className="text-[var(--color-ink-muted)]">
›
</span>
</button>
</li>
)
})
)}
</ul>
</div>
)
}
@@ -3,36 +3,46 @@ import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
export interface FreeTextPathologyInputProps {
export interface FreeTextFindingInputProps {
items: string[]
onChange: (next: string[]) => void
}
export default function FreeTextPathologyInput({
export default function FreeTextFindingInput({
items,
onChange,
}: FreeTextPathologyInputProps) {
}: FreeTextFindingInputProps) {
const [v, setV] = useState('')
function add() {
const trimmed = v.trim()
if (!trimmed) return
onChange([...items, trimmed])
setV('')
}
function remove(i: number) {
onChange(items.filter((_, k) => k !== i))
}
return (
<div className="space-y-2">
<div className="flex gap-2">
<Input
value={v}
onChange={(e) => setV(e.target.value)}
placeholder="Pathologie additionnelle (texte libre)"
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); add() } }}
aria-label="Pathologie libre"
placeholder="Observation additionnelle (texte libre)"
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
add()
}
}}
aria-label="Observation libre"
/>
<Button onClick={add} variant="secondary">Ajouter</Button>
<Button onClick={add} variant="secondary">
Ajouter
</Button>
</div>
{items.length > 0 && (
<ul className="flex flex-wrap gap-2">
+54 -27
View File
@@ -1,5 +1,9 @@
import type { Observation, ObservationZone, Vertebra } from '@/domain/schema/observation'
import type { Pathology } from '@/domain/schema/pathology'
import type {
Observation,
ObservationZone,
Vertebra,
} from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card'
@@ -7,8 +11,8 @@ import Badge from '@/components/ui/Badge'
import Button from '@/components/ui/Button'
import Label from '@/components/ui/Label'
import Textarea from '@/components/ui/Textarea'
import PathologyPicker from './PathologyPicker'
import FreeTextPathologyInput from './FreeTextPathologyInput'
import FindingsTreePicker from './FindingsTreePicker'
import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector'
export interface ObservationCardProps {
@@ -23,8 +27,7 @@ export interface ObservationCardProps {
canMoveDown: boolean
// Editor body props (used only when expanded)
bones: Map<string, Bone>
speciesId: string
pathologyPool: Pathology[]
findings: SpeciesFindings | null
onChange: (next: Observation) => void
onOpenVertebraPicker: (zoneIndex: number) => void
onRemoveZone: (zoneIndex: number) => void
@@ -53,15 +56,14 @@ export default function ObservationCard({
canMoveUp,
canMoveDown,
bones,
speciesId,
pathologyPool,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
}: ObservationCardProps) {
const zoneCount = observation.zones.length
const patCount =
observation.pathologyIds.length + observation.freeTextPathologies.length
const findingCount =
observation.findings.length + observation.freeTextFindings.length
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') {
@@ -77,7 +79,13 @@ export default function ObservationCard({
}
}
const zoneBoneIds = observation.zones.map((z) => z.boneId)
// Deduplicate zones by boneId so we don't render the same picker tree twice.
const uniqueZoneIds = Array.from(new Set(observation.zones.map((z) => z.boneId)))
const zonesWithTree = uniqueZoneIds
.map((id) => ({ id, tree: findings?.zones[id] }))
.filter((z): z is { id: string; tree: NonNullable<typeof z.tree> } =>
Boolean(z.tree),
)
return (
<Card
@@ -115,8 +123,8 @@ export default function ObservationCard({
)}
</div>
<div className="text-sm text-[var(--color-ink-muted)]">
{zoneCount} zone{zoneCount > 1 ? 's' : ''} · {patCount} pathologie
{patCount > 1 ? 's' : ''}
{zoneCount} zone{zoneCount > 1 ? 's' : ''} · {findingCount} constat
{findingCount > 1 ? 's' : ''}
</div>
{!expanded && observation.comment && (
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
@@ -220,24 +228,43 @@ export default function ObservationCard({
</section>
<section>
<Label>Pathologies (référence)</Label>
<PathologyPicker
pool={pathologyPool}
speciesId={speciesId}
boneIds={zoneBoneIds}
selected={observation.pathologyIds}
onChange={(ids) =>
onChange({ ...observation, pathologyIds: ids })
}
/>
<Label>Constats (référentiel)</Label>
{zonesWithTree.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{observation.zones.length === 0
? 'Sélectionnez une zone pour accéder au référentiel.'
: 'Aucun référentiel disponible pour ces zones. Utilisez le texte libre ci-dessous.'}
</p>
) : (
<div className="space-y-4">
{zonesWithTree.map(({ id, tree }) => (
<div
key={id}
className="rounded-xl border border-[var(--color-border)] p-3 bg-[var(--color-surface)]"
>
<div className="text-xs uppercase tracking-wide text-[var(--color-ink-muted)] mb-2">
{tree.name_fr}
</div>
<FindingsTreePicker
zoneId={id}
tree={tree}
selected={observation.findings}
onChange={(next) =>
onChange({ ...observation, findings: next })
}
/>
</div>
))}
</div>
)}
</section>
<section>
<Label>Pathologies (texte libre)</Label>
<FreeTextPathologyInput
items={observation.freeTextPathologies}
<Label>Constats (texte libre)</Label>
<FreeTextFindingInput
items={observation.freeTextFindings}
onChange={(items) =>
onChange({ ...observation, freeTextPathologies: items })
onChange({ ...observation, freeTextFindings: items })
}
/>
</section>
@@ -1,5 +1,5 @@
import type { Observation } from '@/domain/schema/observation'
import type { Pathology } from '@/domain/schema/pathology'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import ObservationCard from './ObservationCard'
import Button from '@/components/ui/Button'
@@ -14,8 +14,7 @@ export interface ObservationListProps {
onMoveDown: (i: number) => void
// Editor body props forwarded to each card
bones: Map<string, Bone>
speciesId: string
pathologyPool: Pathology[]
findings: SpeciesFindings | null
onChange: (i: number, next: Observation) => void
onOpenVertebraPicker: (i: number, zoneIndex: number) => void
onRemoveZone: (i: number, zoneIndex: number) => void
@@ -30,8 +29,7 @@ export default function ObservationList({
onMoveUp,
onMoveDown,
bones,
speciesId,
pathologyPool,
findings,
onChange,
onOpenVertebraPicker,
onRemoveZone,
@@ -66,8 +64,7 @@ export default function ObservationList({
canMoveUp={i > 0}
canMoveDown={i < observations.length - 1}
bones={bones}
speciesId={speciesId}
pathologyPool={pathologyPool}
findings={findings}
onChange={(next) => onChange(i, next)}
onOpenVertebraPicker={(zoneIndex) =>
onOpenVertebraPicker(i, zoneIndex)
@@ -1,65 +0,0 @@
import { useMemo } from 'react'
import type { Pathology } from '@/domain/schema/pathology'
export interface PathologyPickerProps {
pool: Pathology[]
speciesId: string
boneIds: string[]
selected: string[]
onChange: (next: string[]) => void
}
function matches(p: Pathology, speciesId: string, boneIds: string[]): boolean {
const speciesOk = p.speciesIds.length === 0 || p.speciesIds.includes(speciesId)
if (!speciesOk) return false
if (boneIds.length === 0) return true
if (p.boneIds.length === 0) return true
return p.boneIds.some((b) => boneIds.includes(b))
}
export default function PathologyPicker({
pool,
speciesId,
boneIds,
selected,
onChange,
}: PathologyPickerProps) {
const filtered = useMemo(
() => pool.filter((p) => matches(p, speciesId, boneIds)),
[pool, speciesId, boneIds],
)
function toggle(id: string) {
onChange(selected.includes(id) ? selected.filter((x) => x !== id) : [...selected, id])
}
if (filtered.length === 0) {
return (
<p className="text-sm text-[var(--color-ink-muted)]">
Aucune pathologie de référence pour ces zones. Ajoutez-en une en texte libre ci-dessous.
</p>
)
}
return (
<ul className="space-y-2 max-h-64 overflow-auto pr-1">
{filtered.map((p) => (
<li key={p.id}>
<label className="flex items-start gap-2 cursor-pointer">
<input
type="checkbox"
checked={selected.includes(p.id)}
onChange={() => toggle(p.id)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={p.labelFr}
/>
<div>
<div className="text-sm font-medium text-[var(--color-ink)]">{p.labelFr}</div>
<div className="text-xs text-[var(--color-ink-muted)]">{p.description}</div>
</div>
</label>
</li>
))}
</ul>
)
}
-3
View File
@@ -1,3 +0,0 @@
export default function Toast() {
return <div>Toast placeholder</div>
}