diff --git a/src/components/observation/FindingsTreePicker.tsx b/src/components/observation/FindingsTreePicker.tsx
index 0f5b256d..221aae5f 100644
--- a/src/components/observation/FindingsTreePicker.tsx
+++ b/src/components/observation/FindingsTreePicker.tsx
@@ -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])
}
diff --git a/src/components/observation/ObservationCard.tsx b/src/components/observation/ObservationCard.tsx
index a9787488..86de9ea6 100644
--- a/src/components/observation/ObservationCard.tsx
+++ b/src/components/observation/ObservationCard.tsx
@@ -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()
- 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({
) : (
- {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 (
-
- 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"
>
{nameOf(tree)}
+ {side && ` (${t(side === 'left' ? 'lateral.left' : 'lateral.right')})`}
{selectedCount > 0 && (
onChange({ ...observation, findings: next })
diff --git a/src/domain/schema/observation.ts b/src/domain/schema/observation.ts
index 29062523..98ca1051 100644
--- a/src/domain/schema/observation.ts
+++ b/src/domain/schema/observation.ts
@@ -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
diff --git a/src/pdf/render/observationPage.ts b/src/pdf/render/observationPage.ts
index b7d8c956..c301b79c 100644
--- a/src/pdf/render/observationPage.ts
+++ b/src/pdf/render/observationPage.ts
@@ -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()
+ const findingsByZoneSide = new Map()
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