feat(domain): canonical anatomical sheet document, integrity rules, tests
This commit is contained in:
1 parent
aea8902711
commit
36812f4625
13 files changed
+1849
No files matched your search
@@ -0,0 +1,117 @@
|
||||
import {
|
||||
AnatomicalSheetDocumentSchema,
|
||||
FindingNodeSchema,
|
||||
StableIdSchema,
|
||||
type AnatomicalSheetDocumentInput,
|
||||
} from '../src'
|
||||
import { horseSlice, horseSliceInput } from './fixtures/horse-slice'
|
||||
|
||||
// Mutations deliberately break the typed shape, so the draft is untyped.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type LooseDoc = any
|
||||
type Mutation = (doc: LooseDoc) => void
|
||||
|
||||
/** Applies a mutation to the lean fixture and reports whether it parses. */
|
||||
function parsesAfter(mutate: Mutation): boolean {
|
||||
const doc: LooseDoc = horseSliceInput()
|
||||
mutate(doc)
|
||||
return AnatomicalSheetDocumentSchema.safeParse(doc).success
|
||||
}
|
||||
|
||||
describe('AnatomicalSheetDocumentSchema', () => {
|
||||
it('accepts the horse slice fixture', () => {
|
||||
const result = AnatomicalSheetDocumentSchema.safeParse(horseSliceInput())
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('accepts a parsed document again (output is valid input)', () => {
|
||||
expect(AnatomicalSheetDocumentSchema.parse(horseSlice())).toEqual(
|
||||
horseSlice(),
|
||||
)
|
||||
})
|
||||
|
||||
const rejections: Array<[string, Mutation]> = [
|
||||
['an unknown top-level key', (d) => (d.extra = true)],
|
||||
['an unknown nested key', (d) => (d.views[0].zoom = 2)],
|
||||
['a stable id with spaces', (d) => (d.annotations[0].id = 'Hip Joint')],
|
||||
['a stable id with an accent', (d) => (d.categories[0].id = 'É')],
|
||||
['an empty stable id', (d) => (d.finding_zones[0].id = '')],
|
||||
['schema_version 2', (d) => (d.schema_version = 2)],
|
||||
['a non-uuid svg_asset_id', (d) => (d.views[0].svg_asset_id = 'horse')],
|
||||
[
|
||||
'a polygon with 2 points',
|
||||
(d) =>
|
||||
(d.annotations[1].geometry.points = [
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
]),
|
||||
],
|
||||
['a circle with r 0', (d) => (d.annotations[0].geometry.r = 0)],
|
||||
['a region count of 0', (d) => (d.vertebral_config.regions[0].count = 0)],
|
||||
['a missing en label', (d) => delete d.name.en],
|
||||
[
|
||||
'a detail view without parent_view_id',
|
||||
(d) => delete d.views[1].parent_view_id,
|
||||
],
|
||||
[
|
||||
'a detail_trigger with finding_zone_id',
|
||||
(d) => (d.annotations[3].finding_zone_id = 'hip'),
|
||||
],
|
||||
[
|
||||
'a finding category kind foo',
|
||||
(d) => (d.finding_zones[0].categories[0].kind = 'foo'),
|
||||
],
|
||||
]
|
||||
|
||||
it.each(rejections)('rejects %s', (_label, mutate) => {
|
||||
expect(parsesAfter(mutate)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('StableIdSchema', () => {
|
||||
it.each(['hip', 'c7-t1', 'view_main', '0'])('accepts %s', (id) => {
|
||||
expect(StableIdSchema.safeParse(id).success).toBe(true)
|
||||
})
|
||||
|
||||
it.each(['Hip Joint', 'É', '', '-hip', 'a'.repeat(65)])(
|
||||
'rejects %j',
|
||||
(id) => {
|
||||
expect(StableIdSchema.safeParse(id).success).toBe(false)
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe('FindingNodeSchema defaults', () => {
|
||||
it('fills the optional keys of a lean node, recursively', () => {
|
||||
const node = FindingNodeSchema.parse({
|
||||
id: 'articular',
|
||||
name: { fr: 'Articulaire', en: 'Articular' },
|
||||
children: [{ id: 'flexion', name: { fr: 'Flexion', en: 'Flexion' } }],
|
||||
})
|
||||
expect(node.description).toEqual({})
|
||||
expect(node.requires_vet_referral).toBe(false)
|
||||
expect(node.sources).toEqual([])
|
||||
expect(node.children[0]).toEqual({
|
||||
id: 'flexion',
|
||||
name: { fr: 'Flexion', en: 'Flexion' },
|
||||
description: {},
|
||||
requires_vet_referral: false,
|
||||
sources: [],
|
||||
children: [],
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps explicit values of the fixture', () => {
|
||||
const doc = horseSlice()
|
||||
const lameness = doc.finding_zones[0].categories[1].children[0]
|
||||
expect(lameness.requires_vet_referral).toBe(true)
|
||||
const trauma = doc.finding_zones[0].categories[2].children[0]
|
||||
expect(trauma.sources).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('does not add default keys to the lean input', () => {
|
||||
const input: AnatomicalSheetDocumentInput = horseSliceInput()
|
||||
const leaf = input.finding_zones[2].categories[0].children[0]
|
||||
expect(Object.keys(leaf)).toEqual(['id', 'name'])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,426 @@
|
||||
import {
|
||||
AnatomicalSheetDocumentSchema,
|
||||
SheetValidationError,
|
||||
assertPublishable,
|
||||
createEmptySheetDocument,
|
||||
isPublishable,
|
||||
validateSheetDocument,
|
||||
type AnatomicalSheetDocument,
|
||||
type Annotation,
|
||||
type SheetView,
|
||||
} from '../src'
|
||||
import { HORSE_MAIN_ASSET_ID, horseSlice } from './fixtures/horse-slice'
|
||||
|
||||
/** [code, path] pairs: what each rule test pins down. */
|
||||
function issuesOf(doc: AnatomicalSheetDocument): Array<[string, string]> {
|
||||
return validateSheetDocument(doc).map((issue) => [issue.code, issue.path])
|
||||
}
|
||||
|
||||
function mutated(
|
||||
mutate: (doc: AnatomicalSheetDocument) => void,
|
||||
): AnatomicalSheetDocument {
|
||||
const doc = horseSlice()
|
||||
mutate(doc)
|
||||
return doc
|
||||
}
|
||||
|
||||
function point(id: string, fields: Partial<Annotation> = {}): Annotation {
|
||||
return {
|
||||
id,
|
||||
kind: 'point',
|
||||
view_id: 'view-main',
|
||||
category_id: 'articulations',
|
||||
laterality: 'bilateral',
|
||||
geometry: null,
|
||||
name: { fr: id, en: id },
|
||||
finding_zone_id: 'hip',
|
||||
vertebral_region_code: null,
|
||||
...fields,
|
||||
} as Annotation
|
||||
}
|
||||
|
||||
function trigger(id: string, viewId: string, opensViewId: string) {
|
||||
return {
|
||||
id,
|
||||
kind: 'detail_trigger',
|
||||
view_id: viewId,
|
||||
category_id: 'cadrans-du-crane',
|
||||
laterality: 'unpaired',
|
||||
geometry: null,
|
||||
name: null,
|
||||
opens_view_id: opensViewId,
|
||||
} satisfies Annotation
|
||||
}
|
||||
|
||||
function detailView(id: string, parentId: string) {
|
||||
return {
|
||||
id,
|
||||
kind: 'detail',
|
||||
name: { fr: id, en: id },
|
||||
parent_view_id: parentId,
|
||||
svg_asset_id: HORSE_MAIN_ASSET_ID,
|
||||
view_box: null,
|
||||
} satisfies SheetView
|
||||
}
|
||||
|
||||
describe('validateSheetDocument on the horse slice', () => {
|
||||
it('reports no error and no warning', () => {
|
||||
expect(validateSheetDocument(horseSlice())).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('integrity rules (one mutation per code)', () => {
|
||||
it('view.main.count', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views.push({ ...d.views[0], id: 'view-alt' })
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([['view.main.count', 'views']])
|
||||
})
|
||||
|
||||
it('view.main.count with no main view', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views = d.views.filter((view) => view.kind !== 'main')
|
||||
})
|
||||
const codes = issuesOf(doc).map(([code]) => code)
|
||||
expect(codes).toContain('view.main.count')
|
||||
})
|
||||
|
||||
it('view.id.duplicate', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views.push(structuredClone(d.views[1]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([['view.id.duplicate', 'views[2].id']])
|
||||
})
|
||||
|
||||
it('view.parent.missing', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views.push(detailView('view-orphan', 'view-ghost'))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['view.parent.missing', 'views[2].parent_view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('view.parent.cycle (terminates on a two-view loop)', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views.push(detailView('view-a', 'view-b'))
|
||||
d.views.push(detailView('view-b', 'view-a'))
|
||||
d.annotations.push(trigger('open-a', 'view-b', 'view-a'))
|
||||
d.annotations.push(trigger('open-b', 'view-a', 'view-b'))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['view.parent.cycle', 'views[2].parent_view_id'],
|
||||
['view.parent.cycle', 'views[3].parent_view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('view.parent.cycle on a self-parent', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views.push(detailView('view-self', 'view-self'))
|
||||
d.annotations.push(trigger('open-self', 'view-self', 'view-self'))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['view.parent.cycle', 'views[2].parent_view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('view.unreachable', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations = d.annotations.filter((a) => a.id !== 'head-trigger')
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([['view.unreachable', 'views[1]']])
|
||||
})
|
||||
|
||||
it('view.asset.missing on the main view', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views[0].svg_asset_id = null
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['view.asset.missing', 'views[0].svg_asset_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('view.asset.missing on a detail view without asset nor view_box', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views[1].view_box = null
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([['view.asset.missing', 'views[1].view_box']])
|
||||
})
|
||||
|
||||
it('annotation.id.duplicate (across views)', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push({ ...structuredClone(d.annotations[4]) })
|
||||
d.annotations[6].view_id = 'view-main'
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.id.duplicate', 'annotations[6].id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.view.missing', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(point('ghost', { view_id: 'view-ghost' }))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.view.missing', 'annotations[6].view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.category.missing', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations[0].category_id = 'os'
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.category.missing', 'annotations[0].category_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.opens_view.invalid when the target is not a child', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(trigger('loop', 'view-head', 'view-head'))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.opens_view.invalid', 'annotations[6].opens_view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.opens_view.invalid when the target is main or absent', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(trigger('to-main', 'view-main', 'view-main'))
|
||||
d.annotations.push(trigger('to-ghost', 'view-main', 'view-ghost'))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.opens_view.invalid', 'annotations[6].opens_view_id'],
|
||||
['annotation.opens_view.invalid', 'annotations[7].opens_view_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.finding_zone.missing', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(point('stifle', { finding_zone_id: 'stifle' }))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.finding_zone.missing', 'annotations[6].finding_zone_id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.region.missing', () => {
|
||||
const doc = mutated((d) => {
|
||||
const cervical = d.annotations[1]
|
||||
if (cervical.kind === 'detail_trigger') throw new Error('fixture')
|
||||
cervical.vertebral_region_code = 'Q'
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.region.missing', 'annotations[1].vertebral_region_code'],
|
||||
])
|
||||
})
|
||||
|
||||
it('annotation.no_findings is a warning', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(point('mandible', { finding_zone_id: null }))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['annotation.no_findings', 'annotations[6].finding_zone_id'],
|
||||
])
|
||||
expect(validateSheetDocument(doc)[0].severity).toBe('warning')
|
||||
})
|
||||
|
||||
it('region.code.duplicate', () => {
|
||||
const doc = mutated((d) => {
|
||||
const regions = d.vertebral_config.regions
|
||||
regions.push(structuredClone(regions[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['region.code.duplicate', 'vertebral_config.regions[5].code'],
|
||||
])
|
||||
})
|
||||
|
||||
it('category.id.duplicate', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.categories.push(structuredClone(d.categories[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['category.id.duplicate', 'categories[4].id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('finding_zone.id.duplicate', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.finding_zones.push(structuredClone(d.finding_zones[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['finding_zone.id.duplicate', 'finding_zones[5].id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('finding.id.duplicate among finding categories', () => {
|
||||
const doc = mutated((d) => {
|
||||
const categories = d.finding_zones[0].categories
|
||||
categories.push(structuredClone(categories[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['finding.id.duplicate', 'finding_zones[0].categories[3].id'],
|
||||
])
|
||||
})
|
||||
|
||||
it('finding.id.duplicate among nested children', () => {
|
||||
const doc = mutated((d) => {
|
||||
const articular = d.finding_zones[0].categories[0].children[0]
|
||||
articular.children.push(structuredClone(articular.children[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
[
|
||||
'finding.id.duplicate',
|
||||
'finding_zones[0].categories[0].children[0].children[2].id',
|
||||
],
|
||||
])
|
||||
})
|
||||
|
||||
it('finding ids may repeat across different sibling arrays', () => {
|
||||
const doc = mutated((d) => {
|
||||
const hip = d.finding_zones[0].categories
|
||||
hip[1].children.push(structuredClone(hip[0].children[0]))
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([])
|
||||
})
|
||||
|
||||
it('finding_zone.unreferenced is a warning', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.finding_zones.push({
|
||||
id: 'stifle',
|
||||
name: { fr: 'Grasset', en: 'Stifle' },
|
||||
categories: [],
|
||||
})
|
||||
})
|
||||
expect(issuesOf(doc)).toEqual([
|
||||
['finding_zone.unreferenced', 'finding_zones[5]'],
|
||||
])
|
||||
expect(validateSheetDocument(doc)[0].severity).toBe('warning')
|
||||
})
|
||||
})
|
||||
|
||||
describe('publication gate', () => {
|
||||
it('accepts the fixture', () => {
|
||||
expect(isPublishable(validateSheetDocument(horseSlice()))).toBe(true)
|
||||
expect(() => assertPublishable(horseSlice())).not.toThrow()
|
||||
})
|
||||
|
||||
it('accepts a document with warnings only', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.annotations.push(point('mandible', { finding_zone_id: null }))
|
||||
})
|
||||
expect(validateSheetDocument(doc)).toHaveLength(1)
|
||||
expect(isPublishable(validateSheetDocument(doc))).toBe(true)
|
||||
expect(() => assertPublishable(doc)).not.toThrow()
|
||||
})
|
||||
|
||||
it('refuses a document with an error, exposing the issues', () => {
|
||||
const doc = mutated((d) => {
|
||||
d.views[0].svg_asset_id = null
|
||||
})
|
||||
expect(isPublishable(validateSheetDocument(doc))).toBe(false)
|
||||
let caught: unknown
|
||||
try {
|
||||
assertPublishable(doc)
|
||||
} catch (thrown) {
|
||||
caught = thrown
|
||||
}
|
||||
expect(caught).toBeInstanceOf(SheetValidationError)
|
||||
const codes = (caught as SheetValidationError).issues.map((i) => i.code)
|
||||
expect(codes).toEqual(['view.asset.missing'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('createEmptySheetDocument', () => {
|
||||
const empty = () =>
|
||||
createEmptySheetDocument({
|
||||
species_id: 'equine',
|
||||
name: { fr: 'Nouvelle fiche', en: 'New sheet' },
|
||||
})
|
||||
|
||||
it('is valid for the shape tier', () => {
|
||||
expect(AnatomicalSheetDocumentSchema.safeParse(empty()).success).toBe(true)
|
||||
expect(empty().views).toEqual([
|
||||
expect.objectContaining({
|
||||
id: 'view-main',
|
||||
kind: 'main',
|
||||
svg_asset_id: null,
|
||||
view_box: null,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it('is not publishable: the main view has no asset', () => {
|
||||
const issues = validateSheetDocument(empty())
|
||||
expect(issues.map((issue) => issue.code)).toEqual(['view.asset.missing'])
|
||||
expect(() => assertPublishable(empty())).toThrow(SheetValidationError)
|
||||
})
|
||||
})
|
||||
|
||||
/** True for a { fr?, en? } label object, the only thing a translator edits. */
|
||||
function isLabel(value: unknown): value is Record<string, string> {
|
||||
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return false
|
||||
}
|
||||
const keys = Object.keys(value)
|
||||
return keys.length > 0 && keys.every((key) => key === 'fr' || key === 'en')
|
||||
}
|
||||
|
||||
/** Rewrites every label with arbitrary strings, leaving all else intact. */
|
||||
function mapLabels(
|
||||
value: unknown,
|
||||
rewrite: (label: Record<string, string>) => unknown,
|
||||
): unknown {
|
||||
if (isLabel(value)) return rewrite(value)
|
||||
if (Array.isArray(value)) return value.map((v) => mapLabels(v, rewrite))
|
||||
if (value === null || typeof value !== 'object') return value
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([k, v]) => [k, mapLabels(v, rewrite)]),
|
||||
)
|
||||
}
|
||||
|
||||
/** Every id and reference: values of keys named id, *_id or code. */
|
||||
function collectIds(value: unknown, out: string[] = []): string[] {
|
||||
if (Array.isArray(value)) value.forEach((v) => collectIds(v, out))
|
||||
else if (value !== null && typeof value === 'object') {
|
||||
for (const [key, v] of Object.entries(value)) {
|
||||
const isRef = key === 'id' || key.endsWith('_id') || key.endsWith('code')
|
||||
if (isRef && typeof v === 'string') out.push(`${key}=${v}`)
|
||||
else collectIds(v, out)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
describe('ID stability under translation', () => {
|
||||
it('keeps ids, references and validation output when labels change', () => {
|
||||
const original = horseSlice()
|
||||
let counter = 0
|
||||
const relabeled = AnatomicalSheetDocumentSchema.parse(
|
||||
mapLabels(original, (label) =>
|
||||
Object.fromEntries(
|
||||
Object.keys(label).map((locale) => [locale, `x${counter++}`]),
|
||||
),
|
||||
),
|
||||
)
|
||||
expect(counter).toBeGreaterThan(50)
|
||||
expect(JSON.stringify(relabeled)).not.toEqual(JSON.stringify(original))
|
||||
expect(collectIds(relabeled)).toEqual(collectIds(original))
|
||||
const strip = () => null
|
||||
expect(mapLabels(relabeled, strip)).toEqual(mapLabels(original, strip))
|
||||
expect(validateSheetDocument(relabeled)).toEqual(
|
||||
validateSheetDocument(original),
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps validation output identical on a broken document too', () => {
|
||||
const broken = mutated((d) => {
|
||||
d.annotations[0].category_id = 'os'
|
||||
d.views[1].view_box = null
|
||||
})
|
||||
const relabeled = mapLabels(broken, () => ({ fr: 'a', en: 'b' }))
|
||||
expect(validateSheetDocument(relabeled as AnatomicalSheetDocument)).toEqual(
|
||||
validateSheetDocument(broken),
|
||||
)
|
||||
})
|
||||
})
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
import {
|
||||
AnatomicalSheetDocumentSchema,
|
||||
type AnatomicalSheetDocument,
|
||||
type AnatomicalSheetDocumentInput,
|
||||
type FindingNodeInput,
|
||||
} from '../../src'
|
||||
|
||||
/**
|
||||
* Reduced equine sheet built from the real assets: labels come from
|
||||
* apps/app/public/species/equine/{Horse,Horse_head}.svg and from
|
||||
* apps/app/src/domain/species/equine/pathologies.json. It exercises two
|
||||
* views (one cropped detail), a trigger, a spine region, a bilateral joint,
|
||||
* the three finding kinds, a two-level tree, a vet referral and a source.
|
||||
* It references every finding zone, so it validates with zero issues.
|
||||
*/
|
||||
|
||||
export const HORSE_MAIN_ASSET_ID = '3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8'
|
||||
|
||||
function leaf(id: string, fr: string, en: string): FindingNodeInput {
|
||||
return { id, name: { fr, en } }
|
||||
}
|
||||
|
||||
const ANAMNESIS = {
|
||||
id: 'anamnesis',
|
||||
kind: 'anamnesis',
|
||||
name: {
|
||||
fr: 'Anamnèse / facteurs rapportés',
|
||||
en: 'Anamnesis / reported factors',
|
||||
},
|
||||
description: {
|
||||
fr: "Facteurs rapportés par le propriétaire lors de l'anamnèse",
|
||||
},
|
||||
} as const
|
||||
|
||||
const OBSERVATIONS_NAME = {
|
||||
fr: 'Observations / motifs de consultation',
|
||||
en: 'Observations / consultation reasons',
|
||||
}
|
||||
|
||||
const DYSFUNCTIONS_NAME = {
|
||||
fr: 'Dysfonctions ostéopathiques',
|
||||
en: 'Osteopathic dysfunctions',
|
||||
}
|
||||
|
||||
const TRAUMA = leaf(
|
||||
'trauma-direct',
|
||||
'Traumatisme rapporté (choc, chute)',
|
||||
'Reported trauma (blow, fall)',
|
||||
)
|
||||
|
||||
const STRESS = leaf(
|
||||
'stress-context',
|
||||
'Contexte de stress / changement',
|
||||
'Stress / change context',
|
||||
)
|
||||
|
||||
const HIP_ZONE = {
|
||||
id: 'hip',
|
||||
name: { fr: 'Hanche (coxo-fémorale)', en: 'Hip joint' },
|
||||
categories: [
|
||||
{
|
||||
id: 'hip-dysfunctions',
|
||||
kind: 'dysfunction',
|
||||
name: DYSFUNCTIONS_NAME,
|
||||
children: [
|
||||
{
|
||||
id: 'articular',
|
||||
name: {
|
||||
fr: 'Restrictions de mobilité articulaire',
|
||||
en: 'Articular mobility restrictions',
|
||||
},
|
||||
children: [
|
||||
leaf(
|
||||
'restriction-flexion',
|
||||
'Restriction en flexion',
|
||||
'Flexion restriction',
|
||||
),
|
||||
leaf(
|
||||
'restriction-extension',
|
||||
'Restriction en extension',
|
||||
'Extension restriction',
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'hip-observations',
|
||||
kind: 'observation',
|
||||
name: OBSERVATIONS_NAME,
|
||||
children: [
|
||||
{
|
||||
...leaf(
|
||||
'limb-lameness',
|
||||
'Boiterie rapportée (membre concerné)',
|
||||
'Reported lameness (affected limb)',
|
||||
),
|
||||
requires_vet_referral: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
...ANAMNESIS,
|
||||
children: [
|
||||
{
|
||||
...TRAUMA,
|
||||
sources: [
|
||||
{
|
||||
type: 'manual',
|
||||
citation: 'Legacy equine catalog (pathologies.json)',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} satisfies AnatomicalSheetDocumentInput['finding_zones'][number]
|
||||
|
||||
const CERVICAL_ZONE = {
|
||||
id: 'cervical',
|
||||
name: { fr: 'Vertèbres cervicales', en: 'Cervical Vertebrae' },
|
||||
categories: [
|
||||
{
|
||||
id: 'cervical-dysfunctions',
|
||||
kind: 'dysfunction',
|
||||
name: DYSFUNCTIONS_NAME,
|
||||
children: [
|
||||
{
|
||||
id: 'muscular',
|
||||
name: {
|
||||
fr: 'Tensions musculaires paravertébrales',
|
||||
en: 'Paravertebral muscle tensions',
|
||||
},
|
||||
children: [
|
||||
leaf('splenius-tension', 'Tension du splénius', 'Splenius tension'),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'cervical-observations',
|
||||
kind: 'observation',
|
||||
name: OBSERVATIONS_NAME,
|
||||
children: [
|
||||
{
|
||||
...leaf(
|
||||
'stumbling-proprioceptive',
|
||||
'Trébuchements / déficit proprioceptif rapporté',
|
||||
'Reported stumbling / proprioceptive deficit',
|
||||
),
|
||||
requires_vet_referral: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{ ...ANAMNESIS, children: [TRAUMA] },
|
||||
],
|
||||
} satisfies AnatomicalSheetDocumentInput['finding_zones'][number]
|
||||
|
||||
const C7_T1_ZONE = {
|
||||
id: 'c7-t1',
|
||||
name: {
|
||||
fr: 'Charnière C7-T1 (cervico-thoracique)',
|
||||
en: 'C7-T1 (Cervicothoracic)',
|
||||
},
|
||||
categories: [
|
||||
{
|
||||
id: 'c7-t1-dysfunctions',
|
||||
kind: 'dysfunction',
|
||||
name: DYSFUNCTIONS_NAME,
|
||||
children: [
|
||||
leaf(
|
||||
'restriction-rotation',
|
||||
'Restriction en rotation',
|
||||
'Rotation restriction',
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'c7-t1-observations',
|
||||
kind: 'observation',
|
||||
name: OBSERVATIONS_NAME,
|
||||
children: [
|
||||
leaf(
|
||||
'base-neck-stiffness',
|
||||
"Raideur de la base de l'encolure",
|
||||
'Base-of-neck stiffness',
|
||||
),
|
||||
],
|
||||
},
|
||||
{ ...ANAMNESIS, children: [STRESS] },
|
||||
],
|
||||
} satisfies AnatomicalSheetDocumentInput['finding_zones'][number]
|
||||
|
||||
const ATM_ZONE = {
|
||||
id: 'atm',
|
||||
name: {
|
||||
fr: 'Articulation Temporo-Mandibulaire (ATM)',
|
||||
en: 'Temporomandibular Joint (TMJ)',
|
||||
},
|
||||
categories: [
|
||||
{
|
||||
id: 'atm-dysfunctions',
|
||||
kind: 'dysfunction',
|
||||
name: {
|
||||
fr: "Dysfonctions ostéopathiques de l'ATM",
|
||||
en: 'Osteopathic TMJ dysfunctions',
|
||||
},
|
||||
children: [
|
||||
leaf('masseter-tension', 'Tension du masséter', 'Masseter tension'),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'atm-observations',
|
||||
kind: 'observation',
|
||||
name: OBSERVATIONS_NAME,
|
||||
children: [
|
||||
leaf(
|
||||
'bit-defense',
|
||||
'Réactions de défense au mors',
|
||||
'Defense reactions to bit',
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
...ANAMNESIS,
|
||||
children: [
|
||||
leaf(
|
||||
'dental-context',
|
||||
'Suite de soin dentaire récent',
|
||||
'Post recent dental care',
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
} satisfies AnatomicalSheetDocumentInput['finding_zones'][number]
|
||||
|
||||
const SPHENOID_ZONE = {
|
||||
id: 'sphenoid',
|
||||
name: { fr: 'Sphénoïde', en: 'Sphenoid' },
|
||||
categories: [
|
||||
{
|
||||
id: 'ssb-dysfunctions',
|
||||
kind: 'dysfunction',
|
||||
name: DYSFUNCTIONS_NAME,
|
||||
children: [
|
||||
{
|
||||
id: 'physiological',
|
||||
name: {
|
||||
fr: 'Lésions physiologiques (SSB)',
|
||||
en: 'Physiological lesions (SBS)',
|
||||
},
|
||||
children: [
|
||||
leaf('torsion-right', 'Torsion droite', 'Right torsion'),
|
||||
leaf('torsion-left', 'Torsion gauche', 'Left torsion'),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'sphenoid-observations',
|
||||
kind: 'observation',
|
||||
name: OBSERVATIONS_NAME,
|
||||
children: [
|
||||
leaf(
|
||||
'post-trauma-head',
|
||||
'Suite de traumatisme crânien',
|
||||
'Post head trauma',
|
||||
),
|
||||
],
|
||||
},
|
||||
{ ...ANAMNESIS, children: [TRAUMA, STRESS] },
|
||||
],
|
||||
} satisfies AnatomicalSheetDocumentInput['finding_zones'][number]
|
||||
|
||||
const HORSE_SLICE_INPUT: AnatomicalSheetDocumentInput = {
|
||||
schema_version: 1,
|
||||
species_id: 'equine',
|
||||
name: { fr: 'Cheval (extrait)', en: 'Horse (slice)' },
|
||||
description: {
|
||||
fr: 'Extrait de la fiche équine pour les tests du modèle',
|
||||
en: 'Equine sheet slice for model tests',
|
||||
},
|
||||
scope_disclaimer: {
|
||||
fr:
|
||||
"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.',
|
||||
},
|
||||
attribution: { authors: ['Faunosteo'], license: 'MIT', notes: null },
|
||||
vertebral_config: {
|
||||
regions: [
|
||||
{ code: 'C', name: { fr: 'Cervicales', en: 'Cervical' }, count: 7 },
|
||||
{ code: 'T', name: { fr: 'Thoraciques', en: 'Thoracic' }, count: 18 },
|
||||
{ code: 'L', name: { fr: 'Lombaires', en: 'Lumbar' }, count: 6 },
|
||||
{ code: 'S', name: { fr: 'Sacrées', en: 'Sacral' }, count: 5 },
|
||||
{ code: 'Cd', name: { fr: 'Caudales', en: 'Caudal' }, count: 18 },
|
||||
],
|
||||
},
|
||||
categories: [
|
||||
{
|
||||
id: 'articulations',
|
||||
name: { fr: 'Articulations', en: 'Joints' },
|
||||
color: '#ff9500',
|
||||
},
|
||||
{
|
||||
id: 'zone-colonne',
|
||||
name: { fr: 'Zone colonne', en: 'Spine zone' },
|
||||
color: '#e100ff',
|
||||
},
|
||||
{
|
||||
id: 'charnieres-vertebrales',
|
||||
name: { fr: 'Charnières vertébrales', en: 'Vertebral junctions' },
|
||||
color: '#ff0000',
|
||||
},
|
||||
{
|
||||
id: 'cadrans-du-crane',
|
||||
name: { fr: 'Cadrans du crâne', en: 'Skull quadrants' },
|
||||
color: '#1baa08',
|
||||
},
|
||||
],
|
||||
views: [
|
||||
{
|
||||
id: 'view-main',
|
||||
kind: 'main',
|
||||
name: { fr: 'Cheval entier', en: 'Whole horse' },
|
||||
svg_asset_id: HORSE_MAIN_ASSET_ID,
|
||||
view_box: null,
|
||||
},
|
||||
{
|
||||
id: 'view-head',
|
||||
kind: 'detail',
|
||||
name: { fr: 'Tête', en: 'Head' },
|
||||
parent_view_id: 'view-main',
|
||||
svg_asset_id: null,
|
||||
view_box: { min_x: 60, min_y: 100, width: 500, height: 380 },
|
||||
},
|
||||
],
|
||||
annotations: [
|
||||
{
|
||||
id: 'hip',
|
||||
kind: 'point',
|
||||
view_id: 'view-main',
|
||||
category_id: 'articulations',
|
||||
laterality: 'bilateral',
|
||||
geometry: { type: 'circle', cx: 1516, cy: 695, r: 34 },
|
||||
name: { fr: 'Hanche (coxo-fémorale)', en: 'Hip joint' },
|
||||
finding_zone_id: 'hip',
|
||||
vertebral_region_code: null,
|
||||
},
|
||||
{
|
||||
id: 'cervical-vertebrae',
|
||||
kind: 'zone',
|
||||
view_id: 'view-main',
|
||||
category_id: 'zone-colonne',
|
||||
laterality: 'unpaired',
|
||||
geometry: {
|
||||
type: 'polygon',
|
||||
points: [
|
||||
[468, 276],
|
||||
[489, 216],
|
||||
[558, 248],
|
||||
[586, 339],
|
||||
[552, 461],
|
||||
[524, 370],
|
||||
],
|
||||
},
|
||||
name: { fr: 'Vertèbres cervicales', en: 'Cervical Vertebrae' },
|
||||
finding_zone_id: 'cervical',
|
||||
vertebral_region_code: 'C',
|
||||
},
|
||||
{
|
||||
id: 'hinge-c7-t1',
|
||||
kind: 'point',
|
||||
view_id: 'view-main',
|
||||
category_id: 'charnieres-vertebrales',
|
||||
laterality: 'unpaired',
|
||||
geometry: { type: 'circle', cx: 840.17, cy: 399.08, r: 30 },
|
||||
name: {
|
||||
fr: 'Charnière C7-T1 (cervico-thoracique)',
|
||||
en: 'C7-T1 (Cervicothoracic)',
|
||||
},
|
||||
finding_zone_id: 'c7-t1',
|
||||
vertebral_region_code: null,
|
||||
},
|
||||
{
|
||||
id: 'head-trigger',
|
||||
kind: 'detail_trigger',
|
||||
view_id: 'view-main',
|
||||
category_id: 'cadrans-du-crane',
|
||||
laterality: 'unpaired',
|
||||
geometry: {
|
||||
type: 'polygon',
|
||||
points: [
|
||||
[454, 332],
|
||||
[429, 202],
|
||||
[349, 154],
|
||||
[234, 279],
|
||||
[164, 384],
|
||||
[234, 468],
|
||||
],
|
||||
},
|
||||
name: null,
|
||||
opens_view_id: 'view-head',
|
||||
},
|
||||
{
|
||||
id: 'atm',
|
||||
kind: 'point',
|
||||
view_id: 'view-head',
|
||||
category_id: 'articulations',
|
||||
laterality: 'bilateral',
|
||||
geometry: { type: 'circle', cx: 384.94, cy: 314.02, r: 27 },
|
||||
name: {
|
||||
fr: 'Articulation Temporo-Mandibulaire (ATM)',
|
||||
en: 'Temporomandibular Joint (TMJ)',
|
||||
},
|
||||
finding_zone_id: 'atm',
|
||||
vertebral_region_code: null,
|
||||
},
|
||||
{
|
||||
id: 'sphenoid',
|
||||
kind: 'point',
|
||||
view_id: 'view-head',
|
||||
category_id: 'cadrans-du-crane',
|
||||
laterality: 'unpaired',
|
||||
geometry: { type: 'circle', cx: 299, cy: 298, r: 27 },
|
||||
name: { fr: 'Sphénoïde', en: 'Sphenoid' },
|
||||
finding_zone_id: 'sphenoid',
|
||||
vertebral_region_code: null,
|
||||
},
|
||||
],
|
||||
finding_zones: [HIP_ZONE, CERVICAL_ZONE, C7_T1_ZONE, ATM_ZONE, SPHENOID_ZONE],
|
||||
}
|
||||
|
||||
/** Lean authoring form, as a creator or the importer would write it. */
|
||||
export function horseSliceInput(): AnatomicalSheetDocumentInput {
|
||||
return structuredClone(HORSE_SLICE_INPUT)
|
||||
}
|
||||
|
||||
/** Parsed (total) document; a fresh copy so tests can mutate it freely. */
|
||||
export function horseSlice(): AnatomicalSheetDocument {
|
||||
return AnatomicalSheetDocumentSchema.parse(horseSliceInput())
|
||||
}
|
||||
Reference in new issue
Block a user