You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/device/device_transfer_info.dart

79 lines
2.3 KiB
Dart

3 years ago
import '../department.dart';
import '../hospital.dart';
import '../lookup.dart';
3 years ago
3 years ago
class DeviceTransferInfo {
String? userId;
String? comment;
Hospital? client;
Department? department;
String? workingHours;
String? travelingHours;
String? name;
String? signature;
Lookup? status;
3 years ago
DeviceTransferInfo({
this.userId,
this.comment,
this.department,
this.client,
this.name,
this.travelingHours,
this.workingHours,
this.signature,
this.status,
});
3 years ago
Map<String, String> toJson(bool isSender) {
Map<String, String> body = {};
3 years ago
final baseKey = isSender ? "sender_" : "receiver_";
3 years ago
if (comment?.isNotEmpty ?? false) body["${baseKey}comment"] = comment!;
if (workingHours?.isNotEmpty ?? false) {
body["${baseKey}working_hours"] = workingHours!;
}
if (travelingHours?.isNotEmpty ?? false) {
body["${baseKey}travel_hours"] = comment!;
}
final status = this.status;
if (status != null) body["${baseKey}status"] = status.id.toString();
if (signature?.isNotEmpty ?? false) body["${baseKey}image"] = signature!;
3 years ago
return body;
}
3 years ago
bool validate() {
if (client == null) return false;
if (department == null) return false;
3 years ago
return true;
}
fromDetails(DeviceTransferInfo? old, {bool withSignature = true}) {
userId = old?.userId;
name = old?.name;
client = old?.client != null ? Hospital.fromHospital(old?.client) : null;
3 years ago
department =
department != null ? Department.fromDepartment(old?.department!) : null;
workingHours = old?.workingHours;
travelingHours = old?.travelingHours;
comment = old?.comment;
if (withSignature) signature = old?.signature;
status = old?.status;
3 years ago
}
3 years ago
factory DeviceTransferInfo.fromJson(
Map<String, dynamic> parsedJson, String key) {
3 years ago
return DeviceTransferInfo(
workingHours: parsedJson["${key}working_hours"],
travelingHours: parsedJson["${key}travel_hours"],
name: parsedJson["${key}name"],
signature: parsedJson["${key}image"],
userId: parsedJson["${key}id"],
comment: parsedJson["${key}comment"],
client: Hospital.fromJson(parsedJson["${key}client"]),
department: Department.fromJson(parsedJson["${key}department"]),
3 years ago
status: Lookup.fromJson(parsedJson["${key}status"]),
3 years ago
);
}
}