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:
- Creates a HealthProbe for the HEALTH measure type.
- Uses a HealthServiceManager as its device manager.
- On registration, registers its JSON types and a HealthUserTaskFactory, so a HealthAppTask runs as a HealthUserTask.
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
-
- Object
- SamplingPackage
- SmartphoneSamplingPackage
- HealthSamplingPackage
Constructors
HealthSamplingPackage
Constants
HEALTH
Generic measure type for collection of health data from Apple Health or Google Health Connect.
- One-time measure.
- Uses the HealthService device for data collection.
- Use a HealthSamplingConfiguration for sampling configuration.
Use getHealthMeasure to create a measure for the specific health data types to collect.
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
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
The default sampling schemes for all dataTypes in this package.
All sampling packages should defined a DataTypeSamplingScheme for each data type.
Methods
create
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
- List<
HealthDataType> types, [ - 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
Callback method when this package is being registered.