You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/medical/my_trackers/blood_pressure/BloodPressureYeaPage.dart

115 lines
4.8 KiB
Dart

import "package:collection/collection.dart";
import 'package:diplomaticquarterapp/core/viewModels/medical/blood_pressure_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/medical/my_trackers/widget/CurvedChartBloodPressure.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/LineChartCurvedBloodPressure.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class BloodPressureYearPage extends StatelessWidget {
final BloodPressureViewMode model;
BloodPressureYearPage({Key? key, required this.model}) : super(key: key);
List<List> monthlyGroup = [];
late ProjectViewModel projectViewModel;
@override
Widget build(BuildContext context) {
// if (projectViewModel == null)
projectViewModel = Provider.of(context);
groupData();
return ListView(
children: [
Container(
margin: EdgeInsets.only(top: 12, left: 8, right: 8),
color: Colors.white,
child: LineChartCurvedBloodPressure(
title: TranslationBase.of(context).bloodPressure,
timeSeries1: model.weightYearTimeSeriesDataTop.isEmpty ? [TimeSeriesSales2(DateTime.now(), 0.0)] : model.weightYearTimeSeriesDataTop,
timeSeries2: model.weightYearTimeSeriesDataLow.isEmpty ? [TimeSeriesSales2(DateTime.now(), 0.0)] : model.weightYearTimeSeriesDataLow,
indexes: model.weightWeekTimeSeriesDataLow.length ~/ 5.5,
),
),
SizedBox(
height: 12,
),
Container(
padding: EdgeInsets.all(10),
color: Colors.transparent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
model.weightYearTimeSeriesDataTop.isEmpty
? Container(
child: Center(
child: Texts(TranslationBase.of(context).noDataAvailable),
),
)
: Column(children: [
for (var monthly in monthlyGroup)
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(
width: double.maxFinite,
padding: EdgeInsets.only(top: 10, bottom: 10, left: 5, right: 5),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5)),
child: Texts(monthly[0])),
Table(
columnWidths: {
0: FlexColumnWidth(1.8),
2: FlexColumnWidth(1.8),
},
children: fullData(context, monthly[1]),
)
])
]),
SizedBox(height: 80)
],
),
)
],
);
}
List<TableRow> fullData(BuildContext context, model) {
List<TableRow> tableRow = [];
tableRow.add(
TableRow(
children: [
Utils.tableColumnTitle(TranslationBase.of(context).date),
Utils.tableColumnTitle(TranslationBase.of(context).time),
Utils.tableColumnTitle(TranslationBase.of(context).arm),
Utils.tableColumnTitle(TranslationBase.of(context).value),
],
),
);
model.forEach(
(diabtec) {
tableRow.add(
TableRow(
children: [
Utils.tableColumnValue('${DateUtil.getDayMonthYearDateFormatted(diabtec.bloodPressureDate)}', isCapitable: false, mProjectViewModel: projectViewModel),
Utils.tableColumnValue('${diabtec.bloodPressureDate.hour}:${diabtec.bloodPressureDate.minute}', isCapitable: false, mProjectViewModel: projectViewModel),
Utils.tableColumnValue(diabtec.measuredArmDesc, isCapitable: false, mProjectViewModel: projectViewModel),
Utils.tableColumnValue('${diabtec.systolicePressure}/${diabtec.diastolicPressure}', isCapitable: false, mProjectViewModel: projectViewModel),
],
),
);
},
);
return tableRow;
}
groupData() {
monthlyGroup.clear();
var groupedArray = groupBy(model.bloodPressureService.yearDiabtecPatientResult.reversed, (obj) => DateUtil.getMonth(obj.bloodPressureDate!.month) + ' ' + obj.bloodPressureDate!.year.toString());
groupedArray.entries.forEach((e) => monthlyGroup.add([e.key, e.value]));
}
}