readAssociatedData

Reads a set of associated data for a certain target data according to the given request.

For example, measured sleep data is a base data type, and blood oxygen level and skin temperature data are associated data types. The code snippet below shows how to get associated data for a specific SleepType data.

val readRequest = DataTypes.SLEEP.readDataRequestBuilder
    .setLocalTimeFilter(localTimeFilter).build()
val result = healthDataStore.readData(readRequest)

result.dataList.forEach { sleepDataPoint ->

    val sleepId = sleepDataPoint.uid
    val idFilter = IdFilter.fromDataUid(sleepId)
    val request = DataTypes.SLEEP.associatedReadRequestBuilder
        .addAssociatedDataType(DataType.SleepType.Associates.BLOOD_OXYGEN)
        .addAssociatedDataType(DataType.SleepType.Associates.SKIN_TEMPERATURE)
        .setIdFilter(idFilter)
        .build()

    val associatedResult = healthDataStore.readAssociatedData(request)
    associatedResult.dataList.forEach { associatedDataPoints->
        val oxygenDataPoints = associatedDataPoints.getDataPointOf(DataTypes.BLOOD_OXYGEN)
        oxygenDataPoints?.forEach{
            val oxygenSaturation = it.getValue(DataType.BloodOxygenType.OXYGEN_SATURATION)
            // Process the oxygen saturation value
        }

        val skinTemperatureDataPoints = associatedDataPoints.getDataPointOf(DataTypes.SKIN_TEMPERATURE)
        skinTemperatureDataPoints?.forEach {
            val skinTemperature = it.getValue(DataType.SkinTemperatureType.SKIN_TEMPERATURE)
            // Process the skin temperature value
        }
    }
}

Return

The DataResponse instance delivering the result AssociatedDataPoints.

Since

1.0.0

Parameters

request

A ReadDataRequest instance to specify read conditions.

Preferences Submitted

You have successfully updated your cookie preferences.