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:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 03:48:57 +02:00
1 parent f80e161d61
commit d08d773d74
13 files changed
+146 -108

No files matched your search

+21 -2
View File
@@ -3,11 +3,21 @@ import { ReportSchema, type Report } from '@/domain/schema/report'
const FILENAME = 'osteo-report.json'
export class IncompatibleReportVersionError extends Error {
constructor(public readonly foundVersion: number) {
super(
`Ce PDF est au format v${foundVersion}, incompatible avec la version actuelle (v2). ` +
`Réexportez le bilan depuis une version récente de l'application.`,
)
this.name = 'IncompatibleReportVersionError'
}
}
export async function attachReportJson(pdfDoc: PDFDocument, report: Report): Promise<void> {
const bytes = new TextEncoder().encode(JSON.stringify(report, null, 2))
await pdfDoc.attach(bytes, FILENAME, {
mimeType: 'application/json',
description: 'Osteo Report state v1',
description: 'Osteo Report state v2',
creationDate: new Date(),
modificationDate: new Date(),
afRelationship: AFRelationship.Data,
@@ -30,7 +40,16 @@ export async function extractReportJson(pdfDoc: PDFDocument): Promise<Report> {
function parseAttachment(bytes: Uint8Array): Report {
const text = new TextDecoder().decode(bytes)
const data = JSON.parse(text)
const data: unknown = JSON.parse(text)
if (
data !== null &&
typeof data === 'object' &&
'version' in data &&
typeof (data as { version: unknown }).version === 'number' &&
(data as { version: number }).version !== 2
) {
throw new IncompatibleReportVersionError((data as { version: number }).version)
}
return ReportSchema.parse(data)
}
+12 -4
View File
@@ -1,10 +1,13 @@
import { PDFDocument } from 'pdf-lib'
import { extractReportJson } from './attachment'
import { extractReportJson, IncompatibleReportVersionError } from './attachment'
import type { Report } from '@/domain/schema/report'
export class ImportError extends Error {
constructor() {
super("Ce PDF n'a pas été généré par Osteo Report (pas de données détectées).")
constructor(message?: string) {
super(
message ??
"Ce PDF n'a pas été généré par Osteo Report (pas de données détectées).",
)
this.name = 'ImportError'
}
}
@@ -18,7 +21,12 @@ export async function importReportFromPdf(pdfBytes: Uint8Array): Promise<Report>
}
try {
return await extractReportJson(pdfDoc)
} catch {
} catch (err) {
// Version mismatch is a distinct failure mode — surface its message
// to the user instead of the generic "not an osteo PDF" line.
if (err instanceof IncompatibleReportVersionError) {
throw new ImportError(err.message)
}
throw new ImportError()
}
}