BloodPressureRecord.kt
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.health.connect.client.records
import androidx.annotation.StringDef
import androidx.health.connect.client.aggregate.AggregateMetric
import androidx.health.connect.client.records.metadata.Metadata
import androidx.health.connect.client.records.BloodPressureRecord.MeasurementLocation
import androidx.health.connect.client.units.Pressure
import java.time.Instant
import java.time.ZoneOffset
/**
* Captures the blood pressure of a user. Each record represents a single instantaneous blood
* pressure reading.
*/
public class BloodPressureRecord(
/**
* Systolic blood pressure measurement, in [Pressure] unit. Required field. Valid range: 20-200
* mmHg.
*/
public val systolic: Pressure,
/**
* Diastolic blood pressure measurement, in [Pressure] unit. Required field. Valid range:
* 10-180 mmHg.
*/
public val diastolic: Pressure,
/**
* The user's body position when the measurement was taken. Optional field. Allowed values:
* [BodyPosition].
*
* @see BodyPosition
*/
@property:BodyPositions public val bodyPosition: String? = null,
/**
* The arm and part of the arm where the measurement was taken. Optional field. Allowed values:
* [MeasurementLocation].
*
* @see MeasurementLocation
*/
@property:MeasurementLocations public val measurementLocation: String? = null,
override val time: Instant,
override val zoneOffset: ZoneOffset?,
override val metadata: Metadata = Metadata.EMPTY,
) : InstantaneousRecord {
init {
systolic.requireNotLess(other = systolic.zero(), name = "systolic")
diastolic.requireNotLess(other = diastolic.zero(), name = "diastolic")
}
/*
* Generated by the IDE: Code -> Generate -> "equals() and hashCode()".
*/
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is BloodPressureRecord) return false
if (systolic != other.systolic) return false
if (diastolic != other.diastolic) return false
if (bodyPosition != other.bodyPosition) return false
if (measurementLocation != other.measurementLocation) return false
if (time != other.time) return false
if (zoneOffset != other.zoneOffset) return false
if (metadata != other.metadata) return false
return true
}
/*
* Generated by the IDE: Code -> Generate -> "equals() and hashCode()".
*/
override fun hashCode(): Int {
var result = systolic.hashCode()
result = 31 * result + diastolic.hashCode()
result = 31 * result + (bodyPosition?.hashCode() ?: 0)
result = 31 * result + (measurementLocation?.hashCode() ?: 0)
result = 31 * result + time.hashCode()
result = 31 * result + (zoneOffset?.hashCode() ?: 0)
result = 31 * result + metadata.hashCode()
return result
}
/** The arm and part of the arm where a blood pressure measurement was taken. */
public object MeasurementLocation {
const val LEFT_WRIST = "left_wrist"
const val RIGHT_WRIST = "right_wrist"
const val LEFT_UPPER_ARM = "left_upper_arm"
const val RIGHT_UPPER_ARM = "right_upper_arm"
}
/**
* The arm and part of the arm where a blood pressure measurement was taken.
* @suppress
*/
@Retention(AnnotationRetention.SOURCE)
@StringDef(
value =
[
MeasurementLocation.LEFT_WRIST,
MeasurementLocation.RIGHT_WRIST,
MeasurementLocation.LEFT_UPPER_ARM,
MeasurementLocation.RIGHT_UPPER_ARM,
]
)
annotation class MeasurementLocations
companion object {
private const val BLOOD_PRESSURE_NAME = "BloodPressure"
private const val SYSTOLIC_FIELD_NAME = "systolic"
private const val DIASTOLIC_FIELD_NAME = "diastolic"
/**
* Metric identifier to retrieve average systolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val SYSTOLIC_AVG: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.AVERAGE,
fieldName = SYSTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
/**
* Metric identifier to retrieve minimum systolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val SYSTOLIC_MIN: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.MINIMUM,
fieldName = SYSTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
/**
* Metric identifier to retrieve maximum systolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val SYSTOLIC_MAX: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.MAXIMUM,
fieldName = SYSTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
/**
* Metric identifier to retrieve average diastolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val DIASTOLIC_AVG: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.AVERAGE,
fieldName = DIASTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
/**
* Metric identifier to retrieve minimum diastolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val DIASTOLIC_MIN: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.MINIMUM,
fieldName = DIASTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
/**
* Metric identifier to retrieve maximum diastolic from
* [androidx.health.connect.client.aggregate.AggregationResult].
*/
@JvmField
val DIASTOLIC_MAX: AggregateMetric<Pressure> =
AggregateMetric.doubleMetric(
dataTypeName = BLOOD_PRESSURE_NAME,
aggregationType = AggregateMetric.AggregationType.MAXIMUM,
fieldName = DIASTOLIC_FIELD_NAME,
mapper = Pressure::millimetersOfMercury,
)
}
}