- 移除 28 个文件中不再需要的 import React (jsx: react-jsx) - 修复 catch(err: any) → catch(err: unknown) 类型收窄 - 修复 __wxConfig / CanvasRenderingContext2D 全局类型声明 - 修复 DTO 类型不匹配 (UpdateDialysisRecordReq, notificationService) - 移除 52 个未使用的 import/变量/常量 - 修复 services 类型 (auth.ts tenant_id, actionInbox boolean, device-sync)
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { api } from './request';
|
|
import type { NormalizedReading } from './ble/types';
|
|
|
|
interface BatchReadingRequest {
|
|
device_id: string;
|
|
device_model?: string;
|
|
readings: {
|
|
device_type: string;
|
|
values: Record<string, number | string>;
|
|
measured_at: string;
|
|
}[];
|
|
}
|
|
|
|
interface BatchResult {
|
|
accepted: number;
|
|
duplicates: number;
|
|
earliest: string | null;
|
|
latest: string | null;
|
|
}
|
|
|
|
/** 将标准化读数转换为后端批量请求格式并上传 */
|
|
export async function uploadReadings(
|
|
patientId: string,
|
|
deviceId: string,
|
|
deviceModel: string | undefined,
|
|
readings: NormalizedReading[],
|
|
): Promise<number> {
|
|
if (readings.length === 0) return 0;
|
|
|
|
const body: BatchReadingRequest = {
|
|
device_id: deviceId,
|
|
device_model: deviceModel,
|
|
readings: readings.map((r) => ({
|
|
device_type: r.device_type,
|
|
values: r.values,
|
|
measured_at: r.measured_at,
|
|
})),
|
|
};
|
|
|
|
const result = await api.post<BatchResult>(
|
|
`/health/patients/${patientId}/device-readings/batch`,
|
|
body,
|
|
);
|
|
return result.accepted;
|
|
}
|
|
|
|
/** 查询设备原始数据 */
|
|
export async function queryDeviceReadings(
|
|
patientId: string,
|
|
params?: { device_type?: string; hours?: number },
|
|
) {
|
|
return api.get<{ data: unknown[]; total: number }>(
|
|
`/health/patients/${patientId}/device-readings`,
|
|
params,
|
|
);
|
|
}
|
|
|
|
/** 查询小时级降采样数据 */
|
|
export async function queryHourlyReadings(
|
|
patientId: string,
|
|
params: { device_type: string; days?: number },
|
|
) {
|
|
return api.get<{ data: unknown[]; total: number }>(
|
|
`/health/patients/${patientId}/device-readings/hourly`,
|
|
params,
|
|
);
|
|
}
|