Initial commit: 健康管家 AI 健康陪伴助手
- Backend: .NET 10 Minimal API + EF Core + PostgreSQL - Frontend: Flutter + Riverpod + GoRouter + Dio - AI: DeepSeek LLM + Qwen VLM (OpenAI-compatible) - Auth: SMS + JWT (access/refresh tokens) - Features: AI chat, health tracking, medication management, diet analysis, exercise plans, doctor consultations, report analysis
This commit is contained in:
158
health_app/lib/services/health_service.dart
Normal file
158
health_app/lib/services/health_service.dart
Normal file
@@ -0,0 +1,158 @@
|
||||
import '../core/api_client.dart';
|
||||
|
||||
/// 健康数据服务
|
||||
class HealthService {
|
||||
final ApiClient _api;
|
||||
HealthService(this._api);
|
||||
|
||||
/// 获取各指标最新值
|
||||
Future<Map<String, dynamic>> getLatest() async {
|
||||
final res = await _api.get('/api/health-records/latest');
|
||||
return res.data['data'] ?? {};
|
||||
}
|
||||
|
||||
/// 获取趋势数据
|
||||
Future<List<Map<String, dynamic>>> getTrend(String type, {int period = 7}) async {
|
||||
final res = await _api.get('/api/health-records/trend', queryParameters: {'type': type, 'period': period});
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
/// 获取记录列表
|
||||
Future<List<Map<String, dynamic>>> getRecords({String? type, int? days}) async {
|
||||
final params = <String, dynamic>{};
|
||||
if (type != null) params['type'] = type;
|
||||
if (days != null) params['days'] = days;
|
||||
final res = await _api.get('/api/health-records', queryParameters: params);
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
}
|
||||
|
||||
/// 用户服务
|
||||
class UserService {
|
||||
final ApiClient _api;
|
||||
UserService(this._api);
|
||||
|
||||
Future<Map<String, dynamic>?> getProfile() async {
|
||||
final res = await _api.get('/api/user/profile');
|
||||
return res.data['data'];
|
||||
}
|
||||
|
||||
Future<void> updateProfile({String? name, String? gender, String? birthDate}) async {
|
||||
await _api.put('/api/user/profile', data: {'name': name, 'gender': gender, 'birthDate': birthDate});
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getHealthArchive() async {
|
||||
final res = await _api.get('/api/user/health-archive');
|
||||
return res.data['data'];
|
||||
}
|
||||
|
||||
Future<void> updateHealthArchive(Map<String, dynamic> data) async {
|
||||
await _api.put('/api/user/health-archive', data: data);
|
||||
}
|
||||
|
||||
Future<void> deleteAccount() async {
|
||||
await _api.delete('/api/user/account');
|
||||
}
|
||||
}
|
||||
|
||||
/// 用药服务
|
||||
class MedicationService {
|
||||
final ApiClient _api;
|
||||
MedicationService(this._api);
|
||||
|
||||
Future<List<Map<String, dynamic>>> getList() async {
|
||||
final res = await _api.get('/api/medications');
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<void> create(Map<String, dynamic> data) async {
|
||||
await _api.post('/api/medications', data: data);
|
||||
}
|
||||
|
||||
Future<void> update(String id, Map<String, dynamic> data) async {
|
||||
await _api.put('/api/medications/$id', data: data);
|
||||
}
|
||||
|
||||
Future<void> delete(String id) async {
|
||||
await _api.delete('/api/medications/$id');
|
||||
}
|
||||
|
||||
Future<void> confirm(String id) async {
|
||||
await _api.post('/api/medications/$id/confirm');
|
||||
}
|
||||
}
|
||||
|
||||
/// 饮食服务
|
||||
class DietService {
|
||||
final ApiClient _api;
|
||||
DietService(this._api);
|
||||
|
||||
Future<List<Map<String, dynamic>>> getRecords({String? date, String? mealType}) async {
|
||||
final params = <String, dynamic>{};
|
||||
if (date != null) params['date'] = date;
|
||||
if (mealType != null) params['mealType'] = mealType;
|
||||
final res = await _api.get('/api/diet-records', queryParameters: params);
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<void> create(Map<String, dynamic> data) async {
|
||||
await _api.post('/api/diet-records', data: data);
|
||||
}
|
||||
}
|
||||
|
||||
/// 问诊服务
|
||||
class ConsultationService {
|
||||
final ApiClient _api;
|
||||
ConsultationService(this._api);
|
||||
|
||||
Future<List<Map<String, dynamic>>> getDoctors() async {
|
||||
final res = await _api.get('/doctors');
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getQuota() async {
|
||||
final res = await _api.get('/user/consultation-quota');
|
||||
return res.data['data'] ?? {};
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> createConsultation(String doctorId) async {
|
||||
final res = await _api.post('/consultations', data: {'doctorId': doctorId});
|
||||
return res.data['data'];
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getMessages(String consultationId, {String? after}) async {
|
||||
final params = <String, dynamic>{};
|
||||
if (after != null) params['after'] = after;
|
||||
final res = await _api.get('/consultations/$consultationId/messages', queryParameters: params);
|
||||
final list = res.data['data'] as List? ?? [];
|
||||
return list.cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<void> sendMessage(String consultationId, String content) async {
|
||||
await _api.post('/consultations/$consultationId/messages', data: {'content': content});
|
||||
}
|
||||
}
|
||||
|
||||
/// 运动服务
|
||||
class ExerciseService {
|
||||
final ApiClient _api;
|
||||
ExerciseService(this._api);
|
||||
|
||||
Future<Map<String, dynamic>?> getCurrentPlan() async {
|
||||
final res = await _api.get('/exercise-plans/current');
|
||||
return res.data['data'];
|
||||
}
|
||||
|
||||
Future<void> createPlan(Map<String, dynamic> data) async {
|
||||
await _api.post('/exercise-plans', data: data);
|
||||
}
|
||||
|
||||
Future<void> checkIn(String itemId) async {
|
||||
await _api.post('/exercise-plans/items/$itemId/checkin');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user