From 796265b048991227e98c6cc816791aea89a88da6 Mon Sep 17 00:00:00 2001 From: spinel Date: Tue, 30 Nov 2021 04:16:28 +0100 Subject: [PATCH] add functionality to bolus calculation --- TODO | 11 +- lib/models/bolus.dart | 1 - lib/models/log_bolus.dart | 28 +- lib/models/log_entry.dart | 25 +- lib/models/log_event.dart | 3 +- lib/models/log_meal.dart | 5 - lib/objectbox-model.json | 83 ++-- lib/objectbox.g.dart | 227 +++++----- lib/screens/log/active_log_event_list.dart | 4 - .../log/log_entry/log_bolus_detail.dart | 388 ++++++++++++++++-- lib/screens/log/log_entry/log_bolus_list.dart | 9 +- lib/screens/log/log_entry/log_entry.dart | 53 +-- .../log/log_entry/log_meal_detail.dart | 56 --- 13 files changed, 563 insertions(+), 330 deletions(-) diff --git a/TODO b/TODO index 7bcb282..0d2b9e2 100644 --- a/TODO +++ b/TODO @@ -15,12 +15,10 @@ MAIN TASKS: ☐ total bolus and carbs per entry Log Entry: - ☐ replace meal and glucose boli with logbolus entities ☐ check for multiple active events with temporary basal/bolus profiles (smallest covered time frame counts) ☐ provide splitting functionality for overlapping events - - Event Types: - ☐ implement reminders as push notifications + ☐ provide percentage functionality for delayed bolus + ☐ get rid of useless cancellation warnings Settings: ☐ add objectbox class and use instead of shared preferences @@ -37,15 +35,20 @@ FUTURE TASKS: ☐ account for deleted/disabled elements in dropdowns ☐ hide dropdown overlay on tapping anywhere else (especially menu) ☐ add clear button to dropdown (or all text fields?) + ☐ check through all detail forms and set required fields/according messages + ☐ find a better way to work with multiple measurements (or disable it?) Log Overview: ☐ add pagination Event Types: ☐ add colors as indicators for log entries (and later graphs in reports) + ☐ implement reminders as push notifications Settings: ☐ add option to hide extra customization options (ie. changing pre calculated values) ☐ add setting for decimal places Archive: + ✔ display boli correctly @done(21-11-30 04:14) @project(MAIN TASKS.Log Entry) + ✔ replace meal and glucose boli with logbolus entities @done(21-11-30 03:56) @project(MAIN TASKS.Log Entry) ✔ adjust/debug active events view @done(21-11-26 22:54) @project(MAIN TASKS.Log Overview) ✔ show all active events, not just those assigned to the entry @done(21-11-26 22:12) @project(MAIN TASKS.Log Entry) ✔ add active events view (as main menu item) @done(21-11-26 21:28) @project(MAIN TASKS.Log Overview) diff --git a/lib/models/bolus.dart b/lib/models/bolus.dart index 3a8ea48..c87075e 100644 --- a/lib/models/bolus.dart +++ b/lib/models/bolus.dart @@ -1,7 +1,6 @@ import 'package:diameter/config.dart'; import 'package:diameter/main.dart'; import 'package:diameter/models/bolus_profile.dart'; -import 'package:diameter/models/log_event.dart'; import 'package:diameter/utils/date_time_utils.dart'; import 'package:flutter/material.dart'; import 'package:objectbox/objectbox.dart'; diff --git a/lib/models/log_bolus.dart b/lib/models/log_bolus.dart index 985aac9..40edef2 100644 --- a/lib/models/log_bolus.dart +++ b/lib/models/log_bolus.dart @@ -15,15 +15,19 @@ class LogBolus { double units; double? carbs; int? delay; - int? mgPerDl; - double? mmolPerL; + int? mgPerDlCurrent; + int? mgPerDlTarget; + int? mgPerDlCorrection; + double? mmolPerLCurrent; + double? mmolPerLTarget; + double? mmolPerLCorrection; bool setManually; String? notes; // relations final logEntry = ToOne(); final rate = ToOne(); - final meal = ToOne(); + final meal = ToOne(); // constructor LogBolus({ @@ -32,8 +36,12 @@ class LogBolus { this.units = 0, this.carbs, this.delay, - this.mgPerDl, - this.mmolPerL, + this.mgPerDlCurrent, + this.mgPerDlTarget, + this.mgPerDlCorrection, + this.mmolPerLCurrent, + this.mmolPerLTarget, + this.mmolPerLCorrection, this.setManually = false, this.notes, }); @@ -41,13 +49,19 @@ class LogBolus { // methods static LogBolus? get(int id) => box.get(id); static void put(LogBolus logBolus) => box.put(logBolus); - + static List getAllForEntry(int id) { QueryBuilder builder = box.query(LogBolus_.deleted.equals(false)); builder.link(LogBolus_.logEntry, LogEntry_.id.equals(id)); return builder.build().find(); } - + + static bool glucoseBolusForEntryExists(int id) { + QueryBuilder builder = box.query(LogBolus_.deleted.equals(false).and(LogBolus_.mgPerDlCorrection.notNull())); + builder.link(LogBolus_.logEntry, LogEntry_.id.equals(id)); + return builder.build().find().isNotEmpty; + } + static void remove(int id) { final item = box.get(id); if (item != null) { diff --git a/lib/models/log_entry.dart b/lib/models/log_entry.dart index 4587e4c..663eda6 100644 --- a/lib/models/log_entry.dart +++ b/lib/models/log_entry.dart @@ -1,4 +1,6 @@ +import 'package:diameter/config.dart'; import 'package:diameter/main.dart'; +import 'package:diameter/models/log_bolus.dart'; import 'package:diameter/utils/date_time_utils.dart'; import 'package:objectbox/objectbox.dart'; import 'package:diameter/objectbox.g.dart' show LogEntry_; @@ -14,9 +16,6 @@ class LogEntry { DateTime time; int? mgPerDl; double? mmolPerL; - double? bolusGlucose; - int? delayedBolusDuration; - double? delayedBolusRate; String? notes; // constructor @@ -26,9 +25,6 @@ class LogEntry { required this.time, this.mgPerDl, this.mmolPerL, - this.bolusGlucose, - this.delayedBolusDuration, - this.delayedBolusRate, this.notes, }); @@ -36,8 +32,8 @@ class LogEntry { static LogEntry? get(int id) => id == 0 ? null : box.get(id); static List getAll() => box.getAll(); static void put(LogEntry logEntry) => box.put(logEntry); - - static void remove(int id) { + + static void remove(int id) { final item = box.get(id); if (item != null) { item.deleted = true; @@ -45,10 +41,20 @@ class LogEntry { } } + static bool hasUncorrectedGlucose(int id) { + final entry = box.get(id); + if (((entry?.mgPerDl ?? 0) > moderateGlucoseMgPerDl || + (entry?.mmolPerL ?? 0) > moderateGlucoseMmolPerL)) { + return !LogBolus.glucoseBolusForEntryExists(id); + } + return false; + } + static Map> getDailyEntryMap() { Map> dateMap = >{}; - QueryBuilder allByDate = box.query(LogEntry_.deleted.equals(false)) + QueryBuilder allByDate = box + .query(LogEntry_.deleted.equals(false)) ..order(LogEntry_.time, flags: Order.descending); List entries = allByDate.build().find(); DateTime? date; @@ -61,7 +67,6 @@ class LogEntry { return dateMap; } - @override String toString() { return DateTimeUtils.displayDateTime(time); diff --git a/lib/models/log_event.dart b/lib/models/log_event.dart index 7150b85..e29a3e1 100644 --- a/lib/models/log_event.dart +++ b/lib/models/log_event.dart @@ -3,9 +3,8 @@ import 'package:diameter/models/basal_profile.dart'; import 'package:diameter/models/bolus_profile.dart'; import 'package:diameter/models/log_entry.dart'; import 'package:diameter/models/log_event_type.dart'; -import 'package:diameter/objectbox.g.dart'; -// ignore: unnecessary_import import 'package:objectbox/objectbox.dart'; +import 'package:diameter/objectbox.g.dart' show LogEvent_, LogEntry_; @Entity(uid: 4303325892753185970) class LogEvent { diff --git a/lib/models/log_meal.dart b/lib/models/log_meal.dart index 0edb746..98714f4 100644 --- a/lib/models/log_meal.dart +++ b/lib/models/log_meal.dart @@ -19,8 +19,6 @@ class LogMeal { double? carbsRatio; double? portionSize; double? carbsPerPortion; - int? delayedBolusDuration; - double? delayedBolusRate; String? notes; double? bolus; @@ -41,9 +39,6 @@ class LogMeal { this.carbsRatio, this.portionSize, this.carbsPerPortion, - this.bolus, - this.delayedBolusDuration, - this.delayedBolusRate, this.notes, }); diff --git a/lib/objectbox-model.json b/lib/objectbox-model.json index 5e3c451..2046ec4 100644 --- a/lib/objectbox-model.json +++ b/lib/objectbox-model.json @@ -196,21 +196,6 @@ "name": "mmolPerL", "type": 8 }, - { - "id": "5:3678829169126156351", - "name": "bolusGlucose", - "type": 8 - }, - { - "id": "6:1568597071506264632", - "name": "delayedBolusDuration", - "type": 6 - }, - { - "id": "7:8795268969829293398", - "name": "delayedBolusRate", - "type": 8 - }, { "id": "8:6492273995038150006", "name": "notes", @@ -226,7 +211,7 @@ }, { "id": "7:4303325892753185970", - "lastPropertyId": "11:2013538196800336796", + "lastPropertyId": "12:3041952167628926163", "name": "LogEvent", "properties": [ { @@ -299,6 +284,11 @@ "flags": 520, "indexId": "26:4562998391990896273", "relationTarget": "BasalProfile" + }, + { + "id": "12:3041952167628926163", + "name": "reminderDuration", + "type": 6 } ], "relations": [] @@ -394,16 +384,6 @@ "name": "bolus", "type": 8 }, - { - "id": "7:3247926313599127440", - "name": "delayedBolusDuration", - "type": 6 - }, - { - "id": "8:8789440370359282572", - "name": "delayedBolusRate", - "type": 8 - }, { "id": "9:1920579694098037947", "name": "notes", @@ -688,7 +668,7 @@ }, { "id": "14:8033487006694871160", - "lastPropertyId": "12:4765038304548427459", + "lastPropertyId": "18:7503231998671134983", "name": "LogBolus", "properties": [ { @@ -712,16 +692,6 @@ "name": "delay", "type": 6 }, - { - "id": "5:6855574218883169324", - "name": "mgPerDl", - "type": 6 - }, - { - "id": "6:5313708456544000157", - "name": "mmolPerL", - "type": 8 - }, { "id": "7:3065420032567707091", "name": "setManually", @@ -760,6 +730,36 @@ "id": "12:4765038304548427459", "name": "deleted", "type": 1 + }, + { + "id": "13:2530431967957143684", + "name": "mgPerDlCurrent", + "type": 6 + }, + { + "id": "14:5210229118898251877", + "name": "mgPerDlTarget", + "type": 6 + }, + { + "id": "15:657840864788362204", + "name": "mgPerDlCorrection", + "type": 6 + }, + { + "id": "16:3999403624434995450", + "name": "mmolPerLCurrent", + "type": 8 + }, + { + "id": "17:2852253735546692099", + "name": "mmolPerLTarget", + "type": 8 + }, + { + "id": "18:7503231998671134983", + "name": "mmolPerLCorrection", + "type": 8 } ], "relations": [] @@ -825,7 +825,14 @@ 9003780003858349085, 5421422436108145565, 7741631874181070179, - 5471636804765937328 + 5471636804765937328, + 6855574218883169324, + 5313708456544000157, + 3678829169126156351, + 1568597071506264632, + 8795268969829293398, + 3247926313599127440, + 8789440370359282572 ], "retiredRelationUids": [], "version": 1 diff --git a/lib/objectbox.g.dart b/lib/objectbox.g.dart index a898429..9c2e82b 100644 --- a/lib/objectbox.g.dart +++ b/lib/objectbox.g.dart @@ -218,21 +218,6 @@ final _entities = [ name: 'mmolPerL', type: 8, flags: 0), - ModelProperty( - id: const IdUid(5, 3678829169126156351), - name: 'bolusGlucose', - type: 8, - flags: 0), - ModelProperty( - id: const IdUid(6, 1568597071506264632), - name: 'delayedBolusDuration', - type: 6, - flags: 0), - ModelProperty( - id: const IdUid(7, 8795268969829293398), - name: 'delayedBolusRate', - type: 8, - flags: 0), ModelProperty( id: const IdUid(8, 6492273995038150006), name: 'notes', @@ -249,7 +234,7 @@ final _entities = [ ModelEntity( id: const IdUid(7, 4303325892753185970), name: 'LogEvent', - lastPropertyId: const IdUid(11, 2013538196800336796), + lastPropertyId: const IdUid(12, 3041952167628926163), flags: 0, properties: [ ModelProperty( @@ -316,7 +301,12 @@ final _entities = [ type: 11, flags: 520, indexId: const IdUid(26, 4562998391990896273), - relationTarget: 'BasalProfile') + relationTarget: 'BasalProfile'), + ModelProperty( + id: const IdUid(12, 3041952167628926163), + name: 'reminderDuration', + type: 6, + flags: 0) ], relations: [], backlinks: []), @@ -409,16 +399,6 @@ final _entities = [ name: 'bolus', type: 8, flags: 0), - ModelProperty( - id: const IdUid(7, 3247926313599127440), - name: 'delayedBolusDuration', - type: 6, - flags: 0), - ModelProperty( - id: const IdUid(8, 8789440370359282572), - name: 'delayedBolusRate', - type: 8, - flags: 0), ModelProperty( id: const IdUid(9, 1920579694098037947), name: 'notes', @@ -688,7 +668,7 @@ final _entities = [ ModelEntity( id: const IdUid(14, 8033487006694871160), name: 'LogBolus', - lastPropertyId: const IdUid(12, 4765038304548427459), + lastPropertyId: const IdUid(18, 7503231998671134983), flags: 0, properties: [ ModelProperty( @@ -711,16 +691,6 @@ final _entities = [ name: 'delay', type: 6, flags: 0), - ModelProperty( - id: const IdUid(5, 6855574218883169324), - name: 'mgPerDl', - type: 6, - flags: 0), - ModelProperty( - id: const IdUid(6, 5313708456544000157), - name: 'mmolPerL', - type: 8, - flags: 0), ModelProperty( id: const IdUid(7, 3065420032567707091), name: 'setManually', @@ -756,6 +726,36 @@ final _entities = [ id: const IdUid(12, 4765038304548427459), name: 'deleted', type: 1, + flags: 0), + ModelProperty( + id: const IdUid(13, 2530431967957143684), + name: 'mgPerDlCurrent', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(14, 5210229118898251877), + name: 'mgPerDlTarget', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(15, 657840864788362204), + name: 'mgPerDlCorrection', + type: 6, + flags: 0), + ModelProperty( + id: const IdUid(16, 3999403624434995450), + name: 'mmolPerLCurrent', + type: 8, + flags: 0), + ModelProperty( + id: const IdUid(17, 2852253735546692099), + name: 'mmolPerLTarget', + type: 8, + flags: 0), + ModelProperty( + id: const IdUid(18, 7503231998671134983), + name: 'mmolPerLCorrection', + type: 8, flags: 0) ], relations: [], @@ -838,7 +838,14 @@ ModelDefinition getObjectBoxModel() { 9003780003858349085, 5421422436108145565, 7741631874181070179, - 5471636804765937328 + 5471636804765937328, + 6855574218883169324, + 5313708456544000157, + 3678829169126156351, + 1568597071506264632, + 8795268969829293398, + 3247926313599127440, + 8789440370359282572 ], retiredRelationUids: const [], modelVersion: 5, @@ -1023,9 +1030,6 @@ ModelDefinition getObjectBoxModel() { fbb.addInt64(1, object.time.millisecondsSinceEpoch); fbb.addInt64(2, object.mgPerDl); fbb.addFloat64(3, object.mmolPerL); - fbb.addFloat64(4, object.bolusGlucose); - fbb.addInt64(5, object.delayedBolusDuration); - fbb.addFloat64(6, object.delayedBolusRate); fbb.addOffset(7, notesOffset); fbb.addBool(8, object.deleted); fbb.finish(fbb.endTable()); @@ -1045,12 +1049,6 @@ ModelDefinition getObjectBoxModel() { .vTableGetNullable(buffer, rootOffset, 8), mmolPerL: const fb.Float64Reader() .vTableGetNullable(buffer, rootOffset, 10), - bolusGlucose: const fb.Float64Reader() - .vTableGetNullable(buffer, rootOffset, 12), - delayedBolusDuration: const fb.Int64Reader() - .vTableGetNullable(buffer, rootOffset, 14), - delayedBolusRate: const fb.Float64Reader() - .vTableGetNullable(buffer, rootOffset, 16), notes: const fb.StringReader() .vTableGetNullable(buffer, rootOffset, 18)); @@ -1073,7 +1071,7 @@ ModelDefinition getObjectBoxModel() { objectToFB: (LogEvent object, fb.Builder fbb) { final notesOffset = object.notes == null ? null : fbb.writeString(object.notes!); - fbb.startTable(12); + fbb.startTable(13); fbb.addInt64(0, object.id); fbb.addInt64(1, object.time.millisecondsSinceEpoch); fbb.addInt64(2, object.endTime?.millisecondsSinceEpoch); @@ -1085,6 +1083,7 @@ ModelDefinition getObjectBoxModel() { fbb.addBool(8, object.deleted); fbb.addInt64(9, object.bolusProfile.targetId); fbb.addInt64(10, object.basalProfile.targetId); + fbb.addInt64(11, object.reminderDuration); fbb.finish(fbb.endTable()); return object.id; }, @@ -1104,6 +1103,8 @@ ModelDefinition getObjectBoxModel() { : DateTime.fromMillisecondsSinceEpoch(endTimeValue), hasEndTime: const fb.BoolReader() .vTableGet(buffer, rootOffset, 10, false), + reminderDuration: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 26), notes: const fb.StringReader() .vTableGetNullable(buffer, rootOffset, 12)); object.logEntry.targetId = @@ -1199,8 +1200,6 @@ ModelDefinition getObjectBoxModel() { fbb.addFloat64(3, object.portionSize); fbb.addFloat64(4, object.carbsPerPortion); fbb.addFloat64(5, object.bolus); - fbb.addInt64(6, object.delayedBolusDuration); - fbb.addFloat64(7, object.delayedBolusRate); fbb.addOffset(8, notesOffset); fbb.addInt64(9, object.logEntry.targetId); fbb.addInt64(10, object.meal.targetId); @@ -1229,14 +1228,10 @@ ModelDefinition getObjectBoxModel() { .vTableGetNullable(buffer, rootOffset, 10), carbsPerPortion: const fb.Float64Reader() .vTableGetNullable(buffer, rootOffset, 12), - bolus: const fb.Float64Reader() - .vTableGetNullable(buffer, rootOffset, 14), - delayedBolusDuration: const fb.Int64Reader() - .vTableGetNullable(buffer, rootOffset, 16), - delayedBolusRate: const fb.Float64Reader() - .vTableGetNullable(buffer, rootOffset, 18), notes: const fb.StringReader() - .vTableGetNullable(buffer, rootOffset, 20)); + .vTableGetNullable(buffer, rootOffset, 20)) + ..bolus = const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 14); object.logEntry.targetId = const fb.Int64Reader().vTableGet(buffer, rootOffset, 22, 0); object.logEntry.attach(store); @@ -1472,19 +1467,23 @@ ModelDefinition getObjectBoxModel() { objectToFB: (LogBolus object, fb.Builder fbb) { final notesOffset = object.notes == null ? null : fbb.writeString(object.notes!); - fbb.startTable(13); + fbb.startTable(19); fbb.addInt64(0, object.id); fbb.addFloat64(1, object.units); fbb.addFloat64(2, object.carbs); fbb.addInt64(3, object.delay); - fbb.addInt64(4, object.mgPerDl); - fbb.addFloat64(5, object.mmolPerL); fbb.addBool(6, object.setManually); fbb.addOffset(7, notesOffset); fbb.addInt64(8, object.logEntry.targetId); fbb.addInt64(9, object.rate.targetId); fbb.addInt64(10, object.meal.targetId); fbb.addBool(11, object.deleted); + fbb.addInt64(12, object.mgPerDlCurrent); + fbb.addInt64(13, object.mgPerDlTarget); + fbb.addInt64(14, object.mgPerDlCorrection); + fbb.addFloat64(15, object.mmolPerLCurrent); + fbb.addFloat64(16, object.mmolPerLTarget); + fbb.addFloat64(17, object.mmolPerLCorrection); fbb.finish(fbb.endTable()); return object.id; }, @@ -1502,10 +1501,18 @@ ModelDefinition getObjectBoxModel() { .vTableGetNullable(buffer, rootOffset, 8), delay: const fb.Int64Reader() .vTableGetNullable(buffer, rootOffset, 10), - mgPerDl: const fb.Int64Reader() - .vTableGetNullable(buffer, rootOffset, 12), - mmolPerL: const fb.Float64Reader() - .vTableGetNullable(buffer, rootOffset, 14), + mgPerDlCurrent: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 28), + mgPerDlTarget: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 30), + mgPerDlCorrection: const fb.Int64Reader() + .vTableGetNullable(buffer, rootOffset, 32), + mmolPerLCurrent: const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 34), + mmolPerLTarget: const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 36), + mmolPerLCorrection: const fb.Float64Reader() + .vTableGetNullable(buffer, rootOffset, 38), setManually: const fb.BoolReader() .vTableGet(buffer, rootOffset, 16, false), notes: const fb.StringReader() @@ -1694,25 +1701,13 @@ class LogEntry_ { static final mmolPerL = QueryDoubleProperty(_entities[4].properties[3]); - /// see [LogEntry.bolusGlucose] - static final bolusGlucose = - QueryDoubleProperty(_entities[4].properties[4]); - - /// see [LogEntry.delayedBolusDuration] - static final delayedBolusDuration = - QueryIntegerProperty(_entities[4].properties[5]); - - /// see [LogEntry.delayedBolusRate] - static final delayedBolusRate = - QueryDoubleProperty(_entities[4].properties[6]); - /// see [LogEntry.notes] static final notes = - QueryStringProperty(_entities[4].properties[7]); + QueryStringProperty(_entities[4].properties[4]); /// see [LogEntry.deleted] static final deleted = - QueryBooleanProperty(_entities[4].properties[8]); + QueryBooleanProperty(_entities[4].properties[5]); } /// [LogEvent] entity fields to define ObjectBox queries. @@ -1759,6 +1754,10 @@ class LogEvent_ { /// see [LogEvent.basalProfile] static final basalProfile = QueryRelationToOne(_entities[5].properties[10]); + + /// see [LogEvent.reminderDuration] + static final reminderDuration = + QueryIntegerProperty(_entities[5].properties[11]); } /// [LogEventType] entity fields to define ObjectBox queries. @@ -1819,48 +1818,40 @@ class LogMeal_ { /// see [LogMeal.bolus] static final bolus = QueryDoubleProperty(_entities[7].properties[5]); - /// see [LogMeal.delayedBolusDuration] - static final delayedBolusDuration = - QueryIntegerProperty(_entities[7].properties[6]); - - /// see [LogMeal.delayedBolusRate] - static final delayedBolusRate = - QueryDoubleProperty(_entities[7].properties[7]); - /// see [LogMeal.notes] - static final notes = QueryStringProperty(_entities[7].properties[8]); + static final notes = QueryStringProperty(_entities[7].properties[6]); /// see [LogMeal.logEntry] static final logEntry = - QueryRelationToOne(_entities[7].properties[9]); + QueryRelationToOne(_entities[7].properties[7]); /// see [LogMeal.meal] static final meal = - QueryRelationToOne(_entities[7].properties[10]); + QueryRelationToOne(_entities[7].properties[8]); /// see [LogMeal.mealSource] static final mealSource = - QueryRelationToOne(_entities[7].properties[11]); + QueryRelationToOne(_entities[7].properties[9]); /// see [LogMeal.mealCategory] static final mealCategory = - QueryRelationToOne(_entities[7].properties[12]); + QueryRelationToOne(_entities[7].properties[10]); /// see [LogMeal.mealPortionType] static final mealPortionType = - QueryRelationToOne(_entities[7].properties[13]); + QueryRelationToOne(_entities[7].properties[11]); /// see [LogMeal.portionSizeAccuracy] static final portionSizeAccuracy = - QueryRelationToOne(_entities[7].properties[14]); + QueryRelationToOne(_entities[7].properties[12]); /// see [LogMeal.carbsRatioAccuracy] static final carbsRatioAccuracy = - QueryRelationToOne(_entities[7].properties[15]); + QueryRelationToOne(_entities[7].properties[13]); /// see [LogMeal.deleted] static final deleted = - QueryBooleanProperty(_entities[7].properties[16]); + QueryBooleanProperty(_entities[7].properties[14]); } /// [Meal] entity fields to define ObjectBox queries. @@ -2010,37 +2001,53 @@ class LogBolus_ { static final delay = QueryIntegerProperty(_entities[12].properties[3]); - /// see [LogBolus.mgPerDl] - static final mgPerDl = - QueryIntegerProperty(_entities[12].properties[4]); - - /// see [LogBolus.mmolPerL] - static final mmolPerL = - QueryDoubleProperty(_entities[12].properties[5]); - /// see [LogBolus.setManually] static final setManually = - QueryBooleanProperty(_entities[12].properties[6]); + QueryBooleanProperty(_entities[12].properties[4]); /// see [LogBolus.notes] static final notes = - QueryStringProperty(_entities[12].properties[7]); + QueryStringProperty(_entities[12].properties[5]); /// see [LogBolus.logEntry] static final logEntry = - QueryRelationToOne(_entities[12].properties[8]); + QueryRelationToOne(_entities[12].properties[6]); /// see [LogBolus.rate] static final rate = - QueryRelationToOne(_entities[12].properties[9]); + QueryRelationToOne(_entities[12].properties[7]); /// see [LogBolus.meal] static final meal = - QueryRelationToOne(_entities[12].properties[10]); + QueryRelationToOne(_entities[12].properties[8]); /// see [LogBolus.deleted] static final deleted = - QueryBooleanProperty(_entities[12].properties[11]); + QueryBooleanProperty(_entities[12].properties[9]); + + /// see [LogBolus.mgPerDlCurrent] + static final mgPerDlCurrent = + QueryIntegerProperty(_entities[12].properties[10]); + + /// see [LogBolus.mgPerDlTarget] + static final mgPerDlTarget = + QueryIntegerProperty(_entities[12].properties[11]); + + /// see [LogBolus.mgPerDlCorrection] + static final mgPerDlCorrection = + QueryIntegerProperty(_entities[12].properties[12]); + + /// see [LogBolus.mmolPerLCurrent] + static final mmolPerLCurrent = + QueryDoubleProperty(_entities[12].properties[13]); + + /// see [LogBolus.mmolPerLTarget] + static final mmolPerLTarget = + QueryDoubleProperty(_entities[12].properties[14]); + + /// see [LogBolus.mmolPerLCorrection] + static final mmolPerLCorrection = + QueryDoubleProperty(_entities[12].properties[15]); } /// [Accuracy] entity fields to define ObjectBox queries. diff --git a/lib/screens/log/active_log_event_list.dart b/lib/screens/log/active_log_event_list.dart index d8f1526..681d1dd 100644 --- a/lib/screens/log/active_log_event_list.dart +++ b/lib/screens/log/active_log_event_list.dart @@ -1,10 +1,6 @@ -import 'package:diameter/components/dialogs.dart'; -import 'package:diameter/config.dart'; -import 'package:diameter/models/log_entry.dart'; import 'package:diameter/models/log_event.dart'; import 'package:diameter/screens/log/log_entry/log_event_detail.dart'; import 'package:diameter/screens/log/log_entry/log_event_list.dart'; -import 'package:diameter/utils/date_time_utils.dart'; import 'package:flutter/material.dart'; import 'package:diameter/navigation.dart'; diff --git a/lib/screens/log/log_entry/log_bolus_detail.dart b/lib/screens/log/log_entry/log_bolus_detail.dart index 42f8f05..c417b5e 100644 --- a/lib/screens/log/log_entry/log_bolus_detail.dart +++ b/lib/screens/log/log_entry/log_bolus_detail.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:diameter/components/detail.dart'; import 'package:diameter/components/dialogs.dart'; import 'package:diameter/components/dropdown.dart'; @@ -9,15 +11,31 @@ import 'package:diameter/models/log_entry.dart'; import 'package:diameter/models/log_meal.dart'; import 'package:diameter/navigation.dart'; import 'package:diameter/settings.dart'; +import 'package:diameter/utils/utils.dart'; import 'package:flutter/material.dart'; +enum BolusType { + meal, + glucose, +} + +enum GlucoseParameter { + mgdlCurrent, + mgdlTarget, + mgdlCorrection, + mmolCurrent, + mmolTarget, + mmolCorrection, +} + class LogBolusDetailScreen extends StatefulWidget { static const String routeName = '/log-bolus'; final int logEntryId; final int id; - const LogBolusDetailScreen({Key? key, this.logEntryId = 0, this.id = 0}) + const LogBolusDetailScreen( + {Key? key, this.logEntryId = 0, this.id = 0}) : super(key: key); @override @@ -35,12 +53,17 @@ class _LogBolusDetailScreenState extends State { final _unitsController = TextEditingController(text: ''); final _carbsController = TextEditingController(text: ''); - final _mgPerDlController = TextEditingController(text: ''); - final _mmolPerLController = TextEditingController(text: ''); + final _mgPerDlCurrentController = TextEditingController(text: ''); + final _mgPerDlTargetController = TextEditingController(text: ''); + final _mgPerDlCorrectionController = TextEditingController(text: ''); + final _mmolPerLCurrentController = TextEditingController(text: ''); + final _mmolPerLTargetController = TextEditingController(text: ''); + final _mmolPerLCorrectionController = TextEditingController(text: ''); final _delayController = TextEditingController(text: ''); final _notesController = TextEditingController(text: ''); bool _setManually = false; + BolusType _bolusType = BolusType.meal; LogMeal? _meal; Bolus? _rate; @@ -55,10 +78,7 @@ class _LogBolusDetailScreenState extends State { _logMeals = LogMeal.getAllForEntry(widget.logEntryId); if (widget.id != 0) { - _unitsController.text = _logBolus!.units.toString(); _carbsController.text = (_logBolus!.carbs ?? '').toString(); - _mgPerDlController.text = (_logBolus!.mgPerDl ?? '').toString(); - _mmolPerLController.text = (_logBolus!.mmolPerL ?? '').toString(); _delayController.text = (_logBolus!.delay ?? '').toString(); _notesController.text = _logBolus!.notes ?? ''; _setManually = _logBolus!.setManually; @@ -67,6 +87,27 @@ class _LogBolusDetailScreenState extends State { } _rate ??= Bolus.getRateForTime(_logEntry?.time); + + _mgPerDlCurrentController.text = + (_logBolus?.mgPerDlCurrent ?? (LogEntry.hasUncorrectedGlucose(widget.logEntryId) ? _logEntry?.mgPerDl ?? 0 : 0)).toString(); + _mgPerDlTargetController.text = + (_logBolus?.mgPerDlTarget ?? moderateGlucoseMgPerDl).toString(); + _mgPerDlCorrectionController.text = + (_logBolus?.mgPerDlCorrection ?? max((int.tryParse(_mgPerDlCurrentController.text) ?? 0) - (int.tryParse(_mgPerDlTargetController.text) ?? 0), 0)).toString(); + _mmolPerLCurrentController.text = + (_logBolus?.mmolPerLCurrent ?? (LogEntry.hasUncorrectedGlucose(widget.logEntryId) ? _logEntry?.mmolPerL ?? 0 : 0)).toString(); + _mmolPerLTargetController.text = + (_logBolus?.mmolPerLTarget ?? moderateGlucoseMmolPerL).toString(); + _mmolPerLCorrectionController.text = + (_logBolus?.mmolPerLCorrection ?? max((double.tryParse(_mmolPerLCurrentController.text) ?? 0) - (double.tryParse(_mmolPerLTargetController.text) ?? 0), 0)).toString(); + + _unitsController.text = (_logBolus?.units ?? + (_rate != null && !_setManually ? ((int.tryParse(_mgPerDlCorrectionController.text) ?? 0) / ((_rate!.mgPerDl ?? 0) / _rate!.units)) : 0) + ).toString(); + + if (widget.id == 0 && LogEntry.hasUncorrectedGlucose(widget.logEntryId)) { + _bolusType = BolusType.glucose; + } } void reload() { @@ -98,6 +139,68 @@ class _LogBolusDetailScreenState extends State { }); } + void onChangeGlucose({GlucoseMeasurement? calculateFrom}) { + int? mgPerDlCurrent; + int? mgPerDlTarget; + int? mgPerDlCorrection; + + double? mmolPerLCurrent; + double? mmolPerLTarget; + double? mmolPerLCorrection; + + if (calculateFrom != GlucoseMeasurement.mmolPerL && + _mgPerDlCurrentController.text != '' && + _mgPerDlTargetController.text != '') { + mgPerDlCurrent = int.tryParse(_mgPerDlCurrentController.text); + mgPerDlTarget = int.tryParse(_mgPerDlTargetController.text); + mgPerDlCorrection = max((mgPerDlCurrent ?? 0) - (mgPerDlTarget ?? 0), 0); + } + if (calculateFrom != GlucoseMeasurement.mgPerDl && + _mmolPerLCurrentController.text != '') { + mmolPerLCurrent = double.tryParse(_mmolPerLCurrentController.text); + mmolPerLTarget = double.tryParse(_mmolPerLTargetController.text); + mmolPerLCorrection = + max((mmolPerLCurrent ?? 0) - (mmolPerLTarget ?? 0), 0); + } + + if ((mgPerDlCurrent != null && mmolPerLCurrent == null) || + (mgPerDlTarget != null && mmolPerLTarget == null) || + (mgPerDlCorrection != null && mmolPerLCorrection == null)) { + setState(() { + _mgPerDlCorrectionController.text = (mgPerDlCorrection ?? 0).toString(); + _mmolPerLCurrentController.text = + Utils.convertMgPerDlToMmolPerL(mgPerDlCurrent ?? 0).toString(); + _mmolPerLTargetController.text = + Utils.convertMgPerDlToMmolPerL(mgPerDlTarget ?? 0).toString(); + _mmolPerLCorrectionController.text = + Utils.convertMgPerDlToMmolPerL(mgPerDlCorrection ?? 0).toString(); + if (_rate != null && !_setManually) { + _unitsController.text = ((mgPerDlCorrection ?? 0) / + ((_rate!.mgPerDl ?? 0) / _rate!.units)) + .toString(); + } + }); + } + if ((mmolPerLCurrent != null && mgPerDlCurrent == null) || + (mmolPerLTarget != null && mgPerDlTarget == null) || + (mmolPerLCorrection != null && mgPerDlCorrection == null)) { + setState(() { + _mmolPerLCurrentController.text = (mmolPerLCorrection ?? 0).toString(); + _mgPerDlCurrentController.text = + Utils.convertMmolPerLToMgPerDl(mmolPerLCurrent ?? 0).toString(); + _mgPerDlTargetController.text = + Utils.convertMmolPerLToMgPerDl(mmolPerLTarget ?? 0).toString(); + _mgPerDlCorrectionController.text = + Utils.convertMmolPerLToMgPerDl(mmolPerLCorrection ?? 0).toString(); + if (_rate != null && !_setManually) { + _unitsController.text = ((mmolPerLCorrection ?? 0) / + ((_rate!.mmolPerL ?? 0) / _rate!.units)) + .toString(); + } + }); + } + } + void handleSaveAction() async { setState(() { _isSaving = true; @@ -106,13 +209,26 @@ class _LogBolusDetailScreenState extends State { LogBolus logBolus = LogBolus( id: widget.id, units: double.tryParse(_unitsController.text) ?? 0, - carbs: double.tryParse(_carbsController.text), - mgPerDl: int.tryParse(_mgPerDlController.text), - mmolPerL: double.tryParse(_mmolPerLController.text), delay: int.tryParse(_delayController.text), setManually: _setManually, notes: _notesController.text, ); + if (_bolusType == BolusType.meal) { + logBolus.carbs = double.tryParse(_carbsController.text); + logBolus.mgPerDlCurrent = null; + logBolus.mmolPerLCurrent = null; + } else { + logBolus.carbs = null; + logBolus.mgPerDlCurrent = int.tryParse(_mgPerDlCurrentController.text); + logBolus.mmolPerLCurrent = + double.tryParse(_mmolPerLCurrentController.text); + logBolus.mgPerDlTarget = int.tryParse(_mgPerDlTargetController.text); + logBolus.mmolPerLTarget = + double.tryParse(_mmolPerLTargetController.text); + logBolus.mgPerDlCorrection = int.tryParse(_mgPerDlCorrectionController.text); + logBolus.mmolPerLCorrection = + double.tryParse(_mmolPerLCorrectionController.text); + } logBolus.logEntry.target = _logEntry; logBolus.meal.target = _meal; logBolus.rate.target = _rate; @@ -129,8 +245,12 @@ class _LogBolusDetailScreenState extends State { ((_isNew && (_unitsController.text != '' || _carbsController.text != '' || - _mgPerDlController.text != '' || - _mmolPerLController.text != '' || + _mgPerDlCurrentController.text != '' || + _mgPerDlTargetController.text != '' || + _mgPerDlCorrectionController.text != '' || + _mmolPerLCurrentController.text != '' || + _mmolPerLTargetController.text != '' || + _mmolPerLCorrectionController.text != '' || _delayController.text != '' || _setManually || _notesController.text != '')) || @@ -138,10 +258,18 @@ class _LogBolusDetailScreenState extends State { (double.tryParse(_unitsController.text) != _logBolus!.units || double.tryParse(_carbsController.text) != _logBolus!.carbs || - int.tryParse(_mgPerDlController.text) != - _logBolus!.mgPerDl || - double.tryParse(_mmolPerLController.text) != - _logBolus!.mmolPerL || + int.tryParse(_mgPerDlCurrentController.text) != + _logBolus!.mgPerDlCurrent || + int.tryParse(_mgPerDlTargetController.text) != + _logBolus!.mgPerDlTarget || + int.tryParse(_mgPerDlCorrectionController.text) != + _logBolus!.mgPerDlCorrection || + double.tryParse(_mmolPerLCurrentController.text) != + _logBolus!.mmolPerLCurrent || + double.tryParse(_mmolPerLTargetController.text) != + _logBolus!.mmolPerLTarget || + double.tryParse(_mmolPerLCorrectionController.text) != + _logBolus!.mmolPerLCorrection || int.tryParse(_delayController.text) != _logBolus!.delay || _setManually != _logBolus!.setManually || _notesController.text != (_logBolus!.notes ?? ''))))) { @@ -185,37 +313,219 @@ class _LogBolusDetailScreenState extends State { ), BooleanFormField( value: _setManually, - label: 'set Bolus manually', + label: 'set manually', onChanged: (value) { setState(() { _setManually = value; }); }, ), - AutoCompleteDropdownButton( - selectedItem: _meal, - label: 'Meal', - items: _logMeals, - onChanged: (value) { - if (value != null) { - onSelectMeal(value); - } - }, + Row( + children: [ + Expanded( + child: RadioListTile( + title: const Text('for glucose'), + groupValue: _bolusType, + value: BolusType.glucose, + onChanged: (_) { + setState(() { + _bolusType = BolusType.glucose; + }); + }), + ), + Expanded( + child: RadioListTile( + title: const Text('for meal'), + groupValue: _bolusType, + value: BolusType.meal, + onChanged: (value) { + setState(() { + _bolusType = BolusType.meal; + }); + }), + ), + ], ), - TextFormField( - decoration: InputDecoration( - labelText: 'Carbs', - suffixText: nutritionMeasurement == - NutritionMeasurement.grams - ? 'g' - : nutritionMeasurement == NutritionMeasurement.ounces - ? 'oz' - : '', - ), - controller: _carbsController, - onChanged: (_) => onChangeCarbs(), - keyboardType: - const TextInputType.numberWithOptions(decimal: true), + Column( + children: _bolusType == BolusType.glucose + ? [ + Row( + children: glucoseMeasurement == + GlucoseMeasurement.mgPerDl || + glucoseDisplayMode == + GlucoseDisplayMode.both || + glucoseDisplayMode == + GlucoseDisplayMode.bothForDetail + ? [ + Expanded( + child: Padding( + padding: + const EdgeInsets.only(right: 5.0), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Current', + suffixText: 'mg/dl', + ), + controller: _mgPerDlCurrentController, + onChanged: (_) => onChangeGlucose( + calculateFrom: + GlucoseMeasurement.mgPerDl), + keyboardType: const TextInputType + .numberWithOptions(), + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 5.0), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Target', + suffixText: 'mg/dl', + ), + controller: _mgPerDlTargetController, + onChanged: (_) => onChangeGlucose( + calculateFrom: + GlucoseMeasurement.mgPerDl), + keyboardType: const TextInputType + .numberWithOptions(), + ), + ), + ), + Expanded( + child: Padding( + padding: + const EdgeInsets.only(left: 5.0), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Correction', + suffixText: 'mg/dl', + ), + controller: + _mgPerDlCorrectionController, + readOnly: true, + ), + ), + ), + glucoseDisplayMode == + GlucoseDisplayMode.both || + glucoseDisplayMode == + GlucoseDisplayMode.bothForDetail + ? IconButton( + onPressed: () => onChangeGlucose( + calculateFrom: + GlucoseMeasurement + .mmolPerL), + icon: const Icon(Icons.calculate), + ) + : Container(), + ] + : [], + ), + Row( + children: glucoseMeasurement == + GlucoseMeasurement.mmolPerL || + glucoseDisplayMode == + GlucoseDisplayMode.both || + glucoseDisplayMode == + GlucoseDisplayMode.bothForDetail + ? [ + Expanded( + child: Padding( + padding: + const EdgeInsets.only(right: 5), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Current', + suffixText: 'mmol/l', + ), + controller: + _mmolPerLCurrentController, + onChanged: (_) => onChangeGlucose( + calculateFrom: + GlucoseMeasurement.mmolPerL), + keyboardType: const TextInputType + .numberWithOptions(), + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 5.0), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Target', + suffixText: 'mmol/l', + ), + controller: _mmolPerLTargetController, + onChanged: (_) => onChangeGlucose( + calculateFrom: + GlucoseMeasurement.mmolPerL), + keyboardType: const TextInputType + .numberWithOptions(), + ), + ), + ), + Expanded( + child: Padding( + padding: + const EdgeInsets.only(left: 5.0), + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Correction', + suffixText: 'mmol/l', + ), + controller: + _mmolPerLCorrectionController, + readOnly: true, + ), + ), + ), + glucoseDisplayMode == + GlucoseDisplayMode.both || + glucoseDisplayMode == + GlucoseDisplayMode.bothForDetail + ? IconButton( + onPressed: () => onChangeGlucose( + calculateFrom: + GlucoseMeasurement.mgPerDl), + icon: const Icon(Icons.calculate), + ) + : Container(), + ] + : [], + ), + ] + : [ + AutoCompleteDropdownButton( + selectedItem: _meal, + label: 'Meal', + items: _logMeals, + onChanged: (value) { + if (value != null) { + onSelectMeal(value); + } + }, + ), + TextFormField( + decoration: InputDecoration( + labelText: 'Carbs', + suffixText: nutritionMeasurement == + NutritionMeasurement.grams + ? 'g' + : nutritionMeasurement == + NutritionMeasurement.ounces + ? 'oz' + : '', + ), + controller: _carbsController, + onChanged: (_) => onChangeCarbs(), + keyboardType: const TextInputType.numberWithOptions( + decimal: true), + ), + ], ), TextFormField( decoration: const InputDecoration( diff --git a/lib/screens/log/log_entry/log_bolus_list.dart b/lib/screens/log/log_entry/log_bolus_list.dart index d5348f1..0490e9a 100644 --- a/lib/screens/log/log_entry/log_bolus_list.dart +++ b/lib/screens/log/log_entry/log_bolus_list.dart @@ -54,7 +54,7 @@ class _LogBolusListScreenState extends State { void onDelete(LogBolus logBolus) { LogBolus.remove(logBolus.id); - reload(message: 'Meal deleted'); + reload(message: 'Bolus deleted'); } void handleDeleteAction(LogBolus logBolus) async { @@ -94,9 +94,12 @@ class _LogBolusListScreenState extends State { final bolus = widget.logBoli[index]; return ListTile( onTap: () => handleEditAction(bolus), - title: Text( - '${bolus.units} U per ${bolus.carbs}${nutritionMeasurement == NutritionMeasurement.grams ? ' g' : ' oz'} carbs/${glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDl : bolus.mmolPerL} ${glucoseMeasurement == GlucoseMeasurement.mgPerDl ? 'mg/dl' : 'mmol/l'}'), + title: Text('${bolus.units} U'), + subtitle: Text(bolus.carbs != null ? + 'for ${bolus.meal.target.toString()} (${bolus.carbs}${nutritionMeasurement == NutritionMeasurement.grams ? ' g' : ' oz'} carbs)' + : 'to correct ${glucoseMeasurement == GlucoseMeasurement.mgPerDl ? bolus.mgPerDlCorrection : bolus.mmolPerLCorrection} ${glucoseMeasurement == GlucoseMeasurement.mgPerDl ? 'mg/dl' : 'mmol/l'}'), trailing: Row( + mainAxisSize: MainAxisSize.min, children: [ bolus.meal.target != null ? IconButton( diff --git a/lib/screens/log/log_entry/log_entry.dart b/lib/screens/log/log_entry/log_entry.dart index cb58fb6..907a0c4 100644 --- a/lib/screens/log/log_entry/log_entry.dart +++ b/lib/screens/log/log_entry/log_entry.dart @@ -45,9 +45,6 @@ class _LogEntryScreenState extends State { final _dateController = TextEditingController(text: ''); final _mgPerDlController = TextEditingController(text: ''); final _mmolPerLController = TextEditingController(text: ''); - final _bolusGlucoseController = TextEditingController(text: ''); - final _delayedBolusRateController = TextEditingController(text: ''); - final _delayedBolusDurationController = TextEditingController(text: ''); final _notesController = TextEditingController(text: ''); late FloatingActionButton addMealButton; @@ -105,11 +102,6 @@ class _LogEntryScreenState extends State { _time = _logEntry!.time; _mgPerDlController.text = (_logEntry!.mgPerDl ?? '').toString(); _mmolPerLController.text = (_logEntry!.mmolPerL ?? '').toString(); - _bolusGlucoseController.text = (_logEntry!.bolusGlucose ?? '').toString(); - _delayedBolusRateController.text = - (_logEntry!.delayedBolusRate ?? '').toString(); - _delayedBolusDurationController.text = - (_logEntry!.delayedBolusDuration ?? '').toString(); _notesController.text = _logEntry!.notes ?? ''; } @@ -183,10 +175,6 @@ class _LogEntryScreenState extends State { time: _time, mgPerDl: int.tryParse(_mgPerDlController.text), mmolPerL: double.tryParse(_mmolPerLController.text), - bolusGlucose: double.tryParse(_bolusGlucoseController.text), - delayedBolusDuration: - int.tryParse(_delayedBolusDurationController.text), - delayedBolusRate: double.tryParse(_delayedBolusRateController.text), notes: _notesController.text, )); Navigator.pushReplacementNamed(context, '/log', @@ -202,21 +190,11 @@ class _LogEntryScreenState extends State { ((_isNew && (int.tryParse(_mgPerDlController.text) != null || double.tryParse(_mmolPerLController.text) != null || - double.tryParse(_bolusGlucoseController.text) != null || - int.tryParse(_delayedBolusDurationController.text) != - null || - double.tryParse(_delayedBolusRateController.text) != null || _notesController.text != '')) || (!_isNew && (int.tryParse(_mgPerDlController.text) != _logEntry!.mgPerDl || double.tryParse(_mmolPerLController.text) != _logEntry!.mmolPerL || - double.tryParse(_bolusGlucoseController.text) != - _logEntry!.bolusGlucose || - int.tryParse(_delayedBolusDurationController.text) != - _logEntry!.delayedBolusDuration || - double.tryParse(_delayedBolusRateController.text) != - _logEntry!.delayedBolusRate || _notesController.text != (_logEntry!.notes ?? ''))))) { Dialogs.showCancelConfirmationDialog( context: context, @@ -383,7 +361,7 @@ class _LogEntryScreenState extends State { _mmolPerLController.text .trim() .isEmpty) { - return 'How many mg/dl or mmol/l does the rate make up for?'; + return 'How high is your blood sugar?'; } return null; }, @@ -425,7 +403,7 @@ class _LogEntryScreenState extends State { _mgPerDlController.text .trim() .isEmpty) { - return 'How many mg/dl or mmol/l does rhe rate make up for?'; + return 'How high is your blood sugar?'; } return null; }, @@ -445,33 +423,6 @@ class _LogEntryScreenState extends State { : Container(), ], ), - TextFormField( - decoration: const InputDecoration( - labelText: 'Bolus Units', - suffixText: 'U', - ), - controller: _bolusGlucoseController, - keyboardType: const TextInputType.numberWithOptions( - decimal: true), - ), - // ignore: todo - // TODO: change field functionality according to time format - TextFormField( - decoration: const InputDecoration( - labelText: 'Delayed Bolus Duration', - suffixText: ' min', - ), - controller: _delayedBolusDurationController, - keyboardType: TextInputType.number, - ), - TextFormField( - decoration: const InputDecoration( - labelText: 'Delayed Bolus Units', - ), - controller: _delayedBolusRateController, - keyboardType: const TextInputType.numberWithOptions( - decimal: true), - ), TextFormField( controller: _notesController, decoration: const InputDecoration( diff --git a/lib/screens/log/log_entry/log_meal_detail.dart b/lib/screens/log/log_entry/log_meal_detail.dart index d9fb917..5fd120d 100644 --- a/lib/screens/log/log_entry/log_meal_detail.dart +++ b/lib/screens/log/log_entry/log_meal_detail.dart @@ -38,9 +38,6 @@ class _LogMealDetailScreenState extends State { final _carbsRatioController = TextEditingController(text: ''); final _portionSizeController = TextEditingController(text: ''); final _carbsPerPortionController = TextEditingController(text: ''); - final _bolusController = TextEditingController(text: ''); - final _delayedBolusRateController = TextEditingController(text: ''); - final _delayedBolusDurationController = TextEditingController(text: ''); final _notesController = TextEditingController(text: ''); Meal? _meal; @@ -75,11 +72,6 @@ class _LogMealDetailScreenState extends State { _portionSizeController.text = (_logMeal!.portionSize ?? '').toString(); _carbsPerPortionController.text = (_logMeal!.carbsPerPortion ?? '').toString(); - _bolusController.text = (_logMeal!.bolus ?? '').toString(); - _delayedBolusRateController.text = - (_logMeal!.delayedBolusRate ?? '').toString(); - _delayedBolusDurationController.text = - (_logMeal!.delayedBolusDuration ?? '').toString(); _notesController.text = _logMeal!.notes ?? ''; } } @@ -106,13 +98,6 @@ class _LogMealDetailScreenState extends State { if (meal.carbsPerPortion != null) { _carbsPerPortionController.text = meal.carbsPerPortion.toString(); } - if (meal.delayedBolusRate != null) { - _delayedBolusRateController.text = meal.delayedBolusRate.toString(); - } - if (meal.delayedBolusDuration != null) { - _delayedBolusDurationController.text = - meal.delayedBolusDuration.toString(); - } if (meal.mealSource.hasValue) { _mealSource = meal.mealSource.target; } @@ -142,11 +127,6 @@ class _LogMealDetailScreenState extends State { carbsRatio: double.tryParse(_carbsRatioController.text), portionSize: double.tryParse(_portionSizeController.text), carbsPerPortion: double.tryParse(_carbsPerPortionController.text), - bolus: double.tryParse(_bolusController.text), - delayedBolusDuration: - int.tryParse(_delayedBolusDurationController.text), - delayedBolusRate: double.tryParse(_delayedBolusRateController.text), - notes: _notesController.text, ); logMeal.logEntry.targetId = widget.logEntryId; logMeal.meal.target = _meal; @@ -177,10 +157,6 @@ class _LogMealDetailScreenState extends State { double.tryParse(_carbsPerPortionController.text) != null || _carbsRatioAccuracy != null || _portionSizeAccuracy != null || - double.tryParse(_bolusController.text) != null || - int.tryParse(_delayedBolusDurationController.text) != - null || - double.tryParse(_delayedBolusRateController.text) != null || _notesController.text != '')) || (!_isNew && (_valueController.text != _logMeal!.value || @@ -198,11 +174,6 @@ class _LogMealDetailScreenState extends State { _logMeal!.carbsRatioAccuracy.target || _portionSizeAccuracy != _logMeal!.portionSizeAccuracy.target || - double.tryParse(_bolusController.text) != _logMeal!.bolus || - int.tryParse(_delayedBolusDurationController.text) != - _logMeal!.delayedBolusDuration || - double.tryParse(_delayedBolusRateController.text) != - _logMeal!.delayedBolusRate || _notesController.text != (_logMeal!.notes ?? ''))))) { Dialogs.showCancelConfirmationDialog( context: context, @@ -428,33 +399,6 @@ class _LogMealDetailScreenState extends State { }); }, ), - TextFormField( - decoration: const InputDecoration( - labelText: 'Bolus Units', - suffixText: ' U', - ), - controller: _bolusController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - ), - TextFormField( - decoration: const InputDecoration( - labelText: 'Delayed Bolus Duration', - suffixText: ' min', - ), - controller: _delayedBolusDurationController, - keyboardType: const TextInputType.numberWithOptions(), - ), - TextFormField( - decoration: const InputDecoration( - labelText: 'Delayed Bolus Units', - suffixText: ' U', - alignLabelWithHint: true, - ), - controller: _delayedBolusRateController, - keyboardType: - const TextInputType.numberWithOptions(decimal: true), - ), TextFormField( controller: _notesController, decoration: const InputDecoration(