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:
1 parent
d08d773d74
commit
b67f4cd82b
12 files changed
+473
-186
No files matched your search
@@ -121,11 +121,11 @@ osteo/
|
||||
│ │ │ ├─ observation.ts
|
||||
│ │ │ ├─ practitioner.ts
|
||||
│ │ │ ├─ animal.ts
|
||||
│ │ │ └─ pathology.ts
|
||||
│ │ │ └─ findings.ts
|
||||
│ │ └─ species/
|
||||
│ │ ├─ types.ts ← SpeciesManifest interface
|
||||
│ │ ├─ registry.ts ← getSpecies(), getAllSpecies()
|
||||
│ │ └─ equine/{index,vertebrae,pathologies}.ts
|
||||
│ │ └─ equine/{index,vertebrae,pathologies}.{ts,json}
|
||||
│ ├─ state/
|
||||
│ │ ├─ reportStore.ts ← Zustand store
|
||||
│ │ └─ practitionerCache.ts ← localStorage prefill
|
||||
@@ -134,11 +134,11 @@ osteo/
|
||||
│ │ ├─ svgConvention.ts ← parseSvgBones()
|
||||
│ │ └─ svgLoader.ts ← loadSvg(), svgToPngDataUrl()
|
||||
│ ├─ components/
|
||||
│ │ ├─ ui/{Button,Card,Dialog,Input,Label,Select,Textarea,Badge,Chip,Toast}.tsx
|
||||
│ │ ├─ canvas/{AnatomyCanvas,DetailModal,ZoneTooltip}.tsx
|
||||
│ │ ├─ observation/{ObservationList,ObservationCard,ObservationEditor,
|
||||
│ │ │ PathologyPicker,VertebraPicker,SeveritySelector,
|
||||
│ │ │ FreeTextPathologyInput}.tsx
|
||||
│ │ ├─ ui/{Button,Card,Dialog,Input,Label,Select,Textarea,Badge,Chip}.tsx
|
||||
│ │ ├─ canvas/{AnatomyCanvas,DetailModal}.tsx
|
||||
│ │ ├─ observation/{ObservationList,ObservationCard,FindingsTreePicker,
|
||||
│ │ │ VertebraPicker,SeveritySelector,
|
||||
│ │ │ FreeTextFindingInput}.tsx
|
||||
│ │ ├─ report/{ReportHeader,PractitionerForm,AnimalForm,
|
||||
│ │ │ ConclusionPanel,NextAppointmentPicker}.tsx
|
||||
│ │ └─ brand/Brand.tsx
|
||||
|
||||
@@ -19,11 +19,13 @@ import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import { parseSvgBones } from '@/anatomy/svgConvention'
|
||||
import type { Bone, BoneState } from '@/anatomy/types'
|
||||
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 { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
|
||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||
|
||||
export default function EditorRoute() {
|
||||
const navigate = useNavigate()
|
||||
const report = useReportStore((s) => s.report)
|
||||
@@ -43,7 +45,8 @@ export default function EditorRoute() {
|
||||
|
||||
const [bones, setBones] = 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<{
|
||||
id: string
|
||||
src: string
|
||||
@@ -86,6 +89,13 @@ export default function EditorRoute() {
|
||||
closeEditInfos()
|
||||
}
|
||||
|
||||
function acknowledgeDisclaimer() {
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
sessionStorage.setItem(DISCLAIMER_FLAG, '1')
|
||||
}
|
||||
setDisclaimer(null)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!report) navigate('/')
|
||||
}, [report, navigate])
|
||||
@@ -98,9 +108,16 @@ export default function EditorRoute() {
|
||||
useEffect(() => {
|
||||
if (!species) return
|
||||
loadSvg(species.mainSvg).then((root) => setBones(parseSvgBones(root)))
|
||||
species.pathologies().then((m) => setPathologies(m.default))
|
||||
species.findings().then((m) => setFindings(m.default))
|
||||
}, [species])
|
||||
|
||||
useEffect(() => {
|
||||
if (!findings) return
|
||||
if (typeof sessionStorage === 'undefined') return
|
||||
if (sessionStorage.getItem(DISCLAIMER_FLAG)) return
|
||||
setDisclaimer(findings.scope_disclaimer)
|
||||
}, [findings])
|
||||
|
||||
useEffect(() => {
|
||||
if (!detail) return
|
||||
let cancelled = false
|
||||
@@ -248,8 +265,7 @@ export default function EditorRoute() {
|
||||
onMoveUp={moveObservationUp}
|
||||
onMoveDown={moveObservationDown}
|
||||
bones={allBones}
|
||||
speciesId={species.id}
|
||||
pathologyPool={pathologies}
|
||||
findings={findings}
|
||||
onChange={(i, next: Observation) => updateObservation(i, next)}
|
||||
onOpenVertebraPicker={(_i, zoneIndex) =>
|
||||
setVertebraTarget(zoneIndex)
|
||||
@@ -332,6 +348,22 @@ export default function EditorRoute() {
|
||||
</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 &&
|
||||
activeObs &&
|
||||
activeObs.zones[vertebraTarget] && (
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
+17
-7
@@ -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">
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function Toast() {
|
||||
return <div>Toast placeholder</div>
|
||||
}
|
||||
@@ -195,12 +195,16 @@ export async function addObservationPage(
|
||||
const sections: Array<{ label: string; value: string }> = [
|
||||
{ label: 'ZONES', value: zonesText || '—' },
|
||||
]
|
||||
const pathologies = [
|
||||
...observation.pathologyIds,
|
||||
...observation.freeTextPathologies,
|
||||
const findingLabels = [
|
||||
...observation.findings.map((f) =>
|
||||
f.requiresVetReferral
|
||||
? `⚠ ${f.labelFrSnapshot}`
|
||||
: f.labelFrSnapshot,
|
||||
),
|
||||
...observation.freeTextFindings,
|
||||
]
|
||||
if (pathologies.length) {
|
||||
sections.push({ label: 'PATHOLOGIES', value: pathologies.join(' · ') })
|
||||
if (findingLabels.length) {
|
||||
sections.push({ label: 'CONSTATS', value: findingLabels.join(' · ') })
|
||||
}
|
||||
if (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'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user