fix: 功能提交。
This commit is contained in:
109
src/api/health/medicationRecord.js
Normal file
109
src/api/health/medicationRecord.js
Normal file
@@ -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 }
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user