feat(schema): add LateralSideSchema and Bone.lateral for laterality support
Exports LateralSideSchema (z.enum left/right) and LateralSide type. Adds optional side field to ObservationZoneSchema for bilateral zone distinction. Covers new schema with 6 dedicated tests (accepts/rejects for both types). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
db50c67bb6
commit
e0abb1efa1
2 files changed
+49
No files matched your search
@@ -15,6 +15,9 @@ export const VertebraSchema = z.object({
|
|||||||
|
|
||||||
export type Vertebra = z.infer<typeof VertebraSchema>
|
export type Vertebra = z.infer<typeof VertebraSchema>
|
||||||
|
|
||||||
|
export const LateralSideSchema = z.enum(['left', 'right'])
|
||||||
|
export type LateralSide = z.infer<typeof LateralSideSchema>
|
||||||
|
|
||||||
export const ObservationZoneSchema = z.object({
|
export const ObservationZoneSchema = z.object({
|
||||||
/** Must match data-anno-id attribute on the SVG element */
|
/** Must match data-anno-id attribute on the SVG element */
|
||||||
boneId: z.string().min(1),
|
boneId: z.string().min(1),
|
||||||
@@ -22,6 +25,8 @@ export const ObservationZoneSchema = z.object({
|
|||||||
detailSourceId: z.string().optional(),
|
detailSourceId: z.string().optional(),
|
||||||
/** Set when boneId is a spine-zone; replaces the block semantically */
|
/** Set when boneId is a spine-zone; replaces the block semantically */
|
||||||
vertebrae: z.array(VertebraSchema).optional(),
|
vertebrae: z.array(VertebraSchema).optional(),
|
||||||
|
/** Set for bilateral zones to distinguish left from right */
|
||||||
|
side: LateralSideSchema.optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type ObservationZone = z.infer<typeof ObservationZoneSchema>
|
export type ObservationZone = z.infer<typeof ObservationZoneSchema>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import {
|
|||||||
VertebraSchema,
|
VertebraSchema,
|
||||||
SeveritySchema,
|
SeveritySchema,
|
||||||
FindingSchema,
|
FindingSchema,
|
||||||
|
LateralSideSchema,
|
||||||
|
ObservationZoneSchema,
|
||||||
} from '@/domain/schema/observation'
|
} from '@/domain/schema/observation'
|
||||||
|
|
||||||
describe('SeveritySchema', () => {
|
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', () => {
|
describe('ObservationSchema', () => {
|
||||||
const baseObs = {
|
const baseObs = {
|
||||||
id: 'obs-1',
|
id: 'obs-1',
|
||||||
|
|||||||
Reference in new issue
Block a user