feat(miniprogram): 用药提醒从 localStorage 迁移到服务端 API
- 新增 medication-reminder.ts service(list/create/update/delete) - 重写 medication/index.tsx 页面,通过后端 API 持久化数据 - 支持乐观锁(version)、患者 ID 关联、提醒时间数组 - 移除旧的 localStorage 读写逻辑
This commit is contained in:
68
apps/miniprogram/src/services/medication-reminder.ts
Normal file
68
apps/miniprogram/src/services/medication-reminder.ts
Normal 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 });
|
||||
}
|
||||
Reference in New Issue
Block a user