Compare commits
3 Commits
679d83d3b6
...
e7b2e6382a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7b2e6382a | ||
|
|
8a5b14e087 | ||
|
|
83e243f03e |
@@ -172,14 +172,14 @@ export class BLEManager {
|
|||||||
// 监听数据通知
|
// 监听数据通知
|
||||||
Taro.onBLECharacteristicValueChange((res: any) => {
|
Taro.onBLECharacteristicValueChange((res: any) => {
|
||||||
if (res.deviceId !== device.deviceId) return;
|
if (res.deviceId !== device.deviceId) return;
|
||||||
const reading = device.adapter!.parseNotification(
|
const newReadings = device.adapter!.parseNotification(
|
||||||
res.serviceId,
|
res.serviceId,
|
||||||
res.characteristicId,
|
res.characteristicId,
|
||||||
res.value,
|
res.value,
|
||||||
);
|
);
|
||||||
if (reading) {
|
if (newReadings.length > 0) {
|
||||||
this.readings = [...this.readings, reading];
|
this.readings = [...this.readings, ...newReadings];
|
||||||
this.onReadings?.([reading]);
|
this.onReadings?.(newReadings);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -56,27 +56,27 @@ export const XiaomiBandAdapter: DeviceAdapter = {
|
|||||||
_serviceUUID: string,
|
_serviceUUID: string,
|
||||||
charUUID: string,
|
charUUID: string,
|
||||||
data: ArrayBuffer,
|
data: ArrayBuffer,
|
||||||
): NormalizedReading | null {
|
): NormalizedReading[] {
|
||||||
if (charUUID.toUpperCase().includes('2A37')) {
|
if (charUUID.toUpperCase().includes('2A37')) {
|
||||||
const hr = parseHeartRate(data);
|
const hr = parseHeartRate(data);
|
||||||
if (hr !== null && hr > 0 && hr < 300) {
|
if (hr !== null && hr > 0 && hr < 300) {
|
||||||
return {
|
return [{
|
||||||
device_type: 'heart_rate',
|
device_type: 'heart_rate',
|
||||||
values: { heart_rate: hr },
|
values: { heart_rate: hr },
|
||||||
measured_at: new Date().toISOString(),
|
measured_at: new Date().toISOString(),
|
||||||
};
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
parseReadResponse(
|
parseReadResponse(
|
||||||
_serviceUUID: string,
|
_serviceUUID: string,
|
||||||
_charUUID: string,
|
_charUUID: string,
|
||||||
_data: ArrayBuffer,
|
_data: ArrayBuffer,
|
||||||
): NormalizedReading | null {
|
): NormalizedReading[] {
|
||||||
// 读取模式暂不支持,使用通知模式获取数据
|
// 读取模式暂不支持,使用通知模式获取数据
|
||||||
return null;
|
return [];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,16 @@ export type DeviceType =
|
|||||||
| 'steps'
|
| 'steps'
|
||||||
| 'sleep'
|
| 'sleep'
|
||||||
| 'temperature'
|
| 'temperature'
|
||||||
| 'stress';
|
| 'stress'
|
||||||
|
| 'blood_pressure'
|
||||||
|
| 'blood_glucose';
|
||||||
|
|
||||||
/** 标准化的设备读数 */
|
/** 标准化的设备读数 */
|
||||||
export interface NormalizedReading {
|
export interface NormalizedReading {
|
||||||
device_type: DeviceType;
|
device_type: DeviceType;
|
||||||
values: Record<string, number>;
|
values: Record<string, number | string>;
|
||||||
|
/** 多指标设备的具体指标(如 systolic/diastolic) */
|
||||||
|
metric?: string;
|
||||||
measured_at: string;
|
measured_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,14 +42,14 @@ export interface DeviceAdapter {
|
|||||||
serviceUUID: string,
|
serviceUUID: string,
|
||||||
charUUID: string,
|
charUUID: string,
|
||||||
data: ArrayBuffer,
|
data: ArrayBuffer,
|
||||||
): NormalizedReading | null;
|
): NormalizedReading[];
|
||||||
|
|
||||||
/** 解析 BLE 读取数据为标准读数 */
|
/** 解析 BLE 读取数据为标准读数 */
|
||||||
parseReadResponse(
|
parseReadResponse(
|
||||||
serviceUUID: string,
|
serviceUUID: string,
|
||||||
charUUID: string,
|
charUUID: string,
|
||||||
data: ArrayBuffer,
|
data: ArrayBuffer,
|
||||||
): NormalizedReading | null;
|
): NormalizedReading[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 扫描发现的 BLE 设备 */
|
/** 扫描发现的 BLE 设备 */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
reportCompressedSize: false,
|
reportCompressedSize: false,
|
||||||
chunkSizeWarningLimit: 600,
|
chunkSizeWarningLimit: 500,
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: [
|
include: [
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ pub struct Model {
|
|||||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||||
pub device_id: Option<String>,
|
pub device_id: Option<String>,
|
||||||
pub device_type: String,
|
pub device_type: String,
|
||||||
|
#[sea_orm(nullable)]
|
||||||
|
pub metric: Option<String>,
|
||||||
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
#[sea_orm(skip_serializing_if = "Option::is_none")]
|
||||||
pub device_model: Option<String>,
|
pub device_model: Option<String>,
|
||||||
pub raw_value: serde_json::Value,
|
pub raw_value: serde_json::Value,
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ async fn batch_insert_readings(
|
|||||||
patient_id: Set(patient_id),
|
patient_id: Set(patient_id),
|
||||||
device_id: Set(Some(device_id.to_string())),
|
device_id: Set(Some(device_id.to_string())),
|
||||||
device_type: Set(r.device_type.clone()),
|
device_type: Set(r.device_type.clone()),
|
||||||
|
metric: Set(r.values.get("metric").and_then(|v| v.as_str()).map(String::from)),
|
||||||
device_model: Set(device_model.map(String::from)),
|
device_model: Set(device_model.map(String::from)),
|
||||||
raw_value: Set(r.values.clone()),
|
raw_value: Set(r.values.clone()),
|
||||||
measured_at: Set(*measured_at),
|
measured_at: Set(*measured_at),
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ mod m20260428_000088_rls_policy_strict;
|
|||||||
mod m20260428_000089_blind_indexes;
|
mod m20260428_000089_blind_indexes;
|
||||||
mod m20260428_000090_critical_alerts;
|
mod m20260428_000090_critical_alerts;
|
||||||
mod m20260428_000091_dead_letter_events;
|
mod m20260428_000091_dead_letter_events;
|
||||||
|
mod m20260429_000092_device_readings_metric;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@@ -189,6 +190,7 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20260428_000089_blind_indexes::Migration),
|
Box::new(m20260428_000089_blind_indexes::Migration),
|
||||||
Box::new(m20260428_000090_critical_alerts::Migration),
|
Box::new(m20260428_000090_critical_alerts::Migration),
|
||||||
Box::new(m20260428_000091_dead_letter_events::Migration),
|
Box::new(m20260428_000091_dead_letter_events::Migration),
|
||||||
|
Box::new(m20260429_000092_device_readings_metric::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(Alias::new("device_readings"))
|
||||||
|
.add_column(ColumnDef::new(Alias::new("metric")).string().null())
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
manager
|
||||||
|
.create_index(
|
||||||
|
Index::create()
|
||||||
|
.name("idx_dr_metric")
|
||||||
|
.table(Alias::new("device_readings"))
|
||||||
|
.col(Alias::new("tenant_id"))
|
||||||
|
.col(Alias::new("patient_id"))
|
||||||
|
.col(Alias::new("metric"))
|
||||||
|
.col(Alias::new("measured_at"))
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_index(Index::drop().name("idx_dr_metric").to_owned())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(Alias::new("device_readings"))
|
||||||
|
.drop_column(Alias::new("metric"))
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user