From ea2aafc2855d77e1ac909dd0d203f87f33e1024d Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Mon, 25 May 2026 23:20:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=9F=E8=83=BD=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/health/medicationRecord.js | 109 +++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/api/health/medicationRecord.js diff --git a/src/api/health/medicationRecord.js b/src/api/health/medicationRecord.js new file mode 100644 index 0000000..7ddb6b8 --- /dev/null +++ b/src/api/health/medicationRecord.js @@ -0,0 +1,109 @@ +import request from '@/utils/request' + +function today() { + return new Date().toISOString().substring(0, 10) +} + +function normalizeQuery(query = {}) { + const params = { ...query } + if (params.keys && !params.keyword) { + params.keyword = params.keys + } + if (params.status) { + params.status = { + 1: 0, + 2: 1, + 3: 3, + 4: 2 + }[params.status] ?? params.status + } + delete params.keys + return params +} + +function normalizeStatus(status) { + return { + 0: '1', + 1: '2', + 2: '4', + 3: '3' + }[status] || String(status || '') +} + +function normalizeRecord(record = {}) { + const plannedTime = record.plannedTime || '' + const plannedDate = record.plannedDate || '' + return { + ...record, + status: normalizeStatus(record.status), + shortName: record.shortName || record.medicineName || '', + brand: record.brand || '', + dosage: record.dosage || record.plannedDosage || '', + dosageUnit: record.dosageUnit || '', + scheduledTime: record.scheduledTime || `${plannedDate} ${plannedTime}`.trim() + } +} + +function normalizeListResponse(res) { + const rows = (res.rows || []).map(normalizeRecord) + return { + ...res, + rows, + data: Array.isArray(res.data) ? res.data.map(normalizeRecord) : res.data + } +} + +// 查询服药任务列表,兼容页面中的 medicationRecord 命名 +export function listMedicationRecord(query) { + return request({ + url: '/health/medicationTask/list', + method: 'get', + params: normalizeQuery(query) + }).then(normalizeListResponse) +} + +// 查询今日服药任务 +export function getTodayRecords() { + return listMedicationRecord({ + pageNum: 1, + pageSize: 100, + queryDate: today() + }).then(res => ({ + ...res, + data: res.data || res.rows || [] + })) +} + +// 查询某计划某天的服药任务 +export function getRecordsByPlanAndDate(planId, queryDate) { + return listMedicationRecord({ + pageNum: 1, + pageSize: 100, + planId, + queryDate + }).then(res => ({ + ...res, + data: res.data || res.rows || [] + })) +} + +// 确认服药 +export function takeMedication(id, dosage, confirmTime) { + return request({ + url: '/health/medicationTask/confirm/' + id, + method: 'put', + params: { + confirmType: 1, + confirmTime + } + }) +} + +// 跳过服药 +export function skipMedication(id, notes) { + return request({ + url: '/health/medicationTask/skip/' + id, + method: 'put', + params: { notes } + }) +}