Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HEALTH] add new data type for STAND_TIME #866

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Note that for Android, the target phone **needs** to have [Google Fit](https://w
## Data Types

| **Data Type** | **Unit** | **iOS** | **Android (Google Fit)** | **Android (Health Connect)** | **Comments** |
| --------------------------- | ----------------------- | ------- | ------------------------ |------------------------------| -------------------------------------- |
|-----------------------------|-------------------------| ------- |--------------------------|------------------------------| -------------------------------------- |
| ACTIVE_ENERGY_BURNED | CALORIES | yes | yes | yes | |
| BASAL_ENERGY_BURNED | CALORIES | yes | | yes | |
| BLOOD_GLUCOSE | MILLIGRAM_PER_DECILITER | yes | yes | yes | |
Expand All @@ -38,8 +38,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 | | yes |
| PERIPHERAL_PERFUSION_INDEX | PERCENTAGE | yes | | |
| RESPIRATORY_RATE | RESPIRATIONS_PER_MINUTE | yes | | yes |
| PERIPHERAL_PERFUSION_INDEX | PERCENTAGE | yes | | |
| STEPS | COUNT | yes | yes | yes | |
| WAIST_CIRCUMFERENCE | METERS | yes | | | |
| WALKING_HEART_RATE | BEATS_PER_MINUTE | yes | | | |
Expand Down Expand Up @@ -72,6 +72,7 @@ Note that for Android, the target phone **needs** to have [Google Fit](https://w
| AUDIOGRAM | DECIBEL_HEARING_LEVEL | yes | | | |
| ELECTROCARDIOGRAM | VOLT | yes | | | Requires Apple Watch to write the data |
| NUTRITION | NO_UNIT | yes | yes | yes | |
| STAND_TIME | MINUTES | yes | | | |

## Setup

Expand Down
7 changes: 5 additions & 2 deletions packages/health/ios/Classes/SwiftHealthPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
let HEADACHE_SEVERE = "HEADACHE_SEVERE"
let ELECTROCARDIOGRAM = "ELECTROCARDIOGRAM"
let NUTRITION = "NUTRITION"
let STAND_TIME = "STAND_TIME"

// Health Unit types
// MOLE_UNIT_WITH_MOLAR_MASS, // requires molar mass input - not supported yet
Expand Down Expand Up @@ -610,14 +611,16 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {

var predicate = HKQuery.predicateForSamples(
withStart: dateFrom, end: dateTo, options: .strictStartDate)
let watchPredicate = HKQuery.predicateForObjects(withDeviceProperty: HKDevicePropertyKeyModel, allowedValues: ["Watch"])
let combinedPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, watchPredicate])
if (!includeManualEntry) {
let manualPredicate = NSPredicate(format: "metadata.%K != YES", HKMetadataKeyWasUserEntered)
predicate = NSCompoundPredicate(type: .and, subpredicates: [predicate, manualPredicate])
}
let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)

let query = HKSampleQuery(
sampleType: dataType, predicate: predicate, limit: limit, sortDescriptors: [sortDescriptor]
sampleType: dataType, predicate: combinedPredicate, limit: limit, sortDescriptors: [sortDescriptor]
) {
[self]
x, samplesOrNil, error in
Expand Down Expand Up @@ -1194,7 +1197,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
dataTypesDict[WORKOUT] = HKSampleType.workoutType()
dataTypesDict[NUTRITION] = HKSampleType.correlationType(
forIdentifier: .food)!

dataTypesDict[STAND_TIME] = HKSampleType.quantityType(forIdentifier: .appleStandTime)
healthDataTypes = Array(dataTypesDict.values)
}

Expand Down
3 changes: 3 additions & 0 deletions packages/health/lib/src/data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum HealthDataType {
HEADACHE_SEVERE,
HEADACHE_UNSPECIFIED,
NUTRITION,
STAND_TIME,

// Heart Rate events (specific to Apple Watch)
HIGH_HEART_RATE_EVENT,
Expand Down Expand Up @@ -130,6 +131,7 @@ const List<HealthDataType> _dataTypeKeysIOS = [
HealthDataType.HEADACHE_UNSPECIFIED,
HealthDataType.ELECTROCARDIOGRAM,
HealthDataType.NUTRITION,
HealthDataType.STAND_TIME,
];

/// List of data types available on Android
Expand Down Expand Up @@ -234,6 +236,7 @@ const Map<HealthDataType, HealthDataUnit> _dataTypeToUnit = {
HealthDataType.ELECTROCARDIOGRAM: HealthDataUnit.VOLT,

HealthDataType.NUTRITION: HealthDataUnit.NO_UNIT,
HealthDataType.STAND_TIME: HealthDataUnit.MINUTE,

// Health Connect
HealthDataType.TOTAL_CALORIES_BURNED: HealthDataUnit.KILOCALORIE,
Expand Down
Loading