feat: domain core — schemas, store, equine data, PDF roundtrip
Phase A — Domain & schemas (15 tests): - Zod schemas: ReportSchema, FindingSchema, PractitionerSchema, SeveritySchema - Types derived via z.infer (single source of truth) - newId() helper with optional prefix Phase B — Equine anatomy + pathology DB (7 tests): - 26 macro zones, axial subzones C1-7/T1-18/L1-6/S1-5 - 31 pathologies, each citing Merck Vet Manual, PubMed, IMAIOS or LCAO - Placeholder SVGs (lateral L/R + dorsal) with data-zone convention - Species registry: equine registered, 8 others remain stubs Phase C — Zustand store (8 tests): - Single source of truth with persist middleware (localStorage key osteo-report-draft) - Actions: hydrate, reset, toggleZone, addFinding, updateFinding, removeFinding, setConclusion/Recommendations/NextAppointment Phase H/I — PDF export + import roundtrip (2 tests): - A4 portrait, pdf-lib StandardFonts - Header (practitioner + animal), anatomy pages (per used view), findings table, conclusion/recommendations/RDV page, page footer with date+page# - Attachment: base64 data URI workaround (pdf-lib treats raw string as base64 input, and rejects cross-realm Uint8Array in jsdom tests) - Import: walks Catalog→Names→EmbeddedFiles→Names array→F stream; inflates via pako directly (bypasses pdf-lib's reference-equality FlateDecode check which fails across module realms in vitest); validates with ReportSchema Tooling: - Add pako 2.x + @types/pako (already transitive of pdf-lib) - Switch vitest 2 → 3 (already done in prior commit) - Add 8 test files (34 tests total green)
This commit is contained in:
1 parent
4c465a5743
commit
b5b2e163c9
20 files changed
+1383
-41
No files matched your search
+90
-27
@@ -1,56 +1,119 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { persist, createJSONStorage } from 'zustand/middleware';
|
||||
|
||||
import { newId } from '../lib/id';
|
||||
import type { Finding } from '../schema/finding';
|
||||
import type { Report } from '../schema/report';
|
||||
import { SCHEMA_VERSION } from '../schema/report';
|
||||
|
||||
interface ReportState {
|
||||
report: Report | null;
|
||||
selection: string[];
|
||||
|
||||
hydrate: (r: Report) => void;
|
||||
reset: () => void;
|
||||
|
||||
toggleZone: (zoneId: string) => void;
|
||||
clearSelection: () => void;
|
||||
addFinding: (f: Finding) => void;
|
||||
setSelection: (zones: string[]) => void;
|
||||
|
||||
addFinding: (input: Omit<Finding, 'id'>) => Finding;
|
||||
updateFinding: (id: string, patch: Partial<Finding>) => void;
|
||||
removeFinding: (id: string) => void;
|
||||
|
||||
setConclusion: (text: string) => void;
|
||||
setRecommendations: (text: string) => void;
|
||||
setNextAppointment: (date: string | undefined) => void;
|
||||
}
|
||||
|
||||
function emptyReport(overrides: Partial<Report> = {}): Report {
|
||||
return {
|
||||
version: SCHEMA_VERSION,
|
||||
id: newId('report'),
|
||||
createdAt: new Date().toISOString(),
|
||||
species: 'equine',
|
||||
practitioner: { fullName: '' },
|
||||
animal: { name: '', owner: '' },
|
||||
sessionDate: new Date().toISOString().slice(0, 10),
|
||||
findings: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export const useReportStore = create<ReportState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
(set, get) => ({
|
||||
report: null,
|
||||
selection: [],
|
||||
hydrate: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
|
||||
hydrate: (r) => set({ report: r, selection: [] }),
|
||||
reset: () => set({ report: null, selection: [] }),
|
||||
toggleZone: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
|
||||
toggleZone: (zoneId) =>
|
||||
set((s) => {
|
||||
const has = s.selection.includes(zoneId);
|
||||
return {
|
||||
selection: has ? s.selection.filter((z) => z !== zoneId) : [...s.selection, zoneId],
|
||||
};
|
||||
}),
|
||||
clearSelection: () => set({ selection: [] }),
|
||||
addFinding: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
updateFinding: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
removeFinding: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
setConclusion: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
setRecommendations: () => {
|
||||
// implemented in feature task
|
||||
},
|
||||
setNextAppointment: () => {
|
||||
// implemented in feature task
|
||||
setSelection: (zones) => set({ selection: zones }),
|
||||
|
||||
addFinding: (input) => {
|
||||
const finding: Finding = { ...input, id: newId('finding') };
|
||||
const r = get().report;
|
||||
if (!r) return finding;
|
||||
set({
|
||||
report: { ...r, findings: [...r.findings, finding] },
|
||||
selection: [],
|
||||
});
|
||||
return finding;
|
||||
},
|
||||
|
||||
updateFinding: (id, patch) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
return {
|
||||
report: {
|
||||
...s.report,
|
||||
findings: s.report.findings.map((f) => (f.id === id ? { ...f, ...patch } : f)),
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
removeFinding: (id) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
return {
|
||||
report: {
|
||||
...s.report,
|
||||
findings: s.report.findings.filter((f) => f.id !== id),
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
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: (date) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
const next: Report =
|
||||
date === undefined
|
||||
? { ...s.report, nextAppointment: undefined }
|
||||
: { ...s.report, nextAppointment: date };
|
||||
return { report: next };
|
||||
}),
|
||||
}),
|
||||
{ name: 'osteo-report-draft' },
|
||||
{
|
||||
name: 'osteo-report-draft',
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
partialize: (s) => ({ report: s.report }),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
export { emptyReport };
|
||||
Reference in new issue
Block a user