feat(medications): 新增完整的药物管理和服药提醒功能
实现了包含药物信息管理、服药记录追踪、统计分析、自动状态更新和推送提醒的完整药物管理系统。 核心功能: - 药物 CRUD 操作,支持多种剂型和自定义服药时间 - 惰性生成服药记录策略,查询时才生成当天记录 - 定时任务自动更新过期记录状态(每30分钟) - 服药前15分钟自动推送提醒(每5分钟检查) - 每日/范围/总体统计分析功能 - 完整的 API 文档和数据库建表脚本 技术实现: - 使用 Sequelize ORM 管理 MySQL 数据表 - 集成 @nestjs/schedule 实现定时任务 - 复用现有推送通知系统发送提醒 - 采用软删除和权限验证保障数据安全
This commit is contained in:
102
src/medications/medication-records.controller.ts
Normal file
102
src/medications/medication-records.controller.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { MedicationRecordsService } from './medication-records.service';
|
||||
import { TakeMedicationDto } from './dto/take-medication.dto';
|
||||
import { SkipMedicationDto } from './dto/skip-medication.dto';
|
||||
import { UpdateMedicationRecordDto } from './dto/update-medication-record.dto';
|
||||
import { MedicationRecordQueryDto } from './dto/medication-record-query.dto';
|
||||
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
|
||||
import { CurrentUser } from '../common/decorators/current-user.decorator';
|
||||
import { ApiResponseDto } from '../base.dto';
|
||||
|
||||
/**
|
||||
* 服药记录控制器
|
||||
*/
|
||||
@ApiTags('medication-records')
|
||||
@Controller('medication-records')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class MedicationRecordsController {
|
||||
constructor(
|
||||
private readonly recordsService: MedicationRecordsService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '获取服药记录' })
|
||||
@ApiResponse({ status: 200, description: '查询成功' })
|
||||
async findAll(
|
||||
@CurrentUser() user: any,
|
||||
@Query() query: MedicationRecordQueryDto,
|
||||
) {
|
||||
const records = await this.recordsService.findAll(user.sub, query);
|
||||
return ApiResponseDto.success(records, '查询成功');
|
||||
}
|
||||
|
||||
@Get('today')
|
||||
@ApiOperation({ summary: '获取今日服药记录' })
|
||||
@ApiResponse({ status: 200, description: '查询成功' })
|
||||
async getTodayRecords(@CurrentUser() user: any) {
|
||||
const records = await this.recordsService.getTodayRecords(user.sub);
|
||||
return ApiResponseDto.success(records, '查询成功');
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: '获取服药记录详情' })
|
||||
@ApiResponse({ status: 200, description: '查询成功' })
|
||||
async findOne(@CurrentUser() user: any, @Param('id') id: string) {
|
||||
const record = await this.recordsService.findOne(id, user.sub);
|
||||
return ApiResponseDto.success(record, '查询成功');
|
||||
}
|
||||
|
||||
@Post(':id/take')
|
||||
@ApiOperation({ summary: '标记为已服用' })
|
||||
@ApiResponse({ status: 200, description: '操作成功' })
|
||||
async takeMedication(
|
||||
@CurrentUser() user: any,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: TakeMedicationDto,
|
||||
) {
|
||||
const record = await this.recordsService.takeMedication(
|
||||
id,
|
||||
user.sub,
|
||||
dto,
|
||||
);
|
||||
return ApiResponseDto.success(record, '已记录服药');
|
||||
}
|
||||
|
||||
@Post(':id/skip')
|
||||
@ApiOperation({ summary: '跳过服药' })
|
||||
@ApiResponse({ status: 200, description: '操作成功' })
|
||||
async skipMedication(
|
||||
@CurrentUser() user: any,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: SkipMedicationDto,
|
||||
) {
|
||||
const record = await this.recordsService.skipMedication(
|
||||
id,
|
||||
user.sub,
|
||||
dto,
|
||||
);
|
||||
return ApiResponseDto.success(record, '已跳过服药');
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: '更新服药记录' })
|
||||
@ApiResponse({ status: 200, description: '更新成功' })
|
||||
async update(
|
||||
@CurrentUser() user: any,
|
||||
@Param('id') id: string,
|
||||
@Body() dto: UpdateMedicationRecordDto,
|
||||
) {
|
||||
const record = await this.recordsService.update(id, user.sub, dto);
|
||||
return ApiResponseDto.success(record, '更新成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user