feat(editor): integrate LateralityPicker in zone click flow
Insert bilateral check in onZoneClick between vertebral-precision and unpaired toggle logic. Both-sides-present clears all matching zones; otherwise opens LateralityPicker to let user pick L/R/both. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
20d60b939a
commit
5a19ae1f32
1 file changed
+82
@@ -6,6 +6,8 @@ import ObservationList from '@/components/observation/ObservationList'
|
|||||||
import VertebraPicker, {
|
import VertebraPicker, {
|
||||||
regionFromLabel,
|
regionFromLabel,
|
||||||
} from '@/components/observation/VertebraPicker'
|
} from '@/components/observation/VertebraPicker'
|
||||||
|
import LateralityPicker from '@/components/observation/LateralityPicker'
|
||||||
|
import type { LateralSide } from '@/domain/schema/observation'
|
||||||
import ConclusionPanel from '@/components/report/ConclusionPanel'
|
import ConclusionPanel from '@/components/report/ConclusionPanel'
|
||||||
import ReportHeader from '@/components/report/ReportHeader'
|
import ReportHeader from '@/components/report/ReportHeader'
|
||||||
import PractitionerForm from '@/components/report/PractitionerForm'
|
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||||
@@ -58,6 +60,10 @@ export default function EditorRoute() {
|
|||||||
title: string
|
title: string
|
||||||
} | null>(null)
|
} | null>(null)
|
||||||
const [vertebraTarget, setVertebraTarget] = useState<number | null>(null)
|
const [vertebraTarget, setVertebraTarget] = useState<number | null>(null)
|
||||||
|
const [lateralTarget, setLateralTarget] = useState<{
|
||||||
|
boneId: string
|
||||||
|
detailSourceId?: string
|
||||||
|
} | null>(null)
|
||||||
const [exporting, setExporting] = useState(false)
|
const [exporting, setExporting] = useState(false)
|
||||||
const [editOpen, setEditOpen] = useState(false)
|
const [editOpen, setEditOpen] = useState(false)
|
||||||
const [editDraft, setEditDraft] = useState<{
|
const [editDraft, setEditDraft] = useState<{
|
||||||
@@ -240,6 +246,32 @@ export default function EditorRoute() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bone.lateral === 'bilateral') {
|
||||||
|
const sidesPresent = activeObs.zones
|
||||||
|
.filter(
|
||||||
|
(z) =>
|
||||||
|
z.boneId === boneId &&
|
||||||
|
z.detailSourceId === detailSourceId,
|
||||||
|
)
|
||||||
|
.map((z) => z.side)
|
||||||
|
.filter(Boolean) as LateralSide[]
|
||||||
|
|
||||||
|
if (sidesPresent.includes('left') && sidesPresent.includes('right')) {
|
||||||
|
const nextZones = activeObs.zones.filter(
|
||||||
|
(z) =>
|
||||||
|
!(z.boneId === boneId && z.detailSourceId === detailSourceId),
|
||||||
|
)
|
||||||
|
updateObservation(activeIndex, { ...activeObs, zones: nextZones })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setLateralTarget({
|
||||||
|
boneId,
|
||||||
|
...(detailSourceId ? { detailSourceId } : {}),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const newZone: ObservationZone = {
|
const newZone: ObservationZone = {
|
||||||
boneId,
|
boneId,
|
||||||
...(detailSourceId ? { detailSourceId } : {}),
|
...(detailSourceId ? { detailSourceId } : {}),
|
||||||
@@ -424,6 +456,56 @@ export default function EditorRoute() {
|
|||||||
})()}
|
})()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{lateralTarget && activeObs && (
|
||||||
|
<LateralityPicker
|
||||||
|
open
|
||||||
|
onClose={() => setLateralTarget(null)}
|
||||||
|
title={boneLabel(
|
||||||
|
allBones.get(lateralTarget.boneId),
|
||||||
|
locale,
|
||||||
|
lateralTarget.boneId,
|
||||||
|
)}
|
||||||
|
existingSides={
|
||||||
|
activeObs.zones
|
||||||
|
.filter(
|
||||||
|
(z) =>
|
||||||
|
z.boneId === lateralTarget.boneId &&
|
||||||
|
z.detailSourceId === lateralTarget.detailSourceId &&
|
||||||
|
z.side,
|
||||||
|
)
|
||||||
|
.map((z) => z.side!) as LateralSide[]
|
||||||
|
}
|
||||||
|
onSelect={(sides) => {
|
||||||
|
const fresh =
|
||||||
|
useReportStore.getState().report?.observations[activeIndex]
|
||||||
|
if (!fresh) {
|
||||||
|
setLateralTarget(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let nextZones = [...fresh.zones]
|
||||||
|
for (const side of sides) {
|
||||||
|
const exists = nextZones.some(
|
||||||
|
(z) =>
|
||||||
|
z.boneId === lateralTarget.boneId &&
|
||||||
|
z.detailSourceId === lateralTarget.detailSourceId &&
|
||||||
|
z.side === side,
|
||||||
|
)
|
||||||
|
if (!exists) {
|
||||||
|
nextZones.push({
|
||||||
|
boneId: lateralTarget.boneId,
|
||||||
|
...(lateralTarget.detailSourceId
|
||||||
|
? { detailSourceId: lateralTarget.detailSourceId }
|
||||||
|
: {}),
|
||||||
|
side,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateObservation(activeIndex, { ...fresh, zones: nextZones })
|
||||||
|
setLateralTarget(null)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user