@appeeky/expo-healthkit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/LICENSE +92 -0
- package/README.md +453 -0
- package/android/build.gradle +22 -0
- package/android/src/main/AndroidManifest.xml +74 -0
- package/android/src/main/java/expo/modules/healthkit/ExpoHealthKitModule.kt +228 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectMapping.kt +129 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectNutrition.kt +152 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectRationaleActivity.kt +62 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectService.kt +1054 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectUnits.kt +133 -0
- package/android/src/main/java/expo/modules/healthkit/HealthConnectWorkouts.kt +105 -0
- package/android/src/main/java/expo/modules/healthkit/HealthKitExceptions.kt +30 -0
- package/app.plugin.js +1 -0
- package/build/ExpoHealthKitModule.d.ts +39 -0
- package/build/ExpoHealthKitModule.d.ts.map +1 -0
- package/build/ExpoHealthKitModule.js +35 -0
- package/build/ExpoHealthKitModule.js.map +1 -0
- package/build/ExpoHealthKitModule.web.d.ts +39 -0
- package/build/ExpoHealthKitModule.web.d.ts.map +1 -0
- package/build/ExpoHealthKitModule.web.js +105 -0
- package/build/ExpoHealthKitModule.web.js.map +1 -0
- package/build/dates.d.ts +6 -0
- package/build/dates.d.ts.map +1 -0
- package/build/dates.js +13 -0
- package/build/dates.js.map +1 -0
- package/build/errors.d.ts +9 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +18 -0
- package/build/errors.js.map +1 -0
- package/build/identifiers.d.ts +418 -0
- package/build/identifiers.d.ts.map +1 -0
- package/build/identifiers.js +402 -0
- package/build/identifiers.js.map +1 -0
- package/build/index.d.ts +454 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +418 -0
- package/build/index.js.map +1 -0
- package/build/types.d.ts +542 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/docs/banner.jpg +0 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoHealthKit.podspec +30 -0
- package/ios/ExpoHealthKitModule.swift +155 -0
- package/ios/HealthKitAdvancedQueries.swift +458 -0
- package/ios/HealthKitExceptions.swift +109 -0
- package/ios/HealthKitIdentifiers.swift +183 -0
- package/ios/HealthKitRecords.swift +214 -0
- package/ios/HealthKitService.swift +626 -0
- package/ios/PrivacyInfo.xcprivacy +14 -0
- package/package.json +105 -0
- package/plugin/build/index.d.ts +30 -0
- package/plugin/build/index.js +138 -0
- package/src/ExpoHealthKitModule.ts +116 -0
- package/src/ExpoHealthKitModule.web.ts +140 -0
- package/src/dates.ts +17 -0
- package/src/errors.ts +22 -0
- package/src/identifiers.ts +494 -0
- package/src/index.ts +563 -0
- package/src/types.ts +625 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { useEvent } from 'expo';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import ExpoHealthKitModule from './ExpoHealthKitModule';
|
|
5
|
+
import { fromIso, resolveEndDate, toIso, toOptionalIso } from './dates';
|
|
6
|
+
import { HealthKitUnavailableError } from './errors';
|
|
7
|
+
import {
|
|
8
|
+
AuthorizationRequestStatus,
|
|
9
|
+
AuthorizationStatus,
|
|
10
|
+
BiologicalSex,
|
|
11
|
+
BloodType,
|
|
12
|
+
CategoryType,
|
|
13
|
+
CharacteristicType,
|
|
14
|
+
ClinicalType,
|
|
15
|
+
CorrelationType,
|
|
16
|
+
ElectrocardiogramClassification,
|
|
17
|
+
ElectrocardiogramSymptomsStatus,
|
|
18
|
+
ElectrocardiogramType,
|
|
19
|
+
AudiogramType,
|
|
20
|
+
ActivitySummaryType,
|
|
21
|
+
SeriesType,
|
|
22
|
+
FitzpatrickSkinType,
|
|
23
|
+
QuantityType,
|
|
24
|
+
SleepAnalysisValue,
|
|
25
|
+
StatisticsOption,
|
|
26
|
+
Unit,
|
|
27
|
+
UpdateFrequency,
|
|
28
|
+
WheelchairUse,
|
|
29
|
+
WorkoutActivityType,
|
|
30
|
+
WorkoutType,
|
|
31
|
+
} from './identifiers';
|
|
32
|
+
import type {
|
|
33
|
+
AnchoredQueryOptions,
|
|
34
|
+
AnchoredQueryResult,
|
|
35
|
+
AuthorizationOptions,
|
|
36
|
+
CategorySample,
|
|
37
|
+
CategorySampleInput,
|
|
38
|
+
ClinicalRecord,
|
|
39
|
+
ClinicalRecordQueryOptions,
|
|
40
|
+
Correlation,
|
|
41
|
+
CorrelationInput,
|
|
42
|
+
CorrelationQueryOptions,
|
|
43
|
+
DeleteObjectsOptions,
|
|
44
|
+
ElectrocardiogramQueryOptions,
|
|
45
|
+
ElectrocardiogramSample,
|
|
46
|
+
ActivitySummary,
|
|
47
|
+
ActivitySummaryQueryOptions,
|
|
48
|
+
AudiogramSample,
|
|
49
|
+
DateRangeQueryOptions,
|
|
50
|
+
HeartbeatSeriesQueryOptions,
|
|
51
|
+
HeartbeatSeriesSample,
|
|
52
|
+
QuantityQueryOptions,
|
|
53
|
+
QuantitySample,
|
|
54
|
+
SampleQueryOptions,
|
|
55
|
+
QuantitySampleInput,
|
|
56
|
+
Statistics,
|
|
57
|
+
StatisticsCollectionQueryOptions,
|
|
58
|
+
StatisticsQueryOptions,
|
|
59
|
+
WorkoutInput,
|
|
60
|
+
WorkoutQueryOptions,
|
|
61
|
+
WorkoutRoute,
|
|
62
|
+
WorkoutRouteQueryOptions,
|
|
63
|
+
WorkoutSample,
|
|
64
|
+
} from './types';
|
|
65
|
+
|
|
66
|
+
export * from './identifiers';
|
|
67
|
+
export * from './errors';
|
|
68
|
+
export type * from './types';
|
|
69
|
+
|
|
70
|
+
const HK_UNLIMITED = 0;
|
|
71
|
+
|
|
72
|
+
function isHealthPlatform(): boolean {
|
|
73
|
+
return Platform.OS === 'ios' || Platform.OS === 'android';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function assertAvailable(): void {
|
|
77
|
+
if (!isHealthPlatform() || !ExpoHealthKitModule.isHealthDataAvailable()) {
|
|
78
|
+
throw new HealthKitUnavailableError();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isAvailable(): boolean {
|
|
83
|
+
return isHealthPlatform() && ExpoHealthKitModule.isHealthDataAvailable();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function requestAuthorization(options: AuthorizationOptions = {}): Promise<boolean> {
|
|
87
|
+
assertAvailable();
|
|
88
|
+
return ExpoHealthKitModule.requestAuthorization({
|
|
89
|
+
toRead: [...(options.toRead ?? [])],
|
|
90
|
+
toShare: [...(options.toShare ?? [])],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function getAuthorizationStatus(type: string): Promise<AuthorizationStatus> {
|
|
95
|
+
assertAvailable();
|
|
96
|
+
return (await ExpoHealthKitModule.getAuthorizationStatus(type)) as AuthorizationStatus;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function getRequestStatusForAuthorization(
|
|
100
|
+
options: AuthorizationOptions = {}
|
|
101
|
+
): Promise<AuthorizationRequestStatus> {
|
|
102
|
+
assertAvailable();
|
|
103
|
+
return (await ExpoHealthKitModule.getRequestStatusForAuthorization({
|
|
104
|
+
toRead: [...(options.toRead ?? [])],
|
|
105
|
+
toShare: [...(options.toShare ?? [])],
|
|
106
|
+
})) as AuthorizationRequestStatus;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function queryQuantitySamples(
|
|
110
|
+
options: QuantityQueryOptions
|
|
111
|
+
): Promise<QuantitySample[]> {
|
|
112
|
+
assertAvailable();
|
|
113
|
+
const samples = await ExpoHealthKitModule.queryQuantitySamples({
|
|
114
|
+
type: options.type,
|
|
115
|
+
unit: options.unit,
|
|
116
|
+
from: toOptionalIso(options.from),
|
|
117
|
+
to: toOptionalIso(options.to),
|
|
118
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
119
|
+
ascending: options.ascending ?? false,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return samples.map((sample) => ({
|
|
123
|
+
...sample,
|
|
124
|
+
startDate: fromIso(sample.startDate),
|
|
125
|
+
endDate: fromIso(sample.endDate),
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function queryCategorySamples(options: SampleQueryOptions): Promise<CategorySample[]> {
|
|
130
|
+
assertAvailable();
|
|
131
|
+
const samples = await ExpoHealthKitModule.queryCategorySamples({
|
|
132
|
+
type: options.type,
|
|
133
|
+
from: toOptionalIso(options.from),
|
|
134
|
+
to: toOptionalIso(options.to),
|
|
135
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
136
|
+
ascending: options.ascending ?? false,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return samples.map((sample) => ({
|
|
140
|
+
...sample,
|
|
141
|
+
startDate: fromIso(sample.startDate),
|
|
142
|
+
endDate: fromIso(sample.endDate),
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function queryWorkouts(options: WorkoutQueryOptions = {}): Promise<WorkoutSample[]> {
|
|
147
|
+
assertAvailable();
|
|
148
|
+
const samples = await ExpoHealthKitModule.queryWorkouts({
|
|
149
|
+
from: toOptionalIso(options.from),
|
|
150
|
+
to: toOptionalIso(options.to),
|
|
151
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
152
|
+
ascending: options.ascending ?? false,
|
|
153
|
+
activityType: options.activityType,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return samples.map((sample) => ({
|
|
157
|
+
...sample,
|
|
158
|
+
startDate: fromIso(sample.startDate),
|
|
159
|
+
endDate: fromIso(sample.endDate),
|
|
160
|
+
workoutActivityType: sample.workoutActivityType as WorkoutSample['workoutActivityType'],
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function queryElectrocardiograms(
|
|
165
|
+
options: ElectrocardiogramQueryOptions = {}
|
|
166
|
+
): Promise<ElectrocardiogramSample[]> {
|
|
167
|
+
assertAvailable();
|
|
168
|
+
const samples = await ExpoHealthKitModule.queryElectrocardiograms({
|
|
169
|
+
from: toOptionalIso(options.from),
|
|
170
|
+
to: toOptionalIso(options.to),
|
|
171
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
172
|
+
ascending: options.ascending ?? false,
|
|
173
|
+
includeVoltage: options.includeVoltage ?? false,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return samples.map((sample) => ({
|
|
177
|
+
...sample,
|
|
178
|
+
startDate: fromIso(sample.startDate),
|
|
179
|
+
endDate: fromIso(sample.endDate),
|
|
180
|
+
classification: sample.classification as ElectrocardiogramSample['classification'],
|
|
181
|
+
symptomsStatus: sample.symptomsStatus as ElectrocardiogramSample['symptomsStatus'],
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function queryActivitySummaries(
|
|
186
|
+
options: ActivitySummaryQueryOptions = {}
|
|
187
|
+
): Promise<ActivitySummary[]> {
|
|
188
|
+
assertAvailable();
|
|
189
|
+
return ExpoHealthKitModule.queryActivitySummaries({
|
|
190
|
+
from: toOptionalIso(options.from),
|
|
191
|
+
to: toOptionalIso(options.to),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function queryClinicalRecords(
|
|
196
|
+
options: ClinicalRecordQueryOptions
|
|
197
|
+
): Promise<ClinicalRecord[]> {
|
|
198
|
+
assertAvailable();
|
|
199
|
+
const samples = await ExpoHealthKitModule.queryClinicalRecords({
|
|
200
|
+
type: options.type,
|
|
201
|
+
from: toOptionalIso(options.from),
|
|
202
|
+
to: toOptionalIso(options.to),
|
|
203
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
204
|
+
ascending: options.ascending ?? false,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
return samples.map((sample) => ({
|
|
208
|
+
...sample,
|
|
209
|
+
startDate: fromIso(sample.startDate),
|
|
210
|
+
endDate: fromIso(sample.endDate),
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function queryAudiograms(
|
|
215
|
+
options: DateRangeQueryOptions = {}
|
|
216
|
+
): Promise<AudiogramSample[]> {
|
|
217
|
+
assertAvailable();
|
|
218
|
+
const samples = await ExpoHealthKitModule.queryAudiograms({
|
|
219
|
+
from: toOptionalIso(options.from),
|
|
220
|
+
to: toOptionalIso(options.to),
|
|
221
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
222
|
+
ascending: options.ascending ?? false,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return samples.map((sample) => ({
|
|
226
|
+
...sample,
|
|
227
|
+
startDate: fromIso(sample.startDate),
|
|
228
|
+
endDate: fromIso(sample.endDate),
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function queryWorkoutRoute(
|
|
233
|
+
options: WorkoutRouteQueryOptions
|
|
234
|
+
): Promise<WorkoutRoute[]> {
|
|
235
|
+
assertAvailable();
|
|
236
|
+
const routes = await ExpoHealthKitModule.queryWorkoutRoute({
|
|
237
|
+
workoutUUID: options.workoutUUID,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return routes.map((route) => ({
|
|
241
|
+
...route,
|
|
242
|
+
startDate: fromIso(route.startDate),
|
|
243
|
+
endDate: fromIso(route.endDate),
|
|
244
|
+
locations: route.locations.map((location) => ({
|
|
245
|
+
...location,
|
|
246
|
+
timestamp: fromIso(location.timestamp),
|
|
247
|
+
})),
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function mapQuantitySample(sample: {
|
|
252
|
+
uuid: string;
|
|
253
|
+
type: string;
|
|
254
|
+
startDate: string;
|
|
255
|
+
endDate: string;
|
|
256
|
+
value: number;
|
|
257
|
+
unit: string;
|
|
258
|
+
sourceName?: string;
|
|
259
|
+
sourceId?: string;
|
|
260
|
+
metadata?: Record<string, string>;
|
|
261
|
+
}) {
|
|
262
|
+
return {
|
|
263
|
+
...sample,
|
|
264
|
+
startDate: fromIso(sample.startDate),
|
|
265
|
+
endDate: fromIso(sample.endDate),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export async function queryCorrelations(options: CorrelationQueryOptions): Promise<Correlation[]> {
|
|
270
|
+
assertAvailable();
|
|
271
|
+
const samples = await ExpoHealthKitModule.queryCorrelations({
|
|
272
|
+
type: options.type,
|
|
273
|
+
from: toOptionalIso(options.from),
|
|
274
|
+
to: toOptionalIso(options.to),
|
|
275
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
276
|
+
ascending: options.ascending ?? false,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return samples.map((sample) => ({
|
|
280
|
+
...sample,
|
|
281
|
+
startDate: fromIso(sample.startDate),
|
|
282
|
+
endDate: fromIso(sample.endDate),
|
|
283
|
+
objects: sample.objects.map(mapQuantitySample),
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function queryHeartbeatSeries(
|
|
288
|
+
options: HeartbeatSeriesQueryOptions = {}
|
|
289
|
+
): Promise<HeartbeatSeriesSample[]> {
|
|
290
|
+
assertAvailable();
|
|
291
|
+
const samples = await ExpoHealthKitModule.queryHeartbeatSeries({
|
|
292
|
+
from: toOptionalIso(options.from),
|
|
293
|
+
to: toOptionalIso(options.to),
|
|
294
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
295
|
+
ascending: options.ascending ?? false,
|
|
296
|
+
includeBeats: options.includeBeats ?? true,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return samples.map((sample) => ({
|
|
300
|
+
...sample,
|
|
301
|
+
startDate: fromIso(sample.startDate),
|
|
302
|
+
endDate: fromIso(sample.endDate),
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export async function queryStatistics(options: StatisticsQueryOptions): Promise<Statistics> {
|
|
307
|
+
assertAvailable();
|
|
308
|
+
const stats = await ExpoHealthKitModule.queryStatistics({
|
|
309
|
+
type: options.type,
|
|
310
|
+
unit: options.unit,
|
|
311
|
+
from: toOptionalIso(options.from),
|
|
312
|
+
to: toOptionalIso(options.to),
|
|
313
|
+
options: options.options ?? 0,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
...stats,
|
|
318
|
+
startDate: fromIso(stats.startDate),
|
|
319
|
+
endDate: fromIso(stats.endDate),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export async function queryStatisticsCollection(
|
|
324
|
+
options: StatisticsCollectionQueryOptions
|
|
325
|
+
): Promise<Statistics[]> {
|
|
326
|
+
assertAvailable();
|
|
327
|
+
const interval = options.interval ?? { day: 1 };
|
|
328
|
+
const results = await ExpoHealthKitModule.queryStatisticsCollection({
|
|
329
|
+
type: options.type,
|
|
330
|
+
unit: options.unit,
|
|
331
|
+
from: toOptionalIso(options.from),
|
|
332
|
+
to: toOptionalIso(options.to),
|
|
333
|
+
options: options.options ?? 0,
|
|
334
|
+
year: interval.year ?? 0,
|
|
335
|
+
month: interval.month ?? 0,
|
|
336
|
+
day: interval.day ?? 0,
|
|
337
|
+
hour: interval.hour ?? 0,
|
|
338
|
+
minute: interval.minute ?? 0,
|
|
339
|
+
second: interval.second ?? 0,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return results.map((stats) => ({
|
|
343
|
+
...stats,
|
|
344
|
+
startDate: fromIso(stats.startDate),
|
|
345
|
+
endDate: fromIso(stats.endDate),
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export async function queryAnchored(options: AnchoredQueryOptions): Promise<AnchoredQueryResult> {
|
|
350
|
+
assertAvailable();
|
|
351
|
+
const result = await ExpoHealthKitModule.queryAnchored({
|
|
352
|
+
type: options.type,
|
|
353
|
+
unit: options.unit,
|
|
354
|
+
from: toOptionalIso(options.from),
|
|
355
|
+
to: toOptionalIso(options.to),
|
|
356
|
+
limit: options.limit ?? HK_UNLIMITED,
|
|
357
|
+
anchor: options.anchor ?? undefined,
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
added: result.added.map((sample) => ({
|
|
362
|
+
...sample,
|
|
363
|
+
startDate: fromIso(sample.startDate),
|
|
364
|
+
endDate: fromIso(sample.endDate),
|
|
365
|
+
})),
|
|
366
|
+
deleted: result.deleted,
|
|
367
|
+
anchor: result.anchor ?? null,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export async function saveQuantitySample(sample: QuantitySampleInput): Promise<string> {
|
|
372
|
+
assertAvailable();
|
|
373
|
+
return ExpoHealthKitModule.saveQuantitySample({
|
|
374
|
+
type: sample.type,
|
|
375
|
+
unit: sample.unit,
|
|
376
|
+
value: sample.value,
|
|
377
|
+
startDate: toIso(sample.startDate),
|
|
378
|
+
endDate: resolveEndDate(sample.startDate, sample.endDate),
|
|
379
|
+
metadata: sample.metadata,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export async function saveCategorySample(sample: CategorySampleInput): Promise<string> {
|
|
384
|
+
assertAvailable();
|
|
385
|
+
return ExpoHealthKitModule.saveCategorySample({
|
|
386
|
+
type: sample.type,
|
|
387
|
+
value: sample.value,
|
|
388
|
+
startDate: toIso(sample.startDate),
|
|
389
|
+
endDate: resolveEndDate(sample.startDate, sample.endDate),
|
|
390
|
+
metadata: sample.metadata,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export async function saveWorkout(workout: WorkoutInput): Promise<string> {
|
|
395
|
+
assertAvailable();
|
|
396
|
+
return ExpoHealthKitModule.saveWorkout({
|
|
397
|
+
activityType: workout.activityType,
|
|
398
|
+
startDate: toIso(workout.startDate),
|
|
399
|
+
endDate: toIso(workout.endDate),
|
|
400
|
+
energyBurned: workout.energyBurned,
|
|
401
|
+
energyBurnedUnit: workout.energyBurnedUnit,
|
|
402
|
+
distance: workout.distance,
|
|
403
|
+
distanceUnit: workout.distanceUnit,
|
|
404
|
+
metadata: workout.metadata,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export async function saveCorrelation(correlation: CorrelationInput): Promise<string> {
|
|
409
|
+
assertAvailable();
|
|
410
|
+
const startDate = toIso(correlation.startDate);
|
|
411
|
+
const endDate = resolveEndDate(correlation.startDate, correlation.endDate);
|
|
412
|
+
return ExpoHealthKitModule.saveCorrelation({
|
|
413
|
+
type: correlation.type,
|
|
414
|
+
startDate,
|
|
415
|
+
endDate,
|
|
416
|
+
objects: correlation.objects.map((object) => ({
|
|
417
|
+
type: object.type,
|
|
418
|
+
unit: object.unit,
|
|
419
|
+
value: object.value,
|
|
420
|
+
startDate: toIso(object.startDate ?? correlation.startDate),
|
|
421
|
+
endDate: resolveEndDate(
|
|
422
|
+
object.endDate ?? object.startDate ?? correlation.startDate,
|
|
423
|
+
object.endDate ?? correlation.endDate
|
|
424
|
+
),
|
|
425
|
+
metadata: object.metadata,
|
|
426
|
+
})),
|
|
427
|
+
metadata: correlation.metadata,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export async function deleteObjects(options: DeleteObjectsOptions): Promise<number> {
|
|
432
|
+
assertAvailable();
|
|
433
|
+
return ExpoHealthKitModule.deleteObjects({
|
|
434
|
+
uuid: options.uuid,
|
|
435
|
+
type: options.type,
|
|
436
|
+
from: toOptionalIso(options.from),
|
|
437
|
+
to: toOptionalIso(options.to),
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export async function getBiologicalSex(): Promise<BiologicalSex> {
|
|
442
|
+
assertAvailable();
|
|
443
|
+
return (await ExpoHealthKitModule.getBiologicalSex()) as BiologicalSex;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export async function getBloodType(): Promise<BloodType> {
|
|
447
|
+
assertAvailable();
|
|
448
|
+
return (await ExpoHealthKitModule.getBloodType()) as BloodType;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export async function getDateOfBirth(): Promise<Date | null> {
|
|
452
|
+
assertAvailable();
|
|
453
|
+
const value = await ExpoHealthKitModule.getDateOfBirth();
|
|
454
|
+
return value ? fromIso(value) : null;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export async function getFitzpatrickSkinType(): Promise<FitzpatrickSkinType> {
|
|
458
|
+
assertAvailable();
|
|
459
|
+
return (await ExpoHealthKitModule.getFitzpatrickSkinType()) as FitzpatrickSkinType;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export async function getWheelchairUse(): Promise<WheelchairUse> {
|
|
463
|
+
assertAvailable();
|
|
464
|
+
return (await ExpoHealthKitModule.getWheelchairUse()) as WheelchairUse;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export async function enableBackgroundDelivery(
|
|
468
|
+
type: string,
|
|
469
|
+
frequency: UpdateFrequency
|
|
470
|
+
): Promise<boolean> {
|
|
471
|
+
assertAvailable();
|
|
472
|
+
return ExpoHealthKitModule.enableBackgroundDelivery(type, frequency);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export async function disableBackgroundDelivery(type: string): Promise<boolean> {
|
|
476
|
+
assertAvailable();
|
|
477
|
+
return ExpoHealthKitModule.disableBackgroundDelivery(type);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export async function disableAllBackgroundDelivery(): Promise<boolean> {
|
|
481
|
+
assertAvailable();
|
|
482
|
+
return ExpoHealthKitModule.disableAllBackgroundDelivery();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export async function observe(types: readonly string[]): Promise<void> {
|
|
486
|
+
assertAvailable();
|
|
487
|
+
await ExpoHealthKitModule.observeTypes([...types]);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export async function clearObservers(): Promise<void> {
|
|
491
|
+
assertAvailable();
|
|
492
|
+
await ExpoHealthKitModule.clearObserverQueries();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export function addUpdateListener(listener: (event: { type: string }) => void): { remove(): void } {
|
|
496
|
+
return ExpoHealthKitModule.addListener('onUpdate', listener);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export function useHealthKitUpdates() {
|
|
500
|
+
return useEvent(ExpoHealthKitModule, 'onUpdate');
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const HealthKit = {
|
|
504
|
+
isAvailable,
|
|
505
|
+
requestAuthorization,
|
|
506
|
+
getAuthorizationStatus,
|
|
507
|
+
getRequestStatusForAuthorization,
|
|
508
|
+
queryQuantitySamples,
|
|
509
|
+
queryCategorySamples,
|
|
510
|
+
queryWorkouts,
|
|
511
|
+
queryElectrocardiograms,
|
|
512
|
+
queryActivitySummaries,
|
|
513
|
+
queryClinicalRecords,
|
|
514
|
+
queryAudiograms,
|
|
515
|
+
queryWorkoutRoute,
|
|
516
|
+
queryCorrelations,
|
|
517
|
+
queryHeartbeatSeries,
|
|
518
|
+
queryStatistics,
|
|
519
|
+
queryStatisticsCollection,
|
|
520
|
+
queryAnchored,
|
|
521
|
+
saveQuantitySample,
|
|
522
|
+
saveCategorySample,
|
|
523
|
+
saveWorkout,
|
|
524
|
+
saveCorrelation,
|
|
525
|
+
deleteObjects,
|
|
526
|
+
getBiologicalSex,
|
|
527
|
+
getBloodType,
|
|
528
|
+
getDateOfBirth,
|
|
529
|
+
getFitzpatrickSkinType,
|
|
530
|
+
getWheelchairUse,
|
|
531
|
+
enableBackgroundDelivery,
|
|
532
|
+
disableBackgroundDelivery,
|
|
533
|
+
disableAllBackgroundDelivery,
|
|
534
|
+
observe,
|
|
535
|
+
clearObservers,
|
|
536
|
+
addUpdateListener,
|
|
537
|
+
useHealthKitUpdates,
|
|
538
|
+
QuantityType,
|
|
539
|
+
CategoryType,
|
|
540
|
+
CharacteristicType,
|
|
541
|
+
CorrelationType,
|
|
542
|
+
WorkoutType,
|
|
543
|
+
ElectrocardiogramType,
|
|
544
|
+
AudiogramType,
|
|
545
|
+
SeriesType,
|
|
546
|
+
ActivitySummaryType,
|
|
547
|
+
ClinicalType,
|
|
548
|
+
Unit,
|
|
549
|
+
WorkoutActivityType,
|
|
550
|
+
SleepAnalysisValue,
|
|
551
|
+
UpdateFrequency,
|
|
552
|
+
StatisticsOption,
|
|
553
|
+
AuthorizationStatus,
|
|
554
|
+
AuthorizationRequestStatus,
|
|
555
|
+
BiologicalSex,
|
|
556
|
+
BloodType,
|
|
557
|
+
FitzpatrickSkinType,
|
|
558
|
+
WheelchairUse,
|
|
559
|
+
ElectrocardiogramClassification,
|
|
560
|
+
ElectrocardiogramSymptomsStatus,
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
export default HealthKit;
|