Commit 992bf72
Changed files (8)
app
lib
model
screens
subsettings
export_import
test
health_data_store
lib
src
types
app/lib/model/blood_pressure/model.dart
@@ -56,18 +56,18 @@ class BloodPressureModel extends ChangeNotifier {
}
/// Returns all recordings in saved in a range in ascending order
- Future<UnmodifiableListView<BloodPressureRecord>> getInTimeRange(DateTime from, DateTime to) async {
+ Future<UnmodifiableListView<OldBloodPressureRecord>> getInTimeRange(DateTime from, DateTime to) async {
if (!_database.isOpen) return UnmodifiableListView([]);
final dbEntries = await _database.query('bloodPressureModel',
orderBy: 'timestamp DESC',
where: 'timestamp BETWEEN ? AND ?',
whereArgs: [from.millisecondsSinceEpoch, to.millisecondsSinceEpoch],); // descending
- final List<BloodPressureRecord> recordsInRange = _convert(dbEntries);
+ final List<OldBloodPressureRecord> recordsInRange = _convert(dbEntries);
return UnmodifiableListView(recordsInRange);
}
/// Querries all measurements saved in the database.
- Future<UnmodifiableListView<BloodPressureRecord>> get all async {
+ Future<UnmodifiableListView<OldBloodPressureRecord>> get all async {
if (!_database.isOpen) return UnmodifiableListView([]);
return UnmodifiableListView(_convert(await _database.query('bloodPressureModel', columns: ['*'])));
}
@@ -77,12 +77,12 @@ class BloodPressureModel extends ChangeNotifier {
/// Cannot be accessed anymore.
Future<void> close() => _database.close();
- List<BloodPressureRecord> _convert(List<Map<String, Object?>> dbResult) {
- final List<BloodPressureRecord> records = [];
+ List<OldBloodPressureRecord> _convert(List<Map<String, Object?>> dbResult) {
+ final List<OldBloodPressureRecord> records = [];
for (final e in dbResult) {
final needlePinJson = e['needlePin'] as String?;
final needlePin = (needlePinJson != null) ? jsonDecode(needlePinJson) : null;
- records.add(BloodPressureRecord(
+ records.add(OldBloodPressureRecord(
DateTime.fromMillisecondsSinceEpoch(e['timestamp'] as int),
e['systolic'] as int?,
e['diastolic'] as int?,
app/lib/model/blood_pressure/needle_pin.dart
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
@immutable
@Deprecated('only maintained for imports, use health_data_store')
-/// Metadata and secondary information for a [BloodPressureRecord].
+/// Metadata and secondary information for a [OldBloodPressureRecord].
class MeasurementNeedlePin {
/// Create a instance from a map created in older versions.
MeasurementNeedlePin.fromMap(Map<String, dynamic> json)
app/lib/model/blood_pressure/record.dart
@@ -4,9 +4,9 @@ import 'package:flutter/material.dart';
/// Immutable data representation of a saved measurement.
@immutable
@Deprecated('use health data store')
-class BloodPressureRecord {
+class OldBloodPressureRecord {
/// Create a measurement.
- BloodPressureRecord(DateTime creationTime, this.systolic, this.diastolic, this.pulse, this.notes, {
+ OldBloodPressureRecord(DateTime creationTime, this.systolic, this.diastolic, this.pulse, this.notes, {
this.needlePin,
}) {
if (creationTime.millisecondsSinceEpoch > 0) {
@@ -36,14 +36,14 @@ class BloodPressureRecord {
final MeasurementNeedlePin? needlePin;
/// Creates a new record from this one by updating individual properties.
- BloodPressureRecord copyWith({
+ OldBloodPressureRecord copyWith({
DateTime? creationTime,
int? systolic,
int? diastolic,
int? pulse,
String? notes,
MeasurementNeedlePin? needlePin,
- }) => BloodPressureRecord(
+ }) => OldBloodPressureRecord(
creationTime ?? this.creationTime,
systolic ?? this.systolic,
diastolic ?? this.diastolic,
app/lib/model/blood_pressure/update_legacy_entries.dart
@@ -61,7 +61,7 @@ Future<void> updateLegacyEntries(
// Migrating records and notes
try {
final oldBpModel = await BloodPressureModel.create();
- for (final BloodPressureRecord r in await oldBpModel?.all ?? []) {
+ for (final OldBloodPressureRecord r in await oldBpModel?.all ?? []) {
if (r.diastolic != null || r.systolic != null || r.pulse != null) {
await bpRepo.add(hds.BloodPressureRecord(
time: r.creationTime,
app/lib/screens/error_reporting_screen.dart
@@ -113,7 +113,7 @@ class ErrorScreen extends StatelessWidget {
content: Text('ERR: $e'),),);
}
},
- child: const Text('rescue old measurements'),
+ child: const Text('rescue legacy blood_pressure.db'),
),
TextButton(
onPressed: () async {
app/test/model/bood_pressure_test.dart
@@ -8,7 +8,7 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
void main() {
group('BloodPressureRecord', () {
test('should initialize with all values supported by dart', () {
- final BloodPressureRecord record = BloodPressureRecord(DateTime.fromMicrosecondsSinceEpoch(1582991592), 0, -50, 1000,
+ final OldBloodPressureRecord record = OldBloodPressureRecord(DateTime.fromMicrosecondsSinceEpoch(1582991592), 0, -50, 1000,
'((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈๏ แผ่นดินฮั่นเABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ–—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвг, \n \t д∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა',);
expect(record.creationTime, DateTime.fromMicrosecondsSinceEpoch(1582991592));
@@ -19,7 +19,7 @@ void main() {
'((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈๏ แผ่นดินฮั่นเABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ–—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвг, \n \t д∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა',);
});
test('should not save times at or before epoch', () {
- expect(() => BloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(0), 0, 0, 0, ''), throwsAssertionError);
+ expect(() => OldBloodPressureRecord(DateTime.fromMillisecondsSinceEpoch(0), 0, 0, 0, ''), throwsAssertionError);
});
});
health_data_store/lib/src/types/full_entry.dart
@@ -65,6 +65,7 @@ extension FullEntryList on List<FullEntry> {
List<Note> notes,
List<MedicineIntake> intakes,
) {
+ // TODO: make these asserts unneccessary
assert(!records
.any((rOuter) => records
.where((rInner) => rOuter.time == rInner.time).length != 1,