Files
plates-server/src/medications/models/medication-record.model.ts
richarjiang f04c2ccd5d feat(medications): 添加药物超时提醒功能
在MedicationRecord模型中添加overdueReminderSent字段追踪超时提醒状态,在提醒服务中新增定时任务检查超过服药时间1小时的未服用记录,并向用户发送鼓励提醒。该功能每10分钟检查一次,避免重复发送提醒,帮助用户及时补服错过的药物。
2025-11-14 14:47:44 +08:00

105 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Column, Model, Table, DataType, BelongsTo, ForeignKey } from 'sequelize-typescript';
import { MedicationStatusEnum } from '../enums/medication-status.enum';
import { Medication } from './medication.model';
/**
* 服药记录模型
*/
@Table({
tableName: 't_medication_records',
underscored: true,
paranoid: false, // 使用软删除字段 deleted 而不是 deletedAt
})
export class MedicationRecord extends Model {
@Column({
type: DataType.STRING(50),
primaryKey: true,
comment: '记录唯一标识',
})
declare id: string;
@ForeignKey(() => Medication)
@Column({
type: DataType.STRING(50),
allowNull: false,
comment: '关联的药物ID',
})
declare medicationId: string;
@Column({
type: DataType.STRING(50),
allowNull: false,
comment: '用户ID',
})
declare userId: string;
@Column({
type: DataType.DATE,
allowNull: false,
comment: '计划服药时间UTC时间',
})
declare scheduledTime: Date;
@Column({
type: DataType.DATE,
allowNull: true,
comment: '实际服药时间UTC时间',
})
declare actualTime: Date;
@Column({
type: DataType.STRING(20),
allowNull: false,
comment: '服药状态',
})
declare status: MedicationStatusEnum;
@Column({
type: DataType.TEXT,
allowNull: true,
comment: '备注',
})
declare note: string;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
comment: '创建时间',
})
declare createdAt: Date;
@Column({
type: DataType.DATE,
defaultValue: DataType.NOW,
comment: '更新时间',
})
declare updatedAt: Date;
@Column({
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '软删除标记',
})
declare deleted: boolean;
@Column({
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否已发送提醒',
})
declare reminderSent: boolean;
@Column({
type: DataType.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否已发送超时提醒',
})
declare overdueReminderSent: boolean;
// 关联关系
@BelongsTo(() => Medication, 'medicationId')
declare medication: Medication;
}