@flomentumsolutions/capacitor-health-extended 0.0.17 → 0.0.18

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.
@@ -270,7 +270,7 @@ class HealthPlugin : Plugin() {
270
270
  private fun getMetricAndMapper(dataType: String): MetricAndMapper {
271
271
  return when (dataType) {
272
272
  "steps" -> metricAndMapper("steps", CapHealthPermission.READ_STEPS, StepsRecord.COUNT_TOTAL) { it?.toDouble() }
273
- "active-calories" -> metricAndMapper(
273
+ "active-calories", "activeCalories" -> metricAndMapper(
274
274
  "calories",
275
275
  CapHealthPermission.READ_ACTIVE_CALORIES,
276
276
  ActiveCaloriesBurnedRecord.ACTIVE_CALORIES_TOTAL
@@ -301,7 +301,7 @@ class HealthPlugin : Plugin() {
301
301
  CoroutineScope(Dispatchers.IO).launch {
302
302
  try {
303
303
  val result = when (dataType) {
304
- "heart-rate" -> readLatestHeartRate()
304
+ "heart-rate", "heartRate" -> readLatestHeartRate()
305
305
  "weight" -> readLatestWeight()
306
306
  "height" -> readLatestHeight()
307
307
  "steps" -> readLatestSteps()
@@ -370,11 +370,11 @@ class HealthPlugin : Plugin() {
370
370
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
371
371
  pageSize = 1
372
372
  )
373
- val result = healthConnectClient.readRecords(request)
374
- val record = result.records.firstOrNull() ?: throw Exception("No weight data found")
373
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
374
+
375
375
  return JSObject().apply {
376
- put("value", record.weight.inKilograms)
377
- put("timestamp", record.time.epochSecond * 1000) // Convert to milliseconds like iOS
376
+ put("value", record?.weight?.inKilograms ?: 0)
377
+ put("timestamp", (record?.time?.epochSecond ?: 0) * 1000)
378
378
  put("unit", "kg")
379
379
  }
380
380
  }
@@ -388,11 +388,10 @@ class HealthPlugin : Plugin() {
388
388
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
389
389
  pageSize = 1
390
390
  )
391
- val result = healthConnectClient.readRecords(request)
392
- val record = result.records.firstOrNull() ?: throw Exception("No step data found")
391
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
393
392
  return JSObject().apply {
394
- put("value", record.count)
395
- put("timestamp", record.endTime.epochSecond * 1000) // Convert to milliseconds like iOS
393
+ put("value", record?.count ?: 0)
394
+ put("timestamp", (record?.endTime?.epochSecond ?: 0) * 1000)
396
395
  put("unit", "count")
397
396
  }
398
397
  }
@@ -406,11 +405,11 @@ class HealthPlugin : Plugin() {
406
405
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
407
406
  pageSize = 1
408
407
  )
409
- val result = healthConnectClient.readRecords(request)
410
- val record = result.records.firstOrNull() ?: throw Exception("No HRV data found")
408
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
409
+
411
410
  return JSObject().apply {
412
- put("value", record.heartRateVariabilityMillis)
413
- put("timestamp", record.time.epochSecond * 1000) // Convert to milliseconds like iOS
411
+ put("value", record?.heartRateVariabilityMillis ?: 0)
412
+ put("timestamp", (record?.time?.epochSecond ?: 0) * 1000)
414
413
  put("unit", "ms")
415
414
  }
416
415
  }
@@ -424,12 +423,12 @@ class HealthPlugin : Plugin() {
424
423
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
425
424
  pageSize = 1
426
425
  )
427
- val result = healthConnectClient.readRecords(request)
428
- val record = result.records.firstOrNull() ?: throw Exception("No blood pressure data found")
426
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
427
+
429
428
  return JSObject().apply {
430
- put("systolic", record.systolic.inMillimetersOfMercury)
431
- put("diastolic", record.diastolic.inMillimetersOfMercury)
432
- put("timestamp", record.time.epochSecond * 1000) // Convert to milliseconds like iOS
429
+ put("systolic", record?.systolic?.inMillimetersOfMercury ?: 0)
430
+ put("diastolic", record?.diastolic?.inMillimetersOfMercury ?: 0)
431
+ put("timestamp", (record?.time?.epochSecond ?: 0) * 1000)
433
432
  put("unit", "mmHg")
434
433
  }
435
434
  }
@@ -443,11 +442,11 @@ class HealthPlugin : Plugin() {
443
442
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
444
443
  pageSize = 1
445
444
  )
446
- val result = healthConnectClient.readRecords(request)
447
- val record = result.records.firstOrNull() ?: throw Exception("No height data found")
445
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
446
+
448
447
  return JSObject().apply {
449
- put("value", record.height.inMeters)
450
- put("timestamp", record.time.epochSecond * 1000) // Convert to milliseconds like iOS
448
+ put("value", record?.height?.inMeters ?: 0)
449
+ put("timestamp", (record?.time?.epochSecond ?: 0) * 1000)
451
450
  put("unit", "m")
452
451
  }
453
452
  }
@@ -461,11 +460,10 @@ class HealthPlugin : Plugin() {
461
460
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
462
461
  pageSize = 1
463
462
  )
464
- val result = healthConnectClient.readRecords(request)
465
- val record = result.records.firstOrNull() ?: throw Exception("No distance data found")
463
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
466
464
  return JSObject().apply {
467
- put("value", record.distance.inMeters)
468
- put("timestamp", record.endTime.epochSecond * 1000) // Convert to milliseconds like iOS
465
+ put("value", record?.distance?.inMeters ?: 0)
466
+ put("timestamp", (record?.endTime?.epochSecond ?: 0) * 1000)
469
467
  put("unit", "m")
470
468
  }
471
469
  }
@@ -479,11 +477,10 @@ class HealthPlugin : Plugin() {
479
477
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
480
478
  pageSize = 1
481
479
  )
482
- val result = healthConnectClient.readRecords(request)
483
- val record = result.records.firstOrNull() ?: throw Exception("No active calories data found")
480
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
484
481
  return JSObject().apply {
485
- put("value", record.energy.inKilocalories)
486
- put("timestamp", record.endTime.epochSecond * 1000) // Convert to milliseconds like iOS
482
+ put("value", record?.energy?.inKilocalories ?: 0)
483
+ put("timestamp", (record?.endTime?.epochSecond ?: 0) * 1000)
487
484
  put("unit", "kcal")
488
485
  }
489
486
  }
@@ -497,11 +494,10 @@ class HealthPlugin : Plugin() {
497
494
  timeRangeFilter = TimeRangeFilter.after(Instant.EPOCH),
498
495
  pageSize = 1
499
496
  )
500
- val result = healthConnectClient.readRecords(request)
501
- val record = result.records.firstOrNull() ?: throw Exception("No total calories data found")
497
+ val record = healthConnectClient.readRecords(request).records.firstOrNull()
502
498
  return JSObject().apply {
503
- put("value", record.energy.inKilocalories)
504
- put("timestamp", record.endTime.epochSecond * 1000) // Convert to milliseconds like iOS
499
+ put("value", record?.energy?.inKilocalories ?: 0)
500
+ put("timestamp", (record?.endTime?.epochSecond ?: 0) * 1000)
505
501
  put("unit", "kcal")
506
502
  }
507
503
  }
@@ -623,7 +619,7 @@ class HealthPlugin : Plugin() {
623
619
  )
624
620
 
625
621
  return response.map {
626
- val mappedValue = metricAndMapper.getValue(it.result)
622
+ val mappedValue = metricAndMapper.getValue(it.result) ?: 0.0
627
623
  AggregatedSample(it.startTime, it.endTime, mappedValue)
628
624
  }
629
625
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flomentumsolutions/capacitor-health-extended",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Capacitor plugin for Apple HealthKit and Google Health Connect Platform",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",