Skip to content

Commit

Permalink
[Health] Add lean mass data type
Browse files Browse the repository at this point in the history
  • Loading branch information
cachapa committed Dec 17, 2024
1 parent 3784963 commit 079de1b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/health/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 11.2.0

* Add lean mass data type [#1078](https://github.com/cph-cachet/flutter-plugins/issues/1078)

## 11.1.1

* Fix of [#1059](https://github.com/cph-cachet/flutter-plugins/issues/1059)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const val BLOOD_OXYGEN = "BLOOD_OXYGEN"
const val BLOOD_PRESSURE_DIASTOLIC = "BLOOD_PRESSURE_DIASTOLIC"
const val BLOOD_PRESSURE_SYSTOLIC = "BLOOD_PRESSURE_SYSTOLIC"
const val BODY_FAT_PERCENTAGE = "BODY_FAT_PERCENTAGE"
const val LEAN_BODY_MASS = "LEAN_BODY_MASS"
const val BODY_TEMPERATURE = "BODY_TEMPERATURE"
const val BODY_WATER_MASS = "BODY_WATER_MASS"
const val DISTANCE_DELTA = "DISTANCE_DELTA"
Expand Down Expand Up @@ -1596,6 +1597,22 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
),
)

LEAN_BODY_MASS ->
LeanBodyMassRecord(
time =
Instant.ofEpochMilli(
startTime
),
mass =
Mass.kilograms(
value
),
zoneOffset = null,
metadata = Metadata(
recordingMethod = recordingMethod,
),
)

HEIGHT ->
HeightRecord(
time =
Expand Down Expand Up @@ -2398,6 +2415,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
private val mapToType =
hashMapOf(
BODY_FAT_PERCENTAGE to BodyFatRecord::class,
LEAN_BODY_MASS to LeanBodyMassRecord::class,
HEIGHT to HeightRecord::class,
WEIGHT to WeightRecord::class,
STEPS to StepsRecord::class,
Expand Down Expand Up @@ -2451,7 +2469,6 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
// "HeartRate" to HeartRateRecord::class,
// "Height" to HeightRecord::class,
// "Hydration" to HydrationRecord::class,
// "LeanBodyMass" to LeanBodyMassRecord::class,
// "MenstruationPeriod" to MenstruationPeriodRecord::class,
// "Nutrition" to NutritionRecord::class,
// "OvulationTest" to OvulationTestRecord::class,
Expand Down
3 changes: 3 additions & 0 deletions packages/health/ios/Classes/SwiftHealthPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
let BLOOD_PRESSURE_DIASTOLIC = "BLOOD_PRESSURE_DIASTOLIC"
let BLOOD_PRESSURE_SYSTOLIC = "BLOOD_PRESSURE_SYSTOLIC"
let BODY_FAT_PERCENTAGE = "BODY_FAT_PERCENTAGE"
let LEAN_BODY_MASS = "LEAN_BODY_MASS"
let BODY_MASS_INDEX = "BODY_MASS_INDEX"
let BODY_TEMPERATURE = "BODY_TEMPERATURE"
// Nutrition
Expand Down Expand Up @@ -1409,6 +1410,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
forIdentifier: .bloodPressureSystolic)!
dataTypesDict[BODY_FAT_PERCENTAGE] = HKSampleType.quantityType(
forIdentifier: .bodyFatPercentage)!
dataTypesDict[LEAN_BODY_MASS] = HKSampleType.quantityType(forIdentifier: .bodyMass)!
dataTypesDict[BODY_MASS_INDEX] = HKSampleType.quantityType(forIdentifier: .bodyMassIndex)!
dataTypesDict[BODY_TEMPERATURE] = HKSampleType.quantityType(forIdentifier: .bodyTemperature)!

Expand Down Expand Up @@ -1507,6 +1509,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
dataQuantityTypesDict[BLOOD_PRESSURE_DIASTOLIC] = HKQuantityType.quantityType(forIdentifier: .bloodPressureDiastolic)!
dataQuantityTypesDict[BLOOD_PRESSURE_SYSTOLIC] = HKQuantityType.quantityType(forIdentifier: .bloodPressureSystolic)!
dataQuantityTypesDict[BODY_FAT_PERCENTAGE] = HKQuantityType.quantityType(forIdentifier: .bodyFatPercentage)!
dataQuantityTypesDict[LEAN_BODY_MASS] = HKSampleType.quantityType(forIdentifier: .bodyMass)!
dataQuantityTypesDict[BODY_MASS_INDEX] = HKQuantityType.quantityType(forIdentifier: .bodyMassIndex)!
dataQuantityTypesDict[BODY_TEMPERATURE] = HKQuantityType.quantityType(forIdentifier: .bodyTemperature)!

Expand Down
4 changes: 4 additions & 0 deletions packages/health/lib/src/heath_data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum HealthDataType {
BLOOD_PRESSURE_DIASTOLIC,
BLOOD_PRESSURE_SYSTOLIC,
BODY_FAT_PERCENTAGE,
LEAN_BODY_MASS,
BODY_MASS_INDEX,
BODY_TEMPERATURE,
BODY_WATER_MASS,
Expand Down Expand Up @@ -125,6 +126,7 @@ const List<HealthDataType> dataTypeKeysIOS = [
HealthDataType.BLOOD_PRESSURE_DIASTOLIC,
HealthDataType.BLOOD_PRESSURE_SYSTOLIC,
HealthDataType.BODY_FAT_PERCENTAGE,
HealthDataType.LEAN_BODY_MASS,
HealthDataType.BODY_MASS_INDEX,
HealthDataType.BODY_TEMPERATURE,
HealthDataType.DIETARY_CARBS_CONSUMED,
Expand Down Expand Up @@ -216,6 +218,7 @@ const List<HealthDataType> dataTypeKeysAndroid = [
HealthDataType.BLOOD_PRESSURE_DIASTOLIC,
HealthDataType.BLOOD_PRESSURE_SYSTOLIC,
HealthDataType.BODY_FAT_PERCENTAGE,
HealthDataType.LEAN_BODY_MASS,
HealthDataType.BODY_MASS_INDEX,
HealthDataType.BODY_TEMPERATURE,
HealthDataType.BODY_WATER_MASS,
Expand Down Expand Up @@ -256,6 +259,7 @@ const Map<HealthDataType, HealthDataUnit> dataTypeToUnit = {
HealthDataType.BLOOD_PRESSURE_DIASTOLIC: HealthDataUnit.MILLIMETER_OF_MERCURY,
HealthDataType.BLOOD_PRESSURE_SYSTOLIC: HealthDataUnit.MILLIMETER_OF_MERCURY,
HealthDataType.BODY_FAT_PERCENTAGE: HealthDataUnit.PERCENT,
HealthDataType.LEAN_BODY_MASS: HealthDataUnit.KILOGRAM,
HealthDataType.BODY_MASS_INDEX: HealthDataUnit.NO_UNIT,
HealthDataType.BODY_TEMPERATURE: HealthDataUnit.DEGREE_CELSIUS,
HealthDataType.BODY_WATER_MASS: HealthDataUnit.KILOGRAM,
Expand Down

0 comments on commit 079de1b

Please sign in to comment.