129 lines
4.3 KiB
TypeScript
129 lines
4.3 KiB
TypeScript
import type { FindingNodeInput } from '@faunosteo/domain'
|
|
import { renderImportReport, type ImportResult } from '../src'
|
|
import type { LegacyCatalog, LegacyNode } from '../src/legacy/catalog'
|
|
import { loadCatalog, runImport } from './helpers'
|
|
|
|
let result: ImportResult
|
|
let catalog: LegacyCatalog
|
|
|
|
beforeAll(async () => {
|
|
;[result, catalog] = await Promise.all([runImport(), loadCatalog()])
|
|
})
|
|
|
|
function annotation(id: string) {
|
|
const found = result.document.annotations.find((a) => a.id === id)
|
|
if (!found) throw new Error(`annotation ${id} missing`)
|
|
return found
|
|
}
|
|
|
|
function zone(id: string) {
|
|
const found = result.document.finding_zones.find((z) => z.id === id)
|
|
if (!found) throw new Error(`zone ${id} missing`)
|
|
return found
|
|
}
|
|
|
|
/** Id skeleton of a tree: same shape whatever the label language. */
|
|
function idTree(
|
|
nodes: ReadonlyArray<LegacyNode | FindingNodeInput>,
|
|
): unknown[] {
|
|
return nodes.map((n) => [n.id, idTree(n.children ?? [])])
|
|
}
|
|
|
|
describe('equine import special cases', () => {
|
|
it('turns vertebral-precision into a region code', () => {
|
|
expect(annotation('lumbar')).toMatchObject({
|
|
kind: 'zone',
|
|
vertebral_region_code: 'L',
|
|
finding_zone_id: 'lumbar',
|
|
})
|
|
expect(annotation('caudal')).toMatchObject({ vertebral_region_code: 'Cd' })
|
|
})
|
|
|
|
it('makes data-anno-lateral explicit', () => {
|
|
expect(annotation('hip').laterality).toBe('bilateral')
|
|
expect(annotation('c7-t1').laterality).toBe('unpaired')
|
|
})
|
|
|
|
it('imports the trigger without name and without finding zone', () => {
|
|
const trigger = annotation('head-trigger')
|
|
expect(trigger.kind).toBe('detail_trigger')
|
|
expect(trigger.name).toBeNull()
|
|
expect(trigger).not.toHaveProperty('finding_zone_id')
|
|
})
|
|
|
|
it('keeps ssb-dysfunctions under sphenoid and names it in the report', () => {
|
|
expect(zone('sphenoid').categories[0]!.id).toBe('ssb-dysfunctions')
|
|
expect(zone('ssb').categories[0]!.id).toBe('ssb-dysfunctions')
|
|
const report = renderImportReport(result)
|
|
expect(report).toContain('sphenoid/ssb-dysfunctions')
|
|
expect(report).toContain('sphenoid-dysfunctions attendu')
|
|
})
|
|
|
|
it('keeps the anamnesis category in all zones with its three variants', () => {
|
|
const imported = result.document.finding_zones.map((z) => {
|
|
const category = z.categories.find((c) => c.id === 'anamnesis')
|
|
expect(category?.kind).toBe('anamnesis')
|
|
return idTree(category?.children ?? []).join('|')
|
|
})
|
|
const legacy = Object.values(catalog.zones).map((z) =>
|
|
idTree(
|
|
z.categories.find((c) => c.id === 'anamnesis')!.children ?? [],
|
|
).join('|'),
|
|
)
|
|
expect(imported).toHaveLength(26)
|
|
expect(imported).toEqual(legacy)
|
|
expect(new Set(imported).size).toBe(3)
|
|
})
|
|
|
|
it('writes no en key where description_en is absent', () => {
|
|
const category = zone('parietal').categories.find(
|
|
(c) => c.id === 'anamnesis',
|
|
)!
|
|
expect(category.description).toEqual({
|
|
fr: catalog.zones.parietal!.categories[2]!.description_fr,
|
|
})
|
|
const mobility = zone('parietal').categories[0]!.children[0]!
|
|
expect(mobility.description).toBeDefined()
|
|
expect(mobility.description).not.toHaveProperty('en')
|
|
})
|
|
|
|
it('maps category kinds from their ids', () => {
|
|
const kinds = zone('hip').categories.map((c) => [c.id, c.kind])
|
|
expect(kinds).toEqual([
|
|
['hip-dysfunctions', 'dysfunction'],
|
|
['hip-observations', 'consultation_reason'],
|
|
['anamnesis', 'anamnesis'],
|
|
])
|
|
})
|
|
|
|
it('preserves node ids at every level of every zone', () => {
|
|
for (const [key, legacy] of Object.entries(catalog.zones)) {
|
|
expect(idTree(zone(key).categories)).toEqual(idTree(legacy.categories))
|
|
}
|
|
})
|
|
|
|
it('writes the lean form: no default keys on plain leaves', () => {
|
|
const leaf = zone('parietal').categories[0]!.children[0]!.children![0]!
|
|
expect(Object.keys(leaf).sort()).toEqual(['id', 'name'])
|
|
})
|
|
})
|
|
|
|
describe('importer-authored labels', () => {
|
|
it('declares every label written without a source', () => {
|
|
const subjects = result.anomalies
|
|
.filter((a) => a.code === 'label.authored' && a.level === 'a_valider')
|
|
.map((a) => a.subject)
|
|
expect(subjects).toEqual([
|
|
'name',
|
|
'description',
|
|
'views.main',
|
|
'views.head',
|
|
'vertebral_config.C',
|
|
'vertebral_config.T',
|
|
'vertebral_config.L',
|
|
'vertebral_config.S',
|
|
'vertebral_config.Cd',
|
|
])
|
|
})
|
|
})
|