Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Correlations in HealthKit combine multiple related samples into a single entity. The two main correlation types are:
  • Blood Pressure: Combines systolic and diastolic blood pressure readings
  • Food: Combines nutritional information (calories, protein, carbs, fats, etc.)

queryCorrelationSamples

Query correlation samples from HealthKit with optional filtering and sorting.

Signature

function queryCorrelationSamples(
  typeIdentifier: CorrelationTypeIdentifier,
  options: QueryOptionsWithSortOrder
): Promise<readonly CorrelationSample[]>

Parameters

typeIdentifier
CorrelationTypeIdentifier
required
The type of correlation to query:
  • 'HKCorrelationTypeIdentifierBloodPressure' - Blood pressure readings
  • 'HKCorrelationTypeIdentifierFood' - Food/nutrition entries
options
QueryOptionsWithSortOrder
required
Query options for filtering and sorting

Returns

correlations
Promise<CorrelationSample[]>
Array of correlation samples matching the query criteria

Example

import { queryCorrelationSamples } from '@kingstinct/react-native-healthkit'

// Query blood pressure readings
const bloodPressureReadings = await queryCorrelationSamples(
  'HKCorrelationTypeIdentifierBloodPressure',
  {
    limit: 10,
    ascending: false, // newest first
  }
)

for (const reading of bloodPressureReadings) {
  console.log('Blood Pressure:', {
    date: reading.startDate,
    uuid: reading.uuid,
  })
  
  // Extract systolic and diastolic values
  for (const obj of reading.objects) {
    if ('quantityType' in obj) {
      console.log(`${obj.quantityType}: ${obj.quantity} ${obj.unit}`)
    }
  }
}

// Query food entries from last week
const weekAgo = new Date()
weekAgo.setDate(weekAgo.getDate() - 7)

const foodEntries = await queryCorrelationSamples(
  'HKCorrelationTypeIdentifierFood',
  {
    filter: {
      startDate: weekAgo,
    },
    limit: -1, // all entries
    ascending: true,
  }
)

for (const food of foodEntries) {
  console.log('Food:', {
    date: food.startDate,
    foodType: food.metadataFoodType,
  })
  
  // Extract nutritional values
  for (const obj of food.objects) {
    if ('quantityType' in obj) {
      console.log(`${obj.quantityType}: ${obj.quantity} ${obj.unit}`)
    }
  }
}

queryCorrelationSamplesWithAnchor

Query correlation samples using an anchor to track changes and support pagination. This is useful for syncing data efficiently.

Signature

function queryCorrelationSamplesWithAnchor(
  typeIdentifier: CorrelationTypeIdentifier,
  options: QueryOptionsWithAnchor
): Promise<QueryCorrelationSamplesWithAnchorResponse>

Parameters

typeIdentifier
CorrelationTypeIdentifier
required
The type of correlation to query (same as queryCorrelationSamples)
options
QueryOptionsWithAnchor
required
Query options with anchor support

Returns

response
Promise<QueryCorrelationSamplesWithAnchorResponse>

Example

import { queryCorrelationSamplesWithAnchor } from '@kingstinct/react-native-healthkit'

// Initial query
let anchor: string | undefined

const initialResult = await queryCorrelationSamplesWithAnchor(
  'HKCorrelationTypeIdentifierBloodPressure',
  {
    limit: 100,
    anchor: undefined, // first query
  }
)

console.log(`Initial: ${initialResult.correlations.length} readings`)
anchor = initialResult.newAnchor

// Subsequent query - only gets changes since last query
const updateResult = await queryCorrelationSamplesWithAnchor(
  'HKCorrelationTypeIdentifierBloodPressure',
  {
    limit: 100,
    anchor, // use saved anchor
  }
)

console.log(`New readings: ${updateResult.correlations.length}`)
console.log(`Deleted readings: ${updateResult.deletedSamples.length}`)
anchor = updateResult.newAnchor // save for next time

// Handle deletions
for (const deleted of updateResult.deletedSamples) {
  console.log(`Reading ${deleted.uuid} was deleted on ${deleted.deletedDate}`)
}
Anchored queries are ideal for syncing correlation data efficiently. The anchor tracks the state of the HealthKit database, so subsequent queries only return changes since the last query.

Build docs developers (and LLMs) love