115 lines
2.4 KiB
TypeScript
115 lines
2.4 KiB
TypeScript
import { ApiProperty } from '@nestjs/swagger';
|
||
import {
|
||
IsString,
|
||
IsNotEmpty,
|
||
IsEnum,
|
||
IsNumber,
|
||
IsInt,
|
||
IsArray,
|
||
IsDateString,
|
||
IsOptional,
|
||
IsBoolean,
|
||
Min,
|
||
ArrayMinSize,
|
||
Matches,
|
||
} from 'class-validator';
|
||
import { MedicationFormEnum } from '../enums/medication-form.enum';
|
||
import { RepeatPatternEnum } from '../enums/repeat-pattern.enum';
|
||
|
||
/**
|
||
* 创建药物 DTO
|
||
*/
|
||
export class CreateMedicationDto {
|
||
@ApiProperty({ description: '药物名称', example: 'Metformin' })
|
||
@IsString()
|
||
@IsNotEmpty()
|
||
name: string;
|
||
|
||
@ApiProperty({
|
||
description: '药物照片URL',
|
||
example: 'https://cdn.example.com/medications/med_001.jpg',
|
||
required: false,
|
||
})
|
||
@IsString()
|
||
@IsOptional()
|
||
photoUrl?: string;
|
||
|
||
@ApiProperty({
|
||
description: '药物剂型',
|
||
enum: MedicationFormEnum,
|
||
example: MedicationFormEnum.CAPSULE,
|
||
})
|
||
@IsEnum(MedicationFormEnum)
|
||
@IsNotEmpty()
|
||
form: MedicationFormEnum;
|
||
|
||
@ApiProperty({ description: '剂量数值', example: 1 })
|
||
@IsNumber()
|
||
@Min(0.01)
|
||
dosageValue: number;
|
||
|
||
@ApiProperty({ description: '剂量单位', example: '粒' })
|
||
@IsString()
|
||
@IsNotEmpty()
|
||
dosageUnit: string;
|
||
|
||
@ApiProperty({ description: '每日服用次数', example: 2 })
|
||
@IsInt()
|
||
@Min(1)
|
||
timesPerDay: number;
|
||
|
||
@ApiProperty({
|
||
description: '服药时间列表,格式:HH:mm',
|
||
example: ['08:00', '20:00'],
|
||
type: [String],
|
||
})
|
||
@IsArray()
|
||
@ArrayMinSize(1)
|
||
@IsString({ each: true })
|
||
@Matches(/^([01]\d|2[0-3]):([0-5]\d)$/, {
|
||
each: true,
|
||
message: '服药时间格式必须为 HH:mm',
|
||
})
|
||
medicationTimes: string[];
|
||
|
||
@ApiProperty({
|
||
description: '重复模式',
|
||
enum: RepeatPatternEnum,
|
||
example: RepeatPatternEnum.DAILY,
|
||
})
|
||
@IsEnum(RepeatPatternEnum)
|
||
@IsNotEmpty()
|
||
repeatPattern: RepeatPatternEnum;
|
||
|
||
@ApiProperty({
|
||
description: '开始日期,ISO 8601 格式',
|
||
example: '2025-01-01T00:00:00.000Z',
|
||
})
|
||
@IsDateString()
|
||
@IsNotEmpty()
|
||
startDate: string;
|
||
|
||
@ApiProperty({
|
||
description: '结束日期,ISO 8601 格式(可选)',
|
||
example: '2025-12-31T23:59:59.999Z',
|
||
required: false,
|
||
})
|
||
@IsDateString()
|
||
@IsOptional()
|
||
endDate?: string;
|
||
|
||
@ApiProperty({ description: '备注信息', example: '饭后服用', required: false })
|
||
@IsString()
|
||
@IsOptional()
|
||
note?: string;
|
||
|
||
@ApiProperty({
|
||
description: '是否激活',
|
||
example: true,
|
||
required: false,
|
||
default: true
|
||
})
|
||
@IsOptional()
|
||
@IsBoolean()
|
||
isActive?: boolean;
|
||
} |