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.
77 lines
2.5 KiB
Dart
77 lines
2.5 KiB
Dart
import '../department.dart';
|
|
import '../hospital.dart';
|
|
import '../lookup.dart';
|
|
|
|
class DeviceTransferInfo {
|
|
int? userId;
|
|
String? comment;
|
|
Hospital? client;
|
|
Department? department;
|
|
String? workingHours;
|
|
String? travelingHours;
|
|
String? name;
|
|
String? signature;
|
|
Lookup? status;
|
|
|
|
DeviceTransferInfo({
|
|
this.userId,
|
|
this.comment,
|
|
this.department,
|
|
this.client,
|
|
this.name,
|
|
this.travelingHours,
|
|
this.workingHours,
|
|
this.signature,
|
|
this.status,
|
|
});
|
|
|
|
Map<String, String> toJson(bool isSender) {
|
|
Map<String, String> body = {};
|
|
final baseKey = isSender ? "sender" : "receiver";
|
|
|
|
if (comment?.isNotEmpty ?? false) body["${baseKey}Comment"] = comment!;
|
|
if (workingHours?.isNotEmpty ?? false) {
|
|
body["${baseKey}WorkingHours"] = workingHours!;
|
|
}
|
|
if (travelingHours?.isNotEmpty ?? false) {
|
|
body["${baseKey}TravelingHours"] = travelingHours!;
|
|
}
|
|
final status = this.status;
|
|
if (status != null) body["${baseKey}MachineStatusId"] = status.id.toString();
|
|
if (signature?.isNotEmpty ?? false) body["${baseKey}AttachmentUrl"] = signature!;
|
|
return body;
|
|
}
|
|
|
|
bool validate() {
|
|
if (client == null) return false;
|
|
if (department == null) return false;
|
|
return true;
|
|
}
|
|
|
|
fromDetails(DeviceTransferInfo? old, {bool withSignature = true}) {
|
|
userId = old?.userId;
|
|
name = old?.name;
|
|
client = old?.client != null ? Hospital.fromHospital(old?.client) : null;
|
|
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;
|
|
}
|
|
|
|
factory DeviceTransferInfo.fromJson(Map<String, dynamic> parsedJson, String key) {
|
|
return DeviceTransferInfo(
|
|
workingHours: parsedJson["${key}WorkingHours"],
|
|
travelingHours: parsedJson["${key}TravelingHours"],
|
|
name: parsedJson["${key}SiteName"],
|
|
signature: parsedJson["${key}AttachmentUrl"],
|
|
userId: parsedJson["${key}SiteId"],
|
|
comment: parsedJson["${key}Comment"],
|
|
client: Hospital(id: parsedJson["${key}senderAssignedEmployeeId"], name: parsedJson["${key}senderAssignedEmployeeName"]),
|
|
department: Department(id: parsedJson["${key}DepartmentId"], name: parsedJson["${key}DepartmentName"]),
|
|
status: Lookup(id: parsedJson["${key}senderMachineStatusId"], label: parsedJson["${key}senderMachineStatusName"]),
|
|
);
|
|
}
|
|
}
|