From 05111b024314eca6267178bcab24f0afda33b14c Mon Sep 17 00:00:00 2001 From: Matin Zadeh Dolatabad <24797481+matinzd@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:00:39 +0200 Subject: [PATCH] feat: add metadata input for all types (#133) --- .../ReactActiveCaloriesBurnedRecord.kt | 12 +++- .../ReactBasalBodyTemperatureRecord.kt | 10 +++- .../records/ReactBasalMetabolicRateRecord.kt | 11 +++- .../records/ReactBloodGlucoseRecord.kt | 10 +++- .../records/ReactBloodPressureRecord.kt | 3 +- .../records/ReactBodyFatRecord.kt | 4 +- .../records/ReactBodyTemperatureRecord.kt | 10 +++- .../records/ReactBodyWaterMassRecord.kt | 1 + .../records/ReactBoneMassRecord.kt | 8 ++- .../records/ReactCervicalMucusRecord.kt | 2 + .../ReactCyclingPedalingCadenceRecord.kt | 3 +- .../records/ReactDistanceRecord.kt | 3 +- .../records/ReactElevationGainedRecord.kt | 3 +- .../records/ReactExerciseSessionRecord.kt | 1 + .../records/ReactFloorsClimbedRecord.kt | 3 +- .../records/ReactHeartRateRecord.kt | 1 + .../ReactHeartRateVariabilityRmssdRecord.kt | 2 + .../records/ReactHeightRecord.kt | 1 + .../records/ReactHydrationRecord.kt | 3 +- .../ReactIntermenstrualBleedingRecord.kt | 2 + .../records/ReactLeanBodyMassRecord.kt | 1 + .../records/ReactMenstruationFlowRecord.kt | 2 + .../records/ReactMenstruationPeriodRecord.kt | 4 +- .../records/ReactNutritionRecord.kt | 1 + .../records/ReactOvulationTestRecord.kt | 6 +- .../records/ReactOxygenSaturationRecord.kt | 2 + .../healthconnect/records/ReactPowerRecord.kt | 1 + .../records/ReactRespiratoryRateRecord.kt | 4 +- .../records/ReactRestingHeartRateRecord.kt | 3 +- .../records/ReactSexualActivityRecord.kt | 4 +- .../records/ReactSleepSessionRecord.kt | 1 + .../healthconnect/records/ReactSpeedRecord.kt | 1 + .../records/ReactStepsCadenceRecord.kt | 3 +- .../healthconnect/records/ReactStepsRecord.kt | 3 +- .../records/ReactTotalCaloriesBurnedRecord.kt | 3 +- .../records/ReactVo2MaxRecord.kt | 2 + .../records/ReactWeightRecord.kt | 3 +- .../records/ReactWheelchairPushesRecord.kt | 1 + .../healthconnect/utils/HealthConnectUtils.kt | 41 ++++++++++++- docs/docs/api/methods/06-insertRecords.md | 9 +++ example/src/App.tsx | 18 +++++- src/constants.ts | 14 ----- src/index.tsx | 1 + src/types/base.types.ts | 15 +---- src/types/index.ts | 1 + src/types/metadata.types.ts | 57 +++++++++++++++++++ 46 files changed, 237 insertions(+), 57 deletions(-) create mode 100644 src/types/metadata.types.ts diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt index 1cc7853..77c5fab 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactActiveCaloriesBurnedRecord.kt @@ -6,7 +6,14 @@ import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap -import dev.matinzd.healthconnect.utils.* +import dev.matinzd.healthconnect.utils.convertDataOriginsToJsArray +import dev.matinzd.healthconnect.utils.convertJsToDataOriginSet +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap +import dev.matinzd.healthconnect.utils.convertMetadataToJSMap +import dev.matinzd.healthconnect.utils.energyToJsMap +import dev.matinzd.healthconnect.utils.getEnergyFromJsMap +import dev.matinzd.healthconnect.utils.getTimeRangeFilter +import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant class ReactActiveCaloriesBurnedRecord : ReactHealthRecordImpl { @@ -17,7 +24,8 @@ class ReactActiveCaloriesBurnedRecord : ReactHealthRecordImpl { @@ -21,7 +26,8 @@ class ReactBasalBodyTemperatureRecord : ReactHealthRecordImpl { @@ -16,7 +22,8 @@ class ReactBasalMetabolicRateRecord : ReactHealthRecordImpl { @@ -24,7 +29,8 @@ class ReactBloodGlucoseRecord : ReactHealthRecordImpl { relationToMeal = it.getSafeInt( "relationToMeal", BloodGlucoseRecord.RELATION_TO_MEAL_UNKNOWN ), - zoneOffset = null + zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt index b0e3361..967feeb 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBloodPressureRecord.kt @@ -21,7 +21,8 @@ class ReactBloodPressureRecord : ReactHealthRecordImpl { measurementLocation = it.getSafeInt( "measurementLocation", BloodPressureRecord.MEASUREMENT_LOCATION_UNKNOWN ), - zoneOffset = null + zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt index f14edd8..b76bc77 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyFatRecord.kt @@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -18,7 +19,8 @@ class ReactBodyFatRecord : ReactHealthRecordImpl { BodyFatRecord( time = Instant.parse(it.getString("time")), percentage = Percentage(it.getDouble("percentage")), - zoneOffset = null + zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt index 0b9147e..d4d3942 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyTemperatureRecord.kt @@ -8,7 +8,12 @@ import androidx.health.connect.client.units.Temperature import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap -import dev.matinzd.healthconnect.utils.* +import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.InvalidTemperature +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap +import dev.matinzd.healthconnect.utils.convertMetadataToJSMap +import dev.matinzd.healthconnect.utils.getSafeInt +import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant class ReactBodyTemperatureRecord : ReactHealthRecordImpl { @@ -21,7 +26,8 @@ class ReactBodyTemperatureRecord : ReactHealthRecordImpl measurementLocation = it.getSafeInt( "measurementLocation", BodyTemperatureMeasurementLocation.MEASUREMENT_LOCATION_UNKNOWN - ) + ), + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt index e14b4e4..589100b 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBodyWaterMassRecord.kt @@ -16,6 +16,7 @@ class ReactBodyWaterMassRecord : ReactHealthRecordImpl { time = Instant.parse(it.getString("time")), mass = getMassFromJsMap(it.getMap("mass")), zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt index f5b0013..b4d7cc8 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactBoneMassRecord.kt @@ -6,7 +6,12 @@ import androidx.health.connect.client.request.AggregateRequest import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap -import dev.matinzd.healthconnect.utils.* +import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap +import dev.matinzd.healthconnect.utils.convertMetadataToJSMap +import dev.matinzd.healthconnect.utils.getMassFromJsMap +import dev.matinzd.healthconnect.utils.massToJsMap +import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant class ReactBoneMassRecord : ReactHealthRecordImpl { @@ -16,6 +21,7 @@ class ReactBoneMassRecord : ReactHealthRecordImpl { time = Instant.parse(it.getString("time")), mass = getMassFromJsMap(it.getMap("mass")), zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt index c0d3bea..08942be 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCervicalMucusRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.getSafeInt import dev.matinzd.healthconnect.utils.toMapList @@ -20,6 +21,7 @@ class ReactCervicalMucusRecord : ReactHealthRecordImpl { appearance = it.getSafeInt("appearance", CervicalMucusRecord.APPEARANCE_UNKNOWN), sensation = it.getSafeInt("sensation", CervicalMucusRecord.SENSATION_UNKNOWN), zoneOffset = null, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt index 8e8cf3d..2fe0913 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactCyclingPedalingCadenceRecord.kt @@ -23,7 +23,8 @@ class ReactCyclingPedalingCadenceRecord : ReactHealthRecordImpl { endTime = Instant.parse(map.getString("endTime")), distance = getLengthFromJsMap(map.getMap("distance")), endZoneOffset = null, - startZoneOffset = null + startZoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt index 7d09cf7..8114d7f 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactElevationGainedRecord.kt @@ -17,7 +17,8 @@ class ReactElevationGainedRecord : ReactHealthRecordImpl endTime = Instant.parse(it.getString("endTime")), startZoneOffset = null, endZoneOffset = null, - elevation = getLengthFromJsMap(it.getMap("elevation")) + elevation = getLengthFromJsMap(it.getMap("elevation")), + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt index 21d7407..2f01df1 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt @@ -63,6 +63,7 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl } else { null }, + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt index 0f665cf..88f21cf 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactFloorsClimbedRecord.kt @@ -17,7 +17,8 @@ class ReactFloorsClimbedRecord : ReactHealthRecordImpl { endTime = Instant.parse(it.getString("endTime")), startZoneOffset = null, endZoneOffset = null, - floors = it.getDouble("floors") + floors = it.getDouble("floors"), + metadata = convertMetadataFromJSMap(it.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt index 7a06da7..739d92c 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateRecord.kt @@ -24,6 +24,7 @@ class ReactHeartRateRecord : ReactHealthRecordImpl { beatsPerMinute = sample.getDouble("beatsPerMinute").toLong() ) } ?: emptyList(), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt index 4b10d32..8335bb0 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeartRateVariabilityRmssdRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -19,6 +20,7 @@ class ReactHeartRateVariabilityRmssdRecord : time = Instant.parse(map.getString("time")), heartRateVariabilityMillis = map.getDouble("heartRateVariabilityMillis"), zoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt index a88cebb..4058285 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHeightRecord.kt @@ -16,6 +16,7 @@ class ReactHeightRecord : ReactHealthRecordImpl { time = Instant.parse(map.getString("time")), height = getLengthFromJsMap(map.getMap("height")), zoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt index 21b39c7..7ea9b65 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactHydrationRecord.kt @@ -17,7 +17,8 @@ class ReactHydrationRecord : ReactHealthRecordImpl { endTime = Instant.parse(map.getString("endTime")), volume = getVolumeFromJsMap(map.getMap("volume")), endZoneOffset = null, - startZoneOffset = null + startZoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt index dd154c5..13c8630 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactIntermenstrualBleedingRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -17,6 +18,7 @@ class ReactIntermenstrualBleedingRecord : ReactHealthRecordImpl { time = Instant.parse(map.getString("time")), mass = getMassFromJsMap(map.getMap("mass")), zoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt index 2ae068c..0bda1fe 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactMenstruationFlowRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.getSafeInt import dev.matinzd.healthconnect.utils.toMapList @@ -19,6 +20,7 @@ class ReactMenstruationFlowRecord : ReactHealthRecordImpl { zinc = map.getMap("zinc")?.let { getMassFromJsMap(it) }, name = map.getString("name"), mealType = map.getSafeInt("mealType", MealType.MEAL_TYPE_UNKNOWN), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt index 620a2d5..1eae7c6 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOvulationTestRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.getSafeInt import dev.matinzd.healthconnect.utils.toMapList @@ -17,8 +18,9 @@ class ReactOvulationTestRecord : ReactHealthRecordImpl { return records.toMapList().map { map -> OvulationTestRecord( time = Instant.parse(map.getString("time")), zoneOffset = null, result = map.getSafeInt( - "result", OvulationTestRecord.RESULT_INCONCLUSIVE - ) + "result", OvulationTestRecord.RESULT_INCONCLUSIVE + ), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt index e071397..4dba951 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactOxygenSaturationRecord.kt @@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -19,6 +20,7 @@ class ReactOxygenSaturationRecord : ReactHealthRecordImpl { power = getPowerFromJsMap(sample.getMap("power")) ) } ?: emptyList(), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt index 3d97845..48cc963 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRespiratoryRateRecord.kt @@ -7,6 +7,7 @@ import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap import dev.matinzd.healthconnect.utils.AggregationNotSupported +import dev.matinzd.healthconnect.utils.convertMetadataFromJSMap import dev.matinzd.healthconnect.utils.convertMetadataToJSMap import dev.matinzd.healthconnect.utils.toMapList import java.time.Instant @@ -15,7 +16,8 @@ class ReactRespiratoryRateRecord : ReactHealthRecordImpl override fun parseWriteRecord(records: ReadableArray): List { return records.toMapList().map { map -> RespiratoryRateRecord( - time = Instant.parse(map.getString("time")), zoneOffset = null, rate = map.getDouble("rate") + time = Instant.parse(map.getString("time")), zoneOffset = null, rate = map.getDouble("rate"), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt index 0797ec1..b0126a0 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactRestingHeartRateRecord.kt @@ -15,7 +15,8 @@ class ReactRestingHeartRateRecord : ReactHealthRecordImpl { SexualActivityRecord( time = Instant.parse(map.getString("time")), protectionUsed = map.getInt("protectionUsed"), - zoneOffset = null + zoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt index 8d0dfb0..4fc592e 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSleepSessionRecord.kt @@ -27,6 +27,7 @@ class ReactSleepSessionRecord : ReactHealthRecordImpl { endZoneOffset = null, title = map.getString("title"), notes = map.getString("description"), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt index 51028a5..83f3231 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactSpeedRecord.kt @@ -24,6 +24,7 @@ class ReactSpeedRecord : ReactHealthRecordImpl { speed = getVelocityFromJsMap(sample.getMap("speed")) ) } ?: emptyList(), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt index 4bc9705..fd3cab2 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsCadenceRecord.kt @@ -23,7 +23,8 @@ class ReactStepsCadenceRecord : ReactHealthRecordImpl { time = Instant.parse(sample.getString("time")), rate = sample.getDouble("count") ) - } ?: emptyList() + } ?: emptyList(), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt index 98f0701..53b5c6c 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactStepsRecord.kt @@ -17,7 +17,8 @@ class ReactStepsRecord : ReactHealthRecordImpl { endTime = Instant.parse(map.getString("endTime")), startZoneOffset = null, endZoneOffset = null, - count = map.getDouble("count").toLong() + count = map.getDouble("count").toLong(), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt index 708f964..8b299d0 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactTotalCaloriesBurnedRecord.kt @@ -17,7 +17,8 @@ class ReactTotalCaloriesBurnedRecord : ReactHealthRecordImpl { "measurementMethod", Vo2MaxRecord.MEASUREMENT_METHOD_OTHER ), + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt index e366d85..5cc5568 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWeightRecord.kt @@ -15,7 +15,8 @@ class ReactWeightRecord : ReactHealthRecordImpl { WeightRecord( time = Instant.parse(map.getString("time")), weight = getMassFromJsMap(map.getMap("weight")), - zoneOffset = null + zoneOffset = null, + metadata = convertMetadataFromJSMap(map.getMap("metadata")) ) } } diff --git a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt index c7981de..d377c06 100644 --- a/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt +++ b/android/src/main/java/dev/matinzd/healthconnect/records/ReactWheelchairPushesRecord.kt @@ -18,6 +18,7 @@ class ReactWheelchairPushesRecord : ReactHealthRecordImpl> = mapOf( "ActiveCaloriesBurned" to ActiveCaloriesBurnedRecord::class, "BasalBodyTemperature" to BasalBodyTemperatureRecord::class, diff --git a/docs/docs/api/methods/06-insertRecords.md b/docs/docs/api/methods/06-insertRecords.md index 7ee42cc..384a943 100644 --- a/docs/docs/api/methods/06-insertRecords.md +++ b/docs/docs/api/methods/06-insertRecords.md @@ -24,6 +24,15 @@ const insertSampleData = () => { energy: { unit: 'kilocalories', value: 10000 }, startTime: '2023-01-09T10:00:00.405Z', endTime: '2023-01-09T11:53:15.405Z', + metadata: { + recordingMethod: + RecordingMethod.RECORDING_METHOD_AUTOMATICALLY_RECORDED, + device: { + manufacturer: 'Google', + model: 'Pixel 4', + type: DeviceType.TYPE_PHONE, + }, + }, }, { recordType: 'ActiveCaloriesBurned', diff --git a/example/src/App.tsx b/example/src/App.tsx index 30c3df4..13f1245 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -14,6 +14,8 @@ import { openHealthConnectSettings, openHealthConnectDataManagement, readRecord, + RecordingMethod, + DeviceType, } from 'react-native-health-connect'; const getLastWeekDate = (): Date => { @@ -28,6 +30,10 @@ const getTodayDate = (): Date => { return new Date(); }; +const random64BitString = () => { + return Math.floor(Math.random() * 0xffffffffffffffff).toString(16); +}; + export default function App() { const initializeHealthConnect = async () => { const result = await initialize(); @@ -58,6 +64,16 @@ export default function App() { count: 1000, startTime: getLastWeekDate().toISOString(), endTime: getTodayDate().toISOString(), + metadata: { + clientRecordId: random64BitString(), + recordingMethod: + RecordingMethod.RECORDING_METHOD_AUTOMATICALLY_RECORDED, + device: { + manufacturer: 'Google', + model: 'Pixel 4', + type: DeviceType.TYPE_PHONE, + }, + }, }, ]) .then((ids) => { @@ -85,7 +101,7 @@ export default function App() { }; const readSampleDataSingle = () => { - readRecord('Steps', 'a7bdea65-86ce-4eb2-a9ef-a87e6a7d9df2') + readRecord('Steps', '40a67ecf-d929-4648-996e-e8d248727d95') .then((result) => { console.log('Retrieved record: ', JSON.stringify({ result }, null, 2)); }) diff --git a/src/constants.ts b/src/constants.ts index 11d87ee..57a769b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -422,17 +422,3 @@ export const ExerciseSegmentType = { /** Use this type for yoga. */ YOGA: 67, }; - -export const RecordingMethod = { - /** For actively recorded data by the user. */ - RECORDING_METHOD_ACTIVELY_RECORDED: 1, - - /** For passively recorded data by the app. */ - RECORDING_METHOD_AUTOMATICALLY_RECORDED: 2, - - /** For manually entered data by the user. */ - RECORDING_METHOD_MANUAL_ENTRY: 3, - - /** Unknown recording method. */ - RECORDING_METHOD_UNKNOWN: 0, -}; diff --git a/src/index.tsx b/src/index.tsx index 15ae186..36c520f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -176,3 +176,4 @@ export function deleteRecordsByTimeRange( } export * from './constants'; +export * from './types'; diff --git a/src/types/base.types.ts b/src/types/base.types.ts index a28a21a..d20c668 100644 --- a/src/types/base.types.ts +++ b/src/types/base.types.ts @@ -1,3 +1,5 @@ +import type { Metadata } from './metadata.types'; + export interface BaseRecord { metadata?: Metadata; } @@ -16,19 +18,6 @@ export interface IntervalRecord extends BaseRecord { endTime: string; } -export interface Metadata { - id: string; - // package name of the app that created the record - dataOrigin: string; - lastModifiedTime: string; - clientRecordId?: string; - clientRecordVersion: number; - // see: https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Device - device: number; - // Use RecordingType constant to compare - recordingMethod: number; -} - export type TimeRangeFilter = | { operator: 'between'; diff --git a/src/types/index.ts b/src/types/index.ts index e053d68..83ab3c7 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -9,3 +9,4 @@ export * from './records.types'; export * from './results.types'; export * from './aggregate.types'; export * from './changes.types'; +export * from './metadata.types'; diff --git a/src/types/metadata.types.ts b/src/types/metadata.types.ts new file mode 100644 index 0000000..479724a --- /dev/null +++ b/src/types/metadata.types.ts @@ -0,0 +1,57 @@ +export enum DeviceType { + TYPE_UNKNOWN = 0, + TYPE_PHONE = 2, + TYPE_SCALE = 3, + TYPE_RING = 4, + TYPE_HEAD_MOUNTED = 5, + TYPE_FITNESS_BAND = 6, + TYPE_CHEST_STRAP = 7, + TYPE_SMART_DISPLAY = 8, +} + +export enum RecordingMethod { + /** Unknown recording method. */ + RECORDING_METHOD_UNKNOWN = 0, + + /** + * For actively recorded data by the user. + * + * For e.g. An exercise session actively recorded by the user using a phone or a watch + * device. + */ + RECORDING_METHOD_ACTIVELY_RECORDED = 1, + + /** + * For passively recorded data by the app. + * + * For e.g. Steps data recorded by a watch or phone without the user starting a session. + */ + RECORDING_METHOD_AUTOMATICALLY_RECORDED = 2, + + /** + * For manually entered data by the user. + * + * For e.g. Nutrition or weight data entered by the user. + */ + RECORDING_METHOD_MANUAL_ENTRY = 3, +} + +export interface Device { + manufacturer?: string; + model?: string; + type?: DeviceType; +} + +export interface Metadata { + id?: string; + // package name of the app that created the record + dataOrigin?: string; + // ISO 8601 date time string + lastModifiedTime?: string; + clientRecordId?: string; + clientRecordVersion?: number; + // see: https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Device + device?: Device; + // Use RecordingType constant to compare + recordingMethod?: RecordingMethod; +}