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

+7 -7
View File
@@ -121,11 +121,11 @@ osteo/
│ │ │ ├─ observation.ts │ │ │ ├─ observation.ts
│ │ │ ├─ practitioner.ts │ │ │ ├─ practitioner.ts
│ │ │ ├─ animal.ts │ │ │ ├─ animal.ts
│ │ │ └─ pathology.ts │ │ │ └─ findings.ts
│ │ └─ species/ │ │ └─ species/
│ │ ├─ types.ts ← SpeciesManifest interface │ │ ├─ types.ts ← SpeciesManifest interface
│ │ ├─ registry.ts ← getSpecies(), getAllSpecies() │ │ ├─ registry.ts ← getSpecies(), getAllSpecies()
│ │ └─ equine/{index,vertebrae,pathologies}.ts │ │ └─ equine/{index,vertebrae,pathologies}.{ts,json}
│ ├─ state/ │ ├─ state/
│ │ ├─ reportStore.ts ← Zustand store │ │ ├─ reportStore.ts ← Zustand store
│ │ └─ practitionerCache.ts ← localStorage prefill │ │ └─ practitionerCache.ts ← localStorage prefill
@@ -134,11 +134,11 @@ osteo/
│ │ ├─ svgConvention.ts ← parseSvgBones() │ │ ├─ svgConvention.ts ← parseSvgBones()
│ │ └─ svgLoader.ts ← loadSvg(), svgToPngDataUrl() │ │ └─ svgLoader.ts ← loadSvg(), svgToPngDataUrl()
│ ├─ components/ │ ├─ components/
│ │ ├─ ui/{Button,Card,Dialog,Input,Label,Select,Textarea,Badge,Chip,Toast}.tsx │ │ ├─ ui/{Button,Card,Dialog,Input,Label,Select,Textarea,Badge,Chip}.tsx
│ │ ├─ canvas/{AnatomyCanvas,DetailModal,ZoneTooltip}.tsx │ │ ├─ canvas/{AnatomyCanvas,DetailModal}.tsx
│ │ ├─ observation/{ObservationList,ObservationCard,ObservationEditor, │ │ ├─ observation/{ObservationList,ObservationCard,FindingsTreePicker,
│ │ │ PathologyPicker,VertebraPicker,SeveritySelector, │ │ │ VertebraPicker,SeveritySelector,
│ │ │ FreeTextPathologyInput}.tsx │ │ │ FreeTextFindingInput}.tsx
│ │ ├─ report/{ReportHeader,PractitionerForm,AnimalForm, │ │ ├─ report/{ReportHeader,PractitionerForm,AnimalForm,
│ │ │ ConclusionPanel,NextAppointmentPicker}.tsx │ │ │ ConclusionPanel,NextAppointmentPicker}.tsx
│ │ └─ brand/Brand.tsx │ │ └─ brand/Brand.tsx
+37 -5
View File
@@ -19,11 +19,13 @@ import { loadSvg } from '@/anatomy/svgLoader'
import { parseSvgBones } from '@/anatomy/svgConvention' import { parseSvgBones } from '@/anatomy/svgConvention'
import type { Bone, BoneState } from '@/anatomy/types' import type { Bone, BoneState } from '@/anatomy/types'
import type { Observation, ObservationZone } from '@/domain/schema/observation' import type { Observation, ObservationZone } from '@/domain/schema/observation'
import type { Pathology } from '@/domain/schema/pathology' import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Practitioner } from '@/domain/schema/practitioner' import type { Practitioner } from '@/domain/schema/practitioner'
import type { Animal, Owner } from '@/domain/schema/animal' import type { Animal, Owner } from '@/domain/schema/animal'
import { exportReportToPdf } from '@/pdf/export' import { exportReportToPdf } from '@/pdf/export'
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
export default function EditorRoute() { export default function EditorRoute() {
const navigate = useNavigate() const navigate = useNavigate()
const report = useReportStore((s) => s.report) const report = useReportStore((s) => s.report)
@@ -43,7 +45,8 @@ export default function EditorRoute() {
const [bones, setBones] = useState<Map<string, Bone>>(new Map()) const [bones, setBones] = useState<Map<string, Bone>>(new Map())
const [detailBones, setDetailBones] = useState<Map<string, Bone>>(new Map()) const [detailBones, setDetailBones] = useState<Map<string, Bone>>(new Map())
const [pathologies, setPathologies] = useState<Pathology[]>([]) const [findings, setFindings] = useState<SpeciesFindings | null>(null)
const [disclaimer, setDisclaimer] = useState<string | null>(null)
const [detail, setDetail] = useState<{ const [detail, setDetail] = useState<{
id: string id: string
src: string src: string
@@ -86,6 +89,13 @@ export default function EditorRoute() {
closeEditInfos() closeEditInfos()
} }
function acknowledgeDisclaimer() {
if (typeof sessionStorage !== 'undefined') {
sessionStorage.setItem(DISCLAIMER_FLAG, '1')
}
setDisclaimer(null)
}
useEffect(() => { useEffect(() => {
if (!report) navigate('/') if (!report) navigate('/')
}, [report, navigate]) }, [report, navigate])
@@ -98,9 +108,16 @@ export default function EditorRoute() {
useEffect(() => { useEffect(() => {
if (!species) return if (!species) return
loadSvg(species.mainSvg).then((root) => setBones(parseSvgBones(root))) loadSvg(species.mainSvg).then((root) => setBones(parseSvgBones(root)))
species.pathologies().then((m) => setPathologies(m.default)) species.findings().then((m) => setFindings(m.default))
}, [species]) }, [species])
useEffect(() => {
if (!findings) return
if (typeof sessionStorage === 'undefined') return
if (sessionStorage.getItem(DISCLAIMER_FLAG)) return
setDisclaimer(findings.scope_disclaimer)
}, [findings])
useEffect(() => { useEffect(() => {
if (!detail) return if (!detail) return
let cancelled = false let cancelled = false
@@ -248,8 +265,7 @@ export default function EditorRoute() {
onMoveUp={moveObservationUp} onMoveUp={moveObservationUp}
onMoveDown={moveObservationDown} onMoveDown={moveObservationDown}
bones={allBones} bones={allBones}
speciesId={species.id} findings={findings}
pathologyPool={pathologies}
onChange={(i, next: Observation) => updateObservation(i, next)} onChange={(i, next: Observation) => updateObservation(i, next)}
onOpenVertebraPicker={(_i, zoneIndex) => onOpenVertebraPicker={(_i, zoneIndex) =>
setVertebraTarget(zoneIndex) setVertebraTarget(zoneIndex)
@@ -332,6 +348,22 @@ export default function EditorRoute() {
</Dialog> </Dialog>
)} )}
{disclaimer && (
<Dialog
open
onClose={acknowledgeDisclaimer}
title="Périmètre légal de l'ostéopathie animale"
size="md"
>
<div className="space-y-4">
<p className="text-sm text-[var(--color-ink)]">{disclaimer}</p>
<div className="flex justify-end">
<Button onClick={acknowledgeDisclaimer}>Compris</Button>
</div>
</div>
</Dialog>
)}
{vertebraTarget !== null && {vertebraTarget !== null &&
activeObs && activeObs &&
activeObs.zones[vertebraTarget] && ( activeObs.zones[vertebraTarget] && (
-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 Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge' import Badge from '@/components/ui/Badge'
export interface FreeTextPathologyInputProps { export interface FreeTextFindingInputProps {
items: string[] items: string[]
onChange: (next: string[]) => void onChange: (next: string[]) => void
} }
export default function FreeTextPathologyInput({ export default function FreeTextFindingInput({
items, items,
onChange, onChange,
}: FreeTextPathologyInputProps) { }: FreeTextFindingInputProps) {
const [v, setV] = useState('') const [v, setV] = useState('')
function add() { function add() {
const trimmed = v.trim() const trimmed = v.trim()
if (!trimmed) return if (!trimmed) return
onChange([...items, trimmed]) onChange([...items, trimmed])
setV('') setV('')
} }
function remove(i: number) { function remove(i: number) {
onChange(items.filter((_, k) => k !== i)) onChange(items.filter((_, k) => k !== i))
} }
return ( return (
<div className="space-y-2"> <div className="space-y-2">
<div className="flex gap-2"> <div className="flex gap-2">
<Input <Input
value={v} value={v}
onChange={(e) => setV(e.target.value)} onChange={(e) => setV(e.target.value)}
placeholder="Pathologie additionnelle (texte libre)" placeholder="Observation additionnelle (texte libre)"
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); add() } }} onKeyDown={(e) => {
aria-label="Pathologie libre" 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> </div>
{items.length > 0 && ( {items.length > 0 && (
<ul className="flex flex-wrap gap-2"> <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 {
import type { Pathology } from '@/domain/schema/pathology' Observation,
ObservationZone,
Vertebra,
} from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types' import type { Bone } from '@/anatomy/types'
import { AnimatePresence, motion } from 'motion/react' import { AnimatePresence, motion } from 'motion/react'
import Card from '@/components/ui/Card' import Card from '@/components/ui/Card'
@@ -7,8 +11,8 @@ import Badge from '@/components/ui/Badge'
import Button from '@/components/ui/Button' import Button from '@/components/ui/Button'
import Label from '@/components/ui/Label' import Label from '@/components/ui/Label'
import Textarea from '@/components/ui/Textarea' import Textarea from '@/components/ui/Textarea'
import PathologyPicker from './PathologyPicker' import FindingsTreePicker from './FindingsTreePicker'
import FreeTextPathologyInput from './FreeTextPathologyInput' import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector' import SeveritySelector from './SeveritySelector'
export interface ObservationCardProps { export interface ObservationCardProps {
@@ -23,8 +27,7 @@ export interface ObservationCardProps {
canMoveDown: boolean canMoveDown: boolean
// Editor body props (used only when expanded) // Editor body props (used only when expanded)
bones: Map<string, Bone> bones: Map<string, Bone>
speciesId: string findings: SpeciesFindings | null
pathologyPool: Pathology[]
onChange: (next: Observation) => void onChange: (next: Observation) => void
onOpenVertebraPicker: (zoneIndex: number) => void onOpenVertebraPicker: (zoneIndex: number) => void
onRemoveZone: (zoneIndex: number) => void onRemoveZone: (zoneIndex: number) => void
@@ -53,15 +56,14 @@ export default function ObservationCard({
canMoveUp, canMoveUp,
canMoveDown, canMoveDown,
bones, bones,
speciesId, findings,
pathologyPool,
onChange, onChange,
onOpenVertebraPicker, onOpenVertebraPicker,
onRemoveZone, onRemoveZone,
}: ObservationCardProps) { }: ObservationCardProps) {
const zoneCount = observation.zones.length const zoneCount = observation.zones.length
const patCount = const findingCount =
observation.pathologyIds.length + observation.freeTextPathologies.length observation.findings.length + observation.freeTextFindings.length
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) { function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') { 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 ( return (
<Card <Card
@@ -115,8 +123,8 @@ export default function ObservationCard({
)} )}
</div> </div>
<div className="text-sm text-[var(--color-ink-muted)]"> <div className="text-sm text-[var(--color-ink-muted)]">
{zoneCount} zone{zoneCount > 1 ? 's' : ''} · {patCount} pathologie {zoneCount} zone{zoneCount > 1 ? 's' : ''} · {findingCount} constat
{patCount > 1 ? 's' : ''} {findingCount > 1 ? 's' : ''}
</div> </div>
{!expanded && observation.comment && ( {!expanded && observation.comment && (
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]"> <p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
@@ -220,24 +228,43 @@ export default function ObservationCard({
</section> </section>
<section> <section>
<Label>Pathologies (référence)</Label> <Label>Constats (référentiel)</Label>
<PathologyPicker {zonesWithTree.length === 0 ? (
pool={pathologyPool} <p className="text-sm text-[var(--color-ink-muted)]">
speciesId={speciesId} {observation.zones.length === 0
boneIds={zoneBoneIds} ? 'Sélectionnez une zone pour accéder au référentiel.'
selected={observation.pathologyIds} : 'Aucun référentiel disponible pour ces zones. Utilisez le texte libre ci-dessous.'}
onChange={(ids) => </p>
onChange({ ...observation, pathologyIds: ids }) ) : (
} <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>
<section> <section>
<Label>Pathologies (texte libre)</Label> <Label>Constats (texte libre)</Label>
<FreeTextPathologyInput <FreeTextFindingInput
items={observation.freeTextPathologies} items={observation.freeTextFindings}
onChange={(items) => onChange={(items) =>
onChange({ ...observation, freeTextPathologies: items }) onChange({ ...observation, freeTextFindings: items })
} }
/> />
</section> </section>
@@ -1,5 +1,5 @@
import type { Observation } from '@/domain/schema/observation' 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 type { Bone } from '@/anatomy/types'
import ObservationCard from './ObservationCard' import ObservationCard from './ObservationCard'
import Button from '@/components/ui/Button' import Button from '@/components/ui/Button'
@@ -14,8 +14,7 @@ export interface ObservationListProps {
onMoveDown: (i: number) => void onMoveDown: (i: number) => void
// Editor body props forwarded to each card // Editor body props forwarded to each card
bones: Map<string, Bone> bones: Map<string, Bone>
speciesId: string findings: SpeciesFindings | null
pathologyPool: Pathology[]
onChange: (i: number, next: Observation) => void onChange: (i: number, next: Observation) => void
onOpenVertebraPicker: (i: number, zoneIndex: number) => void onOpenVertebraPicker: (i: number, zoneIndex: number) => void
onRemoveZone: (i: number, zoneIndex: number) => void onRemoveZone: (i: number, zoneIndex: number) => void
@@ -30,8 +29,7 @@ export default function ObservationList({
onMoveUp, onMoveUp,
onMoveDown, onMoveDown,
bones, bones,
speciesId, findings,
pathologyPool,
onChange, onChange,
onOpenVertebraPicker, onOpenVertebraPicker,
onRemoveZone, onRemoveZone,
@@ -66,8 +64,7 @@ export default function ObservationList({
canMoveUp={i > 0} canMoveUp={i > 0}
canMoveDown={i < observations.length - 1} canMoveDown={i < observations.length - 1}
bones={bones} bones={bones}
speciesId={speciesId} findings={findings}
pathologyPool={pathologyPool}
onChange={(next) => onChange(i, next)} onChange={(next) => onChange(i, next)}
onOpenVertebraPicker={(zoneIndex) => onOpenVertebraPicker={(zoneIndex) =>
onOpenVertebraPicker(i, 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>
}
+9 -5
View File
@@ -195,12 +195,16 @@ export async function addObservationPage(
const sections: Array<{ label: string; value: string }> = [ const sections: Array<{ label: string; value: string }> = [
{ label: 'ZONES', value: zonesText || '—' }, { label: 'ZONES', value: zonesText || '—' },
] ]
const pathologies = [ const findingLabels = [
...observation.pathologyIds, ...observation.findings.map((f) =>
...observation.freeTextPathologies, f.requiresVetReferral
? `⚠ ${f.labelFrSnapshot}`
: f.labelFrSnapshot,
),
...observation.freeTextFindings,
] ]
if (pathologies.length) { if (findingLabels.length) {
sections.push({ label: 'PATHOLOGIES', value: pathologies.join(' · ') }) sections.push({ label: 'CONSTATS', value: findingLabels.join(' · ') })
} }
if (observation.severity) { if (observation.severity) {
sections.push({ label: 'SÉVÉRITÉ', value: observation.severity }) sections.push({ label: 'SÉVÉRITÉ', value: observation.severity })
@@ -0,0 +1,137 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import FindingsTreePicker from '@/components/observation/FindingsTreePicker'
import type { ZoneFindings } from '@/domain/schema/findings'
import type { Finding } from '@/domain/schema/observation'
const TREE: ZoneFindings = {
id: 'sphenoid',
name_fr: 'Sphénoïde',
name_en: 'Sphenoid',
categories: [
{
id: 'dysfunctions',
name_fr: 'Dysfonctions',
name_en: 'Dysfunctions',
children: [
{
id: 'flexion',
name_fr: 'Flexion',
name_en: 'Flexion',
description_fr: 'Description test',
},
{
id: 'extension',
name_fr: 'Extension',
name_en: 'Extension',
requires_vet_referral: true,
},
],
},
],
}
describe('FindingsTreePicker', () => {
it('renders the zone name in the initial breadcrumb', () => {
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={[]}
onChange={() => {}}
/>,
)
expect(screen.getByText('Sphénoïde')).toBeInTheDocument()
})
it('drills into a category and shows leaves', async () => {
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={[]}
onChange={() => {}}
/>,
)
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
expect(screen.getByLabelText('Flexion')).toBeInTheDocument()
expect(screen.getByLabelText('Extension')).toBeInTheDocument()
})
it('emits a Finding with snapshot labels on leaf select', async () => {
const onChange = vi.fn<(next: Finding[]) => void>()
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={[]}
onChange={onChange}
/>,
)
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
await userEvent.click(screen.getByLabelText('Flexion'))
expect(onChange).toHaveBeenCalledTimes(1)
expect(onChange.mock.calls[0][0]).toEqual([
{
zoneId: 'sphenoid',
path: ['dysfunctions', 'flexion'],
labelFrSnapshot: 'Flexion',
labelEnSnapshot: 'Flexion',
},
])
})
it('flags vet-referral leaves with requiresVetReferral on selection', async () => {
const onChange = vi.fn<(next: Finding[]) => void>()
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={[]}
onChange={onChange}
/>,
)
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
await userEvent.click(screen.getByLabelText('Extension'))
expect(onChange.mock.calls[0][0][0].requiresVetReferral).toBe(true)
})
it('deselects a previously selected leaf', async () => {
const onChange = vi.fn<(next: Finding[]) => void>()
const selected: Finding[] = [
{
zoneId: 'sphenoid',
path: ['dysfunctions', 'flexion'],
labelFrSnapshot: 'Flexion',
labelEnSnapshot: 'Flexion',
},
]
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={selected}
onChange={onChange}
/>,
)
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
await userEvent.click(screen.getByLabelText('Flexion'))
expect(onChange).toHaveBeenCalledWith([])
})
it('navigates back to parent via the Retour button', async () => {
render(
<FindingsTreePicker
zoneId="sphenoid"
tree={TREE}
selected={[]}
onChange={() => {}}
/>,
)
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
expect(screen.getByLabelText('Flexion')).toBeInTheDocument()
await userEvent.click(screen.getByLabelText('Retour au niveau précédent'))
expect(screen.getByLabelText('Ouvrir Dysfonctions')).toBeInTheDocument()
})
})
@@ -1,57 +0,0 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import PathologyPicker from '@/components/observation/PathologyPicker'
import type { Pathology } from '@/domain/schema/pathology'
const POOL: Pathology[] = [
{
id: 'a',
labelFr: 'Aïe',
description: '',
category: 'osseux',
speciesIds: ['equine'],
boneIds: ['epaule'],
sources: [{ type: 'manual', citation: 'X' }],
},
{
id: 'b',
labelFr: 'Aïe-aïe',
description: '',
category: 'osseux',
speciesIds: ['equine'],
boneIds: ['hanche'],
sources: [{ type: 'manual', citation: 'X' }],
},
]
describe('PathologyPicker', () => {
it('shows only pathologies matching zones', () => {
render(
<PathologyPicker
pool={POOL}
speciesId="equine"
boneIds={['epaule']}
selected={[]}
onChange={() => {}}
/>,
)
expect(screen.getByLabelText('Aïe')).toBeInTheDocument()
expect(screen.queryByLabelText('Aïe-aïe')).toBeNull()
})
it('toggles selection', async () => {
const onChange = vi.fn()
render(
<PathologyPicker
pool={POOL}
speciesId="equine"
boneIds={['epaule']}
selected={[]}
onChange={onChange}
/>,
)
await userEvent.click(screen.getByLabelText('Aïe'))
expect(onChange).toHaveBeenCalledWith(['a'])
})
})