Commit 7183d7a
Changed files (6)
health_data_store
health_data_store/lib/src/repositories/blood_pressure_repository_impl.dart
@@ -114,7 +114,6 @@ class BloodPressureRepositoryImpl extends BloodPressureRepository {
if (value.pul != null)
await txn.delete('Pulse', where: 'entryID = ?', whereArgs: [entryID]);
});
- // TODO: implement central cleanup of unused timestamp entries (by no table)
}
}
health_data_store/lib/src/repositories/medicine_intake_repository_impl.dart
@@ -55,12 +55,11 @@ class MedicineIntakeRepositoryImpl extends MedicineIntakeRepository {
@override
Future<List<MedicineIntake>> get(DateRange range) async {
- // TODO: change left join to join
final results = await _db.rawQuery(
'SELECT t.timestampUnixS, dosis, defaultDose, designation, color '
'FROM Timestamps AS t '
- 'LEFT JOIN Intake AS i ON t.entryID = i.entryID '
- 'LEFT JOIN Medicine AS m ON m.medID = i.medID '
+ 'JOIN Intake AS i ON t.entryID = i.entryID '
+ 'JOIN Medicine AS m ON m.medID = i.medID '
'WHERE t.timestampUnixS BETWEEN ? AND ?'
'AND i.dosis IS NOT NULL', // deleted intakes
[range.startStamp, range.endStamp]
health_data_store/lib/src/repositories/medicine_repository_impl.dart
@@ -47,12 +47,17 @@ class MedicineRepositoryImpl extends MedicineRepository {
Future<void> remove(Medicine value) => _db.update('Medicine', {
'removed': 1,
},
- where: 'designation = ? AND color = ? AND defaultDose = ?',
+ where: 'designation = ? AND color '
+ + (value.color == null ? 'IS NULL' : '= ?')
+ + ' AND defaultDose '
+ + (value.dosis == null ? 'IS NULL' : '= ?'),
whereArgs: [
value.designation,
- value.color,
- value.dosis,
- ], // TODO: test for null values
+ if (value.color != null)
+ value.color,
+ if (value.dosis != null)
+ value.dosis,
+ ],
);
}
health_data_store/lib/src/database_manager.dart
@@ -47,7 +47,6 @@ class DatabaseManager {
Database get db => _db.database;
Future<void> _setUpTables() async {
- // TODO: IF NOT EXISTS ?
await _db.execute('CREATE TABLE "Medicine" ('
'"medID" INTEGER NOT NULL UNIQUE,'
'"designation" TEXT NOT NULL,'
@@ -59,7 +58,7 @@ class DatabaseManager {
await _db.execute('CREATE TABLE "Timestamps" ('
'"entryID" INTEGER NOT NULL UNIQUE,'
'"timestampUnixS" INTEGER NOT NULL,'
- 'PRIMARY KEY("entryID")' // TODO: add timezone to determine time of day
+ 'PRIMARY KEY("entryID")'
');');
await _db.execute('CREATE TABLE "Intake" ('
'"entryID" INTEGER NOT NULL,'
@@ -93,6 +92,7 @@ class DatabaseManager {
/// Closes the database.
Future<void> close() => _db.close();
- // TODO: perform cleanup of medicines that are marked as deleted and have no
- // intakes referencing them.
+ // TODO: perform cleanup of:
+ // - medicines that are marked as deleted and have no referencing intakes
+ // - cleanup of timestamp entries used in no table
}
health_data_store/lib/src/health_data_store.dart
@@ -44,6 +44,4 @@ class HealthDataStore {
/// Repository for intakes.
MedicineIntakeRepository get intakeRepo =>
MedicineIntakeRepositoryImpl(_dbMngr.db);
-
- // TODO: test
}
health_data_store/test/src/repositories/medicine_repository_test.dart
@@ -73,5 +73,21 @@ void main() {
await repo.remove(med1);
expect(await repo.getAll(), hasLength(1));
});
+ test('should mark partial medicines as deleted', () async {
+ final db = await mockDBManager();
+ addTearDown(db.close);
+ final repo = MedicineRepositoryImpl(db.db);
+ final med1 = Medicine(designation: 'med1', color: 0xFF226A,);
+ await repo.add(med1);
+ final med2 = Medicine(designation: 'med2', dosis: 43);
+ await repo.add(med2);
+ final med3 = Medicine(designation: 'med3',);
+ await repo.add(med3);
+ expect(await repo.getAll(), hasLength(3));
+ await repo.remove(med1);
+ await repo.remove(med2);
+ await repo.remove(med3);
+ expect(await repo.getAll(), isEmpty);
+ });
}