diff --git a/src/domain/schema/observation.ts b/src/domain/schema/observation.ts index e7d15854..29062523 100644 --- a/src/domain/schema/observation.ts +++ b/src/domain/schema/observation.ts @@ -15,6 +15,9 @@ export const VertebraSchema = z.object({ export type Vertebra = z.infer +export const LateralSideSchema = z.enum(['left', 'right']) +export type LateralSide = z.infer + export const ObservationZoneSchema = z.object({ /** Must match data-anno-id attribute on the SVG element */ boneId: z.string().min(1), @@ -22,6 +25,8 @@ export const ObservationZoneSchema = z.object({ detailSourceId: z.string().optional(), /** Set when boneId is a spine-zone; replaces the block semantically */ vertebrae: z.array(VertebraSchema).optional(), + /** Set for bilateral zones to distinguish left from right */ + side: LateralSideSchema.optional(), }) export type ObservationZone = z.infer diff --git a/tests/unit/schema.observation.test.ts b/tests/unit/schema.observation.test.ts index 318fd993..59c9c96c 100644 --- a/tests/unit/schema.observation.test.ts +++ b/tests/unit/schema.observation.test.ts @@ -4,6 +4,8 @@ import { VertebraSchema, SeveritySchema, FindingSchema, + LateralSideSchema, + ObservationZoneSchema, } from '@/domain/schema/observation' describe('SeveritySchema', () => { @@ -62,6 +64,48 @@ describe('FindingSchema', () => { }) }) +describe('LateralSideSchema', () => { + it('accepts left and right', () => { + expect(LateralSideSchema.parse('left')).toBe('left') + expect(LateralSideSchema.parse('right')).toBe('right') + }) + + it('rejects unknown side', () => { + expect(() => LateralSideSchema.parse('both')).toThrow() + expect(() => LateralSideSchema.parse('')).toThrow() + }) +}) + +describe('ObservationZoneSchema with side', () => { + it('accepts a zone without side (unpaired)', () => { + expect(() => ObservationZoneSchema.parse({ boneId: 'sternum' })).not.toThrow() + }) + + it('accepts a zone with side left', () => { + const parsed = ObservationZoneSchema.parse({ boneId: 'knee', side: 'left' }) + expect(parsed.side).toBe('left') + }) + + it('accepts a zone with side right', () => { + const parsed = ObservationZoneSchema.parse({ boneId: 'knee', side: 'right' }) + expect(parsed.side).toBe('right') + }) + + it('accepts two zones with same boneId but different sides', () => { + const obs = { + id: 'obs-1', + zones: [ + { boneId: 'knee', side: 'left' }, + { boneId: 'knee', side: 'right' }, + ], + findings: [], + freeTextFindings: [], + comment: '', + } + expect(() => ObservationSchema.parse(obs)).not.toThrow() + }) +}) + describe('ObservationSchema', () => { const baseObs = { id: 'obs-1',