|
|
|
|
@ -18,6 +18,7 @@ import 'package:hmg_patient_app_new/routes/app_routes.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/cache_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/navigation_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/services/notification_service.dart';
|
|
|
|
|
import 'package:hmg_patient_app_new/theme/colors.dart';
|
|
|
|
|
|
|
|
|
|
class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
WaterMonitorRepo waterMonitorRepo;
|
|
|
|
|
@ -277,7 +278,7 @@ class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> fetchUserDetailsForMonitoring() async {
|
|
|
|
|
Future<void> fetchUserDetailsForMonitoring({Function(dynamic)? onSuccess, Function(String)? onError}) async {
|
|
|
|
|
try {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
|
|
|
|
|
@ -287,14 +288,21 @@ class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
if (authenticated == null) {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (onError != null) onError('User not authenticated');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final mobile = (authenticated.mobileNumber ?? '').replaceAll('+', '');
|
|
|
|
|
final identification = authenticated.patientIdentificationNo ?? '';
|
|
|
|
|
|
|
|
|
|
final result = await waterMonitorRepo.getUserDetailsForWaterMonitoring(progress: 1, mobileNumber: mobile, identificationNo: identification);
|
|
|
|
|
final result = await waterMonitorRepo.getUserDetailsForWaterMonitoring(
|
|
|
|
|
progress: 1,
|
|
|
|
|
mobileNumber: mobile,
|
|
|
|
|
identificationNo: identification,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
result.fold((failure) {
|
|
|
|
|
_userDetailData = null;
|
|
|
|
|
if (onError != null) onError(failure.message);
|
|
|
|
|
}, (apiModel) {
|
|
|
|
|
_userDetailData = apiModel.data;
|
|
|
|
|
|
|
|
|
|
@ -302,9 +310,12 @@ class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
if (_userDetailData != null) {
|
|
|
|
|
_populateFormFields(_userDetailData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (onSuccess != null) onSuccess(_userDetailData);
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
_userDetailData = null;
|
|
|
|
|
if (onError != null) onError(e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
@ -424,6 +435,48 @@ class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Populate form fields from authenticated user data (for new users)
|
|
|
|
|
void populateFromAuthenticatedUser() {
|
|
|
|
|
try {
|
|
|
|
|
final authenticated = _appState.getAuthenticatedUser();
|
|
|
|
|
if (authenticated == null) return;
|
|
|
|
|
|
|
|
|
|
// Name - use firstName if available
|
|
|
|
|
if (authenticated.firstName != null && authenticated.firstName!.isNotEmpty) {
|
|
|
|
|
nameController.text = authenticated.firstName!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gender - map from patient gender
|
|
|
|
|
if (authenticated.gender != null) {
|
|
|
|
|
final gender = (authenticated.gender == 1 ? 'male' : 'female').toLowerCase();
|
|
|
|
|
if (gender.contains('m') || gender == 'male') {
|
|
|
|
|
_selectedGender = 'Male';
|
|
|
|
|
} else if (gender.contains('f') || gender == 'female') {
|
|
|
|
|
_selectedGender = 'Female';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Age - calculate from DOB if available
|
|
|
|
|
if (authenticated.dateofBirth != null && authenticated.dateofBirth!.isNotEmpty) {
|
|
|
|
|
final age = _calculateAgeFromDOB(authenticated.dateofBirth!);
|
|
|
|
|
if (age > 0) {
|
|
|
|
|
ageController.text = age.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set default units and activity level
|
|
|
|
|
_selectedHeightUnit = 'cm';
|
|
|
|
|
_selectedWeightUnit = 'kg';
|
|
|
|
|
_selectedActivityLevel = 'Lightly active';
|
|
|
|
|
_selectedNumberOfReminders = '3 Time';
|
|
|
|
|
|
|
|
|
|
log('Form fields populated from authenticated user: ${authenticated.firstName}');
|
|
|
|
|
notifyListeners();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('Error populating from authenticated user: $e');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset all fields to default
|
|
|
|
|
void resetFields() {
|
|
|
|
|
nameController.clear();
|
|
|
|
|
@ -755,15 +808,15 @@ class WaterMonitorViewModel extends ChangeNotifier {
|
|
|
|
|
final percent = progressPercent;
|
|
|
|
|
|
|
|
|
|
if (percent >= 90) {
|
|
|
|
|
return const Color(0xFF00C853); // Dark Green
|
|
|
|
|
return AppColors.successColor; // Dark Green
|
|
|
|
|
} else if (percent >= 70) {
|
|
|
|
|
return const Color(0xFF4CAF50); // Green
|
|
|
|
|
return AppColors.successColor; // Green
|
|
|
|
|
} else if (percent >= 50) {
|
|
|
|
|
return const Color(0xFFFFC107); // Amber
|
|
|
|
|
return AppColors.warningColorYellow; //orange
|
|
|
|
|
} else if (percent >= 30) {
|
|
|
|
|
return const Color(0xFFFF9800); // Orange
|
|
|
|
|
return AppColors.warningColorYellow; // Orange
|
|
|
|
|
} else {
|
|
|
|
|
return const Color(0xFFF44336); // Red
|
|
|
|
|
return AppColors.errorColor; // Red
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|