78 lines
3.1 KiB
Dart
78 lines
3.1 KiB
Dart
import 'dart:convert';
|
|
|
|
class DoseRecord {
|
|
final String id;
|
|
final DateTime startTime;
|
|
final DateTime endTime;
|
|
final int flixotidePuffs; // 辅舒酮喷数
|
|
final int ventolinPuffs; // 万托林喷数
|
|
final String? flixotideBottleId; // 关联的辅舒酮药瓶 UUID
|
|
final String? ventolinBottleId; // 关联的万托林药瓶 UUID
|
|
final bool rinsedMouth; // 是否漱口
|
|
final bool washedFace; // 是否洗脸
|
|
final bool isPrime; // 是否为试喷扣除
|
|
final bool isDeleted; // 软删除墓碑标记
|
|
final String? note;
|
|
final DateTime updatedAt; // UTC 更新时间
|
|
|
|
DoseRecord({
|
|
required this.id,
|
|
required this.startTime,
|
|
required this.endTime,
|
|
this.flixotidePuffs = 0,
|
|
this.ventolinPuffs = 0,
|
|
this.flixotideBottleId,
|
|
this.ventolinBottleId,
|
|
this.rinsedMouth = true,
|
|
this.washedFace = true,
|
|
this.isPrime = false,
|
|
this.isDeleted = false,
|
|
this.note,
|
|
DateTime? updatedAt,
|
|
}) : updatedAt = updatedAt ?? DateTime.now().toUtc();
|
|
|
|
Duration get duration => endTime.difference(startTime);
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'startTime': startTime.toUtc().toIso8601String(),
|
|
'endTime': endTime.toUtc().toIso8601String(),
|
|
'flixotidePuffs': flixotidePuffs,
|
|
'ventolinPuffs': ventolinPuffs,
|
|
'flixotideBottleId': flixotideBottleId,
|
|
'ventolinBottleId': ventolinBottleId,
|
|
'rinsedMouth': rinsedMouth,
|
|
'washedFace': washedFace,
|
|
'isPrime': isPrime,
|
|
'isDeleted': isDeleted,
|
|
'note': note,
|
|
'updatedAt': updatedAt.toUtc().toIso8601String(),
|
|
};
|
|
}
|
|
|
|
factory DoseRecord.fromMap(Map<String, dynamic> map) {
|
|
return DoseRecord(
|
|
id: map['id'] as String,
|
|
startTime: DateTime.parse(map['startTime'] as String? ?? (map['start_time'] as String)).toUtc(),
|
|
endTime: DateTime.parse(map['endTime'] as String? ?? (map['end_time'] as String)).toUtc(),
|
|
flixotidePuffs: map['flixotidePuffs'] as int? ?? (map['flixotide_puffs'] as int? ?? 0),
|
|
ventolinPuffs: map['ventolinPuffs'] as int? ?? (map['ventolin_puffs'] as int? ?? 0),
|
|
flixotideBottleId: map['flixotideBottleId'] as String? ?? (map['flixotide_bottle_id'] as String?),
|
|
ventolinBottleId: map['ventolinBottleId'] as String? ?? (map['ventolin_bottle_id'] as String?),
|
|
rinsedMouth: map['rinsedMouth'] as bool? ?? ((map['rinsed_mouth'] as int? ?? 1) == 1),
|
|
washedFace: map['washedFace'] as bool? ?? ((map['washed_face'] as int? ?? 1) == 1),
|
|
isPrime: map['isPrime'] as bool? ?? ((map['is_prime'] as int? ?? 0) == 1),
|
|
isDeleted: map['isDeleted'] as bool? ?? ((map['is_deleted'] as int? ?? 0) == 1),
|
|
note: map['note'] as String?,
|
|
updatedAt: map['updatedAt'] != null
|
|
? DateTime.parse(map['updatedAt'] as String).toUtc()
|
|
: (map['updated_at'] != null ? DateTime.parse(map['updated_at'] as String).toUtc() : DateTime.now().toUtc()),
|
|
);
|
|
}
|
|
|
|
String toJson() => json.encode(toMap());
|
|
factory DoseRecord.fromJson(String source) =>
|
|
DoseRecord.fromMap(json.decode(source) as Map<String, dynamic>);
|
|
}
|