2021-10-26 23:25:40 +00:00
|
|
|
// import 'package:diameter/config.dart';
|
|
|
|
// import 'package:diameter/settings.dart';
|
|
|
|
// import 'package:diameter/utils/date_time_utils.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:diameter/utils/utils.dart';
|
2021-10-26 23:25:40 +00:00
|
|
|
// import 'package:flutter/material.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
|
|
|
|
import 'package:diameter/components/data_table.dart';
|
|
|
|
import 'package:diameter/models/bolus_profile.dart';
|
|
|
|
|
|
|
|
class Bolus extends DataTableContent {
|
|
|
|
late String? objectId;
|
|
|
|
late DateTime startTime;
|
|
|
|
late DateTime endTime;
|
|
|
|
late double units;
|
|
|
|
late double carbs;
|
|
|
|
late int? mgPerDl;
|
|
|
|
late double? mmolPerL;
|
|
|
|
late String bolusProfile;
|
|
|
|
|
|
|
|
Bolus(ParseObject? object) {
|
|
|
|
if (object != null) {
|
|
|
|
objectId = object.get<String>('objectId');
|
2021-10-26 23:25:40 +00:00
|
|
|
startTime = object.get<DateTime>('startTime')!.toLocal();
|
|
|
|
endTime = object.get<DateTime>('endTime')!.toLocal();
|
2021-10-22 23:08:09 +00:00
|
|
|
units = object.get<num>('units')! / 100;
|
|
|
|
carbs = object.get<num>('carbs')!.toDouble();
|
|
|
|
mgPerDl = object.get<num>('mgPerDl') != null
|
|
|
|
? object.get<num>('mgPerDl')!.toInt()
|
|
|
|
: null;
|
|
|
|
mmolPerL = object.get<num>('mmolPerL') != null
|
|
|
|
? object.get<num>('mmolPerL')! / 100
|
|
|
|
: null;
|
|
|
|
bolusProfile =
|
|
|
|
object.get<ParseObject>('bolusProfile')!.get<String>('objectId')!;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Bolus?> get(String objectId) async {
|
|
|
|
QueryBuilder<ParseObject> query =
|
|
|
|
QueryBuilder<ParseObject>(ParseObject('Bolus'))
|
|
|
|
..whereEqualTo('objectId', objectId);
|
2021-10-26 23:25:40 +00:00
|
|
|
|
2021-10-22 23:08:09 +00:00
|
|
|
final ParseResponse apiResponse = await query.query();
|
|
|
|
|
|
|
|
if (apiResponse.success && apiResponse.results != null) {
|
|
|
|
return Bolus(apiResponse.result.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<List<Bolus>> fetchAllForBolusProfile(
|
|
|
|
BolusProfile bolusProfile) async {
|
|
|
|
QueryBuilder<ParseObject> query =
|
|
|
|
QueryBuilder<ParseObject>(ParseObject('Bolus'))
|
|
|
|
..whereEqualTo(
|
|
|
|
'bolusProfile',
|
|
|
|
(ParseObject('BolusProfile')..objectId = bolusProfile.objectId!)
|
2021-10-26 23:25:40 +00:00
|
|
|
.toPointer())
|
|
|
|
..orderByAscending('startTime');
|
2021-10-22 23:08:09 +00:00
|
|
|
final ParseResponse apiResponse = await query.query();
|
|
|
|
|
|
|
|
if (apiResponse.success && apiResponse.results != null) {
|
|
|
|
return apiResponse.results!.map((e) => Bolus(e as ParseObject)).toList();
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> save({
|
|
|
|
required DateTime startTime,
|
|
|
|
required DateTime endTime,
|
|
|
|
required double units,
|
|
|
|
required double carbs,
|
|
|
|
int? mgPerDl,
|
|
|
|
double? mmolPerL,
|
|
|
|
required String bolusProfile,
|
|
|
|
}) async {
|
|
|
|
final bolus = ParseObject('Bolus')
|
2021-10-26 23:25:40 +00:00
|
|
|
..set('startTime', startTime.toUtc())
|
|
|
|
..set('endTime', endTime.toUtc())
|
2021-10-22 23:08:09 +00:00
|
|
|
..set('units', units * 100)
|
|
|
|
..set('carbs', carbs.round())
|
|
|
|
..set('bolusProfile',
|
|
|
|
(ParseObject('BolusProfile')..objectId = bolusProfile).toPointer());
|
|
|
|
|
|
|
|
bolus.set(
|
|
|
|
'mgPerDl',
|
|
|
|
mgPerDl != null
|
|
|
|
? mgPerDl.round()
|
|
|
|
: Utils.convertMmolPerLToMgPerDl(mmolPerL ?? 0));
|
|
|
|
bolus.set(
|
|
|
|
'mmolPerL',
|
|
|
|
mmolPerL != null
|
|
|
|
? mmolPerL * 100
|
|
|
|
: Utils.convertMgPerDlToMmolPerL(mgPerDl ?? 0) * 100);
|
|
|
|
|
|
|
|
await bolus.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> update(
|
|
|
|
String objectId, {
|
|
|
|
DateTime? startTime,
|
|
|
|
DateTime? endTime,
|
|
|
|
double? units,
|
|
|
|
double? carbs,
|
|
|
|
int? mgPerDl,
|
|
|
|
double? mmolPerL,
|
|
|
|
}) async {
|
|
|
|
var bolus = ParseObject('Bolus')..objectId = objectId;
|
|
|
|
if (startTime != null) {
|
2021-10-26 23:25:40 +00:00
|
|
|
bolus.set('startTime', startTime.toUtc());
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
if (endTime != null) {
|
2021-10-26 23:25:40 +00:00
|
|
|
bolus.set('endTime', endTime.toUtc());
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
if (units != null) {
|
|
|
|
bolus.set('units', units * 100);
|
|
|
|
}
|
|
|
|
if (carbs != null) {
|
|
|
|
bolus.set('carbs', carbs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mgPerDl != null || mmolPerL != null) {
|
|
|
|
bolus.set(
|
|
|
|
'mgPerDl',
|
|
|
|
mgPerDl != null
|
|
|
|
? mgPerDl.round()
|
|
|
|
: Utils.convertMmolPerLToMgPerDl(mmolPerL ?? 0));
|
|
|
|
bolus.set(
|
|
|
|
'mmolPerL',
|
|
|
|
mmolPerL != null
|
|
|
|
? mmolPerL * 100
|
|
|
|
: Utils.convertMgPerDlToMmolPerL(mgPerDl ?? 0) * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
await bolus.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> delete() async {
|
|
|
|
var bolus = ParseObject('Bolus')..objectId = objectId;
|
|
|
|
await bolus.delete();
|
|
|
|
}
|
2021-10-26 23:25:40 +00:00
|
|
|
//
|
|
|
|
// @override
|
|
|
|
// List<DataCell> asDataTableCells(List<Widget>? actions) {
|
|
|
|
// var cols = [
|
|
|
|
// DataCell(Text(DateTimeUtils.displayTime(startTime))),
|
|
|
|
// DataCell(Text(DateTimeUtils.displayTime(endTime))),
|
|
|
|
// DataCell(Text('${units.toString()} U')),
|
|
|
|
// DataCell(Text('${carbs.toString()} g')),
|
|
|
|
// ];
|
|
|
|
//
|
|
|
|
// if (glucoseMeasurement == GlucoseMeasurement.mgPerDl ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.both ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.bothForList) {
|
|
|
|
// cols.add(DataCell(Text('${mgPerDl.toString()} mg/dl')));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (glucoseMeasurement == GlucoseMeasurement.mmolPerL ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.both ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.bothForList) {
|
|
|
|
// cols.add(DataCell(Text('${mmolPerL.toString()} mmol/l')));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// cols.add(
|
|
|
|
// DataCell(
|
|
|
|
// Row(
|
|
|
|
// children: actions ?? [],
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// return cols;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// static List<DataColumn> asDataTableColumns() {
|
|
|
|
// var cols = [
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Start Time'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('End Time'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Units'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('per Carbs'))),
|
|
|
|
// ];
|
|
|
|
//
|
|
|
|
// if (glucoseMeasurement == GlucoseMeasurement.mgPerDl ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.both ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.bothForList) {
|
|
|
|
// cols.add(const DataColumn(label: Expanded(child: Text('per mg/dl'))));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (glucoseMeasurement == GlucoseMeasurement.mmolPerL ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.both ||
|
|
|
|
// glucoseDisplayMode == GlucoseDisplayMode.bothForList) {
|
|
|
|
// cols.add(const DataColumn(label: Expanded(child: Text('per mmol/l'))));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// cols.add(
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Actions'))),
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// return cols;
|
|
|
|
// }
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|