72 lines
2.3 KiB
Dart
72 lines
2.3 KiB
Dart
import 'dart:convert';
|
|
|
|
class Canister {
|
|
final String id;
|
|
String name; // e.g. "辅舒酮 (丙酸氟替卡松)"
|
|
final int totalDoses; // e.g. 60
|
|
int remainingDoses; // e.g. 42
|
|
DateTime openedAt; // 开瓶日期
|
|
bool isEnabled; // 是否在当前方案中启用
|
|
int puffsPerSession; // 每次常规吸几喷 (默认 2)
|
|
int inhalationSeconds; // 单喷雾化吸入时长 (默认 15秒)
|
|
final bool isSteroid; // 是否为激素(需提醒漱口洗脸)
|
|
int sortOrder; // 用药先后顺序 (如舒张剂在前排1,激素在后排2)
|
|
String? note;
|
|
|
|
Canister({
|
|
required this.id,
|
|
required this.name,
|
|
required this.totalDoses,
|
|
required this.remainingDoses,
|
|
required this.openedAt,
|
|
this.isEnabled = true,
|
|
this.puffsPerSession = 2,
|
|
this.inhalationSeconds = 15,
|
|
this.isSteroid = true,
|
|
this.sortOrder = 1,
|
|
this.note,
|
|
});
|
|
|
|
bool get isLowDose => remainingDoses <= 10;
|
|
bool get isDepleted => remainingDoses <= 0;
|
|
|
|
double get percentRemaining =>
|
|
totalDoses > 0 ? (remainingDoses / totalDoses).clamp(0.0, 1.0) : 0.0;
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'totalDoses': totalDoses,
|
|
'remainingDoses': remainingDoses,
|
|
'openedAt': openedAt.toIso8601String(),
|
|
'isEnabled': isEnabled,
|
|
'puffsPerSession': puffsPerSession,
|
|
'inhalationSeconds': inhalationSeconds,
|
|
'isSteroid': isSteroid,
|
|
'sortOrder': sortOrder,
|
|
'note': note,
|
|
};
|
|
}
|
|
|
|
factory Canister.fromMap(Map<String, dynamic> map) {
|
|
return Canister(
|
|
id: map['id'] as String,
|
|
name: map['name'] as String,
|
|
totalDoses: map['totalDoses'] as int,
|
|
remainingDoses: map['remainingDoses'] as int,
|
|
openedAt: DateTime.parse(map['openedAt'] as String),
|
|
isEnabled: map['isEnabled'] as bool? ?? true,
|
|
puffsPerSession: map['puffsPerSession'] as int? ?? 2,
|
|
inhalationSeconds: map['inhalationSeconds'] as int? ?? 15,
|
|
isSteroid: map['isSteroid'] as bool? ?? true,
|
|
sortOrder: map['sortOrder'] as int? ?? 1,
|
|
note: map['note'] as String?,
|
|
);
|
|
}
|
|
|
|
String toJson() => json.encode(toMap());
|
|
factory Canister.fromJson(String source) =>
|
|
Canister.fromMap(json.decode(source) as Map<String, dynamic>);
|
|
}
|