Commit 71a2194

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-03-16 10:24:39
implement medicine type
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 34f3401
Changed files (5)
health_data_store/lib/src/types/medicine.dart
@@ -0,0 +1,19 @@
+import 'package:freezed_annotation/freezed_annotation.dart';
+
+part 'medicine.freezed.dart';
+
+/// Description of a medicine.
+@freezed
+class Medicine with _$Medicine {
+  /// Create a medicine description.
+  const factory Medicine({
+    /// Name of the medicine.
+    required String designation,
+    /// Additional data associated with this medicine.
+    ///
+    /// For example serialized colors or tags.
+    String? data,
+    /// Default dosis of medication.
+    int? dosis,
+  }) = _Medicine;
+}
health_data_store/lib/src/types/medicine_intake.dart
@@ -0,0 +1,22 @@
+
+import 'package:freezed_annotation/freezed_annotation.dart';
+import 'package:health_data_store/src/types/medicine.dart';
+
+part 'medicine_intake.freezed.dart';
+
+/// Instance of a [Medicine] intake.
+@freezed
+class MedicineIntake with _$MedicineIntake {
+  /// Create a instance of a medicine intake.
+  const factory MedicineIntake({
+    /// Timestamp when the medicine was taken.
+    required DateTime time,
+    /// Description of the taken medicine.
+    required Medicine medicine,
+    /// Amount of medicine taken.
+    ///
+    /// When the medication has a default value, this must be set to that value,
+    /// as it may change.
+    required int dosis,
+  }) = _MedicineIntake;
+}
health_data_store/test/src/types/medicine_intake_test.dart
@@ -0,0 +1,15 @@
+import 'package:health_data_store/src/types/medicine.dart';
+import 'package:health_data_store/src/types/medicine_intake.dart';
+import 'package:test/test.dart';
+
+void main() {
+  test('should initialize', () {
+    final intake = MedicineIntake(
+      time: DateTime.now(),
+      medicine: Medicine(designation: 'test', dosis: 42),
+      dosis: 42,
+    );
+    expect(intake.medicine, equals(Medicine(designation: 'test', dosis: 42)));
+    expect(intake.dosis, equals(42));
+  });
+}
health_data_store/test/src/types/medicine_test.dart
@@ -0,0 +1,10 @@
+import 'package:health_data_store/src/types/medicine.dart';
+import 'package:test/test.dart';
+
+void main() {
+  test('should initialize', () {
+    final med = Medicine(designation: 'test', dosis: 42);
+    expect(med.designation, equals('test'));
+    expect(med.dosis, equals(42));
+  });
+}
health_data_store/pubspec.yaml
@@ -8,6 +8,7 @@ environment:
 
 dependencies:
   freezed_annotation: ^2.4.1
+  json_annotation: ^4.8.1
   sqflite_common: ^2.5.3
 
 dev_dependencies:
@@ -16,4 +17,5 @@ dev_dependencies:
   test: ^1.25.2
   build_runner: ^2.4.8
   freezed: ^2.4.7
+  json_serializable: ^6.7.1