Skip to content

Commit

Permalink
Update BP categorisation with WHO standards (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
tubopo authored Nov 11, 2023
1 parent 1b2e441 commit d8041b3
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 150 deletions.
12 changes: 7 additions & 5 deletions assets/i18n/be_BLR.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"dismiss": "Закрыць",
"category": {
"LOW": "Нізкае",
"OPTIMAL": "Аптымальнае",
"NORMAL": "Нармальнае",
"ELEVATED": "Павышаннае",
"HYPERTENSION_STAGE_1": "Гіпертанія I стадыя",
"HYPERTENSION_STAGE_2": "Гіпертанія II стадыя",
"HYPERTENSION_CRISIS": "Гіпертанічны крыз"
"HIGH_NORMAL": "Павышаннае",
"GRADE_1_HYPERTENSION": "Гіпертанія I стадыя",
"GRADE_2_HYPERTENSION": "Гіпертанія II стадыя",
"GRADE_3_HYPERTENSION": "Гіпертанія III стадыя",
"ISOLATED_SYSTOLIC_HYPERTENSION": "Гіпертанічны крыз"
},
"appearance": "Знешні выгляд",
"system": "Cістэмны",
Expand All @@ -28,4 +30,4 @@
"en": "English",
"ru": "Русский",
"be": "Беларуская"
}
}
10 changes: 6 additions & 4 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"dismiss": "Dismiss",
"category": {
"LOW": "Low",
"OPTIMAL": "Optimal",
"NORMAL": "Normal",
"ELEVATED": "Pre-High",
"HYPERTENSION_STAGE_1": "Hypertension stage 1",
"HYPERTENSION_STAGE_2": "Hypertension stage 2",
"HYPERTENSION_CRISIS": "Hypertension crisis"
"HIGH_NORMAL": "High Normal",
"GRADE_1_HYPERTENSION": "Hypertension grade 1",
"GRADE_2_HYPERTENSION": "Hypertension grade 2",
"GRADE_3_HYPERTENSION": "Hypertension grade 3",
"ISOLATED_SYSTOLIC_HYPERTENSION": "Systolic Hypertension"
},
"appearance": "Appearance",
"system": "System",
Expand Down
12 changes: 7 additions & 5 deletions assets/i18n/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"dismiss": "Закрыть",
"category": {
"LOW": "Низкое",
"OPTIMAL": "Оптимальное",
"NORMAL": "Норма",
"ELEVATED": "Повышенное",
"HYPERTENSION_STAGE_1": "Гипертония I",
"HYPERTENSION_STAGE_2": "Гипертония II",
"HYPERTENSION_CRISIS": "Гипертонический криз"
"HIGH_NORMAL": "Повышенное",
"GRADE_1_HYPERTENSION": "Гипертония I",
"GRADE_2_HYPERTENSION": "Гипертония II",
"GRADE_3_HYPERTENSION": "Гипертония III",
"ISOLATED_SYSTOLIC_HYPERTENSION": "Гипертонический криз"
},
"appearance": "Внешний вид",
"system": "Системный",
Expand All @@ -28,4 +30,4 @@
"en": "English",
"ru": "Русский",
"be": "Беларуская"
}
}
57 changes: 25 additions & 32 deletions lib/modules/home/service/list_data_transform.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:sys_dia_log/modules/home/model/list_data.dart';
import 'package:sys_dia_log/modules/home/model/list_item.dart';
import 'package:sys_dia_log/modules/measurement/models/blood_pressure_category.dart';
import 'package:sys_dia_log/modules/measurement/models/measurement.dart';
import 'package:sys_dia_log/modules/measurement/service/blood_pressure_category_calc.dart';

class ListDataTransform {
static List<ListItem> transform(Iterable<Measurement> data) {
return _sorted(data)
.map((e) => ListData(
e.bloodPressure.systolic,
e.bloodPressure.diastolic,
_toCategoryDisplayName(e.bloodPressure.category),
_toCategoryColor(e.bloodPressure.category),
e.pulse.bpm,
e.createdAt.toLocal()))
.map((e) => ListItem(e))
.toList();
}
List<ListItem> transformListData(List<Measurement> data) {
//sort data by created date
data.sort((b, a) => a.createdAt.compareTo(b.createdAt));

static List _sorted(Iterable<Measurement> data) {
List sorted = data.toList();
sorted.sort((b, a) => a.createdAt.compareTo(b.createdAt));
return sorted;
}
return data
.map((Measurement m) => _mapToListData(m))
.map((ListData d) => ListItem(d))
.toList();
}

static String _toCategoryDisplayName(String category) {
return "category.$category";
}
ListData _mapToListData(Measurement data) {
int sys = data.bloodPressure.systolic;
int dia = data.bloodPressure.diastolic;

static const colorsMap = <String, Color>{
"LOW": Colors.grey,
"NORMAL": Colors.green,
"ELEVATED": Colors.yellow,
"HYPERTENSION_STAGE_1": Colors.amber,
"HYPERTENSION_STAGE_2": Colors.orange,
"HYPERTENSION_CRISIS": Colors.red,
};
BloodPressureCategory? category =
getBPCategoryByValues(systolic: sys, diastolic: dia);

static Color _toCategoryColor(String category) {
return colorsMap[category] ?? Colors.transparent;
}
return ListData(
sys,
dia,
"category.${(category?.jsonValue ?? "-")}", // unknown category displayed as '-'
Color(category?.hexColor ?? 0xFF424242), //unknown category color as grey
data.pulse.bpm,
data.createdAt,
);
}
2 changes: 1 addition & 1 deletion lib/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _HomeViewState extends State<HomeView>
valueListenable:
Hive.box<Measurement>(measurementsBox).listenable(),
builder: (context, data, child) => MeasurementsList(
items: ListDataTransform.transform(data.values)),
items: transformListData(data.values.toList())),
);
},
),
Expand Down
10 changes: 1 addition & 9 deletions lib/modules/measurement/models/blood_pressure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,31 @@ part 'blood_pressure.g.dart';
/// {
/// "systolic": 120,
/// "diastolic": 80,
/// "category": "HIGH"
/// }
@HiveType(typeId: 1, adapterName: 'BloodPressureHiveAdapter')
class BloodPressure extends HiveObject {
static const String _systolicJsonKey = 'systolic';
static const String _diastolicJsonKey = 'diastolic';
static const String _categoryJsonKey = 'category';

@HiveField(0)
final int systolic;

@HiveField(1)
final int diastolic;

@HiveField(2)
final String category;

BloodPressure({
required this.systolic,
required this.diastolic,
required this.category,
});

BloodPressure.fromMap(Map<String, dynamic> json)
: systolic = json[_systolicJsonKey] as int,
diastolic = json[_diastolicJsonKey] as int,
category = json[_categoryJsonKey] as String;
diastolic = json[_diastolicJsonKey] as int;

Map<String, dynamic> toMap() {
return {
_systolicJsonKey: systolic,
_diastolicJsonKey: diastolic,
_categoryJsonKey: category,
};
}
}
7 changes: 2 additions & 5 deletions lib/modules/measurement/models/blood_pressure.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 35 additions & 7 deletions lib/modules/measurement/models/blood_pressure_category.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
/// The World Health Organization (WHO) and the International Society of Hypertension (ISH) categorizations
enum BloodPressureCategory {
low("LOW"),
normal("NORMAL"),
elevated("ELEVATED"),
hypertensionStage1("HYPERTENSION_STAGE_1"),
hypertensionStage2("HYPERTENSION_STAGE_2"),
hypertensionCrisis("HYPERTENSION_CRISIS");
low(
"LOW",
0xFF42A5F5, //light blue
),
optimal(
"OPTIMAL",
0xFFC8E6C9, //light green
),
normal(
"NORMAL",
0xFFA5D6A7, //green
),
highNormal(
"HIGH_NORMAL",
0xFFFFFF00, //yellow
),
grade1Hypertension(
"GRADE_1_HYPERTENSION",
0xFFFF5722, //dark orange
),
grade2Hypertension(
"GRADE_2_HYPERTENSION",
0xFFE91E63, //pink
),
grade3Hypertension(
"GRADE_3_HYPERTENSION",
0xFFD32F2F, // dark red
),
isolatedSystolicHypertension(
"ISOLATED_SYSTOLIC_HYPERTENSION",
0xFF9C27B0, //purple
);

final String jsonValue;
final int hexColor;

const BloodPressureCategory(this.jsonValue);
const BloodPressureCategory(this.jsonValue, this.hexColor);
}
10 changes: 3 additions & 7 deletions lib/modules/measurement/models/measurement.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:hive/hive.dart';
import 'package:sys_dia_log/modules/measurement/models/blood_pressure_category.dart';

import 'blood_pressure.dart';
import 'pulse.dart';

Expand All @@ -11,7 +11,6 @@ part 'measurement.g.dart';
/// "bloodPressure" : {
/// "systolic": 110,
/// "diastolic": 90,
/// "category": "NORMAL"
/// },
/// "pulse": {
/// "bpm" : 65
Expand Down Expand Up @@ -42,13 +41,10 @@ class Measurement extends HiveObject {
Measurement.values({
required int systolic,
required int diastolic,
required BloodPressureCategory category,
required int bpm,
}) : this(
bloodPressure: BloodPressure(
systolic: systolic,
diastolic: diastolic,
category: category.jsonValue),
bloodPressure:
BloodPressure(systolic: systolic, diastolic: diastolic),
pulse: Pulse(bpm: bpm),
createdAt: DateTime.now().toUtc(),
);
Expand Down
84 changes: 52 additions & 32 deletions lib/modules/measurement/service/blood_pressure_category_calc.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
import 'package:sys_dia_log/modules/measurement/models/blood_pressure_category.dart';

class BloodPressureCategoryCalc {
/// normal: sys < 120 and dia < 80
/// elevated: sys < [120-129] and dia < 80
/// stage1: sys < [130-139] or dia < [80-89]
/// stage2: sys > 140 or dia > 90
/// crisis: sys > 180 and/or > 120
BloodPressureCategory getCategoryByValues({
required int systolic,
required int diastolic,
}) {
if (systolic <= 70 && diastolic <= 40) {
return BloodPressureCategory.low;
}

if (systolic < 120 && diastolic <= 80) {
return BloodPressureCategory.normal;
}

if (systolic < 129 && diastolic <= 80) {
return BloodPressureCategory.elevated;
}

if (systolic < 139 || diastolic < 89) {
return BloodPressureCategory.hypertensionStage1;
}

if ((systolic >= 140 && systolic < 180) ||
(diastolic >= 90 && diastolic < 120)) {
return BloodPressureCategory.hypertensionStage2;
}

return BloodPressureCategory.hypertensionCrisis;
///Optimal Blood Pressure:
// Systolic: Less than 120 mm Hg
// Diastolic: Less than 80 mm Hg
//
// Normal Blood Pressure:
// Systolic: 120-129 mm Hg
// Diastolic: 80-84 mm Hg
//
// High-Normal Blood Pressure:
// Systolic: 130-139 mm Hg
// Diastolic: 85-89 mm Hg
//
// Grade 1 Hypertension (Mild):
// Systolic: 140-159 mm Hg
// Diastolic: 90-99 mm Hg
//
// Grade 2 Hypertension (Moderate):
// Systolic: 160-179 mm Hg
// Diastolic: 100-109 mm Hg
//
// Grade 3 Hypertension (Severe):
// Systolic: 180 mm Hg or higher
// Diastolic: 110 mm Hg or higher
//
// Isolated Systolic Hypertension:
// Systolic: 140 mm Hg or higher
// Diastolic: Less than 90 mm Hg
BloodPressureCategory? getBPCategoryByValues({
required int systolic,
required int diastolic,
}) {
if (systolic < 90 || diastolic < 60) {
return BloodPressureCategory.low;
} else if (systolic < 120 && diastolic < 80) {
return BloodPressureCategory.optimal;
} else if ((systolic >= 120 && systolic <= 129) &&
(diastolic >= 60 && diastolic <= 84)) {
return BloodPressureCategory.normal;
} else if ((systolic >= 130 && systolic <= 139) ||
(diastolic >= 85 && diastolic <= 89)) {
return BloodPressureCategory.highNormal;
} else if (systolic >= 140 && diastolic < 90) {
return BloodPressureCategory.isolatedSystolicHypertension;
} else if ((systolic >= 140 && systolic <= 159) &&
(diastolic >= 90 && diastolic <= 99)) {
return BloodPressureCategory.grade1Hypertension;
} else if ((systolic >= 160 && systolic <= 179) &&
(diastolic >= 100 && diastolic <= 109)) {
return BloodPressureCategory.grade2Hypertension;
} else if (systolic >= 180 || diastolic >= 110) {
return BloodPressureCategory.grade3Hypertension;
}
return null;
}
5 changes: 0 additions & 5 deletions lib/modules/measurement/service/measurement_service.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import 'package:hive/hive.dart';
import 'package:sys_dia_log/hive/hive_box.dart';
import 'package:sys_dia_log/modules/measurement/models/measurement.dart';
import 'package:sys_dia_log/modules/measurement/service/blood_pressure_category_calc.dart';

class MeasurementService {
final BloodPressureCategoryCalc categoryCalc = BloodPressureCategoryCalc();
final Box<Measurement> box = Hive.box(measurementsBox);

Measurement createNewMeasurement(int sys, int dia, int bpm) {
final measurement = Measurement.values(
systolic: sys,
diastolic: dia,
category: categoryCalc.getCategoryByValues(systolic: sys, diastolic: dia),
bpm: bpm,
);

box.add(measurement);

return measurement;
}
}
Loading

0 comments on commit d8041b3

Please sign in to comment.