Skip to content

HealthSamplingPackage

The sampling package for health data from Apple Health or Google Health Connect.

Provides the single measure type dk.cachet.carp.health (HEALTH). Which health data to collect is set by a HealthSamplingConfiguration; use getHealthMeasure to create a Measure for a list of HealthDataTypes. Works on Android and iOS and needs the HealthService connected device.

Key points:

Example of a protocol that collects health data once per hour:

 final healthService = HealthService();
 protocol.addConnectedDevice(healthService, phone);

 protocol.addTaskControl(
     PeriodicTrigger(period: Duration(minutes: 60)),
     BackgroundTask(measures: [
       HealthSamplingPackage.getHealthMeasure([
         HealthDataType.STEPS,
         HealthDataType.BASAL_ENERGY_BURNED,
         HealthDataType.WEIGHT,
         HealthDataType.SLEEP_SESSION,
       ])
     ]),
     healthService);

Register this package before running a study:

  SamplingPackageRegistry().register(HealthSamplingPackage());
Inheritance

Constructors

HealthSamplingPackage

HealthSamplingPackage()

Constants

HEALTH

String const HEALTH

Generic measure type for collection of health data from Apple Health or Google Health Connect.

Use getHealthMeasure to create a measure for the specific health data types to collect.

HEALTH_NAMESPACE

String const HEALTH_NAMESPACE

The namespace of the health measure types, dk.cachet.carp.health.

Properties

deviceManager

Get the DeviceManager for the device used by this package.

deviceType

String get deviceType
override

What device type is this package using?

This device type is matched with the DeviceConfiguration.roleName when a PrimaryDeviceConfiguration is deployed on the phone and executed by a SmartphoneStudyController.

Note that it is assumed that a sampling package only supports one type of device.

samplingSchemes

DataTypeSamplingSchemeMap get samplingSchemes
override

The default sampling schemes for all dataTypes in this package.

All sampling packages should defined a DataTypeSamplingScheme for each data type.

Methods

create

Probe? create(
  1. String type
)
override

Creates a new Probe of the specified type. Note that type should be one of the dataTypes that this package supports. Returns null if a probe cannot be created for the type.

getHealthMeasure

Measure getHealthMeasure(
  1. List<HealthDataType> types, [
  2. int days = 30
])

Returns a HEALTH measure that collects the health data types.

The first collection fetches data days days back in time. Defaults to 30 days, which is the maximum that Google Health Connect allows. Later collections start from the last time data was collected.

onRegister

void onRegister()
override

Callback method when this package is being registered.