feat(miniprogram): 用药提醒从 localStorage 迁移到服务端 API
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 新增 medication-reminder.ts service(list/create/update/delete)
- 重写 medication/index.tsx 页面,通过后端 API 持久化数据
- 支持乐观锁(version)、患者 ID 关联、提醒时间数组
- 移除旧的 localStorage 读写逻辑
This commit is contained in:
iven
2026-05-03 09:38:24 +08:00
parent 32df9c0655
commit 1a6409eb30
2 changed files with 148 additions and 55 deletions

View File

@@ -0,0 +1,68 @@
import Taro from '@tarojs/taro';
import { api } from './request';
export interface MedicationReminder {
id: string;
patient_id: string;
medication_name: string;
dosage?: string;
frequency?: string;
reminder_times: string[];
start_date?: string;
end_date?: string;
is_active: boolean;
notes?: string;
version: number;
created_at: string;
updated_at: string;
}
export interface CreateReminderReq {
patient_id: string;
medication_name: string;
dosage?: string;
frequency?: string;
reminder_times: string[];
start_date?: string;
end_date?: string;
is_active?: boolean;
notes?: string;
}
export interface UpdateReminderReq {
medication_name?: string;
dosage?: string;
frequency?: string;
reminder_times?: string[];
start_date?: string;
end_date?: string;
is_active?: boolean;
notes?: string;
version: number;
}
function getPatientId(): string {
return Taro.getStorageSync('current_patient_id') || '';
}
export async function listReminders() {
const patientId = getPatientId();
if (!patientId) return { data: [] as MedicationReminder[], total: 0 };
return api.get<{ data: MedicationReminder[]; total: number }>(
`/health/patients/${patientId}/medication-reminders`,
{ page: 1, page_size: 100 },
0,
);
}
export async function createReminder(req: CreateReminderReq) {
return api.post<MedicationReminder>('/health/medication-reminders', req);
}
export async function updateReminder(id: string, req: UpdateReminderReq) {
return api.put<MedicationReminder>(`/health/medication-reminders/${id}`, req);
}
export async function deleteReminder(id: string, version: number) {
return api.delete<void>(`/health/medication-reminders/${id}`, { version });
}