feat(schema): bump report to v2 + observation findings + drop pathology
ObservationSchema now carries a hierarchical Finding (zoneId + path + labelFrSnapshot + labelEnSnapshot + requiresVetReferral?) plus a renamed freeTextFindings list, replacing the flat pathologyIds / freeTextPathologies pair. Snapshot labels keep already-exported reports readable if the catalog is later edited. ReportSchema.version bumped from 1 → 2. PDF import surfaces a distinct, French-language error message on legacy v1 attachments instead of the generic "not an osteo PDF" line, via a new IncompatibleReportVersionError detected before the strict Zod parse runs. Store seed and tests updated for the new shape. The standalone Pathology Zod schema and its test are removed — the new findings tree is the single source of truth for what an observation can carry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f80e161d61
commit
d08d773d74
13 files changed
+146
-108
No files matched your search
@@ -4,7 +4,7 @@ import { attachReportJson, extractReportJson } from '@/pdf/attachment'
|
||||
import type { Report } from '@/domain/schema/report'
|
||||
|
||||
const report: Report = {
|
||||
version: 1,
|
||||
version: 2,
|
||||
id: 'r1',
|
||||
createdAt: '2026-05-18T10:00:00Z',
|
||||
date: '2026-05-18',
|
||||
@@ -27,7 +27,7 @@ describe('PDF attachment roundtrip', () => {
|
||||
const out = await extractReportJson(reopened)
|
||||
expect(out.conclusion).toBe('tout va bien')
|
||||
expect(out.animal.name).toBe('Mistral')
|
||||
expect(out.version).toBe(1)
|
||||
expect(out.version).toBe(2)
|
||||
})
|
||||
|
||||
it('throws on PDFs without the attachment', async () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { AFRelationship, PDFDocument } from 'pdf-lib'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import { importReportFromPdf, ImportError } from '@/pdf/import'
|
||||
import type { Report } from '@/domain/schema/report'
|
||||
@@ -6,7 +7,7 @@ import type { Report } from '@/domain/schema/report'
|
||||
vi.mock('@/pdf/render/svgToPng', () => ({ rasterizeSvg: async () => new Uint8Array([137, 80, 78, 71]) }))
|
||||
|
||||
const report: Report = {
|
||||
version: 1,
|
||||
version: 2,
|
||||
id: 'r1',
|
||||
createdAt: '2026-05-18T10:00:00Z',
|
||||
date: '2026-05-18',
|
||||
@@ -28,5 +29,31 @@ describe('PDF roundtrip', () => {
|
||||
const bytes = await exportReportToPdf(report)
|
||||
const imported = await importReportFromPdf(bytes)
|
||||
expect(imported.animal.name).toBe('Mistral')
|
||||
expect(imported.version).toBe(2)
|
||||
})
|
||||
|
||||
it('rejects a legacy v1 PDF with a version-specific message', async () => {
|
||||
const doc = await PDFDocument.create()
|
||||
doc.addPage()
|
||||
const legacyPayload = {
|
||||
version: 1,
|
||||
id: 'legacy',
|
||||
createdAt: '2025-12-01T00:00:00Z',
|
||||
date: '2025-12-01',
|
||||
practitioner: { name: 'Dr. Dupont' },
|
||||
animal: { speciesId: 'equine', name: 'Mistral' },
|
||||
owner: { name: 'Jean Martin' },
|
||||
observations: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
}
|
||||
const bytes = new TextEncoder().encode(JSON.stringify(legacyPayload))
|
||||
await doc.attach(bytes, 'osteo-report.json', {
|
||||
mimeType: 'application/json',
|
||||
description: 'Osteo Report state v1',
|
||||
afRelationship: AFRelationship.Data,
|
||||
})
|
||||
const pdfBytes = await doc.save()
|
||||
await expect(importReportFromPdf(pdfBytes)).rejects.toThrow(/v1/)
|
||||
})
|
||||
})
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ObservationSchema,
|
||||
VertebraSchema,
|
||||
SeveritySchema,
|
||||
FindingSchema,
|
||||
} from '@/domain/schema/observation'
|
||||
|
||||
describe('SeveritySchema', () => {
|
||||
@@ -34,12 +35,39 @@ describe('VertebraSchema', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('FindingSchema', () => {
|
||||
const base = {
|
||||
zoneId: 'sphenoid',
|
||||
path: ['sphenoid-dysfunctions', 'physiological', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
}
|
||||
|
||||
it('accepts a minimal finding', () => {
|
||||
expect(() => FindingSchema.parse(base)).not.toThrow()
|
||||
})
|
||||
|
||||
it('accepts the optional vet-referral flag', () => {
|
||||
expect(() =>
|
||||
FindingSchema.parse({ ...base, requiresVetReferral: true }),
|
||||
).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects an empty path', () => {
|
||||
expect(() => FindingSchema.parse({ ...base, path: [] })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects an empty zoneId', () => {
|
||||
expect(() => FindingSchema.parse({ ...base, zoneId: '' })).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('ObservationSchema', () => {
|
||||
const baseObs = {
|
||||
id: 'obs-1',
|
||||
zones: [{ boneId: 'epaule' }],
|
||||
pathologyIds: [],
|
||||
freeTextPathologies: [],
|
||||
findings: [],
|
||||
freeTextFindings: [],
|
||||
comment: '',
|
||||
}
|
||||
|
||||
@@ -63,6 +91,22 @@ describe('ObservationSchema', () => {
|
||||
expect(() => ObservationSchema.parse(obs)).not.toThrow()
|
||||
})
|
||||
|
||||
it('accepts an observation with findings and free-text additions', () => {
|
||||
const obs = {
|
||||
...baseObs,
|
||||
findings: [
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['sphenoid-dysfunctions', 'physiological', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
},
|
||||
],
|
||||
freeTextFindings: ['note libre'],
|
||||
}
|
||||
expect(() => ObservationSchema.parse(obs)).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects empty id', () => {
|
||||
expect(() => ObservationSchema.parse({ ...baseObs, id: '' })).toThrow()
|
||||
})
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { PathologySchema } from '@/domain/schema/pathology'
|
||||
|
||||
describe('PathologySchema', () => {
|
||||
const base = {
|
||||
id: 'desmite-suspenseur',
|
||||
labelFr: 'Desmite du ligament suspenseur',
|
||||
description: 'Inflammation du ligament suspenseur du boulet.',
|
||||
category: 'tendino-ligamentaire' as const,
|
||||
speciesIds: ['equine'],
|
||||
boneIds: ['boulet-ant', 'boulet-post'],
|
||||
sources: [
|
||||
{ type: 'manual' as const, citation: 'Merck Vet Manual (2024).' },
|
||||
],
|
||||
}
|
||||
|
||||
it('accepts a valid entry', () => {
|
||||
expect(() => PathologySchema.parse(base)).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects zero sources', () => {
|
||||
expect(() => PathologySchema.parse({ ...base, sources: [] })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects empty id', () => {
|
||||
expect(() => PathologySchema.parse({ ...base, id: '' })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects non-URL urls', () => {
|
||||
expect(() =>
|
||||
PathologySchema.parse({
|
||||
...base,
|
||||
sources: [{ type: 'web', citation: 'X', url: 'not-a-url' }],
|
||||
}),
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
|
||||
import { ReportSchema } from '@/domain/schema/report'
|
||||
|
||||
const minimal = {
|
||||
version: 1 as const,
|
||||
version: 2 as const,
|
||||
id: 'r1',
|
||||
createdAt: '2026-05-18T10:00:00Z',
|
||||
date: '2026-05-18',
|
||||
@@ -37,8 +37,12 @@ describe('ReportSchema', () => {
|
||||
).not.toThrow()
|
||||
})
|
||||
|
||||
it('rejects version !== 1', () => {
|
||||
expect(() => ReportSchema.parse({ ...minimal, version: 2 })).toThrow()
|
||||
it('rejects legacy v1 reports', () => {
|
||||
expect(() => ReportSchema.parse({ ...minimal, version: 1 })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects unknown future versions', () => {
|
||||
expect(() => ReportSchema.parse({ ...minimal, version: 3 })).toThrow()
|
||||
})
|
||||
|
||||
it('rejects empty practitioner.name', () => {
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('skeleton smoke test', () => {
|
||||
|
||||
it('ReportSchema parses a valid minimal report', () => {
|
||||
const validReport = {
|
||||
version: 1 as const,
|
||||
version: 2 as const,
|
||||
id: generateId(),
|
||||
createdAt: nowIso(),
|
||||
date: todayIso(),
|
||||
|
||||
@@ -16,10 +16,10 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('reportStore.initReport', () => {
|
||||
it('sets a report with version=1, id, and createdAt', () => {
|
||||
it('sets a report with version=2, id, and createdAt', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
const r = useReportStore.getState().report!
|
||||
expect(r.version).toBe(1)
|
||||
expect(r.version).toBe(2)
|
||||
expect(r.id.length).toBeGreaterThan(0)
|
||||
expect(r.createdAt).toMatch(/^\d{4}-\d{2}-\d{2}T/)
|
||||
expect(r.practitioner.name).toBe('Dr. Dupont')
|
||||
|
||||
Reference in new issue
Block a user