Skip to content

Commit

Permalink
Merge pull request #579 from xjodoin/new_data_types
Browse files Browse the repository at this point in the history
[health] Add support for RESPIRATORY_RATE and PERIPHERAL_PERFUSION_INDEX
  • Loading branch information
hoffmatteo authored Jul 20, 2023
2 parents 502563a + 1d1aa45 commit b2114ab
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Note that for Android, the target phone **needs** to have [Google Fit](https://w
| HEART_RATE | BEATS_PER_MINUTE | yes | yes | yes | |
| HEIGHT | METERS | yes | yes | yes | |
| RESTING_HEART_RATE | BEATS_PER_MINUTE | yes | | yes | |
| RESPIRATORY_RATE | RESPIRATIONS_PER_MINUTE | yes | | |
| PERIPHERAL_PERFUSION_INDEX | PERCENTAGE | yes | | |
| STEPS | COUNT | yes | yes | yes | |
| WAIST_CIRCUMFERENCE | METERS | yes | | | |
| WALKING_HEART_RATE | BEATS_PER_MINUTE | yes | | | |
Expand Down
10 changes: 8 additions & 2 deletions packages/health/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _HealthAppState extends State<HealthApp> {
// NOTE: These are only the ones supported on Androids new API Health Connect.
// Both Android's Google Fit and iOS' HealthKit have more types that we support in the enum list [HealthDataType]
// Add more - like AUDIOGRAM, HEADACHE_SEVERE etc. to try them.
static final types = dataTypesAndroid;
static final types = dataTypesIOS;
// Or selected types
// static final types = [
// HealthDataType.WEIGHT,
Expand Down Expand Up @@ -169,7 +169,7 @@ class _HealthAppState extends State<HealthApp> {
0.0, HealthDataType.SLEEP_AWAKE, earlier, now);
success &= await health.writeHealthData(
0.0, HealthDataType.SLEEP_DEEP, earlier, now);
*/
success &= await health.writeHealthData(
50.0, HealthDataType.RESTING_HEART_RATE, earlier, now);
Expand All @@ -180,6 +180,12 @@ class _HealthAppState extends State<HealthApp> {
success &= await health.writeHealthData(
50, HealthDataType.BASAL_ENERGY_BURNED, earlier, now);
*/
success &= await health.writeHealthData(
50, HealthDataType.RESPIRATORY_RATE, earlier, now);
success &= await health.writeHealthData(
50, HealthDataType.PERIPHERAL_PERFUSION_INDEX, earlier, now);

// Store an Audiogram
// Uncomment these on iOS - only available on iOS
// const frequencies = [125.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0];
Expand Down
14 changes: 8 additions & 6 deletions packages/health/example/lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const List<HealthDataType> dataTypesIOS = [
HealthDataType.HEART_RATE,
HealthDataType.HEART_RATE_VARIABILITY_SDNN,
HealthDataType.HEIGHT,
HealthDataType.HIGH_HEART_RATE_EVENT,
HealthDataType.IRREGULAR_HEART_RATE_EVENT,
HealthDataType.LOW_HEART_RATE_EVENT,
//HealthDataType.HIGH_HEART_RATE_EVENT,
HealthDataType.RESPIRATORY_RATE,
HealthDataType.PERIPHERAL_PERFUSION_INDEX,
//HealthDataType.IRREGULAR_HEART_RATE_EVENT,
//HealthDataType.LOW_HEART_RATE_EVENT,
HealthDataType.RESTING_HEART_RATE,
HealthDataType.STEPS,
HealthDataType.WAIST_CIRCUMFERENCE,
HealthDataType.WALKING_HEART_RATE,
//HealthDataType.WALKING_HEART_RATE,
HealthDataType.WEIGHT,
HealthDataType.FLIGHTS_CLIMBED,
HealthDataType.DISTANCE_WALKING_RUNNING,
Expand All @@ -38,14 +40,14 @@ const List<HealthDataType> dataTypesIOS = [
HealthDataType.SLEEP_DEEP,
HealthDataType.SLEEP_REM,
HealthDataType.WATER,
HealthDataType.EXERCISE_TIME,
//HealthDataType.EXERCISE_TIME,
HealthDataType.WORKOUT,
HealthDataType.HEADACHE_NOT_PRESENT,
HealthDataType.HEADACHE_MILD,
HealthDataType.HEADACHE_MODERATE,
HealthDataType.HEADACHE_SEVERE,
HealthDataType.HEADACHE_UNSPECIFIED,
HealthDataType.ELECTROCARDIOGRAM,
//HealthDataType.ELECTROCARDIOGRAM,
];

/// List of data types available on Android
Expand Down
7 changes: 7 additions & 0 deletions packages/health/ios/Classes/SwiftHealthPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
let IRREGULAR_HEART_RATE_EVENT = "IRREGULAR_HEART_RATE_EVENT"
let LOW_HEART_RATE_EVENT = "LOW_HEART_RATE_EVENT"
let RESTING_HEART_RATE = "RESTING_HEART_RATE"
let RESPIRATORY_RATE = "RESPIRATORY_RATE"
let PERIPHERAL_PERFUSION_INDEX = "PERIPHERAL_PERFUSION_INDEX"
let STEPS = "STEPS"
let WAIST_CIRCUMFERENCE = "WAIST_CIRCUMFERENCE"
let WALKING_HEART_RATE = "WALKING_HEART_RATE"
Expand Down Expand Up @@ -107,6 +109,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
let COUNT = "COUNT"
let PERCENT = "PERCENT"
let BEATS_PER_MINUTE = "BEATS_PER_MINUTE"
let RESPIRATIONS_PER_MINUTE = "RESPIRATIONS_PER_MINUTE"
let MILLIGRAM_PER_DECILITER = "MILLIGRAM_PER_DECILITER"
let UNKNOWN_UNIT = "UNKNOWN_UNIT"
let NO_UNIT = "NO_UNIT"
Expand Down Expand Up @@ -763,6 +766,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
unitDict[COUNT] = HKUnit.count()
unitDict[PERCENT] = HKUnit.percent()
unitDict[BEATS_PER_MINUTE] = HKUnit.init(from: "count/min")
unitDict[RESPIRATIONS_PER_MINUTE] = HKUnit.init(from: "count/min")
unitDict[MILLIGRAM_PER_DECILITER] = HKUnit.init(from: "mg/dL")
unitDict[UNKNOWN_UNIT] = HKUnit.init(from: "")
unitDict[NO_UNIT] = HKUnit.init(from: "")
Expand Down Expand Up @@ -859,6 +863,9 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
forIdentifier: .basalEnergyBurned)!
dataTypesDict[BLOOD_GLUCOSE] = HKSampleType.quantityType(forIdentifier: .bloodGlucose)!
dataTypesDict[BLOOD_OXYGEN] = HKSampleType.quantityType(forIdentifier: .oxygenSaturation)!
dataTypesDict[RESPIRATORY_RATE] = HKSampleType.quantityType(forIdentifier: .respiratoryRate)!
dataTypesDict[PERIPHERAL_PERFUSION_INDEX] = HKSampleType.quantityType(forIdentifier: .peripheralPerfusionIndex)!

dataTypesDict[BLOOD_PRESSURE_DIASTOLIC] = HKSampleType.quantityType(
forIdentifier: .bloodPressureDiastolic)!
dataTypesDict[BLOOD_PRESSURE_SYSTOLIC] = HKSampleType.quantityType(
Expand Down
7 changes: 7 additions & 0 deletions packages/health/lib/src/data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum HealthDataType {
HEART_RATE_VARIABILITY_SDNN,
HEIGHT,
RESTING_HEART_RATE,
RESPIRATORY_RATE,
PERIPHERAL_PERFUSION_INDEX,
STEPS,
WAIST_CIRCUMFERENCE,
WALKING_HEART_RATE,
Expand Down Expand Up @@ -87,6 +89,8 @@ const List<HealthDataType> _dataTypeKeysIOS = [
HealthDataType.IRREGULAR_HEART_RATE_EVENT,
HealthDataType.LOW_HEART_RATE_EVENT,
HealthDataType.RESTING_HEART_RATE,
HealthDataType.RESPIRATORY_RATE,
HealthDataType.PERIPHERAL_PERFUSION_INDEX,
HealthDataType.STEPS,
HealthDataType.WAIST_CIRCUMFERENCE,
HealthDataType.WALKING_HEART_RATE,
Expand Down Expand Up @@ -159,6 +163,8 @@ const Map<HealthDataType, HealthDataUnit> _dataTypeToUnit = {
HealthDataType.ELECTRODERMAL_ACTIVITY: HealthDataUnit.SIEMEN,
HealthDataType.FORCED_EXPIRATORY_VOLUME: HealthDataUnit.LITER,
HealthDataType.HEART_RATE: HealthDataUnit.BEATS_PER_MINUTE,
HealthDataType.RESPIRATORY_RATE: HealthDataUnit.RESPIRATIONS_PER_MINUTE,
HealthDataType.PERIPHERAL_PERFUSION_INDEX: HealthDataUnit.PERCENT,
HealthDataType.HEIGHT: HealthDataUnit.METER,
HealthDataType.RESTING_HEART_RATE: HealthDataUnit.BEATS_PER_MINUTE,
HealthDataType.STEPS: HealthDataUnit.COUNT,
Expand Down Expand Up @@ -278,6 +284,7 @@ enum HealthDataUnit {

// Other units
BEATS_PER_MINUTE,
RESPIRATIONS_PER_MINUTE,
MILLIGRAM_PER_DECILITER,
UNKNOWN_UNIT,
NO_UNIT,
Expand Down

0 comments on commit b2114ab

Please sign in to comment.