feat(app): application on the canonical sheet — report v3 store with v2 draft migration, bundled SheetProvider (SHEET_BUNDLE), annotation layer rendered from the document, zone interaction service, pickers and cards on the sheet index, PDF v3 export with v2 archive import; legacy registry, matchers, editors and assets removed
This commit is contained in:
1 parent
0a17e390cf
commit
ce2ec26112
114 files changed
+3560
-14637
No files matched your search
@@ -1,15 +1,12 @@
|
||||
import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom'
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
||||
import { ConfigProvider } from './providers/ConfigProvider'
|
||||
import Footer from '@/components/brand/Footer'
|
||||
import HomeRoute from './routes/HomeRoute'
|
||||
import NewReportRoute from './routes/NewReportRoute'
|
||||
import EditorRoute from './routes/EditorRoute'
|
||||
import SvgEditorRoute from './routes/SvgEditorRoute'
|
||||
import EditorsRoute from './routes/EditorsRoute'
|
||||
import NotFoundRoute from './routes/NotFoundRoute'
|
||||
|
||||
function AppShell() {
|
||||
const hideFooter = useLocation().pathname === '/svg-editor'
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<main className="flex-1 flex flex-col">
|
||||
@@ -17,12 +14,10 @@ function AppShell() {
|
||||
<Route path="/" element={<HomeRoute />} />
|
||||
<Route path="/new" element={<NewReportRoute />} />
|
||||
<Route path="/editor" element={<EditorRoute />} />
|
||||
<Route path="/svg-editor" element={<SvgEditorRoute />} />
|
||||
<Route path="/editors" element={<EditorsRoute />} />
|
||||
<Route path="*" element={<NotFoundRoute />} />
|
||||
</Routes>
|
||||
</main>
|
||||
{!hideFooter && <Footer />}
|
||||
<Footer />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import type {
|
||||
Animal,
|
||||
LateralSide,
|
||||
Owner,
|
||||
Practitioner,
|
||||
} from '@faunosteo/domain'
|
||||
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
|
||||
import DetailModal from '@/components/canvas/DetailModal'
|
||||
import ObservationList from '@/components/observation/ObservationList'
|
||||
import VertebraPicker from '@/components/observation/VertebraPicker'
|
||||
import { regionFromLabel } from '@/lib/spineZones'
|
||||
import LateralityPicker from '@/components/observation/LateralityPicker'
|
||||
import type { LateralSide } from '@/domain/schema/observation'
|
||||
import ConclusionPanel from '@/components/report/ConclusionPanel'
|
||||
import ReportHeader from '@/components/report/ReportHeader'
|
||||
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||
@@ -15,315 +19,155 @@ import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { writeCachedPractitioner } from '@/state/practitionerCache'
|
||||
import { getSpecies } from '@/domain/species/registry'
|
||||
import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import { parseSvgBones } from '@/anatomy/svgConvention'
|
||||
import { collectSpineVertebrae, syncSpineZones } from '@/lib/spineZones'
|
||||
import type { Bone, BoneState } from '@/anatomy/types'
|
||||
import type { Observation, ObservationZone } from '@/domain/schema/observation'
|
||||
import type { Report } from '@/domain/schema/report'
|
||||
import type { SpeciesFindings } from '@/domain/schema/findings'
|
||||
import type { Practitioner } from '@/domain/schema/practitioner'
|
||||
import type { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useSheet } from '@/sheets/useSheet'
|
||||
import { isObservable, pickLabel, type SheetIndex } from '@/services/sheetIndex'
|
||||
import {
|
||||
addSides,
|
||||
collectVertebrae,
|
||||
decideZoneClick,
|
||||
ensureZone,
|
||||
refOf,
|
||||
removeAllSides,
|
||||
removeZoneAt,
|
||||
sidesPresent,
|
||||
syncVertebrae,
|
||||
toggleZone,
|
||||
type ZoneRef,
|
||||
} from '@/services/zoneInteraction'
|
||||
import type { ViewStates } from '@/anatomy/drawing'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { boneLabel } from '@/anatomy/labels'
|
||||
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
||||
|
||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||
|
||||
/** Merges newly parsed bones into the accumulated map without overwriting. */
|
||||
function mergeBones(prev: Map<string, Bone>, parsed: Map<string, Bone>) {
|
||||
const merged = new Map(prev)
|
||||
parsed.forEach((b, id) => {
|
||||
if (!merged.has(id)) merged.set(id, b)
|
||||
})
|
||||
return merged
|
||||
interface Identity {
|
||||
practitioner: Practitioner
|
||||
animal: Animal
|
||||
owner: Owner
|
||||
}
|
||||
|
||||
/** Editor on the reference sheet: wires the canvas, the pickers and the store. */
|
||||
export default function EditorRoute() {
|
||||
const navigate = useNavigate()
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const report = useReportStore((s) => s.report)
|
||||
const activeIndex = useReportStore((s) => s.activeObservationIndex)
|
||||
const addObservation = useReportStore((s) => s.addObservation)
|
||||
const updateObservation = useReportStore((s) => s.updateObservation)
|
||||
const removeObservation = useReportStore((s) => s.removeObservation)
|
||||
const moveObservationUp = useReportStore((s) => s.moveObservationUp)
|
||||
const moveObservationDown = useReportStore((s) => s.moveObservationDown)
|
||||
const setActiveObservation = useReportStore((s) => s.setActiveObservation)
|
||||
const setConclusion = useReportStore((s) => s.setConclusion)
|
||||
const setRecommendations = useReportStore((s) => s.setRecommendations)
|
||||
const setNextAppointment = useReportStore((s) => s.setNextAppointment)
|
||||
const setPractitioner = useReportStore((s) => s.setPractitioner)
|
||||
const setAnimal = useReportStore((s) => s.setAnimal)
|
||||
const setOwner = useReportStore((s) => s.setOwner)
|
||||
const store = useReportStore()
|
||||
const { report, activeObservationIndex: activeIndex } = store
|
||||
// Without a report yet (draft restore), the default species' sheet carries the migration map.
|
||||
const sheet = useSheet(report?.animal.speciesId ?? DEFAULT_SPECIES_ID)
|
||||
|
||||
const [bones, setBones] = useState<Map<string, Bone>>(new Map())
|
||||
const [detailBones, setDetailBones] = useState<Map<string, Bone>>(new Map())
|
||||
const [findings, setFindings] = useState<SpeciesFindings | null>(null)
|
||||
const [disclaimer, setDisclaimer] = useState<string | null>(null)
|
||||
const [detail, setDetail] = useState<{
|
||||
id: string
|
||||
src: string
|
||||
title: string
|
||||
} | null>(null)
|
||||
const [detailViewId, setDetailViewId] = useState<string | null>(null)
|
||||
const [vertebraTarget, setVertebraTarget] = useState<number | null>(null)
|
||||
const [lateralTarget, setLateralTarget] = useState<{
|
||||
boneId: string
|
||||
detailSourceId?: string
|
||||
} | null>(null)
|
||||
const [lateralTarget, setLateralTarget] = useState<ZoneRef | null>(null)
|
||||
const [disclaimer, setDisclaimer] = useState<string | null>(null)
|
||||
const [exporting, setExporting] = useState(false)
|
||||
const [editOpen, setEditOpen] = useState(false)
|
||||
const [editDraft, setEditDraft] = useState<{
|
||||
practitioner: Practitioner
|
||||
animal: Animal
|
||||
owner: Owner
|
||||
} | null>(null)
|
||||
|
||||
function openEditInfos() {
|
||||
if (!report) return
|
||||
setEditDraft({
|
||||
practitioner: report.practitioner,
|
||||
animal: report.animal,
|
||||
owner: report.owner,
|
||||
})
|
||||
setEditOpen(true)
|
||||
}
|
||||
|
||||
function closeEditInfos() {
|
||||
setEditOpen(false)
|
||||
setEditDraft(null)
|
||||
}
|
||||
|
||||
function saveEditInfos() {
|
||||
if (!editDraft) return closeEditInfos()
|
||||
const name = editDraft.practitioner.name.trim()
|
||||
const animalName = editDraft.animal.name.trim()
|
||||
const ownerName = editDraft.owner.name.trim()
|
||||
if (!name || !animalName || !ownerName) return
|
||||
setPractitioner(editDraft.practitioner)
|
||||
setAnimal(editDraft.animal)
|
||||
setOwner(editDraft.owner)
|
||||
writeCachedPractitioner(editDraft.practitioner)
|
||||
closeEditInfos()
|
||||
}
|
||||
|
||||
function acknowledgeDisclaimer() {
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
sessionStorage.setItem(DISCLAIMER_FLAG, '1')
|
||||
}
|
||||
setDisclaimer(null)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!report) navigate('/')
|
||||
}, [report, navigate])
|
||||
const [editDraft, setEditDraft] = useState<Identity | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0, left: 0, behavior: 'auto' })
|
||||
}, [])
|
||||
|
||||
const species = useMemo(
|
||||
() => (report ? getSpecies(report.animal.speciesId) : undefined),
|
||||
[report],
|
||||
)
|
||||
// No report in memory: restore the per-tab draft once the sheet is known.
|
||||
useEffect(() => {
|
||||
if (report) return
|
||||
if (sheet.status === 'ready')
|
||||
store.restoreDraft(sheet.index.sheet.migrationMap)
|
||||
if (sheet.status !== 'loading' && !useReportStore.getState().report)
|
||||
navigate('/')
|
||||
}, [report, sheet, store, navigate])
|
||||
|
||||
useEffect(() => {
|
||||
if (!species) return
|
||||
loadSvg(species.mainSvg).then((root) => setBones(parseSvgBones(root)))
|
||||
species.findings().then((m) => setFindings(m.default))
|
||||
|
||||
// Eagerly preload every detail SVG so observation zones imported
|
||||
// from a PDF (which can carry detail-popup boneIds without the user
|
||||
// ever re-opening the popup) resolve their labels and findings
|
||||
// pickers immediately on mount. Each fetch is independent — a 404
|
||||
// on one detail asset must not prevent the others from loading.
|
||||
Object.values(species.details).forEach((path) => {
|
||||
loadSvg(path)
|
||||
.then((root) => {
|
||||
const parsed = parseSvgBones(root)
|
||||
setDetailBones((prev) => mergeBones(prev, parsed))
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(`EditorRoute: failed to preload detail SVG ${path}`, err)
|
||||
})
|
||||
})
|
||||
}, [species])
|
||||
|
||||
useEffect(() => {
|
||||
if (!findings) return
|
||||
if (typeof sessionStorage === 'undefined') return
|
||||
if (sheet.status !== 'ready' || typeof sessionStorage === 'undefined')
|
||||
return
|
||||
if (sessionStorage.getItem(DISCLAIMER_FLAG)) return
|
||||
setDisclaimer(findings.scope_disclaimer)
|
||||
}, [findings])
|
||||
|
||||
useEffect(() => {
|
||||
if (!detail) return
|
||||
let cancelled = false
|
||||
loadSvg(detail.src).then((root) => {
|
||||
if (cancelled) return
|
||||
const parsed = parseSvgBones(root)
|
||||
setDetailBones((prev) => mergeBones(prev, parsed))
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [detail])
|
||||
|
||||
const allBones = useMemo(() => {
|
||||
const m = new Map(bones)
|
||||
detailBones.forEach((b, id) => {
|
||||
if (!m.has(id)) m.set(id, b)
|
||||
})
|
||||
return m
|
||||
}, [bones, detailBones])
|
||||
const text = sheet.index.sheet.document.scope_disclaimer
|
||||
setDisclaimer(
|
||||
pickLabel({ fr: text.fr ?? '', en: text.en ?? '' }, locale) || null,
|
||||
)
|
||||
}, [sheet, locale])
|
||||
|
||||
const activeObs =
|
||||
activeIndex >= 0 ? report?.observations[activeIndex] : undefined
|
||||
|
||||
const boneStates = useMemo<Map<string, BoneState>>(() => {
|
||||
const map = new Map<string, BoneState>()
|
||||
if (!report || activeIndex < 0) return map
|
||||
const active = report.observations[activeIndex]
|
||||
if (!active) return map
|
||||
active.zones.forEach((z) => {
|
||||
map.set(z.boneId, 'current')
|
||||
})
|
||||
const states = useMemo<ViewStates>(() => {
|
||||
const map = new Map<string, 'current'>()
|
||||
activeObs?.zones.forEach((z) => map.set(z.annotationId, 'current'))
|
||||
return map
|
||||
}, [report, activeIndex])
|
||||
}, [activeObs])
|
||||
|
||||
function onToggleCard(index: number) {
|
||||
setActiveObservation(activeIndex === index ? -1 : index)
|
||||
}
|
||||
|
||||
/** Opens the detail-popup modal for a bone that carries data-anno-opens-detail. */
|
||||
function handleDetailOpen(bone: Bone, detailId: string, detailSrc: string) {
|
||||
setDetail({
|
||||
id: detailId,
|
||||
src: detailSrc,
|
||||
title: boneLabel(bone, locale, detailId),
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* No expanded observation — auto-expand the most recent one (or the
|
||||
* first if no rows yet) so the click lands somewhere. Defers the actual
|
||||
* zone add to the next render where activeObs is set.
|
||||
*/
|
||||
function activateFallbackObservation(report: Report) {
|
||||
const fallbackIndex =
|
||||
report.observations.length > 0 ? report.observations.length - 1 : -1
|
||||
if (fallbackIndex < 0) return
|
||||
setActiveObservation(fallbackIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Spine-zone behavior: always open VertebraPicker on click. Adds the
|
||||
* zone if missing; never toggles it off here (use the ✕ button).
|
||||
*/
|
||||
function handleSpineZone(
|
||||
activeObs: Observation,
|
||||
boneId: string,
|
||||
detailSourceId: string | undefined,
|
||||
existingIndex: number,
|
||||
) {
|
||||
let targetIndex = existingIndex
|
||||
if (existingIndex < 0) {
|
||||
const newZone: ObservationZone = {
|
||||
boneId,
|
||||
...(detailSourceId ? { detailSourceId } : {}),
|
||||
const onZoneClick = useCallback(
|
||||
(annotationId: string) => {
|
||||
// Fresh state: two clicks may land before React re-renders the handler.
|
||||
const { report, activeObservationIndex: activeIndex } =
|
||||
useReportStore.getState()
|
||||
if (sheet.status !== 'ready' || !report) return
|
||||
const activeObs =
|
||||
activeIndex >= 0 ? report.observations[activeIndex] : undefined
|
||||
const index = sheet.index
|
||||
const annotation = index.annotation(annotationId)
|
||||
const decision = decideZoneClick(annotation, activeObs)
|
||||
if (!annotation) return
|
||||
switch (decision.kind) {
|
||||
case 'ignore':
|
||||
return
|
||||
case 'open_view':
|
||||
return setDetailViewId(decision.viewId)
|
||||
case 'activate_fallback':
|
||||
return store.setActiveObservation(report.observations.length - 1)
|
||||
case 'open_vertebra_picker': {
|
||||
const { observation, index: zoneIndex } = ensureZone(
|
||||
activeObs!,
|
||||
annotation,
|
||||
)
|
||||
store.updateObservation(activeIndex, observation)
|
||||
return setVertebraTarget(zoneIndex)
|
||||
}
|
||||
case 'open_laterality_picker':
|
||||
return setLateralTarget(refOf(annotation))
|
||||
case 'remove_both_sides':
|
||||
return store.updateObservation(
|
||||
activeIndex,
|
||||
removeAllSides(activeObs!, refOf(annotation)),
|
||||
)
|
||||
case 'toggle':
|
||||
return store.updateObservation(
|
||||
activeIndex,
|
||||
toggleZone(activeObs!, annotation),
|
||||
)
|
||||
}
|
||||
const nextZones = [...activeObs.zones, newZone]
|
||||
targetIndex = nextZones.length - 1
|
||||
updateObservation(activeIndex, { ...activeObs, zones: nextZones })
|
||||
}
|
||||
setVertebraTarget(targetIndex)
|
||||
},
|
||||
[sheet, store],
|
||||
)
|
||||
|
||||
function acknowledgeDisclaimer() {
|
||||
sessionStorage?.setItem(DISCLAIMER_FLAG, '1')
|
||||
setDisclaimer(null)
|
||||
}
|
||||
|
||||
/** Bilateral zone: adding a side, or clearing both once left+right are set. */
|
||||
function handleBilateralZone(
|
||||
activeObs: Observation,
|
||||
boneId: string,
|
||||
detailSourceId: string | undefined,
|
||||
) {
|
||||
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 })
|
||||
function saveEditInfos() {
|
||||
if (!editDraft) return
|
||||
if (
|
||||
![
|
||||
editDraft.practitioner.name,
|
||||
editDraft.animal.name,
|
||||
editDraft.owner.name,
|
||||
].every((v) => v.trim())
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
setLateralTarget({
|
||||
boneId,
|
||||
...(detailSourceId ? { detailSourceId } : {}),
|
||||
})
|
||||
store.setPractitioner(editDraft.practitioner)
|
||||
store.setAnimal(editDraft.animal)
|
||||
store.setOwner(editDraft.owner)
|
||||
writeCachedPractitioner(editDraft.practitioner)
|
||||
setEditDraft(null)
|
||||
}
|
||||
|
||||
/** Plain zone: toggles it on the active observation. */
|
||||
function toggleZone(
|
||||
activeObs: Observation,
|
||||
boneId: string,
|
||||
detailSourceId: string | undefined,
|
||||
existingIndex: number,
|
||||
) {
|
||||
const newZone: ObservationZone = {
|
||||
boneId,
|
||||
...(detailSourceId ? { detailSourceId } : {}),
|
||||
}
|
||||
const nextZones =
|
||||
existingIndex >= 0
|
||||
? activeObs.zones.filter((_, k) => k !== existingIndex)
|
||||
: [...activeObs.zones, newZone]
|
||||
updateObservation(activeIndex, { ...activeObs, zones: nextZones })
|
||||
}
|
||||
|
||||
function onZoneClick(boneId: string, detailSourceId?: string) {
|
||||
if (!report) return
|
||||
const bone = bones.get(boneId) ?? detailBones.get(boneId)
|
||||
if (!bone) return
|
||||
|
||||
if (bone.opensDetail && species?.details[bone.opensDetail]) {
|
||||
handleDetailOpen(bone, bone.opensDetail, species.details[bone.opensDetail])
|
||||
return
|
||||
}
|
||||
|
||||
if (!activeObs || activeIndex < 0) {
|
||||
activateFallbackObservation(report)
|
||||
return
|
||||
}
|
||||
|
||||
const matches = (z: ObservationZone) =>
|
||||
z.boneId === boneId && z.detailSourceId === detailSourceId
|
||||
const existingIndex = activeObs.zones.findIndex(matches)
|
||||
|
||||
if (bone.special === 'vertebral-precision') {
|
||||
handleSpineZone(activeObs, boneId, detailSourceId, existingIndex)
|
||||
return
|
||||
}
|
||||
|
||||
if (bone.lateral === 'bilateral') {
|
||||
handleBilateralZone(activeObs, boneId, detailSourceId)
|
||||
return
|
||||
}
|
||||
|
||||
toggleZone(activeObs, boneId, detailSourceId, existingIndex)
|
||||
}
|
||||
|
||||
async function onExport() {
|
||||
async function onExport(index: SheetIndex) {
|
||||
if (!report) return
|
||||
setExporting(true)
|
||||
try {
|
||||
const bytes = await exportReportToPdf(report, { locale })
|
||||
const bytes = await exportReportToPdf(report, index, { locale })
|
||||
const blob = new Blob([bytes as BlobPart], { type: 'application/pdf' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
@@ -339,73 +183,109 @@ export default function EditorRoute() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!report || !species) return null
|
||||
if (!report) return null
|
||||
if (sheet.status === 'loading') {
|
||||
return (
|
||||
<p className="p-6 text-sm text-[var(--color-ink-muted)]">
|
||||
{t('sheet.loading')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
if (sheet.status === 'none') return null
|
||||
const index = sheet.index
|
||||
const vertebraZone =
|
||||
vertebraTarget !== null ? activeObs?.zones[vertebraTarget] : undefined
|
||||
const vertebraAnnotation =
|
||||
vertebraZone && index.annotation(vertebraZone.annotationId)
|
||||
const lateralAnnotation =
|
||||
lateralTarget && index.annotation(lateralTarget.annotationId)
|
||||
const detailView = detailViewId ? index.view(detailViewId) : undefined
|
||||
|
||||
return (
|
||||
<main className="min-h-screen flex flex-col">
|
||||
<ReportHeader report={report} onEditInfos={openEditInfos} />
|
||||
<ReportHeader
|
||||
report={report}
|
||||
onEditInfos={() =>
|
||||
setEditDraft({
|
||||
practitioner: report.practitioner,
|
||||
animal: report.animal,
|
||||
owner: report.owner,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<div className="flex-1 grid grid-cols-1 lg:grid-cols-[2fr_3fr] gap-4 sm:gap-6 p-4 sm:p-6">
|
||||
<section className="border border-[var(--color-border)] rounded-2xl bg-[var(--color-surface)] overflow-hidden max-h-[55vh] lg:max-h-none">
|
||||
<section className="border border-[var(--color-border)] rounded-2xl bg-[var(--color-surface)] overflow-hidden max-h-[55vh] lg:max-h-none flex flex-col">
|
||||
<AnatomyCanvas
|
||||
src={species.mainSvg}
|
||||
boneStates={boneStates}
|
||||
onZoneClick={(id) => onZoneClick(id)}
|
||||
index={index}
|
||||
viewId={index.mainView.id}
|
||||
states={states}
|
||||
onZoneClick={onZoneClick}
|
||||
className="flex-1"
|
||||
/>
|
||||
<p
|
||||
className="px-3 py-1.5 text-xs text-[var(--color-ink-muted)] border-t border-[var(--color-border)]"
|
||||
data-testid="sheet-status"
|
||||
>
|
||||
{t(
|
||||
index.sheet.status === 'draft'
|
||||
? 'sheet.status.draft'
|
||||
: 'sheet.status.published',
|
||||
)}
|
||||
</p>
|
||||
</section>
|
||||
<section className="space-y-4 sm:space-y-6">
|
||||
<ObservationList
|
||||
observations={report.observations}
|
||||
activeIndex={activeIndex}
|
||||
onToggle={onToggleCard}
|
||||
onAdd={addObservation}
|
||||
onDelete={removeObservation}
|
||||
onMoveUp={moveObservationUp}
|
||||
onMoveDown={moveObservationDown}
|
||||
bones={allBones}
|
||||
findings={findings}
|
||||
onChange={(i, next: Observation) => updateObservation(i, next)}
|
||||
onToggle={(i) =>
|
||||
store.setActiveObservation(activeIndex === i ? -1 : i)
|
||||
}
|
||||
onAdd={store.addObservation}
|
||||
onDelete={store.removeObservation}
|
||||
onMoveUp={store.moveObservationUp}
|
||||
onMoveDown={store.moveObservationDown}
|
||||
sheet={index}
|
||||
onChange={store.updateObservation}
|
||||
onOpenVertebraPicker={(_i, zoneIndex) =>
|
||||
setVertebraTarget(zoneIndex)
|
||||
}
|
||||
onRemoveZone={(i, zoneIndex) => {
|
||||
const obs = report.observations[i]
|
||||
if (!obs) return
|
||||
const zones = obs.zones.filter((_, k) => k !== zoneIndex)
|
||||
updateObservation(i, { ...obs, zones })
|
||||
if (obs) store.updateObservation(i, removeZoneAt(obs, zoneIndex))
|
||||
}}
|
||||
/>
|
||||
<ConclusionPanel
|
||||
conclusion={report.conclusion}
|
||||
recommendations={report.recommendations}
|
||||
nextAppointment={report.nextAppointment}
|
||||
onChangeConclusion={setConclusion}
|
||||
onChangeRecommendations={setRecommendations}
|
||||
onChangeNextAppointment={setNextAppointment}
|
||||
onChangeConclusion={store.setConclusion}
|
||||
onChangeRecommendations={store.setRecommendations}
|
||||
onChangeNextAppointment={store.setNextAppointment}
|
||||
/>
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={onExport} disabled={exporting}>
|
||||
<Button onClick={() => onExport(index)} disabled={exporting}>
|
||||
{exporting ? t('editor.exporting') : t('editor.export')}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{detail && (
|
||||
{detailView && (
|
||||
<DetailModal
|
||||
open
|
||||
onClose={() => setDetail(null)}
|
||||
detailSrc={detail.src}
|
||||
detailId={detail.id}
|
||||
title={`${t('editor.detail_title_prefix')}${detail.title}`}
|
||||
boneStates={boneStates}
|
||||
onZoneClick={(id, did) => onZoneClick(id, did)}
|
||||
onClose={() => setDetailViewId(null)}
|
||||
index={index}
|
||||
viewId={detailView.id}
|
||||
title={pickLabel(detailView.name, locale)}
|
||||
states={states}
|
||||
onZoneClick={onZoneClick}
|
||||
/>
|
||||
)}
|
||||
|
||||
{editDraft && (
|
||||
<Dialog
|
||||
open={editOpen}
|
||||
onClose={closeEditInfos}
|
||||
open
|
||||
onClose={() => setEditDraft(null)}
|
||||
title={t('editor.edit_dialog_title')}
|
||||
size="lg"
|
||||
>
|
||||
@@ -419,6 +299,9 @@ export default function EditorRoute() {
|
||||
<AnimalForm
|
||||
animal={editDraft.animal}
|
||||
owner={editDraft.owner}
|
||||
species={[
|
||||
{ id: index.sheet.speciesId, name: index.sheet.document.name },
|
||||
]}
|
||||
onChangeAnimal={(next) =>
|
||||
setEditDraft((d) => (d ? { ...d, animal: next } : d))
|
||||
}
|
||||
@@ -427,15 +310,17 @@ export default function EditorRoute() {
|
||||
}
|
||||
/>
|
||||
<div className="flex gap-3 justify-end pt-2 border-t border-[var(--color-border)]">
|
||||
<Button variant="ghost" onClick={closeEditInfos}>
|
||||
<Button variant="ghost" onClick={() => setEditDraft(null)}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={saveEditInfos}
|
||||
disabled={
|
||||
!editDraft.practitioner.name.trim() ||
|
||||
!editDraft.animal.name.trim() ||
|
||||
!editDraft.owner.name.trim()
|
||||
![
|
||||
editDraft.practitioner.name,
|
||||
editDraft.animal.name,
|
||||
editDraft.owner.name,
|
||||
].every((v) => v.trim())
|
||||
}
|
||||
>
|
||||
{t('common.save')}
|
||||
@@ -455,7 +340,9 @@ export default function EditorRoute() {
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-[var(--color-ink)]">{disclaimer}</p>
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={acknowledgeDisclaimer}>{t('common.understood')}</Button>
|
||||
<Button onClick={acknowledgeDisclaimer}>
|
||||
{t('common.understood')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
@@ -463,86 +350,45 @@ export default function EditorRoute() {
|
||||
|
||||
{vertebraTarget !== null &&
|
||||
activeObs &&
|
||||
activeObs.zones[vertebraTarget] && (
|
||||
vertebraZone &&
|
||||
isObservable(vertebraAnnotation) && (
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => setVertebraTarget(null)}
|
||||
onConfirm={(vertebrae) => {
|
||||
const fresh =
|
||||
useReportStore.getState().report?.observations[activeIndex]
|
||||
if (!fresh?.zones[vertebraTarget]) {
|
||||
setVertebraTarget(null)
|
||||
return
|
||||
if (fresh) {
|
||||
store.updateObservation(
|
||||
activeIndex,
|
||||
syncVertebrae(fresh, vertebrae, index, vertebraZone.viewId),
|
||||
)
|
||||
}
|
||||
// Picker edits every region at once: reconcile all spine zones —
|
||||
// spawn newly picked regions, prune emptied ones, keep the rest.
|
||||
const next = syncSpineZones(fresh.zones, vertebrae, bones)
|
||||
updateObservation(activeIndex, { ...fresh, zones: next })
|
||||
setVertebraTarget(null)
|
||||
}}
|
||||
initial={collectSpineVertebrae(
|
||||
activeObs.zones,
|
||||
bones,
|
||||
activeObs.zones[vertebraTarget].boneId,
|
||||
)}
|
||||
formula={species.vertebralFormula}
|
||||
title={`${t('vertebra.title_prefix')}${boneLabel(
|
||||
bones.get(activeObs.zones[vertebraTarget].boneId),
|
||||
locale,
|
||||
'',
|
||||
)}`}
|
||||
initialRegion={(() => {
|
||||
const b = bones.get(activeObs.zones[vertebraTarget].boneId)
|
||||
return regionFromLabel(b?.fr ?? '') ?? regionFromLabel(b?.en ?? '')
|
||||
})()}
|
||||
initial={collectVertebrae(activeObs, index, vertebraTarget)}
|
||||
regions={index.regions()}
|
||||
title={`${t('vertebra.title_prefix')}${pickLabel(vertebraAnnotation.name, locale)}`}
|
||||
initialRegion={
|
||||
vertebraAnnotation.vertebral_region_code ?? undefined
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{lateralTarget && activeObs && (
|
||||
{lateralTarget && activeObs && lateralAnnotation && (
|
||||
<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) => {
|
||||
title={pickLabel(index.name(lateralAnnotation), locale)}
|
||||
existingSides={sidesPresent(activeObs, lateralTarget)}
|
||||
onSelect={(sides: LateralSide[]) => {
|
||||
const fresh =
|
||||
useReportStore.getState().report?.observations[activeIndex]
|
||||
if (!fresh) {
|
||||
setLateralTarget(null)
|
||||
return
|
||||
}
|
||||
const newSideZones = sides
|
||||
.filter(
|
||||
(side) =>
|
||||
!fresh.zones.some(
|
||||
(z) =>
|
||||
z.boneId === lateralTarget.boneId &&
|
||||
z.detailSourceId === lateralTarget.detailSourceId &&
|
||||
z.side === side,
|
||||
),
|
||||
if (fresh)
|
||||
store.updateObservation(
|
||||
activeIndex,
|
||||
addSides(fresh, lateralAnnotation, sides),
|
||||
)
|
||||
.map((side) => ({
|
||||
boneId: lateralTarget.boneId,
|
||||
...(lateralTarget.detailSourceId
|
||||
? { detailSourceId: lateralTarget.detailSourceId }
|
||||
: {}),
|
||||
side,
|
||||
}))
|
||||
const nextZones = [...fresh.zones, ...newSideZones]
|
||||
updateObservation(activeIndex, { ...fresh, zones: nextZones })
|
||||
setLateralTarget(null)
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
import AppHeader from '@/components/brand/AppHeader'
|
||||
import Card from '@/components/ui/Card'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export default function EditorsRoute() {
|
||||
const t = useT()
|
||||
|
||||
return (
|
||||
<main className="flex-1 flex flex-col">
|
||||
<AppHeader />
|
||||
<section className="flex-1 grid place-items-center px-4 sm:px-6">
|
||||
<div className="grid gap-4 md:grid-cols-2 max-w-3xl w-full">
|
||||
<Card className="p-4 sm:p-6 space-y-3 sm:space-y-4">
|
||||
<h2 className="font-serif text-xl sm:text-2xl">{t('editors.svg.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editors.svg.description')}
|
||||
</p>
|
||||
<Link
|
||||
to="/svg-editor"
|
||||
className="inline-block rounded-lg bg-[var(--color-accent)] px-5 py-2 text-sm font-medium text-white hover:bg-[var(--color-accent-strong)] transition-colors"
|
||||
>
|
||||
{t('editors.svg.cta')}
|
||||
</Link>
|
||||
</Card>
|
||||
<Card className="p-4 sm:p-6 space-y-3 sm:space-y-4">
|
||||
<h2 className="font-serif text-xl sm:text-2xl">{t('editors.pathology.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editors.pathology.description')}
|
||||
</p>
|
||||
<a
|
||||
href="/pathology-editor.html"
|
||||
className="inline-block rounded-lg bg-[var(--color-accent)] px-5 py-2 text-sm font-medium text-white hover:bg-[var(--color-accent-strong)] transition-colors"
|
||||
>
|
||||
{t('editors.pathology.cta')}
|
||||
</a>
|
||||
</Card>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -5,25 +5,42 @@ import Button from '@/components/ui/Button'
|
||||
import Card from '@/components/ui/Card'
|
||||
import { importReportFromPdf, ImportError } from '@/pdf/import'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useSheet } from '@/sheets/useSheet'
|
||||
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export default function HomeRoute() {
|
||||
const navigate = useNavigate()
|
||||
const fileRef = useRef<HTMLInputElement | null>(null)
|
||||
const hydrate = useReportStore((s) => s.hydrateReport)
|
||||
const sheet = useSheet(DEFAULT_SPECIES_ID)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const t = useT()
|
||||
|
||||
async function onPickFile(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0]
|
||||
if (!file) return
|
||||
if (!file || sheet.status !== 'ready') return
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
const bytes = new Uint8Array(await file.arrayBuffer())
|
||||
const report = await importReportFromPdf(bytes)
|
||||
hydrate(report)
|
||||
const outcome = await importReportFromPdf(
|
||||
bytes,
|
||||
sheet.index.sheet.migrationMap,
|
||||
)
|
||||
if (
|
||||
outcome.migrated &&
|
||||
outcome.unresolvedFindings + outcome.unresolvedZones > 0
|
||||
) {
|
||||
window.alert(
|
||||
t('home.import.migrated').replace(
|
||||
'{count}',
|
||||
String(outcome.unresolvedFindings + outcome.unresolvedZones),
|
||||
),
|
||||
)
|
||||
}
|
||||
hydrate(outcome.report)
|
||||
navigate('/editor')
|
||||
} catch (err) {
|
||||
if (err instanceof ImportError) {
|
||||
@@ -48,21 +65,58 @@ export default function HomeRoute() {
|
||||
}
|
||||
}
|
||||
|
||||
const noSheet = sheet.status === 'none'
|
||||
|
||||
return (
|
||||
<main className="flex-1 flex flex-col">
|
||||
<AppHeader />
|
||||
<section className="flex-1 grid place-items-center px-4 sm:px-6">
|
||||
<div className="grid gap-4 md:grid-cols-2 max-w-3xl w-full">
|
||||
{noSheet && (
|
||||
<Card className="p-4 sm:p-6 space-y-2 md:col-span-2">
|
||||
<h2 className="font-serif text-xl sm:text-2xl">
|
||||
{t('home.no_sheet.title')}
|
||||
</h2>
|
||||
<p className="text-sm text-red-700">
|
||||
{t('home.no_sheet.description')}
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
<Card className="p-4 sm:p-6 space-y-3 sm:space-y-4">
|
||||
<h2 className="font-serif text-xl sm:text-2xl">{t('home.new_report.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('home.new_report.description')}</p>
|
||||
<Button onClick={() => navigate('/new')} size="lg">{t('home.new_report.cta')}</Button>
|
||||
<h2 className="font-serif text-xl sm:text-2xl">
|
||||
{t('home.new_report.title')}
|
||||
</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('home.new_report.description')}
|
||||
</p>
|
||||
<Button
|
||||
onClick={() => navigate('/new')}
|
||||
size="lg"
|
||||
disabled={noSheet}
|
||||
>
|
||||
{t('home.new_report.cta')}
|
||||
</Button>
|
||||
</Card>
|
||||
<Card className="p-4 sm:p-6 space-y-3 sm:space-y-4">
|
||||
<h2 className="font-serif text-xl sm:text-2xl">{t('home.import.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('home.import.description')}</p>
|
||||
<input ref={fileRef} type="file" accept="application/pdf,.pdf" className="hidden" onChange={onPickFile} />
|
||||
<Button variant="secondary" size="lg" onClick={() => fileRef.current?.click()} disabled={busy}>
|
||||
<h2 className="font-serif text-xl sm:text-2xl">
|
||||
{t('home.import.title')}
|
||||
</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('home.import.description')}
|
||||
</p>
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="application/pdf,.pdf"
|
||||
className="hidden"
|
||||
onChange={onPickFile}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="lg"
|
||||
onClick={() => fileRef.current?.click()}
|
||||
disabled={busy || sheet.status !== 'ready'}
|
||||
>
|
||||
{busy ? t('home.import.loading') : t('home.import.cta')}
|
||||
</Button>
|
||||
{error && <p className="text-sm text-red-700">{error}</p>}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import type { Animal, Owner, Practitioner } from '@faunosteo/domain'
|
||||
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||
import AnimalForm from '@/components/report/AnimalForm'
|
||||
import AppHeader from '@/components/brand/AppHeader'
|
||||
@@ -7,18 +8,29 @@ import Button from '@/components/ui/Button'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Label from '@/components/ui/Label'
|
||||
import { todayIso } from '@/lib/dates'
|
||||
import { readCachedPractitioner, writeCachedPractitioner } from '@/state/practitionerCache'
|
||||
import {
|
||||
readCachedPractitioner,
|
||||
writeCachedPractitioner,
|
||||
} from '@/state/practitionerCache'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useSheet } from '@/sheets/useSheet'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** The one species this build ships a sheet for. */
|
||||
export const DEFAULT_SPECIES_ID = 'equine'
|
||||
|
||||
export default function NewReportRoute() {
|
||||
const navigate = useNavigate()
|
||||
const initReport = useReportStore((s) => s.initReport)
|
||||
const t = useT()
|
||||
const sheet = useSheet(DEFAULT_SPECIES_ID)
|
||||
|
||||
const [practitioner, setPractitioner] = useState({ name: '' })
|
||||
const [animal, setAnimal] = useState({ speciesId: 'equine', name: '' })
|
||||
const [owner, setOwner] = useState({ name: '' })
|
||||
const [practitioner, setPractitioner] = useState<Practitioner>({ name: '' })
|
||||
const [animal, setAnimal] = useState<Animal>({
|
||||
speciesId: DEFAULT_SPECIES_ID,
|
||||
name: '',
|
||||
})
|
||||
const [owner, setOwner] = useState<Owner>({ name: '' })
|
||||
const [date, setDate] = useState(todayIso())
|
||||
|
||||
useEffect(() => {
|
||||
@@ -26,20 +38,27 @@ export default function NewReportRoute() {
|
||||
if (cached) setPractitioner(cached)
|
||||
}, [])
|
||||
|
||||
const canSubmit = practitioner.name.trim() && animal.name.trim() && owner.name.trim()
|
||||
const canSubmit =
|
||||
practitioner.name.trim() &&
|
||||
animal.name.trim() &&
|
||||
owner.name.trim() &&
|
||||
sheet.status === 'ready'
|
||||
|
||||
function submit() {
|
||||
if (!canSubmit) return
|
||||
if (!canSubmit || sheet.status !== 'ready') return
|
||||
writeCachedPractitioner(practitioner)
|
||||
initReport({
|
||||
date,
|
||||
practitioner,
|
||||
animal,
|
||||
owner,
|
||||
observations: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
})
|
||||
initReport(
|
||||
{
|
||||
date,
|
||||
practitioner,
|
||||
animal,
|
||||
owner,
|
||||
observations: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
},
|
||||
sheet.index.sheet.ref,
|
||||
)
|
||||
navigate('/editor')
|
||||
}
|
||||
|
||||
@@ -47,16 +66,52 @@ export default function NewReportRoute() {
|
||||
<main className="min-h-screen">
|
||||
<AppHeader />
|
||||
<div className="max-w-3xl mx-auto px-4 sm:px-6 py-6 sm:py-8 space-y-6 sm:space-y-8">
|
||||
<h1 className="font-serif text-2xl sm:text-3xl">{t('new_report.title')}</h1>
|
||||
<h1 className="font-serif text-2xl sm:text-3xl">
|
||||
{t('new_report.title')}
|
||||
</h1>
|
||||
{sheet.status === 'none' && (
|
||||
<p className="text-sm text-red-700">
|
||||
{t('home.no_sheet.description')}
|
||||
</p>
|
||||
)}
|
||||
<div>
|
||||
<Label htmlFor="date">{t('new_report.date_label')}</Label>
|
||||
<Input id="date" type="date" value={date} onChange={(e) => setDate(e.target.value)} />
|
||||
<Input
|
||||
id="date"
|
||||
type="date"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<PractitionerForm value={practitioner} onChange={setPractitioner} />
|
||||
<AnimalForm animal={animal} owner={owner} onChangeAnimal={setAnimal} onChangeOwner={setOwner} />
|
||||
<AnimalForm
|
||||
animal={animal}
|
||||
owner={owner}
|
||||
species={
|
||||
sheet.status === 'ready'
|
||||
? [
|
||||
{
|
||||
id: sheet.index.sheet.speciesId,
|
||||
name: sheet.index.sheet.document.name,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
id: DEFAULT_SPECIES_ID,
|
||||
name: { fr: 'Cheval', en: 'Horse' },
|
||||
},
|
||||
]
|
||||
}
|
||||
onChangeAnimal={setAnimal}
|
||||
onChangeOwner={setOwner}
|
||||
/>
|
||||
<div className="flex gap-3 justify-end">
|
||||
<Button variant="ghost" onClick={() => navigate('/')}>{t('common.cancel')}</Button>
|
||||
<Button disabled={!canSubmit} onClick={submit}>{t('new_report.submit')}</Button>
|
||||
<Button variant="ghost" onClick={() => navigate('/')}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button disabled={!canSubmit} onClick={submit}>
|
||||
{t('new_report.submit')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -9,8 +9,12 @@ export default function NotFoundRoute() {
|
||||
<main className="min-h-screen grid place-items-center">
|
||||
<div className="text-center space-y-4">
|
||||
<h1 className="font-serif text-4xl">{t('not_found.title')}</h1>
|
||||
<p className="text-[var(--color-ink-muted)]">{t('not_found.description')}</p>
|
||||
<Button onClick={() => navigate('/')}>{t('common.back_to_home')}</Button>
|
||||
<p className="text-[var(--color-ink-muted)]">
|
||||
{t('not_found.description')}
|
||||
</p>
|
||||
<Button onClick={() => navigate('/')}>
|
||||
{t('common.back_to_home')}
|
||||
</Button>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user