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
+241
-3
@@ -1,9 +1,247 @@
|
||||
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
|
||||
|
||||
import { FR } from '../i18n/fr';
|
||||
import { formatDateFr } from '../lib/date';
|
||||
import type { Report } from '../schema/report';
|
||||
import type { SpeciesAnatomy } from '../species/types';
|
||||
|
||||
import { PDF_ATTACHMENT_NAME } from './version';
|
||||
|
||||
const A4 = { width: 595.28, height: 841.89 } as const;
|
||||
const MARGIN = 48;
|
||||
const FOOT = 32;
|
||||
|
||||
export interface AnatomyAssets {
|
||||
svg: Record<string, string>;
|
||||
anatomy: SpeciesAnatomy;
|
||||
rasters: Partial<Record<'lateral_left' | 'lateral_right' | 'dorsal', Uint8Array | ArrayBuffer>>;
|
||||
}
|
||||
|
||||
export function exportReport(_report: Report, _assets: AnatomyAssets): Promise<Blob> {
|
||||
return Promise.reject(new Error('exportReport not implemented'));
|
||||
function zoneLabel(anatomy: SpeciesAnatomy, id: string): string {
|
||||
return anatomy.zones.find((z) => z.id === id)?.label ?? id;
|
||||
}
|
||||
|
||||
export async function exportReportBytes(report: Report, assets: AnatomyAssets): Promise<Uint8Array> {
|
||||
const pdf = await PDFDocument.create();
|
||||
pdf.setTitle(`Bilan ostéopathique — ${report.animal.name}`);
|
||||
pdf.setAuthor(report.practitioner.fullName);
|
||||
pdf.setSubject(FR.app.tagline);
|
||||
pdf.setCreator(FR.app.name);
|
||||
pdf.setProducer('pdf-lib');
|
||||
pdf.setCreationDate(new Date(report.createdAt));
|
||||
|
||||
const font = await pdf.embedFont(StandardFonts.Helvetica);
|
||||
const fontBold = await pdf.embedFont(StandardFonts.HelveticaBold);
|
||||
|
||||
let page = pdf.addPage([A4.width, A4.height]);
|
||||
let y = A4.height - MARGIN;
|
||||
|
||||
// ───────── Header
|
||||
page.drawText(FR.app.name, {
|
||||
x: MARGIN,
|
||||
y,
|
||||
size: 18,
|
||||
font: fontBold,
|
||||
color: rgb(0.29, 0.49, 0.35),
|
||||
});
|
||||
page.drawText(FR.app.tagline, { x: MARGIN, y: y - 16, size: 9, font, color: rgb(0.4, 0.4, 0.4) });
|
||||
y -= 36;
|
||||
|
||||
page.drawText(`Animal : ${report.animal.name}`, { x: MARGIN, y, size: 11, font: fontBold });
|
||||
page.drawText(`Propriétaire : ${report.animal.owner}`, { x: MARGIN, y: y - 14, size: 11, font });
|
||||
page.drawText(`Séance : ${formatDateFr(report.sessionDate)}`, { x: MARGIN, y: y - 28, size: 11, font });
|
||||
|
||||
const practX = A4.width / 2 + 20;
|
||||
page.drawText(report.practitioner.fullName, { x: practX, y, size: 11, font: fontBold });
|
||||
let practY = y - 14;
|
||||
for (const line of [
|
||||
report.practitioner.title,
|
||||
report.practitioner.phone,
|
||||
report.practitioner.email,
|
||||
report.practitioner.address,
|
||||
report.practitioner.siret ? `SIRET ${report.practitioner.siret}` : undefined,
|
||||
]) {
|
||||
if (!line) continue;
|
||||
page.drawText(line, { x: practX, y: practY, size: 10, font });
|
||||
practY -= 12;
|
||||
}
|
||||
y = Math.min(y - 60, practY - 24);
|
||||
page.drawLine({
|
||||
start: { x: MARGIN, y },
|
||||
end: { x: A4.width - MARGIN, y },
|
||||
thickness: 0.6,
|
||||
color: rgb(0.29, 0.49, 0.35),
|
||||
});
|
||||
y -= 20;
|
||||
|
||||
// ───────── Anatomy pages (one per view with selected zones)
|
||||
const viewLabels: Record<keyof AnatomyAssets['rasters'], string> = {
|
||||
lateral_left: 'Vue latérale gauche',
|
||||
lateral_right: 'Vue latérale droite',
|
||||
dorsal: 'Vue dorsale',
|
||||
};
|
||||
const viewsInUse = new Set<keyof AnatomyAssets['rasters']>();
|
||||
for (const f of report.findings) {
|
||||
for (const zId of [...f.zones, ...f.linkedZones]) {
|
||||
const z = assets.anatomy.zones.find((zz) => zz.id === zId);
|
||||
if (!z) continue;
|
||||
for (const v of z.views) viewsInUse.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
for (const view of viewsInUse) {
|
||||
const raster = assets.rasters[view];
|
||||
if (!raster) continue;
|
||||
page = pdf.addPage([A4.width, A4.height]);
|
||||
page.drawText(viewLabels[view], {
|
||||
x: MARGIN,
|
||||
y: A4.height - MARGIN,
|
||||
size: 14,
|
||||
font: fontBold,
|
||||
});
|
||||
const png = await pdf.embedPng(raster);
|
||||
const maxW = A4.width - MARGIN * 2;
|
||||
const maxH = A4.height - MARGIN * 2 - 50;
|
||||
const ratio = Math.min(maxW / png.width, maxH / png.height);
|
||||
const w = png.width * ratio;
|
||||
const h = png.height * ratio;
|
||||
page.drawImage(png, { x: MARGIN, y: A4.height - MARGIN - 30 - h, width: w, height: h });
|
||||
}
|
||||
|
||||
// ───────── Findings table
|
||||
page = pdf.addPage([A4.width, A4.height]);
|
||||
y = A4.height - MARGIN;
|
||||
page.drawText('Observations cliniques', { x: MARGIN, y, size: 14, font: fontBold });
|
||||
y -= 22;
|
||||
|
||||
if (report.findings.length === 0) {
|
||||
page.drawText('Aucune observation enregistrée.', { x: MARGIN, y, size: 10, font });
|
||||
}
|
||||
|
||||
for (let i = 0; i < report.findings.length; i++) {
|
||||
const f = report.findings[i];
|
||||
if (!f) continue;
|
||||
if (y < MARGIN + 120) {
|
||||
page = pdf.addPage([A4.width, A4.height]);
|
||||
y = A4.height - MARGIN;
|
||||
}
|
||||
const zones = f.zones.map((id) => zoneLabel(assets.anatomy, id)).join(', ');
|
||||
const linked = f.linkedZones.length
|
||||
? ` (liées : ${f.linkedZones.map((id) => zoneLabel(assets.anatomy, id)).join(', ')})`
|
||||
: '';
|
||||
const pathos = f.pathologies.map((p) => p.label).join(', ') || '—';
|
||||
const sev = FR.severity[f.severity] ?? f.severity;
|
||||
|
||||
page.drawText(`#${(i + 1).toString()} ${zones}${linked}`, {
|
||||
x: MARGIN,
|
||||
y,
|
||||
size: 11,
|
||||
font: fontBold,
|
||||
});
|
||||
page.drawText(`Pathologies : ${pathos}`, { x: MARGIN, y: y - 14, size: 10, font });
|
||||
page.drawText(`Sévérité : ${sev}`, { x: MARGIN, y: y - 28, size: 10, font });
|
||||
if (f.comment) {
|
||||
const wrapped = wrap(f.comment, 90);
|
||||
let yy = y - 44;
|
||||
page.drawText('Commentaire :', { x: MARGIN, y: yy, size: 10, font: fontBold });
|
||||
yy -= 14;
|
||||
for (const line of wrapped) {
|
||||
page.drawText(line, { x: MARGIN + 8, y: yy, size: 10, font });
|
||||
yy -= 12;
|
||||
}
|
||||
y = yy - 8;
|
||||
} else {
|
||||
y -= 50;
|
||||
}
|
||||
}
|
||||
|
||||
// ───────── Conclusion + recommandations + RDV
|
||||
if (report.conclusion || report.recommendations || report.nextAppointment) {
|
||||
page = pdf.addPage([A4.width, A4.height]);
|
||||
y = A4.height - MARGIN;
|
||||
if (report.conclusion) {
|
||||
page.drawText('Conclusion', { x: MARGIN, y, size: 14, font: fontBold });
|
||||
y -= 20;
|
||||
for (const line of wrap(report.conclusion, 90)) {
|
||||
page.drawText(line, { x: MARGIN, y, size: 11, font });
|
||||
y -= 14;
|
||||
}
|
||||
y -= 12;
|
||||
}
|
||||
if (report.recommendations) {
|
||||
page.drawText('Recommandations', { x: MARGIN, y, size: 14, font: fontBold });
|
||||
y -= 20;
|
||||
for (const line of wrap(report.recommendations, 90)) {
|
||||
page.drawText(line, { x: MARGIN, y, size: 11, font });
|
||||
y -= 14;
|
||||
}
|
||||
y -= 12;
|
||||
}
|
||||
if (report.nextAppointment) {
|
||||
page.drawText(`Prochain rendez-vous : ${formatDateFr(report.nextAppointment)}`, {
|
||||
x: MARGIN,
|
||||
y,
|
||||
size: 12,
|
||||
font: fontBold,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ───────── Footer on each page
|
||||
const pages = pdf.getPages();
|
||||
const exported = new Date().toISOString().slice(0, 10);
|
||||
for (let i = 0; i < pages.length; i++) {
|
||||
const p = pages[i];
|
||||
if (!p) continue;
|
||||
p.drawText(`${FR.app.name} · exporté le ${formatDateFr(exported)} · page ${(i + 1).toString()}/${pages.length.toString()}`, {
|
||||
x: MARGIN,
|
||||
y: FOOT,
|
||||
size: 8,
|
||||
font,
|
||||
color: rgb(0.45, 0.45, 0.45),
|
||||
});
|
||||
}
|
||||
|
||||
// ───────── Attach report.json
|
||||
// pdf-lib's `attach` treats a raw string as base64-data-URI input (not as
|
||||
// UTF-8 text), and rejects cross-realm Uint8Array/ArrayBuffer in tests.
|
||||
// Wrap the JSON in a base64 data-URI string so it's portable everywhere.
|
||||
const json = JSON.stringify(report);
|
||||
const jsonBytes = new TextEncoder().encode(json);
|
||||
let base64 = '';
|
||||
const chunk = 8192;
|
||||
for (let i = 0; i < jsonBytes.length; i += chunk) {
|
||||
base64 += String.fromCharCode(
|
||||
...jsonBytes.subarray(i, Math.min(i + chunk, jsonBytes.length)),
|
||||
);
|
||||
}
|
||||
const dataUri = `data:application/json;base64,${btoa(base64)}`;
|
||||
await pdf.attach(dataUri, PDF_ATTACHMENT_NAME, {
|
||||
mimeType: 'application/json',
|
||||
description: 'Données sources du bilan (réimport possible).',
|
||||
creationDate: new Date(report.createdAt),
|
||||
modificationDate: new Date(),
|
||||
});
|
||||
|
||||
return pdf.save();
|
||||
}
|
||||
|
||||
export async function exportReport(report: Report, assets: AnatomyAssets): Promise<Blob> {
|
||||
const bytes = await exportReportBytes(report, assets);
|
||||
return new Blob([bytes], { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
function wrap(text: string, max: number): string[] {
|
||||
const words = text.split(/\s+/);
|
||||
const lines: string[] = [];
|
||||
let buf = '';
|
||||
for (const w of words) {
|
||||
if ((buf + ' ' + w).trim().length > max) {
|
||||
lines.push(buf);
|
||||
buf = w;
|
||||
} else {
|
||||
buf = (buf + ' ' + w).trim();
|
||||
}
|
||||
}
|
||||
if (buf) lines.push(buf);
|
||||
return lines;
|
||||
}
|
||||
+100
-2
@@ -1,5 +1,11 @@
|
||||
import * as pako from 'pako';
|
||||
import { PDFDocument, PDFName, type PDFRawStream } from 'pdf-lib';
|
||||
|
||||
import { ReportSchema } from '../schema/report';
|
||||
import type { Report } from '../schema/report';
|
||||
|
||||
import { PDF_ATTACHMENT_NAME } from './version';
|
||||
|
||||
export type ImportFailure =
|
||||
| { ok: false; reason: 'NO_ATTACHMENT' }
|
||||
| { ok: false; reason: 'INVALID_JSON'; details?: string }
|
||||
@@ -8,6 +14,98 @@ export type ImportFailure =
|
||||
|
||||
export type ImportResult = { ok: true; report: Report } | ImportFailure;
|
||||
|
||||
export function importReport(_file: File): Promise<ImportResult> {
|
||||
return Promise.reject(new Error('importReport not implemented'));
|
||||
export async function importReport(file: File | Blob | ArrayBuffer | Uint8Array): Promise<ImportResult> {
|
||||
let pdf: PDFDocument;
|
||||
try {
|
||||
const buf = await toBytes(file);
|
||||
pdf = await PDFDocument.load(buf, { ignoreEncryption: true });
|
||||
} catch (e) {
|
||||
return { ok: false, reason: 'UNREADABLE_PDF', details: (e as Error).message };
|
||||
}
|
||||
|
||||
const json = extractAttachment(pdf, PDF_ATTACHMENT_NAME);
|
||||
if (!json) return { ok: false, reason: 'NO_ATTACHMENT' };
|
||||
|
||||
let parsed: unknown;
|
||||
try {
|
||||
const decoded = new TextDecoder().decode(json);
|
||||
parsed = JSON.parse(decoded);
|
||||
} catch (e) {
|
||||
return {
|
||||
ok: false,
|
||||
reason: 'INVALID_JSON',
|
||||
details: `${(e as Error).message} | first 80 bytes: ${Array.from(json.slice(0, 80))
|
||||
.map((b) => b.toString(16).padStart(2, '0'))
|
||||
.join(' ')}`,
|
||||
};
|
||||
}
|
||||
|
||||
const result = ReportSchema.safeParse(parsed);
|
||||
if (!result.success) {
|
||||
return { ok: false, reason: 'SCHEMA_MISMATCH', details: result.error.message };
|
||||
}
|
||||
return { ok: true, report: result.data };
|
||||
}
|
||||
|
||||
async function toBytes(input: File | Blob | ArrayBuffer | Uint8Array): Promise<Uint8Array> {
|
||||
if (input instanceof Uint8Array) return input;
|
||||
if (input instanceof ArrayBuffer) return new Uint8Array(input);
|
||||
return new Uint8Array(await input.arrayBuffer());
|
||||
}
|
||||
|
||||
function extractAttachment(pdf: PDFDocument, name: string): Uint8Array | null {
|
||||
// Walk catalog → Names → EmbeddedFiles → Names array → filespec → EF → F
|
||||
// pdf-lib has no public attachment-extract API, so we navigate the tree.
|
||||
const catalog = pdf.catalog;
|
||||
const names = catalog.lookup(PDFName.of('Names')) as
|
||||
| { lookup?: (n: PDFName) => unknown }
|
||||
| undefined;
|
||||
if (!names?.lookup) return null;
|
||||
const embeddedFiles = names.lookup(PDFName.of('EmbeddedFiles')) as
|
||||
| { lookup?: (n: PDFName) => unknown }
|
||||
| undefined;
|
||||
if (!embeddedFiles?.lookup) return null;
|
||||
const namesArr = embeddedFiles.lookup(PDFName.of('Names')) as
|
||||
| { size?: () => number; lookup?: (i: number) => unknown }
|
||||
| undefined;
|
||||
if (!namesArr?.lookup || typeof namesArr.size !== 'function') return null;
|
||||
const size = namesArr.size();
|
||||
for (let i = 0; i < size; i += 2) {
|
||||
const k = namesArr.lookup(i) as { decodeText?: () => string } | undefined;
|
||||
const fname = k?.decodeText?.();
|
||||
if (fname !== name) continue;
|
||||
const fileSpec = namesArr.lookup(i + 1) as
|
||||
| { lookup?: (n: PDFName) => unknown }
|
||||
| undefined;
|
||||
if (!fileSpec?.lookup) continue;
|
||||
const ef = fileSpec.lookup(PDFName.of('EF')) as
|
||||
| { lookup?: (n: PDFName) => unknown }
|
||||
| undefined;
|
||||
if (!ef?.lookup) continue;
|
||||
const stream = (ef.lookup(PDFName.of('F')) ?? ef.lookup(PDFName.of('UF'))) as
|
||||
| { dict?: unknown; contents?: Uint8Array }
|
||||
| undefined;
|
||||
if (!stream) continue;
|
||||
// Duck-type instead of `instanceof PDFRawStream` (instanceof fails when
|
||||
// multiple pdf-lib realms coexist, e.g. during tests).
|
||||
if (stream.dict !== undefined && stream.contents !== undefined) {
|
||||
const s = stream as PDFRawStream;
|
||||
const filter = (s.dict as { lookup?: (n: PDFName) => unknown }).lookup?.(
|
||||
PDFName.of('Filter'),
|
||||
);
|
||||
const filterName = (filter as { encodedName?: string } | undefined)?.encodedName;
|
||||
// We bypass pdf-lib's `decodePDFRawStream` because its reference-equality
|
||||
// check on `PDFName.of('FlateDecode')` is unreliable across module realms
|
||||
// (e.g. when vitest dual-loads pdf-lib). Use pako directly on raw bytes.
|
||||
if (filterName === '/FlateDecode') {
|
||||
return pako.inflate(s.contents);
|
||||
}
|
||||
if (filterName === undefined || filter === null) {
|
||||
return s.contents;
|
||||
}
|
||||
// Other filters (ASCII85, LZW, etc.) not expected for embedded files we wrote.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1,13 +1,54 @@
|
||||
import type { SpeciesAnatomy } from '../types';
|
||||
import type { SpeciesAnatomy, Subzone, Zone } from '../types';
|
||||
|
||||
const range = (prefix: string, count: number): Subzone[] =>
|
||||
Array.from({ length: count }, (_, i) => ({
|
||||
id: `${prefix}${i + 1}`,
|
||||
label: `${prefix}${i + 1}`,
|
||||
}));
|
||||
|
||||
const CERVICAL: Subzone[] = range('C', 7);
|
||||
const THORACIC: Subzone[] = range('T', 18);
|
||||
const LUMBAR: Subzone[] = range('L', 6);
|
||||
const SACRAL: Subzone[] = range('S', 5);
|
||||
|
||||
const ZONES: Zone[] = [
|
||||
{ id: 'head', label: 'Tête', category: 'head', views: ['lateral_left', 'lateral_right', 'dorsal'] },
|
||||
{ id: 'neck', label: 'Encolure', category: 'axial', views: ['lateral_left', 'lateral_right', 'dorsal'], subzones: CERVICAL },
|
||||
{ id: 'withers', label: 'Garrot', category: 'axial', views: ['lateral_left', 'lateral_right', 'dorsal'] },
|
||||
{ id: 'thoracic-back', label: 'Dos thoracique', category: 'axial', views: ['lateral_left', 'lateral_right', 'dorsal'], subzones: THORACIC },
|
||||
{ id: 'lumbar', label: 'Lombaire', category: 'axial', views: ['lateral_left', 'lateral_right', 'dorsal'], subzones: LUMBAR },
|
||||
{ id: 'sacrum', label: 'Sacrum', category: 'axial', views: ['lateral_left', 'lateral_right', 'dorsal'], subzones: SACRAL },
|
||||
{ id: 'sacro-iliac-l', label: 'Sacro-iliaque gauche', category: 'axial', views: ['lateral_left', 'dorsal'] },
|
||||
{ id: 'sacro-iliac-r', label: 'Sacro-iliaque droite', category: 'axial', views: ['lateral_right', 'dorsal'] },
|
||||
{ id: 'tail', label: 'Queue', category: 'tail', views: ['lateral_left', 'lateral_right', 'dorsal'] },
|
||||
|
||||
{ id: 'shoulder-l', label: 'Épaule gauche', category: 'limb', views: ['lateral_left', 'dorsal'] },
|
||||
{ id: 'shoulder-r', label: 'Épaule droite', category: 'limb', views: ['lateral_right', 'dorsal'] },
|
||||
{ id: 'elbow-l', label: 'Coude gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'elbow-r', label: 'Coude droit', category: 'limb', views: ['lateral_right'] },
|
||||
{ id: 'knee-l', label: 'Genou antérieur gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'knee-r', label: 'Genou antérieur droit', category: 'limb', views: ['lateral_right'] },
|
||||
{ id: 'fetlock-front-l', label: 'Boulet antérieur gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'fetlock-front-r', label: 'Boulet antérieur droit', category: 'limb', views: ['lateral_right'] },
|
||||
|
||||
{ id: 'hip-l', label: 'Hanche gauche', category: 'limb', views: ['lateral_left', 'dorsal'] },
|
||||
{ id: 'hip-r', label: 'Hanche droite', category: 'limb', views: ['lateral_right', 'dorsal'] },
|
||||
{ id: 'stifle-l', label: 'Grasset gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'stifle-r', label: 'Grasset droit', category: 'limb', views: ['lateral_right'] },
|
||||
{ id: 'hock-l', label: 'Jarret gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'hock-r', label: 'Jarret droit', category: 'limb', views: ['lateral_right'] },
|
||||
{ id: 'fetlock-rear-l', label: 'Boulet postérieur gauche', category: 'limb', views: ['lateral_left'] },
|
||||
{ id: 'fetlock-rear-r', label: 'Boulet postérieur droit', category: 'limb', views: ['lateral_right'] },
|
||||
];
|
||||
|
||||
export const EQUINE_ANATOMY: SpeciesAnatomy = {
|
||||
id: 'equine',
|
||||
label: 'Cheval',
|
||||
vertebralFormula: { cervical: 7, thoracic: 18, lumbar: 6, sacral: 5 },
|
||||
zones: [],
|
||||
zones: ZONES,
|
||||
svg: {
|
||||
lateral_left: '',
|
||||
lateral_right: '',
|
||||
dorsal: '',
|
||||
lateral_left: '/species/equine/lateral-left.svg',
|
||||
lateral_right: '/species/equine/lateral-right.svg',
|
||||
dorsal: '/species/equine/dorsal.svg',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { registerSpecies } from '../registry';
|
||||
|
||||
import { EQUINE_ANATOMY } from './anatomy';
|
||||
import { EQUINE_PATHOLOGIES } from './pathologies';
|
||||
|
||||
registerSpecies('equine', {
|
||||
anatomy: EQUINE_ANATOMY,
|
||||
pathologies: EQUINE_PATHOLOGIES,
|
||||
});
|
||||
|
||||
export { EQUINE_ANATOMY, EQUINE_PATHOLOGIES };
|
||||
@@ -1,3 +1,295 @@
|
||||
import type { PathologyEntry } from '../types';
|
||||
|
||||
export const EQUINE_PATHOLOGIES: PathologyEntry[] = [];
|
||||
const MVM = (slug: string): string => `https://www.merckvetmanual.com/horse-owners/${slug}`;
|
||||
const IMAIOS = 'https://www.imaios.com/en/vet-anatomy/horse';
|
||||
const PUBMED = (id: string): string => `https://pubmed.ncbi.nlm.nih.gov/${id}/`;
|
||||
|
||||
export const EQUINE_PATHOLOGIES: PathologyEntry[] = [
|
||||
// ─── Axial : encolure / dos / lombaire / sacrum ───────────────────────────
|
||||
{
|
||||
id: 'eq_kissing_spines',
|
||||
label: 'Syndrome des processus épineux chevauchants (kissing spines)',
|
||||
description:
|
||||
'Contact ou chevauchement des processus épineux thoraciques, principalement entre T13 et T18. Source fréquente de douleur dorsale.',
|
||||
category: 'osseux',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'withers', 'lumbar'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/disorders-of-the-back-and-pelvis-of-horses'), PUBMED('29071751')],
|
||||
},
|
||||
{
|
||||
id: 'eq_cervical_facet_arthropathy',
|
||||
label: 'Arthropathie des facettes articulaires cervicales',
|
||||
description: 'Remaniements arthrosiques des articulations zygapophysaires cervicales, souvent C5-C7.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['neck'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/cervical-vertebral-malformation-in-horses'), PUBMED('22416782')],
|
||||
},
|
||||
{
|
||||
id: 'eq_cervical_stenotic_myelopathy',
|
||||
label: 'Myélopathie cervicale sténosante (wobbler)',
|
||||
description: 'Compression médullaire cervicale par malformation vertébrale ou sténose dynamique.',
|
||||
category: 'nerveux',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['neck'],
|
||||
sources: [MVM('horse-owners/brain-spinal-cord-and-nerve-disorders-of-horses/cervical-vertebral-malformation-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_lumbosacral_pain',
|
||||
label: 'Dysfonction lombo-sacrée',
|
||||
description: 'Douleur localisée à la jonction L6-S1 et autour du sacrum.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['lumbar', 'sacrum'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/disorders-of-the-back-and-pelvis-of-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_sacroiliac_dysfunction',
|
||||
label: 'Dysfonction sacro-iliaque',
|
||||
description: 'Restriction de mobilité ou douleur au niveau des articulations sacro-iliaques.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['sacro-iliac-l', 'sacro-iliac-r', 'sacrum'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/disorders-of-the-back-and-pelvis-of-horses'), PUBMED('20840713')],
|
||||
},
|
||||
{
|
||||
id: 'eq_thoracolumbar_muscular',
|
||||
label: 'Tension musculaire thoraco-lombaire',
|
||||
description: 'Hypertonie des muscles long dorsal / longissimus, souvent secondaire à une selle inadaptée.',
|
||||
category: 'musculaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'lumbar', 'withers'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/muscle-disorders-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_supraspinous_ligament_desmitis',
|
||||
label: 'Desmite du ligament supra-épineux',
|
||||
description: 'Inflammation chronique du ligament supra-épineux dorsal, parfois associée aux kissing spines.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'lumbar', 'withers'],
|
||||
sources: [PUBMED('15510510')],
|
||||
},
|
||||
{
|
||||
id: 'eq_nuchal_ligament_desmopathy',
|
||||
label: 'Desmopathie du ligament nuchal',
|
||||
description: 'Atteinte chronique du ligament nuchal, douleur à la flexion cervicale.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['neck', 'head'],
|
||||
sources: [IMAIOS],
|
||||
},
|
||||
{
|
||||
id: 'eq_tail_set_dysfunction',
|
||||
label: 'Restriction de mobilité de la queue',
|
||||
description: "Manque d'oscillation latérale ou de portée de la queue, signe d'irritation sacro-coccygienne.",
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['tail', 'sacrum'],
|
||||
sources: [IMAIOS],
|
||||
},
|
||||
{
|
||||
id: 'eq_tmj_dysfunction',
|
||||
label: 'Dysfonction temporo-mandibulaire',
|
||||
description: 'Asymétrie ou restriction de l’ATM, souvent associée à un déséquilibre dentaire.',
|
||||
category: 'cranio-sacre',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['head'],
|
||||
sources: [PUBMED('21916951')],
|
||||
},
|
||||
|
||||
// ─── Membres antérieurs ───────────────────────────────────────────────────
|
||||
{
|
||||
id: 'eq_navicular_syndrome',
|
||||
label: 'Syndrome naviculaire (douleur podotrochléaire)',
|
||||
description: 'Douleur chronique de l’appareil podotrochléaire, fréquente cause de boiterie antérieure.',
|
||||
category: 'osseux',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['fetlock-front-l', 'fetlock-front-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/navicular-disease-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_ringbone',
|
||||
label: 'Phalangite (ringbone)',
|
||||
description: 'Ostéoarthrose des articulations interphalangiennes, classiquement membres antérieurs.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['fetlock-front-l', 'fetlock-front-r', 'fetlock-rear-l', 'fetlock-rear-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/ringbone-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_splints',
|
||||
label: 'Suros (splints)',
|
||||
description: 'Inflammation périostée entre métacarpien principal et stylet, surtout chez le jeune cheval.',
|
||||
category: 'osseux',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['knee-l', 'knee-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/splints-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_carpal_osteoarthritis',
|
||||
label: 'Ostéoarthrose du carpe',
|
||||
description: 'Usure articulaire du carpe (genou antérieur), fréquente chez les chevaux de course.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['knee-l', 'knee-r'],
|
||||
sources: [PUBMED('20840713')],
|
||||
},
|
||||
{
|
||||
id: 'eq_suspensory_desmitis_front',
|
||||
label: 'Desmite suspensorale antérieure',
|
||||
description: 'Atteinte du ligament suspenseur du boulet, branches ou corps, des antérieurs.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['fetlock-front-l', 'fetlock-front-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/tendinitis-and-tendinosis-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_sdft_tendinitis',
|
||||
label: 'Tendinite du tendon fléchisseur superficiel',
|
||||
description: 'Atteinte du SDFT, classiquement à la moitié distale du métacarpe.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['fetlock-front-l', 'fetlock-front-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/tendinitis-and-tendinosis-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_shoulder_sweeney',
|
||||
label: 'Atrophie scapulaire (sweeney)',
|
||||
description: 'Atrophie des muscles supra-épineux/infra-épineux par lésion du nerf suprascapulaire.',
|
||||
category: 'nerveux',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['shoulder-l', 'shoulder-r'],
|
||||
sources: [MVM('horse-owners/brain-spinal-cord-and-nerve-disorders-of-horses/suprascapular-nerve-injury-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_elbow_capped',
|
||||
label: 'Hygroma du coude (capped elbow)',
|
||||
description: 'Bursite olécrânienne par traumatisme répété.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['elbow-l', 'elbow-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/bursitis-in-horses')],
|
||||
},
|
||||
|
||||
// ─── Membres postérieurs ──────────────────────────────────────────────────
|
||||
{
|
||||
id: 'eq_bone_spavin',
|
||||
label: 'Éparvin osseux (bone spavin)',
|
||||
description: 'Ostéoarthrose des articulations distales du tarse, principale cause d’éparvin.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hock-l', 'hock-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/bone-spavin-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_bog_spavin',
|
||||
label: 'Vessigon articulaire du jarret (bog spavin)',
|
||||
description: 'Distension synoviale de l’articulation tibio-tarsienne.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hock-l', 'hock-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/bog-spavin-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_curb',
|
||||
label: 'Courbe du jarret (curb)',
|
||||
description: 'Desmite du ligament tarsien plantaire long, palpable en arrière du jarret.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hock-l', 'hock-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/curb-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_stifle_upward_fixation_patella',
|
||||
label: 'Accrochement intermittent de la rotule',
|
||||
description: 'Blocage transitoire de la rotule sur la trochlée fémorale, fréquent chez le jeune cheval.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['stifle-l', 'stifle-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/upward-fixation-of-the-patella-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_stifle_meniscal_injury',
|
||||
label: 'Lésion méniscale du grasset',
|
||||
description: 'Atteinte du ménisque médial ou latéral, conséquence de torsion ou de surcharge.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['stifle-l', 'stifle-r'],
|
||||
sources: [PUBMED('20840713')],
|
||||
},
|
||||
{
|
||||
id: 'eq_suspensory_desmitis_rear',
|
||||
label: 'Desmite suspensorale postérieure (PSD)',
|
||||
description: 'Desmite chronique du suspenseur, branche médiale postérieure principalement.',
|
||||
category: 'tendino-ligamentaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hock-l', 'hock-r', 'fetlock-rear-l', 'fetlock-rear-r'],
|
||||
sources: [MVM('horse-owners/lameness-in-horses/tendinitis-and-tendinosis-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_coxofemoral_arthrosis',
|
||||
label: 'Arthrose coxo-fémorale',
|
||||
description: 'Atteinte dégénérative de la hanche, plus rare mais source de boiterie postérieure.',
|
||||
category: 'articulaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hip-l', 'hip-r'],
|
||||
sources: [IMAIOS],
|
||||
},
|
||||
{
|
||||
id: 'eq_gluteal_strain',
|
||||
label: 'Lésion musculaire glutéale',
|
||||
description: 'Élongation ou contracture des muscles fessiers, fréquente après effort intense.',
|
||||
category: 'musculaire',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['hip-l', 'hip-r'],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/muscle-disorders-in-horses')],
|
||||
},
|
||||
|
||||
// ─── Fascial / viscéral / autre ───────────────────────────────────────────
|
||||
{
|
||||
id: 'eq_thoracolumbar_fascial_restriction',
|
||||
label: 'Restriction fasciale thoraco-lombaire',
|
||||
description: 'Adhérences fasciales limitant la flexion et l’extension dorsale.',
|
||||
category: 'fascial',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'lumbar'],
|
||||
sources: [PUBMED('33555115')],
|
||||
},
|
||||
{
|
||||
id: 'eq_diaphragmatic_restriction',
|
||||
label: 'Restriction diaphragmatique',
|
||||
description: 'Limitation de mobilité diaphragmatique, palpable en pression abdominale antérieure.',
|
||||
category: 'visceral',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'withers'],
|
||||
sources: [IMAIOS],
|
||||
},
|
||||
{
|
||||
id: 'eq_gastric_visceral_dysfunction',
|
||||
label: 'Dysfonction viscérale gastrique',
|
||||
description: 'Sensibilité épigastrique, parfois associée à ulcères gastriques (EGUS).',
|
||||
category: 'visceral',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['thoracic-back', 'lumbar'],
|
||||
sources: [MVM('horse-owners/digestive-disorders-of-horses/gastric-ulcers-in-horses')],
|
||||
},
|
||||
{
|
||||
id: 'eq_cranio_sacral_restriction',
|
||||
label: 'Restriction crânio-sacrée',
|
||||
description: 'Perte de rythme crânio-sacré, palpation crânienne et sacrée combinées.',
|
||||
category: 'cranio-sacre',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: ['head', 'sacrum'],
|
||||
sources: ['London College of Animal Osteopathy — https://lcao.com'],
|
||||
},
|
||||
{
|
||||
id: 'eq_post_fall_global',
|
||||
label: 'Conséquences post-traumatiques (chute)',
|
||||
description: 'Tableau combiné de tensions multi-zones après chute, à différencier d’une lésion focalisée.',
|
||||
category: 'autre',
|
||||
applicableSpecies: ['equine'],
|
||||
applicableZones: [],
|
||||
sources: [MVM('horse-owners/bone-joint-and-muscle-disorders-of-horses/disorders-of-the-back-and-pelvis-of-horses')],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
import './equine';
|
||||
|
||||
export { SPECIES, getSpecies, isSpeciesAvailable } from './registry';
|
||||
export type {
|
||||
PathologyEntry,
|
||||
SpeciesAnatomy,
|
||||
SpeciesId,
|
||||
Subzone,
|
||||
View,
|
||||
Zone,
|
||||
ZoneCategory,
|
||||
VertebralFormula,
|
||||
} from './types';
|
||||
+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