This repository has been archived on 2024-10-18. You can view files and clone it, but cannot push or open issues or pull requests.
ftc_patient_app/lib/models/user_model.dart

224 lines
6.7 KiB
Dart

class UserModel {
FcmTokenModel fcmTokens = FcmTokenModel.empty();
LocationModel locationModel = LocationModel.empty();
String id = "";
String userModelName = "";
String name = "";
String version = "" ;
String email = "" ;
String phoneNumber = "";
bool active = false;
String role = "" ;
String profilePictureUrl = "" ;
String deviceId = "" ;
String verificationCode = "" ;
bool isVerified = false;
bool approved = false;
bool blocked = false;
String createdAt = "" ;
String updatedAt = "" ;
int v = -1;
String password = "" ;
UserSettingsModel userSettingsModel = UserSettingsModel.empty();
bool newUser = false;
//old fields for UI
String profilePicture = "";
String homeAddress = "";
String nextOfKin = "";
String diagnosisHistory = "";
String diagnosisDate = "";
String aboutPatient = "";
UserModel.empty();
UserModel({
required this.name,
required this.profilePicture,
required this.phoneNumber,
required this.homeAddress,
required this.nextOfKin,
required this.diagnosisHistory,
required this.diagnosisDate,
required this.aboutPatient,
this.role ="",
});
@override
String toString() {
return 'UserModel{fcmTokens: $fcmTokens, locationModel: $locationModel, id: $id, userModelName: $userModelName, name: $name, version: $version, email: $email, phoneNumber: $phoneNumber, active: $active, role: $role, profilePictureUrl: $profilePictureUrl, deviceId: $deviceId, verificationCode: $verificationCode, isVerified: $isVerified, approved: $approved, blocked: $blocked, createdAt: $createdAt, updatedAt: $updatedAt, v: $v, password: $password, userSettingsModel: $userSettingsModel, newUser: $newUser, profilePicture: $profilePicture, homeAddress: $homeAddress, nextOfKin: $nextOfKin, diagnosisHistory: $diagnosisHistory, diagnosisDate: $diagnosisDate, aboutPatient: $aboutPatient}';
}
UserModel.fromJson(Map<String,dynamic> json){
fcmTokens = FcmTokenModel.fromJson(json['fcm_tokens']??"");
locationModel = LocationModel.fromJson(json['location']??"");
id = json["_id"]??"";
userModelName = json["userModelName"]??"";
name = json["name"]??"";
version = json["version"]??'';
email = json["email"]??'';
phoneNumber = json["phoneNumber"]??'';
active = json["active"]??false;
role = json["role"]??'';
profilePictureUrl = json["profile_picture_url"]??'';
deviceId = json["deviceId"]??'';
verificationCode = json["verification_code"]??'';
isVerified = json["is_verified"]??false;
approved = json["approved"]??false;
blocked = json["blocked"]??false;
createdAt = json["createdAt"]??'';
updatedAt = json["updatedAt"]??'';
v = json["__v"]??-1;
password = json["password"]??'';
userSettingsModel = UserSettingsModel.fromJson(json["userSettings"]??"");
newUser = json['new_user'];
}
Map<String,dynamic> toJson(){
Map<String,dynamic> json = {};
json['fcm_tokens'] = fcmTokens.toJson();
json['location'] = locationModel.toJson();
json["_id"] = id;
json["userModelName"] = userModelName;
json["name"] = name;
json["version"] = version;
json["email"] = email;
json["phoneNumber"] = phoneNumber;
json["active"] = active;
json["role"] = role;
json["profile_picture_url"] = profilePictureUrl;
json["deviceId"] = deviceId;
json["verification_code"] = verificationCode;
json["is_verified"] = isVerified ;
json["approved"] = approved ;
json["blocked"] = blocked ;
json["createdAt"] = createdAt;
json["updatedAt"] = updatedAt;
json["__v"] = v;
json["password"] = password;
json["userSettings"] = userSettingsModel.toJson();
json['new_user'] = newUser;
return json;
}
}
class FcmTokenModel{
String token = "";
String deviceType = "";
FcmTokenModel.empty();
FcmTokenModel.fromJson(Map<String,dynamic> json){
token = json["token"] ?? "";
deviceType = json["deviceType"] ?? "";
}
Map<String,dynamic> toJson(){
Map<String,dynamic> json = {};
json["token"] = token ;
json["deviceType"] = deviceType ;
return json;
}
@override
String toString() {
return 'FcmTokenModel{token: $token, deviceType: $deviceType}';
}
}
class LocationModel{
String type = "";
List coordinates = [];
LocationModel.empty();
LocationModel.fromJson(Map<String,dynamic> json){
type = json["type"]??"";
coordinates = json["coordinates"]??[];
}
double getLatitude(){return coordinates.first;}
double getLongitude(){return coordinates.last;}
Map<String,dynamic> toJson(){
Map<String,dynamic> json = {};
json["type"] = type ;
json["coordinates"] = coordinates ;
return json;
}
@override
String toString() {
return 'LocationModel{type: $type, coordinates: $coordinates}';
}
}
class UserSettingsModel{
String id = "";
String user = "";
bool active = false;
String createdAt = "";
String updatedAt = "";
String v = "";
NotificationSettings notificationSettings = NotificationSettings.empty();
UserSettingsModel.empty();
UserSettingsModel.fromJson(Map<String,dynamic> json){
id = json["id"]??"";
user = json["user"]??"";
active = json["active"]??false;
createdAt = json["createdAt"]??"";
updatedAt = json["updatedAt"]??"";
v = json["v"]??"";
notificationSettings =
NotificationSettings.fromJson(json["notificationSettings"] ?? {"": ""});
}
Map<String,dynamic> toJson(){
Map<String,dynamic> json = {};
json["id"] = id;
json["user"] = user;
json["active"] = active;
json["createdAt"] = createdAt;
json["updatedAt"] = updatedAt;
json["v"] = v;
return json;
}
@override
String toString() {
return 'UserSettingsModel{id: $id, user: $user, active: $active, createdAt: $createdAt, updatedAt: $updatedAt, v: $v, notificationSettings: $notificationSettings}';
}
}
class NotificationSettings{
bool showActive = false;
bool pauseNotification = false;
String pauseDuration = "";
String durationUnit = "";
NotificationSettings.empty();
NotificationSettings.fromJson(Map<String,dynamic> json){
showActive = json["showActive"]??false;
pauseNotification = json["pauseNotification"]??false;
pauseDuration = json["pauseDuration"]??"";
durationUnit = json["durationUnit"]??"";
}
Map<String,dynamic> toJson(){
Map<String,dynamic> json = {};
json["showActive"] = showActive;
json["pauseNotification"] = pauseNotification;
json["pauseDuration"] = pauseDuration;
json["durationUnit"] = durationUnit;
return json;
}
@override
String toString() {
return 'NotificationSettings{showActive: $showActive, pauseNotification: $pauseNotification, pauseDuration: $pauseDuration, durationUnit: $durationUnit}';
}
}