diff --git a/packages/health/CHANGELOG.md b/packages/health/CHANGELOG.md index d1e668fd7..9a417c7ab 100644 --- a/packages/health/CHANGELOG.md +++ b/packages/health/CHANGELOG.md @@ -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) diff --git a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt index 216aff7ea..002e824b3 100644 --- a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt +++ b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt @@ -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" @@ -1083,6 +1084,29 @@ class HealthPlugin(private var channel: MethodChannel? = null) : ), ) + is LeanBodyMassRecord -> + return listOf( + mapOf( + "uuid" to + metadata.id, + "value" to + record.mass + .inKilograms, + "date_from" to + record.time + .toEpochMilli(), + "date_to" to + record.time + .toEpochMilli(), + "source_id" to "", + "source_name" to + metadata.dataOrigin + .packageName, + "recording_method" to + metadata.recordingMethod + ), + ) + is StepsRecord -> return listOf( mapOf( @@ -1596,6 +1620,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 = @@ -2398,6 +2438,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, @@ -2438,7 +2479,6 @@ class HealthPlugin(private var channel: MethodChannel? = null) : // "BasalMetabolicRate" to BasalMetabolicRateRecord::class, // "BloodGlucose" to BloodGlucoseRecord::class, // "BloodPressure" to BloodPressureRecord::class, - // "BodyFat" to BodyFatRecord::class, // "BodyTemperature" to BodyTemperatureRecord::class, // "BoneMass" to BoneMassRecord::class, // "CervicalMucus" to CervicalMucusRecord::class, @@ -2451,7 +2491,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, diff --git a/packages/health/ios/Classes/SwiftHealthPlugin.swift b/packages/health/ios/Classes/SwiftHealthPlugin.swift index d7af83e05..d2fce50c0 100644 --- a/packages/health/ios/Classes/SwiftHealthPlugin.swift +++ b/packages/health/ios/Classes/SwiftHealthPlugin.swift @@ -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 @@ -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: .leanBodyMass)! dataTypesDict[BODY_MASS_INDEX] = HKSampleType.quantityType(forIdentifier: .bodyMassIndex)! dataTypesDict[BODY_TEMPERATURE] = HKSampleType.quantityType(forIdentifier: .bodyTemperature)! @@ -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: .leanBodyMass)! dataQuantityTypesDict[BODY_MASS_INDEX] = HKQuantityType.quantityType(forIdentifier: .bodyMassIndex)! dataQuantityTypesDict[BODY_TEMPERATURE] = HKQuantityType.quantityType(forIdentifier: .bodyTemperature)! diff --git a/packages/health/lib/src/heath_data_types.dart b/packages/health/lib/src/heath_data_types.dart index f50762721..0989381b9 100644 --- a/packages/health/lib/src/heath_data_types.dart +++ b/packages/health/lib/src/heath_data_types.dart @@ -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, @@ -125,6 +126,7 @@ const List 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, @@ -216,6 +218,7 @@ const List 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, @@ -256,6 +259,7 @@ const Map 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,