feat(schema): add findings tree + parse species JSON via Zod

Replaces the flat Pathology[] model with a hierarchical SpeciesFindings
tree (zones → categories → nested children → leaves) authored as JSON and
validated at boot. Equine catalog JSON is now wired through
SpeciesFindingsSchema.parse() so malformed data fails loudly instead of
corrupting an observation later.

Species manifest swaps `pathologies` loader for `findings`. JSON species
id renamed equin → equine to match the registry. Old equine pathology
test deleted; new findings test covers parse + FR/EN label coverage +
zone/category/leaf structure.

Foundational step of the v2 domain pivot; callers in observation/store/
UI/PDF migrated in follow-up commits.

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:43 +02:00
1 parent 31be3155ef
commit f80e161d61
7 files changed
+135 -52

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
import { z } from 'zod'
/**
* Schema for the species findings tree.
*
* Source of truth for what a practitioner can attach to an observation:
* a hierarchical tree of dysfunctions/observations per anatomical zone,
* authored by the domain expert in JSON and parsed at boot.
*
* Field names match the JSON authoring contract (snake_case).
* Recursive children are typed via z.lazy + an explicit ZodType annotation
* so TS can resolve the self-reference.
*/
export const SourceRefSchema = z.object({
type: z.enum(['manual', 'journal', 'database', 'web']),
citation: z.string().min(1),
url: z.string().url().optional(),
})
export type SourceRef = z.infer<typeof SourceRefSchema>
export interface FindingNode {
id: string
name_fr: string
name_en: string
description_fr?: string
description_en?: string
requires_vet_referral?: boolean
sources?: SourceRef[]
children?: FindingNode[]
}
export const FindingNodeSchema: z.ZodType<FindingNode> = z.lazy(() =>
z.object({
id: z.string().min(1),
name_fr: z.string().min(1),
name_en: z.string().min(1),
description_fr: z.string().optional(),
description_en: z.string().optional(),
requires_vet_referral: z.boolean().optional(),
sources: z.array(SourceRefSchema).optional(),
children: z.array(FindingNodeSchema).optional(),
}),
)
export const ZoneFindingsSchema = z.object({
id: z.string().min(1),
name_fr: z.string().min(1),
name_en: z.string().min(1),
categories: z.array(FindingNodeSchema),
})
export type ZoneFindings = z.infer<typeof ZoneFindingsSchema>
export const SpeciesFindingsSchema = z.object({
schema_version: z.string().min(1),
scope_disclaimer: z.string().min(1),
species: z.object({
id: z.string().min(1),
name_fr: z.string().min(1),
name_en: z.string().min(1),
}),
zones: z.record(z.string(), ZoneFindingsSchema),
})
export type SpeciesFindings = z.infer<typeof SpeciesFindingsSchema>
+1 -1
View File
@@ -9,5 +9,5 @@ export const equine: SpeciesManifest = {
head: '/species/equine/Horse_head.svg',
},
vertebralFormula: EQUINE_VERTEBRAL_FORMULA,
pathologies: () => import('./pathologies'),
findings: () => import('./pathologies'),
}
+1 -1
View File
@@ -2,7 +2,7 @@
"schema_version": "1.1",
"scope_disclaimer": "Les éléments listés correspondent au périmètre légal de l'ostéopathie animale : dysfonctions ostéopathiques palpées, observations cliniques et motifs de consultation. Aucun diagnostic médical n'est posé. Toute pathologie organique relève du vétérinaire.",
"species": {
"id": "equin",
"id": "equine",
"name_fr": "Cheval",
"name_en": "Horse"
},
+9 -6
View File
@@ -1,10 +1,13 @@
import type { Pathology } from '@/domain/schema/pathology'
import {
SpeciesFindingsSchema,
type SpeciesFindings,
} from '@/domain/schema/findings'
import data from './pathologies.json'
/**
* Equine pathology database.
* To be authored post-scaffold (40–60 entries, source-cited).
* Each entry must pass PathologySchema.parse() and have ≥1 source.
* Equine findings tree. Authored as JSON, parsed via Zod at boot so any
* malformed data crashes loudly instead of corrupting an observation later.
*/
const EQUINE_PATHOLOGIES: Pathology[] = []
const EQUINE_FINDINGS: SpeciesFindings = SpeciesFindingsSchema.parse(data)
export default EQUINE_PATHOLOGIES
export default EQUINE_FINDINGS
+5 -5
View File
@@ -1,4 +1,4 @@
import type { Pathology } from '@/domain/schema/pathology'
import type { SpeciesFindings } from '@/domain/schema/findings'
/** Vertebral formula defines segment counts for a species. */
export interface VertebralFormula {
@@ -9,8 +9,8 @@ export interface VertebralFormula {
Cd: number
}
/** Lazy import returning a module with a default export of Pathology[]. */
export type PathologiesLoader = () => Promise<{ default: Pathology[] }>
/** Lazy import returning a module with a default export of SpeciesFindings. */
export type FindingsLoader = () => Promise<{ default: SpeciesFindings }>
/** Species manifest — one per registered species. */
export interface SpeciesManifest {
@@ -25,6 +25,6 @@ export interface SpeciesManifest {
*/
details: Record<string, string>
vertebralFormula: VertebralFormula
/** Lazy-loaded pathology database for this species */
pathologies: PathologiesLoader
/** Lazy-loaded findings tree (zones + categories + leaves) for this species */
findings: FindingsLoader
}