feat(medications): 实现完整的用药管理功能
添加了药物管理的核心功能,包括: - 药物列表展示和状态管理 - 添加新药物的完整流程 - 服药记录的创建和状态更新 - 药物管理界面,支持激活/停用操作 - Redux状态管理和API服务层 - 相关类型定义和辅助函数 主要文件: - app/(tabs)/medications.tsx - 主界面,集成Redux数据 - app/medications/add-medication.tsx - 添加药物流程 - app/medications/manage-medications.tsx - 药物管理界面 - store/medicationsSlice.ts - Redux状态管理 - services/medications.ts - API服务层 - types/medication.ts - 类型定义
This commit is contained in:
93
types/medication.ts
Normal file
93
types/medication.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 药物管理类型定义
|
||||
*/
|
||||
|
||||
// 药物剂型
|
||||
export type MedicationForm =
|
||||
| 'capsule' // 胶囊
|
||||
| 'pill' // 药片
|
||||
| 'injection' // 注射
|
||||
| 'spray' // 喷雾
|
||||
| 'drop' // 滴剂
|
||||
| 'syrup' // 糖浆
|
||||
| 'other'; // 其他
|
||||
|
||||
// 服药状态
|
||||
export type MedicationStatus =
|
||||
| 'upcoming' // 待服用
|
||||
| 'taken' // 已服用
|
||||
| 'missed' // 已错过
|
||||
| 'skipped'; // 已跳过
|
||||
|
||||
// 重复模式
|
||||
export type RepeatPattern =
|
||||
| 'daily' // 每日
|
||||
| 'weekly' // 每周
|
||||
| 'custom'; // 自定义
|
||||
|
||||
/**
|
||||
* 药物基础信息
|
||||
*/
|
||||
export interface Medication {
|
||||
id: string;
|
||||
userId: string; // 用户ID(由服务端返回)
|
||||
name: string; // 药物名称
|
||||
photoUrl?: string | null; // 药物照片
|
||||
form: MedicationForm; // 剂型
|
||||
dosageValue: number; // 剂量值
|
||||
dosageUnit: string; // 剂量单位
|
||||
timesPerDay: number; // 每日次数
|
||||
medicationTimes: string[]; // 服药时间列表 ['08:00', '20:00']
|
||||
startDate: string; // 开始日期 ISO
|
||||
endDate?: string | null; // 结束日期 ISO(可选)
|
||||
repeatPattern: RepeatPattern; // 重复模式
|
||||
note?: string; // 备注
|
||||
isActive: boolean; // 是否激活
|
||||
deleted: boolean; // 是否已删除(软删除标记)
|
||||
createdAt: string; // 创建时间
|
||||
updatedAt: string; // 更新时间
|
||||
}
|
||||
|
||||
/**
|
||||
* 服药记录
|
||||
*/
|
||||
export interface MedicationRecord {
|
||||
id: string;
|
||||
medicationId: string; // 关联的药物ID
|
||||
userId: string; // 用户ID(由服务端返回)
|
||||
medication?: Medication; // 关联的药物信息(可选,用于展示)
|
||||
scheduledTime: string; // 计划服药时间 ISO
|
||||
actualTime?: string | null; // 实际服药时间 ISO
|
||||
status: MedicationStatus; // 服药状态
|
||||
note?: string; // 记录备注
|
||||
deleted: boolean; // 是否已删除(软删除标记)
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每日服药统计
|
||||
*/
|
||||
export interface DailyMedicationStats {
|
||||
date: string; // 日期 'YYYY-MM-DD'
|
||||
totalScheduled: number; // 计划总数
|
||||
taken: number; // 已服用
|
||||
missed: number; // 已错过
|
||||
upcoming: number; // 待服用
|
||||
completionRate: number; // 完成率 0-100
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于展示的药物记录(组合了药物信息和服药记录)
|
||||
*/
|
||||
export interface MedicationDisplayItem {
|
||||
id: string;
|
||||
name: string;
|
||||
dosage: string; // 格式化的剂量字符串,如 "1 粒胶囊"
|
||||
scheduledTime: string; // 格式化的时间,如 "09:00"
|
||||
frequency: string; // 频率描述,如 "每日"
|
||||
status: MedicationStatus;
|
||||
image?: any; // 图片资源
|
||||
recordId?: string; // 服药记录ID(用于更新状态)
|
||||
medicationId: string; // 药物ID
|
||||
}
|
||||
Reference in New Issue
Block a user