Skip to content

Commit

Permalink
feat: add metadata input for all types (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
matinzd authored Aug 9, 2024
1 parent 7601b32 commit 05111b0
Show file tree
Hide file tree
Showing 46 changed files with 237 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActiveCaloriesBurnedRecord> {
Expand All @@ -17,7 +24,8 @@ class ReactActiveCaloriesBurnedRecord : ReactHealthRecordImpl<ActiveCaloriesBurn
endTime = Instant.parse(it.getString("endTime")),
energy = getEnergyFromJsMap(it.getMap("energy")),
endZoneOffset = null,
startZoneOffset = null
startZoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ReactBasalBodyTemperatureRecord : ReactHealthRecordImpl<BasalBodyTemperatureRecord> {
Expand All @@ -21,7 +26,8 @@ class ReactBasalBodyTemperatureRecord : ReactHealthRecordImpl<BasalBodyTemperatu
measurementLocation = it.getSafeInt(
"measurementLocation",
BodyTemperatureMeasurementLocation.MEASUREMENT_LOCATION_UNKNOWN
)
),
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import androidx.health.connect.client.units.Power
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.InvalidPower
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.getTimeRangeFilter
import dev.matinzd.healthconnect.utils.toMapList
import java.time.Instant

class ReactBasalMetabolicRateRecord : ReactHealthRecordImpl<BasalMetabolicRateRecord> {
Expand All @@ -16,7 +22,8 @@ class ReactBasalMetabolicRateRecord : ReactHealthRecordImpl<BasalMetabolicRateRe
BasalMetabolicRateRecord(
time = Instant.parse(it.getString("time")),
basalMetabolicRate = getPowerFromJsMap(it.getMap("basalMetabolicRate")),
zoneOffset = null
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import androidx.health.connect.client.units.BloodGlucose
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.InvalidBloodGlucoseLevel
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 ReactBloodGlucoseRecord : ReactHealthRecordImpl<BloodGlucoseRecord> {
Expand All @@ -24,7 +29,8 @@ class ReactBloodGlucoseRecord : ReactHealthRecordImpl<BloodGlucoseRecord> {
relationToMeal = it.getSafeInt(
"relationToMeal", BloodGlucoseRecord.RELATION_TO_MEAL_UNKNOWN
),
zoneOffset = null
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ReactBloodPressureRecord : ReactHealthRecordImpl<BloodPressureRecord> {
measurementLocation = it.getSafeInt(
"measurementLocation", BloodPressureRecord.MEASUREMENT_LOCATION_UNKNOWN
),
zoneOffset = null
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +19,8 @@ class ReactBodyFatRecord : ReactHealthRecordImpl<BodyFatRecord> {
BodyFatRecord(
time = Instant.parse(it.getString("time")),
percentage = Percentage(it.getDouble("percentage")),
zoneOffset = null
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BodyTemperatureRecord> {
Expand All @@ -21,7 +26,8 @@ class ReactBodyTemperatureRecord : ReactHealthRecordImpl<BodyTemperatureRecord>
measurementLocation = it.getSafeInt(
"measurementLocation",
BodyTemperatureMeasurementLocation.MEASUREMENT_LOCATION_UNKNOWN
)
),
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ReactBodyWaterMassRecord : ReactHealthRecordImpl<BodyWaterMassRecord> {
time = Instant.parse(it.getString("time")),
mass = getMassFromJsMap(it.getMap("mass")),
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoneMassRecord> {
Expand All @@ -16,6 +21,7 @@ class ReactBoneMassRecord : ReactHealthRecordImpl<BoneMassRecord> {
time = Instant.parse(it.getString("time")),
mass = getMassFromJsMap(it.getMap("mass")),
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +21,7 @@ class ReactCervicalMucusRecord : ReactHealthRecordImpl<CervicalMucusRecord> {
appearance = it.getSafeInt("appearance", CervicalMucusRecord.APPEARANCE_UNKNOWN),
sensation = it.getSafeInt("sensation", CervicalMucusRecord.SENSATION_UNKNOWN),
zoneOffset = null,
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ReactCyclingPedalingCadenceRecord : ReactHealthRecordImpl<CyclingPedalingC
)
} ?: emptyList(),
endZoneOffset = null,
startZoneOffset = null
startZoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReactDistanceRecord : ReactHealthRecordImpl<DistanceRecord> {
endTime = Instant.parse(map.getString("endTime")),
distance = getLengthFromJsMap(map.getMap("distance")),
endZoneOffset = null,
startZoneOffset = null
startZoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReactElevationGainedRecord : ReactHealthRecordImpl<ElevationGainedRecord>
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"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl<ExerciseSessionRecord>
} else {
null
},
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReactFloorsClimbedRecord : ReactHealthRecordImpl<FloorsClimbedRecord> {
endTime = Instant.parse(it.getString("endTime")),
startZoneOffset = null,
endZoneOffset = null,
floors = it.getDouble("floors")
floors = it.getDouble("floors"),
metadata = convertMetadataFromJSMap(it.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ReactHeartRateRecord : ReactHealthRecordImpl<HeartRateRecord> {
beatsPerMinute = sample.getDouble("beatsPerMinute").toLong()
)
} ?: emptyList(),
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,7 @@ class ReactHeartRateVariabilityRmssdRecord :
time = Instant.parse(map.getString("time")),
heartRateVariabilityMillis = map.getDouble("heartRateVariabilityMillis"),
zoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ReactHeightRecord : ReactHealthRecordImpl<HeightRecord> {
time = Instant.parse(map.getString("time")),
height = getLengthFromJsMap(map.getMap("height")),
zoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReactHydrationRecord : ReactHealthRecordImpl<HydrationRecord> {
endTime = Instant.parse(map.getString("endTime")),
volume = getVolumeFromJsMap(map.getMap("volume")),
endZoneOffset = null,
startZoneOffset = null
startZoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +18,7 @@ class ReactIntermenstrualBleedingRecord : ReactHealthRecordImpl<IntermenstrualBl
IntermenstrualBleedingRecord(
time = Instant.parse(map.getString("time")),
zoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ReactLeanBodyMassRecord : ReactHealthRecordImpl<LeanBodyMassRecord> {
time = Instant.parse(map.getString("time")),
mass = getMassFromJsMap(map.getMap("mass")),
zoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,7 @@ class ReactMenstruationFlowRecord : ReactHealthRecordImpl<MenstruationFlowRecord
time = Instant.parse(map.getString("time")),
flow = map.getSafeInt("flow", MenstruationFlowRecord.FLOW_UNKNOWN),
zoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +19,8 @@ class ReactMenstruationPeriodRecord : ReactHealthRecordImpl<MenstruationPeriodRe
startTime = Instant.parse(map.getString("startTime")),
endTime = Instant.parse(map.getString("endTime")),
endZoneOffset = null,
startZoneOffset = null
startZoneOffset = null,
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ReactNutritionRecord : ReactHealthRecordImpl<NutritionRecord> {
zinc = map.getMap("zinc")?.let { getMassFromJsMap(it) },
name = map.getString("name"),
mealType = map.getSafeInt("mealType", MealType.MEAL_TYPE_UNKNOWN),
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,8 +18,9 @@ class ReactOvulationTestRecord : ReactHealthRecordImpl<OvulationTestRecord> {
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"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +20,7 @@ class ReactOxygenSaturationRecord : ReactHealthRecordImpl<OxygenSaturationRecord
time = Instant.parse(map.getString("time")),
zoneOffset = null,
percentage = Percentage(map.getDouble("percentage")),
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ReactPowerRecord : ReactHealthRecordImpl<PowerRecord> {
power = getPowerFromJsMap(sample.getMap("power"))
)
} ?: emptyList(),
metadata = convertMetadataFromJSMap(map.getMap("metadata"))
)
}
}
Expand Down
Loading

0 comments on commit 05111b0

Please sign in to comment.