docs(docs): add anatomical audit of existing SVG, catalog and report systems
Read-only technical audit before the SaaS redesign: 13 reports, a logical anatomical-sheet JSON built from real horse data, verbatim copies of the 52 relevant source files, and a self-contained ZIP.
This commit is contained in:
1 parent
83e40af99b
commit
e471d41c6b
70 files changed
+22075
No files matched your search
@@ -0,0 +1,166 @@
|
||||
import { create } from 'zustand'
|
||||
import { ReportSchema, type Report } from '@/domain/schema/report'
|
||||
import type { Observation } from '@/domain/schema/observation'
|
||||
import type { Practitioner } from '@/domain/schema/practitioner'
|
||||
import type { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { generateId } from '@/lib/id'
|
||||
import { nowIso } from '@/lib/dates'
|
||||
|
||||
export interface ReportStore {
|
||||
report: Report | null
|
||||
activeObservationIndex: number
|
||||
initReport: (draft: Omit<Report, 'id' | 'createdAt' | 'version'>) => void
|
||||
hydrateReport: (report: Report) => void
|
||||
addObservation: () => void
|
||||
removeObservation: (index: number) => void
|
||||
moveObservationUp: (index: number) => void
|
||||
moveObservationDown: (index: number) => void
|
||||
updateObservation: (index: number, obs: Observation) => void
|
||||
setActiveObservation: (index: number) => void
|
||||
setPractitioner: (next: Practitioner) => void
|
||||
setAnimal: (next: Animal) => void
|
||||
setOwner: (next: Owner) => void
|
||||
setConclusion: (text: string) => void
|
||||
setRecommendations: (text: string) => void
|
||||
setNextAppointment: (next: Report['nextAppointment']) => void
|
||||
reset: () => void
|
||||
}
|
||||
|
||||
function emptyObservation(): Observation {
|
||||
return {
|
||||
id: generateId(),
|
||||
zones: [],
|
||||
findings: [],
|
||||
freeTextFindings: [],
|
||||
comment: '',
|
||||
}
|
||||
}
|
||||
|
||||
const DRAFT_KEY = 'osteo:draft'
|
||||
|
||||
/** Reads the auto-saved draft back from sessionStorage (null if absent/invalid). */
|
||||
export function readPersistedDraft(): Report | null {
|
||||
if (typeof sessionStorage === 'undefined') return null
|
||||
const raw = sessionStorage.getItem(DRAFT_KEY)
|
||||
if (!raw) return null
|
||||
try {
|
||||
const parsed = ReportSchema.safeParse(JSON.parse(raw))
|
||||
return parsed.success ? parsed.data : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export const useReportStore = create<ReportStore>((set) => ({
|
||||
// Restore the per-tab draft so a page refresh never loses the session.
|
||||
report: readPersistedDraft(),
|
||||
activeObservationIndex: 0,
|
||||
|
||||
initReport: (draft) =>
|
||||
set({
|
||||
report: {
|
||||
...draft,
|
||||
version: 2,
|
||||
id: generateId(),
|
||||
createdAt: nowIso(),
|
||||
observations:
|
||||
draft.observations.length === 0
|
||||
? [emptyObservation()]
|
||||
: draft.observations,
|
||||
},
|
||||
activeObservationIndex: 0,
|
||||
}),
|
||||
|
||||
hydrateReport: (report) => set({ report, activeObservationIndex: 0 }),
|
||||
|
||||
addObservation: () =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const obs = emptyObservation()
|
||||
const observations = [...s.report.observations, obs]
|
||||
return {
|
||||
report: { ...s.report, observations },
|
||||
activeObservationIndex: observations.length - 1,
|
||||
}
|
||||
}),
|
||||
|
||||
removeObservation: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const observations = s.report.observations.filter((_, i) => i !== index)
|
||||
const active = Math.min(
|
||||
s.activeObservationIndex,
|
||||
Math.max(0, observations.length - 1),
|
||||
)
|
||||
return {
|
||||
report: { ...s.report, observations },
|
||||
activeObservationIndex: active,
|
||||
}
|
||||
}),
|
||||
|
||||
moveObservationUp: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report || index <= 0) return s
|
||||
const observations = [...s.report.observations]
|
||||
;[observations[index - 1], observations[index]] = [
|
||||
observations[index],
|
||||
observations[index - 1],
|
||||
]
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
moveObservationDown: (index) =>
|
||||
set((s) => {
|
||||
if (!s.report || index >= s.report.observations.length - 1) return s
|
||||
const observations = [...s.report.observations]
|
||||
;[observations[index], observations[index + 1]] = [
|
||||
observations[index + 1],
|
||||
observations[index],
|
||||
]
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
updateObservation: (index, obs) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s
|
||||
const observations = s.report.observations.map((o, i) =>
|
||||
i === index ? obs : o,
|
||||
)
|
||||
return { report: { ...s.report, observations } }
|
||||
}),
|
||||
|
||||
setActiveObservation: (index) => set({ activeObservationIndex: index }),
|
||||
|
||||
setPractitioner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, practitioner: next } } : s)),
|
||||
|
||||
setAnimal: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, animal: next } } : s)),
|
||||
|
||||
setOwner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, owner: next } } : s)),
|
||||
|
||||
setConclusion: (text) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, conclusion: text } } : s)),
|
||||
|
||||
setRecommendations: (text) =>
|
||||
set((s) =>
|
||||
s.report ? { report: { ...s.report, recommendations: text } } : s,
|
||||
),
|
||||
|
||||
setNextAppointment: (next) =>
|
||||
set((s) =>
|
||||
s.report ? { report: { ...s.report, nextAppointment: next } } : s,
|
||||
),
|
||||
|
||||
reset: () => set({ report: null, activeObservationIndex: 0 }),
|
||||
}))
|
||||
|
||||
useReportStore.subscribe((state) => {
|
||||
if (typeof sessionStorage === 'undefined') return
|
||||
if (state.report) {
|
||||
sessionStorage.setItem(DRAFT_KEY, JSON.stringify(state.report))
|
||||
} else {
|
||||
sessionStorage.removeItem(DRAFT_KEY)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user