feat(medications): 增强AI药品识别质量控制和多图片支持

- 新增图片可读性预检查机制,识别前先判断图片质量
- 设置置信度阈值为60%,低于阈值自动识别失败
- 支持多图片上传(正面、侧面、辅助图片)提高识别准确度
- 完善识别失败场景的错误分类和用户指导提示
- 新增药品有效期字段支持
- 优化AI提示词,强调安全优先原则
- 更新模型版本为 glm-4.5v 和 glm-4.5-air

数据库变更:
- Medication表新增 sideImageUrl, auxiliaryImageUrl, expiryDate 字段
- DTO层同步支持新增字段的传递和更新

质量控制策略:
- 图片模糊或不可读时直接返回失败
- 无法识别药品名称时主动失败
- 置信度<60%时拒绝识别,建议重新拍摄
- 宁可识别失败也不提供不准确的药品信息
This commit is contained in:
richarjiang
2025-11-21 16:59:36 +08:00
parent a17fe0b965
commit f8fcc81438
7 changed files with 254 additions and 42 deletions

View File

@@ -45,6 +45,8 @@ export class MedicationsService {
userId,
name: createDto.name,
photoUrl: createDto.photoUrl,
sideImageUrl: createDto.sideImageUrl,
auxiliaryImageUrl: createDto.auxiliaryImageUrl,
form: createDto.form,
dosageValue: createDto.dosageValue,
dosageUnit: createDto.dosageUnit,
@@ -53,6 +55,7 @@ export class MedicationsService {
repeatPattern: createDto.repeatPattern,
startDate: new Date(createDto.startDate),
endDate: createDto.endDate ? new Date(createDto.endDate) : null,
expiryDate: createDto.expiryDate ? new Date(createDto.expiryDate) : null,
note: createDto.note,
isActive: createDto.isActive !== undefined ? createDto.isActive : true,
deleted: false,
@@ -133,6 +136,12 @@ export class MedicationsService {
if (updateDto.photoUrl !== undefined) {
medication.photoUrl = updateDto.photoUrl;
}
if (updateDto.sideImageUrl !== undefined) {
medication.sideImageUrl = updateDto.sideImageUrl;
}
if (updateDto.auxiliaryImageUrl !== undefined) {
medication.auxiliaryImageUrl = updateDto.auxiliaryImageUrl;
}
if (updateDto.form !== undefined) {
medication.form = updateDto.form;
}
@@ -155,7 +164,10 @@ export class MedicationsService {
medication.startDate = new Date(updateDto.startDate);
}
if (updateDto.endDate !== undefined) {
medication.endDate = new Date(updateDto.endDate);
medication.endDate = updateDto.endDate ? new Date(updateDto.endDate) : null;
}
if (updateDto.expiryDate !== undefined) {
medication.expiryDate = updateDto.expiryDate ? new Date(updateDto.expiryDate) : null;
}
if (updateDto.note !== undefined) {
medication.note = updateDto.note;
@@ -163,6 +175,10 @@ export class MedicationsService {
if (updateDto.isActive !== undefined) {
medication.isActive = updateDto.isActive;
}
// 支持更新 AI 分析结果
if ((updateDto as any).aiAnalysis !== undefined) {
medication.aiAnalysis = (updateDto as any).aiAnalysis;
}
await medication.save();