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 lean mass data type #1097

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
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 @@ -1083,6 +1084,29 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
),
)

is LeanBodyMassRecord ->
return listOf(
mapOf<String, Any>(
"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<String, Any>(
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
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: .leanBodyMass)!
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: .leanBodyMass)!
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