-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update BP categorisation with WHO standards (#4)
- Loading branch information
Showing
12 changed files
with
170 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
42 changes: 35 additions & 7 deletions
42
lib/modules/measurement/models/blood_pressure_category.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 52 additions & 32 deletions
84
lib/modules/measurement/service/blood_pressure_category_calc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.