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