96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import type { LateralSide, Observation } from '@faunosteo/domain'
|
|
import VertebraPicker from '@/components/observation/VertebraPicker'
|
|
import LateralityPicker from '@/components/observation/LateralityPicker'
|
|
import { useReportStore } from '@/state/reportStore'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { isObservable, pickLabel, type SheetIndex } from '@/services/sheetIndex'
|
|
import {
|
|
addSides,
|
|
collectVertebrae,
|
|
sidesPresent,
|
|
syncVertebrae,
|
|
type ZoneRef,
|
|
} from '@/services/zoneInteraction'
|
|
import { useT } from '@/i18n/useT'
|
|
|
|
export interface ObservationPickersProps {
|
|
sheet: SheetIndex
|
|
activeIndex: number
|
|
activeObs: Observation | undefined
|
|
vertebraTarget: number | null
|
|
lateralTarget: ZoneRef | null
|
|
onCloseVertebra: () => void
|
|
onCloseLateral: () => void
|
|
}
|
|
|
|
/** Vertebra and laterality pickers of the active observation. */
|
|
export default function ObservationPickers({
|
|
sheet,
|
|
activeIndex,
|
|
activeObs,
|
|
vertebraTarget,
|
|
lateralTarget,
|
|
onCloseVertebra,
|
|
onCloseLateral,
|
|
}: ObservationPickersProps) {
|
|
const t = useT()
|
|
const locale = useLocaleStore((s) => s.locale)
|
|
const updateObservation = useReportStore((s) => s.updateObservation)
|
|
const vertebraZone =
|
|
vertebraTarget !== null ? activeObs?.zones[vertebraTarget] : undefined
|
|
const vertebraAnnotation =
|
|
vertebraZone && sheet.annotation(vertebraZone.annotationId)
|
|
const lateralAnnotation =
|
|
lateralTarget && sheet.annotation(lateralTarget.annotationId)
|
|
|
|
return (
|
|
<>
|
|
{vertebraTarget !== null &&
|
|
activeObs &&
|
|
vertebraZone &&
|
|
isObservable(vertebraAnnotation) && (
|
|
<VertebraPicker
|
|
open
|
|
onClose={onCloseVertebra}
|
|
onConfirm={(vertebrae) => {
|
|
const fresh =
|
|
useReportStore.getState().report?.observations[activeIndex]
|
|
if (fresh) {
|
|
updateObservation(
|
|
activeIndex,
|
|
syncVertebrae(fresh, vertebrae, sheet, vertebraZone.viewId),
|
|
)
|
|
}
|
|
onCloseVertebra()
|
|
}}
|
|
initial={collectVertebrae(activeObs, sheet, vertebraTarget)}
|
|
regions={sheet.regions()}
|
|
title={`${t('vertebra.title_prefix')}${pickLabel(vertebraAnnotation.name, locale)}`}
|
|
initialRegion={
|
|
vertebraAnnotation.vertebral_region_code ?? undefined
|
|
}
|
|
/>
|
|
)}
|
|
|
|
{lateralTarget && activeObs && lateralAnnotation && (
|
|
<LateralityPicker
|
|
open
|
|
onClose={onCloseLateral}
|
|
title={pickLabel(sheet.name(lateralAnnotation), locale)}
|
|
existingSides={sidesPresent(activeObs, lateralTarget)}
|
|
onSelect={(sides: LateralSide[]) => {
|
|
const fresh =
|
|
useReportStore.getState().report?.observations[activeIndex]
|
|
if (fresh)
|
|
updateObservation(
|
|
activeIndex,
|
|
addSides(fresh, lateralAnnotation, sides),
|
|
)
|
|
onCloseLateral()
|
|
}}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|