feat(ui): separate findings pickers per side for bilateral zones

Bilateral zones now get distinct findings pickers (e.g. "Épaule (Gauche)"
and "Épaule (Droite)") instead of one shared picker. Finding schema gains
optional `side` field so pathologies are tracked per-side. PDF export
groups findings by zone+side with side label in section headers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.6 committed 2026-05-27 04:22:35 +02:00
1 parent 53f62f7bf6
commit c853c681f9
4 files changed
+45 -24

No files matched your search

@@ -4,7 +4,7 @@ import type {
FindingNode, FindingNode,
ZoneFindings, ZoneFindings,
} from '@/domain/schema/findings' } from '@/domain/schema/findings'
import type { Finding } from '@/domain/schema/observation' import type { Finding, LateralSide } from '@/domain/schema/observation'
import Button from '@/components/ui/Button' import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT' import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore' import { useLocaleStore } from '@/state/localeStore'
@@ -17,6 +17,7 @@ const levelVariants = {
export interface FindingsTreePickerProps { export interface FindingsTreePickerProps {
zoneId: string zoneId: string
tree: ZoneFindings tree: ZoneFindings
side?: LateralSide
selected: Finding[] selected: Finding[]
onChange: (next: Finding[]) => void onChange: (next: Finding[]) => void
} }
@@ -58,6 +59,7 @@ function findNode(
export default function FindingsTreePicker({ export default function FindingsTreePicker({
zoneId, zoneId,
tree, tree,
side,
selected, selected,
onChange, onChange,
}: FindingsTreePickerProps) { }: FindingsTreePickerProps) {
@@ -112,16 +114,20 @@ export default function FindingsTreePicker({
return crumbs return crumbs
}, [tree, path, locale]) }, [tree, path, locale])
function matchesSide(f: Finding): boolean {
return f.zoneId === zoneId && f.side === side
}
function isLeafSelected(leafPath: string[]): boolean { function isLeafSelected(leafPath: string[]): boolean {
return selected.some( return selected.some(
(f) => f.zoneId === zoneId && samePath(f.path, leafPath), (f) => matchesSide(f) && samePath(f.path, leafPath),
) )
} }
function countSelectedUnder(nodePath: string[]): number { function countSelectedUnder(nodePath: string[]): number {
let n = 0 let n = 0
for (const f of selected) { for (const f of selected) {
if (f.zoneId !== zoneId) continue if (!matchesSide(f)) continue
if (!pathStartsWith(f.path, nodePath)) continue if (!pathStartsWith(f.path, nodePath)) continue
n += 1 n += 1
} }
@@ -132,7 +138,7 @@ export default function FindingsTreePicker({
if (isLeafSelected(leafPath)) { if (isLeafSelected(leafPath)) {
onChange( onChange(
selected.filter( selected.filter(
(f) => !(f.zoneId === zoneId && samePath(f.path, leafPath)), (f) => !(matchesSide(f) && samePath(f.path, leafPath)),
), ),
) )
return return
@@ -144,6 +150,7 @@ export default function FindingsTreePicker({
labelEnSnapshot: leaf.name_en, labelEnSnapshot: leaf.name_en,
} }
if (leaf.requires_vet_referral) next.requiresVetReferral = true if (leaf.requires_vet_referral) next.requiresVetReferral = true
if (side) next.side = side
onChange([...selected, next]) onChange([...selected, next])
} }
+21 -12
View File
@@ -3,6 +3,7 @@ import type {
Observation, Observation,
ObservationZone, ObservationZone,
Vertebra, Vertebra,
LateralSide,
} from '@/domain/schema/observation' } from '@/domain/schema/observation'
import type { import type {
SpeciesFindings, SpeciesFindings,
@@ -123,9 +124,10 @@ export default function ObservationCard({
) )
const zonesWithTree = useMemo(() => { const zonesWithTree = useMemo(() => {
if (zonesArray.length === 0) return [] as { tree: ZoneFindings }[] if (zonesArray.length === 0)
return [] as { tree: ZoneFindings; side?: LateralSide }[]
const seen = new Set<string>() const seen = new Set<string>()
const out: { tree: ZoneFindings }[] = [] const out: { tree: ZoneFindings; side?: LateralSide }[] = []
for (const z of observation.zones) { for (const z of observation.zones) {
const bone = bones.get(z.boneId) const bone = bones.get(z.boneId)
if (!bone) continue if (!bone) continue
@@ -134,9 +136,10 @@ export default function ObservationCard({
zonesArray, zonesArray,
) )
if (!tree) continue if (!tree) continue
if (seen.has(tree.id)) continue const key = z.side ? `${tree.id}:${z.side}` : tree.id
seen.add(tree.id) if (seen.has(key)) continue
out.push({ tree }) seen.add(key)
out.push({ tree, side: z.side })
} }
return out return out
}, [observation.zones, bones, zonesArray]) }, [observation.zones, bones, zonesArray])
@@ -289,10 +292,14 @@ export default function ObservationCard({
</p> </p>
) : ( ) : (
<ul className="space-y-2"> <ul className="space-y-2">
{zonesWithTree.map(({ tree }) => { {zonesWithTree.map(({ tree, side }) => {
const expanded = expandedZoneId === tree.id const pickerKey = side
? `${tree.id}:${side}`
: tree.id
const expanded = expandedZoneId === pickerKey
const selectedCount = observation.findings.filter( const selectedCount = observation.findings.filter(
(f) => f.zoneId === tree.id, (f) =>
f.zoneId === tree.id && f.side === side,
).length ).length
const selectedAria = `${selectedCount} ${ const selectedAria = `${selectedCount} ${
selectedCount > 1 selectedCount > 1
@@ -301,7 +308,7 @@ export default function ObservationCard({
}` }`
return ( return (
<li <li
key={tree.id} key={pickerKey}
className={[ className={[
'rounded-xl border bg-[var(--color-surface)] transition', 'rounded-xl border bg-[var(--color-surface)] transition',
expanded expanded
@@ -312,15 +319,16 @@ export default function ObservationCard({
<button <button
type="button" type="button"
onClick={() => onClick={() =>
setExpandedZoneId(expanded ? null : tree.id) setExpandedZoneId(expanded ? null : pickerKey)
} }
aria-expanded={expanded} aria-expanded={expanded}
aria-controls={`findings-zone-${tree.id}`} aria-controls={`findings-zone-${pickerKey}`}
className="w-full flex items-center justify-between gap-2 px-3 py-2 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40" className="w-full flex items-center justify-between gap-2 px-3 py-2 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40"
> >
<span className="flex items-center gap-2"> <span className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]"> <span className="text-sm font-medium text-[var(--color-ink)]">
{nameOf(tree)} {nameOf(tree)}
{side && ` (${t(side === 'left' ? 'lateral.left' : 'lateral.right')})`}
</span> </span>
{selectedCount > 0 && ( {selectedCount > 0 && (
<span <span
@@ -342,7 +350,7 @@ export default function ObservationCard({
{expanded && ( {expanded && (
<motion.div <motion.div
key="picker-body" key="picker-body"
id={`findings-zone-${tree.id}`} id={`findings-zone-${pickerKey}`}
initial={{ height: 0, opacity: 0 }} initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }} animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }} exit={{ height: 0, opacity: 0 }}
@@ -353,6 +361,7 @@ export default function ObservationCard({
<FindingsTreePicker <FindingsTreePicker
zoneId={tree.id} zoneId={tree.id}
tree={tree} tree={tree}
side={side}
selected={observation.findings} selected={observation.findings}
onChange={(next) => onChange={(next) =>
onChange({ ...observation, findings: next }) onChange({ ...observation, findings: next })
+1
View File
@@ -43,6 +43,7 @@ export const FindingSchema = z.object({
labelFrSnapshot: z.string().min(1), labelFrSnapshot: z.string().min(1),
labelEnSnapshot: z.string().min(1), labelEnSnapshot: z.string().min(1),
requiresVetReferral: z.boolean().optional(), requiresVetReferral: z.boolean().optional(),
side: LateralSideSchema.optional(),
}) })
export type Finding = z.infer<typeof FindingSchema> export type Finding = z.infer<typeof FindingSchema>
+12 -8
View File
@@ -384,26 +384,30 @@ export async function addObservationPage(
const sections: Array<{ label: string; value: string }> = [ const sections: Array<{ label: string; value: string }> = [
{ label: dict['pdf.section.zones'], value: zonesText || dict['pdf.empty'] }, { label: dict['pdf.section.zones'], value: zonesText || dict['pdf.empty'] },
] ]
// Group catalog findings by their JSON zoneId so each zone gets its const findingsByZoneSide = new Map<string, Finding[]>()
// own labelled section. Preserves first-seen order so the on-screen
// pick order survives the export.
const findingsByZone = new Map<string, Finding[]>()
for (const f of observation.findings) { for (const f of observation.findings) {
const list = findingsByZone.get(f.zoneId) const key = f.side ? `${f.zoneId}:${f.side}` : f.zoneId
const list = findingsByZoneSide.get(key)
if (list) { if (list) {
list.push(f) list.push(f)
} else { } else {
findingsByZone.set(f.zoneId, [f]) findingsByZoneSide.set(key, [f])
} }
} }
for (const [zoneId, group] of findingsByZone) { for (const [key, group] of findingsByZoneSide) {
const zoneId = key.split(':')[0]
const side = group[0]?.side
const zoneTree = findingsTree?.zones[zoneId] const zoneTree = findingsTree?.zones[zoneId]
const zoneName = zoneTree let zoneName = zoneTree
? locale === 'en' ? locale === 'en'
? zoneTree.name_en ? zoneTree.name_en
: zoneTree.name_fr : zoneTree.name_fr
: zoneId : zoneId
if (side) {
const sideLabel = dict[side === 'left' ? 'lateral.left' : 'lateral.right']
zoneName = `${zoneName} (${sideLabel})`
}
const value = group const value = group
.map((f) => { .map((f) => {
const lbl = locale === 'en' ? f.labelEnSnapshot : f.labelFrSnapshot const lbl = locale === 'en' ? f.labelEnSnapshot : f.labelFrSnapshot