From dd2f2c34a8f009c13ea4eb2aae8faa135bece16a Mon Sep 17 00:00:00 2001 From: Cirych Date: Thu, 21 Mar 2024 13:48:57 +0100 Subject: [PATCH 01/16] fix types --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- RCTAppleHealthKit/{Types => }/RCTAggregatorType.h | 0 RCTAppleHealthKit/{Types => }/RCTInterval.h | 0 RCTAppleHealthKit/{Types => }/RCTStatisticRequest.h | 0 RCTAppleHealthKit/{Types => }/RCTStatisticRequest.m | 0 RCTAppleHealthKit/RCTTypes.h | 6 +++--- RNAppleHealthKit.podspec | 8 ++++---- package.json | 6 +++--- 9 files changed, 12 insertions(+), 12 deletions(-) rename RCTAppleHealthKit/{Types => }/RCTAggregatorType.h (100%) rename RCTAppleHealthKit/{Types => }/RCTInterval.h (100%) rename RCTAppleHealthKit/{Types => }/RCTStatisticRequest.h (100%) rename RCTAppleHealthKit/{Types => }/RCTStatisticRequest.m (100%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f75ed932..66628427 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,7 @@ name: Bug report about: Create a report to help us improve title: '' labels: bug -assignees: lucaspbordignon +assignees: @ornament-health/mobiledev --- **Describe the bug** diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 3ade1769..1fe49f78 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,7 +3,7 @@ name: Feature request about: Suggest an idea for this project title: '' labels: enhancement -assignees: lucaspbordignon +assignees: @ornament-health/mobiledev --- **Is your feature request related to a problem? Please describe.** diff --git a/RCTAppleHealthKit/Types/RCTAggregatorType.h b/RCTAppleHealthKit/RCTAggregatorType.h similarity index 100% rename from RCTAppleHealthKit/Types/RCTAggregatorType.h rename to RCTAppleHealthKit/RCTAggregatorType.h diff --git a/RCTAppleHealthKit/Types/RCTInterval.h b/RCTAppleHealthKit/RCTInterval.h similarity index 100% rename from RCTAppleHealthKit/Types/RCTInterval.h rename to RCTAppleHealthKit/RCTInterval.h diff --git a/RCTAppleHealthKit/Types/RCTStatisticRequest.h b/RCTAppleHealthKit/RCTStatisticRequest.h similarity index 100% rename from RCTAppleHealthKit/Types/RCTStatisticRequest.h rename to RCTAppleHealthKit/RCTStatisticRequest.h diff --git a/RCTAppleHealthKit/Types/RCTStatisticRequest.m b/RCTAppleHealthKit/RCTStatisticRequest.m similarity index 100% rename from RCTAppleHealthKit/Types/RCTStatisticRequest.m rename to RCTAppleHealthKit/RCTStatisticRequest.m diff --git a/RCTAppleHealthKit/RCTTypes.h b/RCTAppleHealthKit/RCTTypes.h index 55ac2b16..09fcdac8 100644 --- a/RCTAppleHealthKit/RCTTypes.h +++ b/RCTAppleHealthKit/RCTTypes.h @@ -3,6 +3,6 @@ // Copyright (c) 2021 Greg Wilson. All rights reserved. // -#import "Types/RCTInterval.h" -#import "Types/RCTAggregatorType.h" -#import "Types/RCTStatisticRequest.h" +#import "RCTInterval.h" +#import "RCTAggregatorType.h" +#import "RCTStatisticRequest.h" diff --git a/RNAppleHealthKit.podspec b/RNAppleHealthKit.podspec index 144eeb5c..2e419068 100644 --- a/RNAppleHealthKit.podspec +++ b/RNAppleHealthKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'RNAppleHealthKit' - s.version = '1.7.0' + s.version = '1.19.1' s.summary = 'A React Native package to interact with Apple HealthKit' # This description is used to generate tags and improve search results. @@ -21,12 +21,12 @@ Pod::Spec.new do |s| A React Native package to interact with Apple HealthKit DESC - s.homepage = 'https://github.com/agencyenterprise/react-native-health' + s.homepage = 'https://github.com/Ornament-Health/react-native-health' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Agency Enterprise' => '' } - s.source = { :git => 'https://github.com/agencyenterprise/react-native-healthkit.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/Ornament-Health/react-native-health.git', :tag => s.version.to_s } - s.ios.deployment_target = '9.0' + s.ios.deployment_target = '14.0' s.swift_version = '4.2' s.source_files = 'RCTAppleHealthKit/**/*' diff --git a/package.json b/package.json index 9f780629..bc29296f 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "react-native-health", - "version": "1.19.0", + "version": "1.19.1", "description": "A React Native package to interact with Apple HealthKit", "main": "index.js", "repository": { "type": "git", - "url": "git+https://github.com/agencyenterprise/react-native-healthkit.git" + "url": "git+https://github.com/Ornament-Health/react-native-health.git" }, "keywords": [ "Apple", @@ -18,7 +18,7 @@ "ios" ], "bugs": { - "url": "https://github.com/agencyenterprise/react-native-healthkit/issues" + "url": "https://github.com/Ornament-Health/react-native-health/issues" }, "license": "MIT", "devDependencies": { From 8de78d54a86288fa5b8f6ca09edcbc5048e7981b Mon Sep 17 00:00:00 2001 From: Cirych Date: Thu, 21 Mar 2024 14:10:23 +0100 Subject: [PATCH 02/16] remove expo --- app.plugin.js | 56 ---------------------------------------------- docs/Expo.md | 61 --------------------------------------------------- package.json | 3 --- 3 files changed, 120 deletions(-) delete mode 100644 app.plugin.js delete mode 100644 docs/Expo.md diff --git a/app.plugin.js b/app.plugin.js deleted file mode 100644 index 8dbb66a4..00000000 --- a/app.plugin.js +++ /dev/null @@ -1,56 +0,0 @@ -const { withEntitlementsPlist, withInfoPlist } = require('@expo/config-plugins') - -const HEALTH_SHARE = 'Allow $(PRODUCT_NAME) to check health info' -const HEALTH_UPDATE = 'Allow $(PRODUCT_NAME) to update health info' -const HEALTH_CLINIC_SHARE = 'Allow $(PRODUCT_NAME) to check health clinical info' - -const withHealthKit = ( - config, - { healthSharePermission, healthUpdatePermission, isClinicalDataEnabled, healthClinicalDescription } = {}, -) => { - // Add permissions - config = withInfoPlist(config, (config) => { - config.modResults.NSHealthShareUsageDescription = - healthSharePermission || - config.modResults.NSHealthShareUsageDescription || - HEALTH_SHARE - config.modResults.NSHealthUpdateUsageDescription = - healthUpdatePermission || - config.modResults.NSHealthUpdateUsageDescription || - HEALTH_UPDATE - isClinicalDataEnabled ? - config.modResults.NSHealthClinicalHealthRecordsShareUsageDescription = - healthClinicalDescription || - config.modResults.NSHealthClinicalHealthRecordsShareUsageDescription || - HEALTH_CLINIC_SHARE : - null - - return config - }) - - // Add entitlements. These are automatically synced when using EAS build for production apps. - config = withEntitlementsPlist(config, (config) => { - config.modResults['com.apple.developer.healthkit'] = true - if ( - !Array.isArray(config.modResults['com.apple.developer.healthkit.access']) - ) { - config.modResults['com.apple.developer.healthkit.access'] = [] - } - - if (isClinicalDataEnabled) { - config.modResults['com.apple.developer.healthkit.access'].push( - 'health-records', - ) - - // Remove duplicates - config.modResults['com.apple.developer.healthkit.access'] = [ - ...new Set(config.modResults['com.apple.developer.healthkit.access']), - ] - } - - return config - }) - - return config -} -module.exports = withHealthKit diff --git a/docs/Expo.md b/docs/Expo.md deleted file mode 100644 index 8dcf86f1..00000000 --- a/docs/Expo.md +++ /dev/null @@ -1,61 +0,0 @@ -# Expo installation - -> This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.dev/workflow/customizing/). - -First install the package with yarn, npm, or [`npx expo install`](https://docs.expo.dev/more/expo-cli/#installation). - -```sh -expo install react-native-health -``` - -After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`: - -```json -{ - "expo": { - "plugins": ["react-native-health"] - } -} -``` - -Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.dev/workflow/customizing/) guide. - -## API - -The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used. - -- `healthSharePermission` (_string_): Sets the iOS `NSHealthShareUsageDescription` permission message to the `Info.plist`. Defaults to `Allow $(PRODUCT_NAME) to check health info`. -- `healthUpdatePermission` (_string_): Sets the iOS `NSHealthUpdateUsageDescription` permission message to the `Info.plist`. Defaults to `Allow $(PRODUCT_NAME) to update health info`. -- `isClinicalDataEnabled` (_boolean_): Adds `health-records` to the `com.apple.developer.healthkit.access` entitlement in the iOS project. Defaults to false. -- `healthClinicalDescription` (_string_): Sets the iOS `NSHealthClinicalHealthRecordsShareUsageDescription` permission message to the `Info.plist`. Defaults to `Allow $(PRODUCT_NAME) to check health info`. - -`app.config.js` - -```json -{ - "expo": { - "plugins": [ - [ - "react-native-health", - { - "isClinicalDataEnabled": true, - "healthSharePermission": "Custom health share permission", - "healthUpdatePermission": "Custom health update permission", - "healthClinicalDescription": "Custom health share permission for clinical data" - } - ] - ] - } -} -``` - -## Background Processing - -Background processing is not currently supported by this plugin. - -## Capabilities - -This plugin will enable the iOS `com.apple.developer.healthkit` entitlement, but in order to sync this with the bundle identifier' production capabilities you'll need to do one of two things: - -- Automatic: Build the app with [EAS build](https://docs.expo.io/build/introduction/) -- Manual: Visit [Apple developer portal](https://developer.apple.com/account/resources/identifiers/list) and enable the HealthKit capability for your bundle identifier before building for production. This can also be done via Xcode. diff --git a/package.json b/package.json index bc29296f..8a9f2490 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,5 @@ }, "peerDependencies": { "react-native": ">=0.40.0" - }, - "dependencies": { - "@expo/config-plugins": "^2.0.0" } } From 680f24b013af5681c1da80f7a9f51c0c6270f3f7 Mon Sep 17 00:00:00 2001 From: Cirych Date: Thu, 21 Mar 2024 14:10:51 +0100 Subject: [PATCH 03/16] version --- RNAppleHealthKit.podspec | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RNAppleHealthKit.podspec b/RNAppleHealthKit.podspec index 2e419068..86b92062 100644 --- a/RNAppleHealthKit.podspec +++ b/RNAppleHealthKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'RNAppleHealthKit' - s.version = '1.19.1' + s.version = '1.19.2' s.summary = 'A React Native package to interact with Apple HealthKit' # This description is used to generate tags and improve search results. diff --git a/package.json b/package.json index 8a9f2490..64ddd1e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-health", - "version": "1.19.1", + "version": "1.19.2", "description": "A React Native package to interact with Apple HealthKit", "main": "index.js", "repository": { From e7de898a70e1ae7136cab5750b5db37e394e3247 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:26:51 +0200 Subject: [PATCH 04/16] feat: dietary and insulin statistics methods added --- RCTAppleHealthKit/RCTAppleHealthKit.m | 66 -------- .../RTCAppleHealthKit+Methods_Statistics.h | 12 +- .../RTCAppleHealthKit+Methods_Statistics.m | 147 ------------------ index.d.ts | 52 ------- 4 files changed, 1 insertion(+), 276 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 4486c2b8..96ee361c 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -701,72 +701,6 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryWater:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietarySugar:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryFatSaturated:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryCholesterol:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryCalcium:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryIron:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryPotassium:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietarySodium:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminA:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminC:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminD:input callback:callback]; -} - RCT_EXPORT_METHOD(getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index a3db63ea..0b622d9b 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -29,17 +29,7 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 1707eea3..23c04f09 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -131,7 +131,6 @@ - (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RC quantity:HKQuantityTypeIdentifierDietaryProtein unit:unit]; } - - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -144,7 +143,6 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTR quantity:HKQuantityTypeIdentifierDietaryFiber unit:unit]; } - - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -157,7 +155,6 @@ - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(R quantity:HKQuantityTypeIdentifierDietaryFatTotal unit:unit]; } - - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -170,150 +167,6 @@ - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTR quantity:HKQuantityTypeIdentifierDietaryWater unit:unit]; } - -- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietarySugar - unit:unit]; -} - -- (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryFatSaturated - unit:unit]; -} - -- (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryCholesterol - unit:unit]; -} - -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryCarbohydrates - unit:unit]; -} - -- (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryCalcium - unit:unit]; -} - -- (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryIron - unit:unit]; -} - -- (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryPotassium - unit:unit]; -} - -- (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietarySodium - unit:unit]; -} - -- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminA - unit:unit]; -} - -- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminC - unit:unit]; -} - -- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminD - unit:unit]; -} - - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { diff --git a/index.d.ts b/index.d.ts index dd3d15b1..cf5c4324 100644 --- a/index.d.ts +++ b/index.d.ts @@ -549,58 +549,6 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void - getStatisticDietarySugar( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryFatSaturated( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryCholesterol( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryCarbohydrates( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryCalcium( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryIron( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - getStatisticDietaryPotassium( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - getStatisticDietarySodium( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - getStatisticDietaryVitaminA( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryVitaminC( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - - getStatisticDietaryVitaminD( - options: HealthStatisticsDietaryInputOptions, - callback: (err: string, results: Array) => void, - ): void - getStatisticInsulinDelivery( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, From 49ef5006263992970bd7564b941359fa9b0d8580 Mon Sep 17 00:00:00 2001 From: Anastasia M <40164951+mobileapps23@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:40:45 +0200 Subject: [PATCH 05/16] Update statistics.md --- docs/statistics.md | 53 ++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/docs/statistics.md b/docs/statistics.md index 7c3ae924..adfef9fc 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -2,38 +2,27 @@ Query statistic (aggregated) biomarkers. -| Value | Methods | -|---------------------------------------------|------------------------------------| -| bodyMass (body weight) | getStatisticBodyMass | -| bloodPressureSystolic (systolic pressure) | getStatisticBloodPressureSystolic | -| bloodPressureDiastolic (diastolic pressure) | getStatisticBloodPressureDiastolic | -| bloodGlucose (blood glucose) | getStatisticBloodGlucose | -| bodyMassIndex (body mass index) | getStatisticBodyMassIndex | -| height (body height) | getStatisticHeight | -| stepCount (number of steps) | getStatisticStepCount | -| heartRate (pulse) | getStatisticHeartRate | -| bodyTemperature (body temperature) | getStatisticBodyTemperature | -| oxygenSaturation (oxygen saturation) | getStatisticOxygenSaturation | -| restingHeartRate (resting heart rate) | getStatisticRestingHeartRate | -| Dietary | | -| energyConsumed (energy value) | getStatisticDietaryEnergyConsumed | -| protein (protein) | getStatisticDietaryProtein | -| fiber (cellulose) | getStatisticDietaryFiber | -| totalFat (fats) | getStatisticDietaryTotalFat | -| water | getStatisticDietaryWater (water) | -| sugar | getStatisticDietarySugar (sugar) | -| fatSaturated | getStatisticDietaryFatSaturated | -| cholesterol | getStatisticDietaryCholesterol | -| carbohydrates | getStatisticDietaryCarbohydrates | -| calcium | getStatisticDietaryCalcium | -| iron | getStatisticDietaryIron | -| potassium | getStatisticDietaryPotassium | -| sodium | getStatisticDietarySodium | -| vitaminA | getStatisticDietaryVitaminA | -| vitaminC | getStatisticDietaryVitaminC | -| vitaminD | getStatisticDietarySugar | -| Lab and Test Results || -| insulinDelivery (insulin delivery) | getStatisticInsulinDelivery | +|Value|Methods| +|---|---| +|bodyMass (вес)|getStatisticBodyMass| +|bloodPressureSystolic (систолическое давление)|getStatisticBloodPressureSystolic| +|bloodPressureDiastolic (диастолическое давление)|getStatisticBloodPressureDiastolic| +|bloodGlucose (глюкоза в крови)|getStatisticBloodGlucose| +|bodyMassIndex (индекс массы тела)|getStatisticBodyMassIndex| +|height (рост)|getStatisticHeight| +|stepCount (количество шагов)|getStatisticStepCount| +|heartRate (пульс)|getStatisticHeartRate| +|bodyTemperature (температура тела)|getStatisticBodyTemperature| +|oxygenSaturation (насыщение кислородом)|getStatisticOxygenSaturation| +|restingHeartRate (пульс в покое)|getStatisticRestingHeartRate| +|Dietary| | +|energyConsumed (энергетическая ценность)|getStatisticDietaryEnergyConsumed| +|protein (белок)|getStatisticDietaryProtein| +|fiber (клетчатка)|getStatisticDietaryFiber| +|totalFat (жиры)|getStatisticDietaryTotalFat| +|water|getStatisticDietaryWater (вода)| +|Lab and Test Results|| +|insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| From bd903cbb6735ad737b91cdb76d58464c93f2e924 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:34:57 +0300 Subject: [PATCH 06/16] feat: method getStatisticDietarySugar added --- RCTAppleHealthKit/RCTAppleHealthKit.m | 6 ++++++ .../RTCAppleHealthKit+Methods_Statistics.h | 1 + .../RTCAppleHealthKit+Methods_Statistics.m | 17 +++++++++++++++++ docs/statistics.md | 1 + index.d.ts | 5 +++++ 5 files changed, 30 insertions(+) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 96ee361c..0e2b74bd 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -701,6 +701,12 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryWater:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietarySugar:input callback:callback]; +} + RCT_EXPORT_METHOD(getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index 0b622d9b..5b4c04d2 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -29,6 +29,7 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 23c04f09..6b4d71ae 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -131,6 +131,7 @@ - (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RC quantity:HKQuantityTypeIdentifierDietaryProtein unit:unit]; } + - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -143,6 +144,7 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTR quantity:HKQuantityTypeIdentifierDietaryFiber unit:unit]; } + - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -155,6 +157,7 @@ - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(R quantity:HKQuantityTypeIdentifierDietaryFatTotal unit:unit]; } + - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -167,6 +170,20 @@ - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTR quantity:HKQuantityTypeIdentifierDietaryWater unit:unit]; } + +- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietarySugar + unit:unit]; +} + - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { diff --git a/docs/statistics.md b/docs/statistics.md index adfef9fc..c4ce53b3 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -21,6 +21,7 @@ Query statistic (aggregated) biomarkers. |fiber (клетчатка)|getStatisticDietaryFiber| |totalFat (жиры)|getStatisticDietaryTotalFat| |water|getStatisticDietaryWater (вода)| +|sugar|getStatisticDietarySugar (сахар)| |Lab and Test Results|| |insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| diff --git a/index.d.ts b/index.d.ts index cf5c4324..2cc99d56 100644 --- a/index.d.ts +++ b/index.d.ts @@ -549,6 +549,11 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void + getStatisticDietarySugar( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticInsulinDelivery( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, From e5d2e1b2a87bebcdcf922bcc4d2a2b6467f7c0b1 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Wed, 15 Nov 2023 19:03:42 +0300 Subject: [PATCH 07/16] feat: dietary statistics methods added --- RCTAppleHealthKit/RCTAppleHealthKit.m | 60 ++++++++ .../RTCAppleHealthKit+Methods_Statistics.h | 11 +- .../RTCAppleHealthKit+Methods_Statistics.m | 130 ++++++++++++++++++ docs/statistics.md | 10 ++ index.d.ts | 47 +++++++ 5 files changed, 257 insertions(+), 1 deletion(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 0e2b74bd..4486c2b8 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -707,6 +707,66 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietarySugar:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryFatSaturated:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryCholesterol:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryCalcium:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryIron:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryPotassium:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietarySodium:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminA:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminC:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminD:input callback:callback]; +} + RCT_EXPORT_METHOD(getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index 5b4c04d2..a3db63ea 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -30,7 +30,16 @@ - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - +- (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 6b4d71ae..1707eea3 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -184,6 +184,136 @@ - (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTR unit:unit]; } +- (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryFatSaturated + unit:unit]; +} + +- (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryCholesterol + unit:unit]; +} + +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryCarbohydrates + unit:unit]; +} + +- (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryCalcium + unit:unit]; +} + +- (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryIron + unit:unit]; +} + +- (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryPotassium + unit:unit]; +} + +- (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietarySodium + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminA + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminC + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminD + unit:unit]; +} + - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { diff --git a/docs/statistics.md b/docs/statistics.md index c4ce53b3..a75055c6 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -22,6 +22,16 @@ Query statistic (aggregated) biomarkers. |totalFat (жиры)|getStatisticDietaryTotalFat| |water|getStatisticDietaryWater (вода)| |sugar|getStatisticDietarySugar (сахар)| +|fatSaturated|getStatisticDietaryFatSaturated| +|cholesterol|getStatisticDietaryCholesterol| +|carbohydrates|getStatisticDietaryCarbohydrates| +|calcium|getStatisticDietaryCalcium| +|iron|getStatisticDietaryIron| +|potassium|getStatisticDietaryPotassium| +|sodium|getStatisticDietarySodium| +|vitaminA|getStatisticDietaryVitaminA| +|vitaminC|getStatisticDietaryVitaminC| +|vitaminD|getStatisticDietarySugar| |Lab and Test Results|| |insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| diff --git a/index.d.ts b/index.d.ts index 2cc99d56..dd3d15b1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -554,6 +554,53 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void + getStatisticDietaryFatSaturated( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryCholesterol( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryCarbohydrates( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryCalcium( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryIron( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietaryPotassium( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietarySodium( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietaryVitaminA( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminC( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminD( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticInsulinDelivery( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, From 93be935ed028dfccb3a4097b85c42d96e74046d9 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Mon, 27 Nov 2023 17:24:56 +0300 Subject: [PATCH 08/16] feat: nutrition statistic methods added --- RCTAppleHealthKit/RCTAppleHealthKit.m | 166 ++++++++- .../RTCAppleHealthKit+Methods_Statistics.h | 57 ++- .../RTCAppleHealthKit+Methods_Statistics.m | 340 +++++++++++++++++- docs/statistics.md | 61 +++- index.d.ts | 151 +++++++- 5 files changed, 712 insertions(+), 63 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 4486c2b8..7ef75e83 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -677,10 +677,10 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryEnergyConsumed:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryProtein:input callback:callback]; + [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -689,22 +689,28 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryFiber:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietarySugar:input callback:callback]; +} + RCT_EXPORT_METHOD(getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; [self statistics_getStatisticDietaryTotalFat:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryWater:input callback:callback]; + [self statistics_getStatisticDietaryFatMonounsaturated:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryFatPolyunsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietarySugar:input callback:callback]; + [self statistics_getStatisticDietaryFatPolyunsaturated:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -719,10 +725,88 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryCholesterol:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; + [self statistics_getStatisticDietaryProtein:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminA:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryThiamin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryThiamin:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryRiboflavin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryRiboflavin:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryNiacin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryNiacin:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryPantothenicAcid:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryPantothenicAcid:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminB6:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminB6:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryBiotin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryBiotin:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminB12:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminB12:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminC:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminD:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminE:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminE:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminK:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminK:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryFolate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryFolate:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -731,12 +815,30 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryCalcium:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDietaryChloride:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryChloride:input callback:callback]; +} + RCT_EXPORT_METHOD(getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; [self statistics_getStatisticDietaryIron:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDietaryMagnesium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryMagnesium:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryPhosphorus:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryPhosphorus:input callback:callback]; +} + RCT_EXPORT_METHOD(getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; @@ -749,22 +851,58 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietarySodium:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminA:input callback:callback]; + [self statistics_getStatisticDietaryZinc:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminC:input callback:callback]; + [self statistics_getStatisticDietaryWater:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryCaffeine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminD:input callback:callback]; + [self statistics_getStatisticDietaryCaffeine:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryChromium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryChromium:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryCopper:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryCopper:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryIodine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryIodine:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryManganese:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryManganese:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryMolybdenum:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryMolybdenum:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietarySelenium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietarySelenium:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index a3db63ea..f88f87b2 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -22,24 +22,65 @@ - (void)statistics_getStatisticOxygenSaturation:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticRestingHeartRate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -// Dietary +// MARK: - Dietary + +// MARK: - Macronutrients - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryFatPolyunsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Vitamins + +- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryThiamin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryRiboflavin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryNiacin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryPantothenicAcid:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminB6:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryBiotin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminB12:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminE:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryVitaminK:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryFolate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Minerals + - (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryChloride:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryMagnesium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryPhosphorus:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Hydration + +- (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Caffeination + +- (void)statistics_getStatisticDietaryCaffeine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Ultratrace Minerals + +- (void)statistics_getStatisticDietaryChromium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCopper:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryIodine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryManganese:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryMolybdenum:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietarySelenium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 1707eea3..8b412562 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -104,6 +104,7 @@ - (void)statistics_getStatisticRestingHeartRate:(NSDictionary *)input callback:( } // MARK: - Dietary +// MARK: - Macronutrients - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; @@ -119,7 +120,7 @@ - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callb unit:unit]; } -- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -128,7 +129,7 @@ - (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RC HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryProtein + quantity:HKQuantityTypeIdentifierDietaryCarbohydrates unit:unit]; } @@ -145,6 +146,19 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTR unit:unit]; } +- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietarySugar + unit:unit]; +} + - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -158,20 +172,20 @@ - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(R unit:unit]; } -- (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); return; } - HKUnit *unit = HKUnit.literUnit; + HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryWater + quantity:HKQuantityTypeIdentifierDietaryFatMonounsaturated unit:unit]; } -- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryFatPolyunsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -180,7 +194,7 @@ - (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTR HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietarySugar + quantity:HKQuantityTypeIdentifierDietaryFatPolyunsaturated unit:unit]; } @@ -210,7 +224,7 @@ - (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback unit:unit]; } -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -219,10 +233,183 @@ - (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callba HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryCarbohydrates + quantity:HKQuantityTypeIdentifierDietaryProtein + unit:unit]; +} + +// MARK: - Vitamins + +- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminA + unit:unit]; +} + +- (void)statistics_getStatisticDietaryThiamin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryThiamin + unit:unit]; +} + +- (void)statistics_getStatisticDietaryRiboflavin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryRiboflavin + unit:unit]; +} + +- (void)statistics_getStatisticDietaryNiacin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryNiacin + unit:unit]; +} + +- (void)statistics_getStatisticDietaryPantothenicAcid:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryPantothenicAcid + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminB6:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminB6 + unit:unit]; +} + +- (void)statistics_getStatisticDietaryBiotin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryBiotin + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminB12:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminB12 + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminC + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminD unit:unit]; } +- (void)statistics_getStatisticDietaryVitaminE:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminE + unit:unit]; +} + +- (void)statistics_getStatisticDietaryVitaminK:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryVitaminK + unit:unit]; +} + +- (void)statistics_getStatisticDietaryFolate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryFolate + unit:unit]; +} + +// MARK: - Minerals + - (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -236,6 +423,19 @@ - (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RC unit:unit]; } +- (void)statistics_getStatisticDietaryChloride:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryChloride + unit:unit]; +} + - (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -249,6 +449,32 @@ - (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTRe unit:unit]; } +- (void)statistics_getStatisticDietaryMagnesium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryMagnesium + unit:unit]; +} + +- (void)statistics_getStatisticDietaryPhosphorus:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryPhosphorus + unit:unit]; +} + - (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { @@ -275,7 +501,7 @@ - (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCT unit:unit]; } -- (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -284,11 +510,28 @@ - (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(R HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminA + quantity:HKQuantityTypeIdentifierDietaryZinc unit:unit]; } -- (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +// MARK: - Hydration + +- (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.literUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryWater + unit:unit]; +} + +// MARK: - Caffeination + +- (void)statistics_getStatisticDietaryCaffeine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -297,11 +540,13 @@ - (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(R HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminC + quantity:HKQuantityTypeIdentifierDietaryCaffeine unit:unit]; } -- (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +// MARK: - Ultratrace Minerals + +- (void)statistics_getStatisticDietaryChromium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; if (aggregatorType != 3) { callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); @@ -310,7 +555,72 @@ - (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(R HKUnit *unit = HKUnit.gramUnit; [self basicStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryVitaminD + quantity:HKQuantityTypeIdentifierDietaryChromium + unit:unit]; +} + +- (void)statistics_getStatisticDietaryCopper:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryCopper + unit:unit]; +} + +- (void)statistics_getStatisticDietaryIodine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryIodine + unit:unit]; +} + +- (void)statistics_getStatisticDietaryManganese:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryManganese + unit:unit]; +} + +- (void)statistics_getStatisticDietaryMolybdenum:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietaryMolybdenum + unit:unit]; +} + +- (void)statistics_getStatisticDietarySelenium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.gramUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDietarySelenium unit:unit]; } diff --git a/docs/statistics.md b/docs/statistics.md index a75055c6..2129db1b 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -16,22 +16,51 @@ Query statistic (aggregated) biomarkers. |oxygenSaturation (насыщение кислородом)|getStatisticOxygenSaturation| |restingHeartRate (пульс в покое)|getStatisticRestingHeartRate| |Dietary| | -|energyConsumed (энергетическая ценность)|getStatisticDietaryEnergyConsumed| -|protein (белок)|getStatisticDietaryProtein| -|fiber (клетчатка)|getStatisticDietaryFiber| -|totalFat (жиры)|getStatisticDietaryTotalFat| -|water|getStatisticDietaryWater (вода)| -|sugar|getStatisticDietarySugar (сахар)| -|fatSaturated|getStatisticDietaryFatSaturated| -|cholesterol|getStatisticDietaryCholesterol| -|carbohydrates|getStatisticDietaryCarbohydrates| -|calcium|getStatisticDietaryCalcium| -|iron|getStatisticDietaryIron| -|potassium|getStatisticDietaryPotassium| -|sodium|getStatisticDietarySodium| -|vitaminA|getStatisticDietaryVitaminA| -|vitaminC|getStatisticDietaryVitaminC| -|vitaminD|getStatisticDietarySugar| +|Macronutrients| | +|EnergyConsumed|getStatisticDietaryEnergyConsumed| +|Carbohydrates|geStatisticDietaryCarbohydrates| +|Fiber|getStatisticDietaryFiber| +|Sugar|getStatisticDietarySugar| +|TotalFat|getStatisticDietaryTotalFat| +|FatMonounsaturated|getStatisticDietaryFatMonounsaturated| +|FatPolyunsaturated|getStatisticDietaryFatPolyunsaturated| +|FatSaturated|getStatisticDietaryFatSaturated| +|Cholesterol|getStatisticDietaryCholesterol| +|Protein|getStatisticDietaryProtein| +|Vitamins| | +|VitaminA|getStatisticDietaryVitaminA| +|Thiamin|getStatisticDietaryThiamin| +|Riboflavin|getStatisticDietaryRiboflavin| +|Niacin|getStatisticDietaryNiacin| +|PantothenicAcid|getStatisticDietaryPantothenicAcid| +|VitaminB6|getStatisticDietaryVitaminB6| +|Biotin|getStatisticDietaryBiotin| +|VitaminB12|getStatisticDietaryVitaminB12| +|VitaminC|getStatisticDietaryVitaminC| +|VitaminD|getStatisticDietaryVitaminD| +|VitaminE|getStatisticDietaryVitaminE| +|VitaminK|getStatisticDietaryVitaminK| +|Folate|getStatisticDietaryFolate| +|Minerals| | +|Calcium|getStatisticDietaryCalcium| +|Chloride|getStatisticDietaryChloride| +|Iron|getStatisticDietaryIron| +|Magnesium|getStatisticDietaryMagnesium| +|Phosphorus|getStatisticDietaryPhosphorus| +|Potassium|getStatisticDietaryPotassium| +|Sodium|getStatisticDietarySodium| +|Zinc|getStatisticDietaryZinc| +|Hydration| | +|Water|getStatisticDietaryWater| +|Caffeination| | +|Caffeine|getStatisticDietaryCaffeine| +|Ultratrace Minerals| | +|Chromium|getStatisticDietaryChromium| +|Copper|getStatisticDietaryCopper| +|Iodine|getStatisticDietaryIodine| +|Manganese|getStatisticDietaryManganese| +|Molybdenum|getStatisticDietaryMolybdenum| +|Selenium|getStatisticDietarySelenium| |Lab and Test Results|| |insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| diff --git a/index.d.ts b/index.d.ts index dd3d15b1..d27be42f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -524,12 +524,15 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void + // Dietary + + // Macronutrients getStatisticDietaryEnergyConsumed( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryProtein( + getStatisticDietaryCarbohydrates( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void @@ -538,65 +541,193 @@ declare module 'react-native-health' { options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - + + getStatisticDietarySugar( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietaryTotalFat( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void + + getStatisticDietaryFatMonounsaturated( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryFatPolyunsaturated( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryFatSaturated( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryCholesterol( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryProtein( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void - getStatisticDietaryWater( + // Vitamins + + getStatisticDietaryVitaminA( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietarySugar( + getStatisticDietaryThiamin( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryFatSaturated( + getStatisticDietaryRiboflavin( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryCholesterol( + getStatisticDietaryNiacin( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryCarbohydrates( + getStatisticDietaryPantothenicAcid( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminB6( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryBiotin( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminB12( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminC( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminD( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void + getStatisticDietaryVitaminE( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryVitaminK( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryFolate( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Minerals + getStatisticDietaryCalcium( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void + getStatisticDietaryChloride( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietaryIron( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void + + getStatisticDietaryMagnesium( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryPhosphorus( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + getStatisticDietaryPotassium( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void + getStatisticDietarySodium( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryVitaminA( + + getStatisticDietaryZinc( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryVitaminC( + // Hydration + + getStatisticDietaryWater( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void - getStatisticDietaryVitaminD( + // Caffeination + + getStatisticDietaryCaffeine( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Ultratrace Minerals + + getStatisticDietaryChromium( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryCopper( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryIodine( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryManganese( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietaryMolybdenum( + options: HealthStatisticsDietaryInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticDietarySelenium( options: HealthStatisticsDietaryInputOptions, callback: (err: string, results: Array) => void, ): void From 3fe59304c0c91dcd8a00a8daec1fdfe5b0ef2b39 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:44:37 +0300 Subject: [PATCH 09/16] statistics methods list extended; statctics input interface refactoring --- .../RCTAppleHealthKit+TypesAndPermissions.m | 16 +- RCTAppleHealthKit/RCTAppleHealthKit.m | 54 +++++++ .../RTCAppleHealthKit+Methods_Statistics.h | 28 ++++ .../RTCAppleHealthKit+Methods_Statistics.m | 130 +++++++++++++++ docs/statistics.md | 29 ++-- index.d.ts | 151 ++++++++++++------ src/constants/Permissions.js | 7 + 7 files changed, 354 insertions(+), 61 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m index 4145f141..74d10b25 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m @@ -43,6 +43,8 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex]; } else if ([@"LeanBodyMass" isEqualToString: key]) { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierLeanBodyMass]; + } else if ([@"AppleSleepingWristTemperature" isEqualToString: key] && systemVersion >= 16.0) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierAppleSleepingWristTemperature]; } // Hearing Identifiers @@ -81,6 +83,8 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierNikeFuel]; } else if ([@"AppleExerciseTime" isEqualToString: key] && systemVersion >= 9.3) { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierAppleExerciseTime]; + } else if ([@"DistanceWheelchair" isEqualToString: key] && systemVersion >= 10.0) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWheelchair]; } else if ([@"AppleStandHour" isEqualToString: key]) { return [HKObjectType quantityTypeForIdentifier:HKCategoryTypeIdentifierAppleStandHour]; } else if ([@"RunningPower" isEqualToString:key]) { @@ -320,6 +324,10 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierRespiratoryRate]; } else if ([@"OxygenSaturation" isEqualToString: key]) { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierOxygenSaturation]; + } else if ([@"heartRateRecoveryOneMinute" isEqualToString: key] && systemVersion >= 16.0) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRateRecoveryOneMinute]; + } else if ([@"AtrialFibrillationBurden" isEqualToString: key] && systemVersion >= 16.0) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierAtrialFibrillationBurden]; } if (@available(iOS 12.2, *)) { if ([@"HighHeartRateEvent" isEqualToString: key]) { @@ -415,13 +423,19 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key { return [HKObjectType workoutType]; } else if ([@"Workout" isEqualToString: key]) { return [HKObjectType workoutType]; - }else if ([@"WorkoutRoute" isEqualToString:key]){ + } else if ([@"WorkoutRoute" isEqualToString:key]){ return [HKSeriesType workoutRouteType]; } // Lab and tests if ([@"BloodAlcoholContent" isEqualToString: key]) { return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodAlcoholContent]; + } else if ([@"NumberOfTimesFallen" isEqualToString:key]) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierNumberOfTimesFallen]; + } else if ([@"PeakExpiratoryFlowRate" isEqualToString:key]) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeakExpiratoryFlowRate]; + } else if ([@"PeripheralPerfusionIndex" isEqualToString:key]) { + return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierPeripheralPerfusionIndex]; } // Activity Summary diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 7ef75e83..6afa2a35 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -911,6 +911,60 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticInsulinDelivery:input callback:callback]; } +RCT_EXPORT_METHOD(getStatisticDistanceWheelchair:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDistanceWheelchair:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticAppleExerciseTime:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticAppleExerciseTime:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticAppleSleepingWristTemperature:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticAppleSleepingWristTemperature:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticHeartRateRecoveryOneMinute:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticHeartRateRecoveryOneMinute:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticAtrialFibrillationBurden:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticAtrialFibrillationBurden:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticNumberOfTimesFallen:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticNumberOfTimesFallen:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticPeakExpiratoryFlowRate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticPeakExpiratoryFlowRate:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticPeripheralPerfusionIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticPeripheralPerfusionIndex:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticUvExposure:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticUvExposure:input callback:callback]; +} + RCT_EXPORT_METHOD(getMedianStatistic:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index f88f87b2..85ed1ae7 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -84,4 +84,32 @@ - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +// MARK: - Activity + +- (void)statistics_getStatisticDistanceWheelchair:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +- (void)statistics_getStatisticAppleExerciseTime:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Body Measurments + +- (void)statistics_getStatisticAppleSleepingWristTemperature:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Vital Signs + +- (void)statistics_getStatisticHeartRateRecoveryOneMinute:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +- (void)statistics_getStatisticAtrialFibrillationBurden:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - Lab And Test Results + +- (void)statistics_getStatisticNumberOfTimesFallen:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +- (void)statistics_getStatisticPeakExpiratoryFlowRate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +- (void)statistics_getStatisticPeripheralPerfusionIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + +// MARK: - UV Exposure + +- (void)statistics_getStatisticUvExposure:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; + @end diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 8b412562..669c1bb7 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -637,6 +637,136 @@ - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(R unit:unit]; } +// MARK: - Activity + +- (void)statistics_getStatisticDistanceWheelchair:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.meterUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierDistanceWheelchair + unit:unit]; +} + +- (void)statistics_getStatisticAppleExerciseTime:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.minuteUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierAppleExerciseTime + unit:unit]; +} + +// MARK: - Body Measurments + +- (void)statistics_getStatisticAppleSleepingWristTemperature:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.degreeCelsiusUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierAppleSleepingWristTemperature + unit:unit]; +} + +// MARK: - Vital Signs + +- (void)statistics_getStatisticHeartRateRecoveryOneMinute:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *count = [HKUnit countUnit]; + HKUnit *minute = [HKUnit minuteUnit]; + + HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[count unitDividedByUnit:minute]]; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierHeartRateRecoveryOneMinute + unit:unit]; +} + +- (void)statistics_getStatisticAtrialFibrillationBurden:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.percentUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierAtrialFibrillationBurden + unit:unit]; +} + +// MARK: - Lab And Test Results + +- (void)statistics_getStatisticNumberOfTimesFallen:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType != 3) { + callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.countUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierNumberOfTimesFallen + unit:unit]; +} + +- (void)statistics_getStatisticPeakExpiratoryFlowRate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[[HKUnit literUnit] unitDividedByUnit:[HKUnit minuteUnit]]]; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierPeakExpiratoryFlowRate + unit:unit]; +} + +- (void)statistics_getStatisticPeripheralPerfusionIndex:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.percentUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierPeripheralPerfusionIndex + unit:unit]; +} + +// MARK: - UV Exposure + +- (void)statistics_getStatisticUvExposure:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.countUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierUVExposure + unit:unit]; +} + // MARK: - Private - (void)basicStatisticsRequest:(NSDictionary *)input diff --git a/docs/statistics.md b/docs/statistics.md index 2129db1b..7485f829 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -63,7 +63,19 @@ Query statistic (aggregated) biomarkers. |Selenium|getStatisticDietarySelenium| |Lab and Test Results|| |insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| - +|number Of Times Fallen|getStatisticNumberOfTimesFallen| +|Peak Expiratory Flow Rate|getStatisticPeakExpiratoryFlowRate| +|Peripheral Perfusion Index|getStatisticPeripheralPerfusionIndex| +|Activity|| +|Distance Wheelchair|getStatisticDistanceWheelchair| +|Apple Exercise Time|getStatisticAppleExerciseTime| +|Body Measurments|| +|Apple Sleeping Wrist Temperature|getStatisticAppleSleepingWristTemperature| +|Vital Signs|| +|Heart Rate Recovery One Minute|getStatisticHeartRateRecoveryOneMinute| +|Atrial Fibrillation Burden|getStatisticAtrialFibrillationBurden| +|UV Exposure|| +|UV Exposure|getStatisticUvExposure| ## Example call @@ -77,16 +89,6 @@ let options = { endDate: new Date().toISOString(), // optional; default now } ``` -For dietary and insulinDelivery: -```typescript -let options: HealthStatisticsDietaryInputOptions = { - aggregator: HealthStatisticsDietaryAggregatorType.CUMULATIVE_SUM, - interval: HealthStatisticsIntervalType.DAY, // optional; default HealthStatisticsIntervalType.MONTH - unit: 'calorie', // optional - startDate: new Date(2021, 0, 0).toISOString(), - endDate: new Date().toISOString(), - } -``` Method call example: @@ -107,7 +109,7 @@ AppleHealthKit.getStatisticBodyMass( |name|type|required| |---|---|---| -|aggregator|HealthStatisticsCommonAggregatorType or HealthStatisticsStepsAggregatorType or HealthStatisticsDietaryAggregatorType|✓| +|aggregator|HealthStatisticsCommonAggregatorType or HealthStatisticsStepsAggregatorType or CumulativeAggregatorsType|✓| |interval|HealthStatisticsIntervalType|| |unit|string|| |startDate|string|✓| @@ -131,9 +133,8 @@ enum CumulativeAggregatorsType { export type HealthStatisticsCommonAggregatorType = GenericAggregatorsType | AverageAggregatorsType; -export type HealthStatisticsStepsAggregatorType = GenericAggregatorsType | CumulativeAggregatorsType; +export type HealthStatisticsStepsAggregatorType = GenericAggregatorsType | CumulativeAggregatorsType -export type HealthStatisticsDietaryAggregatorType = CumulativeAggregatorsType ``` ## Response diff --git a/index.d.ts b/index.d.ts index d27be42f..0b1c2395 100644 --- a/index.d.ts +++ b/index.d.ts @@ -528,212 +528,267 @@ declare module 'react-native-health' { // Macronutrients getStatisticDietaryEnergyConsumed( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryCarbohydrates( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFiber( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietarySugar( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryTotalFat( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatMonounsaturated( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatPolyunsaturated( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatSaturated( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryCholesterol( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryProtein( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void // Vitamins getStatisticDietaryVitaminA( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryThiamin( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryRiboflavin( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryNiacin( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPantothenicAcid( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminB6( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryBiotin( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminB12( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminC( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminD( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminE( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminK( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFolate( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void // Minerals getStatisticDietaryCalcium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryChloride( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryIron( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryMagnesium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPhosphorus( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPotassium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietarySodium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryZinc( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void // Hydration getStatisticDietaryWater( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void // Caffeination getStatisticDietaryCaffeine( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void // Ultratrace Minerals getStatisticDietaryChromium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryCopper( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryIodine( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryManganese( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryMolybdenum( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietarySelenium( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticInsulinDelivery( - options: HealthStatisticsDietaryInputOptions, + options: HealthStatisticsCumulativeInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Activity + + getStatisticDistanceWheelchair( + options: HealthStatisticsCumulativeInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticAppleExerciseTime( + options: HealthStatisticsCumulativeInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Body Measurments + + getStatisticAppleSleepingWristTemperature( + options: HealthStatisticsCommonInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Vital Signs + + getStatisticHeartRateRecoveryOneMinute( + options: HealthStatisticsCommonInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticAtrialFibrillationBurden( + options: HealthStatisticsCommonInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // Lab And Test Results + + getStatisticNumberOfTimesFallen( + options: HealthStatisticsCumulativeInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticPeakExpiratoryFlowRate( + options: HealthStatisticsCommonInputOptions, + callback: (err: string, results: Array) => void, + ): void + + getStatisticPeripheralPerfusionIndex( + options: HealthStatisticsCommonInputOptions, + callback: (err: string, results: Array) => void, + ): void + + // UV Exposure + + getStatisticUvExposure( + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void @@ -879,10 +934,7 @@ declare module 'react-native-health' { export enum HealthStatisticsIntervalType { MONTH = 0, DAY = 1, - } - - export type HealthStatisticsDietaryAggregatorType = - | CumulativeAggregatorsType + } export interface HealthStatisticsCommonInputOptions extends HealthUnitOptions { @@ -899,8 +951,8 @@ declare module 'react-native-health' { endDate?: string } - export interface HealthStatisticsDietaryInputOptions extends HealthUnitOptions { - aggregator: HealthStatisticsDietaryAggregatorType + export interface HealthStatisticsCumulativeInputOptions extends HealthUnitOptions { + aggregator: CumulativeAggregatorsType interval?: HealthStatisticsIntervalType startDate: string endDate: string @@ -1232,10 +1284,12 @@ declare module 'react-native-health' { AllergyRecord = 'AllergyRecord', AppleExerciseTime = 'AppleExerciseTime', AppleMoveTime = 'AppleMoveTime', + AppleSleepingWristTemperature = 'AppleSleepingWristTemperature', AppleStandHour = 'AppleStandHour', AppleStandTime = 'AppleStandTime', AppleWalkingSteadiness = 'AppleWalkingSteadiness', AppleWalkingSteadinessEvent = 'AppleWalkingSteadinessEvent', + AtrialFibrillationBurden = 'AtrialFibrillationBurden', BasalBodyTemperature = 'BasalBodyTemperature', BasalEnergyBurned = 'BasalEnergyBurned', BiologicalSex = 'BiologicalSex', @@ -1261,6 +1315,7 @@ declare module 'react-native-health' { ConditionRecord = 'ConditionRecord', Copper = 'Copper', CoverageRecord = 'CoverageRecord', + DistanceWheelchair = 'DistanceWheelchair', ElectrodermalActivity = 'ElectrodermalActivity', EnergyConsumed = 'EnergyConsumed', EnvironmentalAudioExposure = 'EnvironmentalAudioExposure', @@ -1273,6 +1328,7 @@ declare module 'react-native-health' { ForcedExpiratoryVolume1 = 'ForcedExpiratoryVolume1', ForcedVitalCapacity = 'ForcedVitalCapacity', HeadphoneAudioExposure = 'HeadphoneAudioExposure', + HeartRateRecoveryOneMinute = 'HeartRateRecoveryOneMinute', ImmunizationRecord = 'ImmunizationRecord', InhalerUsage = 'InhalerUsage', InsulinDelivery = 'InsulinDelivery', @@ -1289,9 +1345,12 @@ declare module 'react-native-health' { Molybdenum = 'Molybdenum', Niacin = 'Niacin', NumberOfAlcoholicBeverages = 'NumberOfAlcoholicBeverages', + NumberOfTimesFallen = 'NumberOfTimesFallen', OvulationTestResult = 'OvulationTestResult', OxygenSaturation = 'OxygenSaturation', PantothenicAcid = 'PantothenicAcid', + PeakExpiratoryFlowRate = 'PeakExpiratoryFlowRate', + PeripheralPerfusionIndex = 'PeripheralPerfusionIndex', Phosphorus = 'Phosphorus', Potassium = 'Potassium', Pregnancy = 'Pregnancy', diff --git a/src/constants/Permissions.js b/src/constants/Permissions.js index e2c513c2..9d86932c 100644 --- a/src/constants/Permissions.js +++ b/src/constants/Permissions.js @@ -9,10 +9,12 @@ export const Permissions = { AllergyRecord: 'AllergyRecord', AppleExerciseTime: 'AppleExerciseTime', AppleMoveTime: 'AppleMoveTime', + AppleSleepingWristTemperature: 'AppleSleepingWristTemperature', AppleStandHour: 'AppleStandHour', AppleStandTime: 'AppleStandTime', AppleWalkingSteadiness: 'AppleWalkingSteadiness', AppleWalkingSteadinessEvent: 'AppleWalkingSteadinessEvent', + AtrialFibrillationBurden: 'AtrialFibrillationBurden', BasalBodyTemperature: 'BasalBodyTemperature', BasalEnergyBurned: 'BasalEnergyBurned', BiologicalSex: 'BiologicalSex', @@ -38,6 +40,7 @@ export const Permissions = { Contraceptive: 'Contraceptive', Copper: 'Copper', CoverageRecord: 'CoverageRecord', + DistanceWheelchair: 'DistanceWheelchair', EnergyConsumed: 'EnergyConsumed', ElectrodermalActivity: 'ElectrodermalActivity', EnvironmentalAudioExposure: 'EnvironmentalAudioExposure', @@ -50,6 +53,7 @@ export const Permissions = { ForcedExpiratoryVolume1: 'ForcedExpiratoryVolume1', ForcedVitalCapacity: 'ForcedVitalCapacity', HeadphoneAudioExposure: 'HeadphoneAudioExposure', + HeartRateRecoveryOneMinute: 'HeartRateRecoveryOneMinute', ImmunizationRecord: 'ImmunizationRecord', InhalerUsage: 'InhalerUsage', InsulinDelivery: 'InsulinDelivery', @@ -66,9 +70,12 @@ export const Permissions = { Molybdenum: 'Molybdenum', Niacin: 'Niacin', NumberOfAlcoholicBeverages: 'NumberOfAlcoholicBeverages', + NumberOfTimesFallen: 'NumberOfTimesFallen', OvulationTestResult: 'OvulationTestResult', OxygenSaturation: 'OxygenSaturation', PantothenicAcid: 'PantothenicAcid', + PeakExpiratoryFlowRate: 'PeakExpiratoryFlowRate', + PeripheralPerfusionIndex: 'PeripheralPerfusionIndex', Phosphorus: 'Phosphorus', Potassium: 'Potassium', Pregnancy: 'Pregnancy', From b8c616fcc32be34bef6b10f4eab3ceb73e920bc9 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:08:23 +0300 Subject: [PATCH 10/16] dietary statistics requests extended with average values --- .../RTCAppleHealthKit+Methods_Statistics.m | 556 +++++++++--------- 1 file changed, 288 insertions(+), 268 deletions(-) diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 669c1bb7..651f3113 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -107,131 +107,80 @@ - (void)statistics_getStatisticRestingHeartRate:(NSDictionary *)input callback:( // MARK: - Macronutrients - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } - HKUnit *unit = HKUnit.kilocalorieUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryEnergyConsumed unit:unit]; } - (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryCarbohydrates unit:unit]; } - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFiber unit:unit]; } - (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietarySugar unit:unit]; } - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFatTotal unit:unit]; } - (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFatMonounsaturated unit:unit]; } - (void)statistics_getStatisticDietaryFatPolyunsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFatPolyunsaturated unit:unit]; } - (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFatSaturated unit:unit]; } - (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryCholesterol unit:unit]; } - (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryProtein unit:unit]; @@ -240,169 +189,104 @@ - (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RC // MARK: - Vitamins - (void)statistics_getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminA unit:unit]; } - (void)statistics_getStatisticDietaryThiamin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryThiamin unit:unit]; } - (void)statistics_getStatisticDietaryRiboflavin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryRiboflavin unit:unit]; } - (void)statistics_getStatisticDietaryNiacin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryNiacin unit:unit]; } - (void)statistics_getStatisticDietaryPantothenicAcid:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryPantothenicAcid unit:unit]; } - (void)statistics_getStatisticDietaryVitaminB6:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminB6 unit:unit]; } - (void)statistics_getStatisticDietaryBiotin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryBiotin unit:unit]; } - (void)statistics_getStatisticDietaryVitaminB12:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminB12 unit:unit]; } - (void)statistics_getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminC unit:unit]; } - (void)statistics_getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminD unit:unit]; } - (void)statistics_getStatisticDietaryVitaminE:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminE unit:unit]; } - (void)statistics_getStatisticDietaryVitaminK:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryVitaminK unit:unit]; } - (void)statistics_getStatisticDietaryFolate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryFolate unit:unit]; @@ -411,104 +295,64 @@ - (void)statistics_getStatisticDietaryFolate:(NSDictionary *)input callback:(RCT // MARK: - Minerals - (void)statistics_getStatisticDietaryCalcium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryCalcium unit:unit]; } - (void)statistics_getStatisticDietaryChloride:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryChloride unit:unit]; } - (void)statistics_getStatisticDietaryIron:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryIron unit:unit]; } - (void)statistics_getStatisticDietaryMagnesium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryMagnesium unit:unit]; } - (void)statistics_getStatisticDietaryPhosphorus:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryPhosphorus unit:unit]; } - (void)statistics_getStatisticDietaryPotassium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryPotassium unit:unit]; } - (void)statistics_getStatisticDietarySodium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietarySodium unit:unit]; } - (void)statistics_getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryZinc unit:unit]; @@ -517,13 +361,8 @@ - (void)statistics_getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTRe // MARK: - Hydration - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.literUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryWater unit:unit]; @@ -532,13 +371,8 @@ - (void)statistics_getStatisticDietaryWater:(NSDictionary *)input callback:(RCTR // MARK: - Caffeination - (void)statistics_getStatisticDietaryCaffeine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryCaffeine unit:unit]; @@ -547,91 +381,56 @@ - (void)statistics_getStatisticDietaryCaffeine:(NSDictionary *)input callback:(R // MARK: - Ultratrace Minerals - (void)statistics_getStatisticDietaryChromium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryChromium unit:unit]; } - (void)statistics_getStatisticDietaryCopper:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryCopper unit:unit]; } - (void)statistics_getStatisticDietaryIodine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryIodine unit:unit]; } - (void)statistics_getStatisticDietaryManganese:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryManganese unit:unit]; } - (void)statistics_getStatisticDietaryMolybdenum:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietaryMolybdenum unit:unit]; } - (void)statistics_getStatisticDietarySelenium:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.gramUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierDietarySelenium unit:unit]; } - (void)statistics_getStatisticInsulinDelivery:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType != 3) { - callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]); - return; - } HKUnit *unit = HKUnit.internationalUnit; - [self basicStatisticsRequest:input + [self basicDietaryStatisticsRequest:input callback:callback quantity:HKQuantityTypeIdentifierInsulinDelivery unit:unit]; @@ -668,47 +467,63 @@ - (void)statistics_getStatisticAppleExerciseTime:(NSDictionary *)input callback: // MARK: - Body Measurments - (void)statistics_getStatisticAppleSleepingWristTemperature:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType == 3) { - callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + if (@available(iOS 16.0, *)) { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.degreeCelsiusUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierAppleSleepingWristTemperature + unit:unit]; + } else { + callback(@[RCTMakeError(@"HKQuantityTypeIdentifierAppleSleepingWristTemperature is only available on iOS 16.0 or newer", nil, nil)]); return; } - HKUnit *unit = HKUnit.degreeCelsiusUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierAppleSleepingWristTemperature - unit:unit]; + } // MARK: - Vital Signs - (void)statistics_getStatisticHeartRateRecoveryOneMinute:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType == 3) { - callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + if (@available(iOS 16.0, *)) { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *count = [HKUnit countUnit]; + HKUnit *minute = [HKUnit minuteUnit]; + + HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[count unitDividedByUnit:minute]]; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierHeartRateRecoveryOneMinute + unit:unit]; + } else { + callback(@[RCTMakeError(@"HKQuantityTypeIdentifierHeartRateRecoveryOneMinute is only available on iOS 16.0 or newer", nil, nil)]); return; } - HKUnit *count = [HKUnit countUnit]; - HKUnit *minute = [HKUnit minuteUnit]; - - HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[count unitDividedByUnit:minute]]; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierHeartRateRecoveryOneMinute - unit:unit]; } - (void)statistics_getStatisticAtrialFibrillationBurden:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; - if (aggregatorType == 3) { - callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + if (@available(iOS 16.0, *)) { + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + if (aggregatorType == 3) { + callback(@[RCTMakeError(@"aggregator shouldn't be CUMULATIVE_SUM = 3", nil, nil)]); + return; + } + HKUnit *unit = HKUnit.percentUnit; + [self basicStatisticsRequest:input + callback:callback + quantity:HKQuantityTypeIdentifierAtrialFibrillationBurden + unit:unit]; + } else { + callback(@[RCTMakeError(@"'HKQuantityTypeIdentifierAtrialFibrillationBurden' is only available on iOS 16.0 or newer", nil, nil)]); return; } - HKUnit *unit = HKUnit.percentUnit; - [self basicStatisticsRequest:input - callback:callback - quantity:HKQuantityTypeIdentifierAtrialFibrillationBurden - unit:unit]; } // MARK: - Lab And Test Results @@ -879,4 +694,209 @@ - (void)handleStatisticsQuantity:(HKQuantityType *)quantityType }); } +- (void)basicDietaryStatisticsRequest:(NSDictionary *)input + callback:(RCTResponseSenderBlock)callback + quantity:(HKQuantityTypeIdentifier)quantity + unit:(HKUnit *)unit { + + NSUInteger aggregatorType = [RCTAppleHealthKit uintFromOptions:input key:@"aggregator" withDefault:-1]; + + if (aggregatorType == 2) { + [self averageDietaryStatisticsRequest:input + callback:callback + quantity:quantity + unit:unit]; + } else if (aggregatorType == 3) { + [self basicStatisticsRequest:input + callback:callback + quantity:quantity + unit:unit]; + } else { + callback(@[RCTMakeError(@"RNHealth: Aggregator should be CUMULATIVE_SUM = 3 or AVERAGE = 2", nil, nil)]); + return; + } +} + +- (void)averageDietaryStatisticsRequest:(NSDictionary *)input + callback:(RCTResponseSenderBlock)callback + quantity:(HKQuantityTypeIdentifier)quantity + unit:(HKUnit *)unit { + + NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; + NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; + + RCTInterval intervalType = (RCTInterval) [RCTAppleHealthKit uintFromOptions:input key:@"interval" withDefault:RCTIntervalMonth]; + + if (!((intervalType == RCTIntervalDay) || (intervalType == RCTIntervalMonth))) { + callback(@[RCTMakeError(@"RNHealth: interval type isn't valid", nil, nil)]); + return; + } + + NSMutableArray *samplesOutput = [NSMutableArray new]; + HKSampleType *sample =[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryFiber]; + + if ([sample isKindOfClass:[HKCharacteristicType class]]) { + callback(@[RCTMakeError(@"RNHealth: Could not load data for HKCharacteristicType", nil, nil)]); + return; + } + + if (sample == nil) { + callback(@[RCTMakeError(@"RNHealth: Could not load data: sample is null", nil, nil)]); + return; + } + + int limit = 5000; + __block HKQueryAnchor *anchor = nil; + __block NSMutableArray<__kindof HKSample *> *samplesResultArray = [NSMutableArray new]; + + __block BOOL hasResults = YES; + __block NSString *anchorString = nil; + + while (hasResults) { + if (anchorString != nil) { + NSData* anchorData = [[NSData alloc] initWithBase64EncodedString:anchorString options:0]; + anchor = [NSKeyedUnarchiver unarchiveObjectWithData:anchorData]; + } + + NSPredicate *anchorPredicate = [RCTAppleHealthKit predicateForAnchoredQueries:anchor startDate:startDate endDate:endDate]; + + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + + [self fetchBatchOfSamples:sample + predicate:anchorPredicate + anchor:anchor + limit:limit + completion:^(NSDictionary *results, NSError *error) { + + if (results) { + @try { + + NSMutableArray<__kindof HKSample *> *data = results[@"data"]; + + if (data == nil) { + hasResults = NO; + NSLog(@"RNHealth averageDietaryStatisticsRequest: An error occured"); + dispatch_semaphore_signal(semaphore); + } + + if (data.count > 0) { + [samplesResultArray addObjectsFromArray:data]; + + anchorString = results[@"anchor"]; + + } else { + hasResults = NO; + } + dispatch_semaphore_signal(semaphore); + } @catch (NSException *exception) { + hasResults = NO; + NSLog(@"RNHealth averageDietaryStatisticsRequest: An error occured"); + dispatch_semaphore_signal(semaphore); + } + } else { + hasResults = NO; + NSLog(@"RNHealth averageDietaryStatisticsRequest: An error occured"); + dispatch_semaphore_signal(semaphore); + } + }]; + + dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); + }; + + NSDateFormatter *intervalDateFormatter = [[NSDateFormatter alloc] init]; + if (intervalType == RCTIntervalDay) { + [intervalDateFormatter setDateFormat:@"yyyy-MM-dd"]; + } else { + [intervalDateFormatter setDateFormat:@"yyyy-MM"]; + } + + for (HKQuantitySample *sample in samplesResultArray) { + NSString *interval = [intervalDateFormatter stringFromDate:sample.startDate]; + + HKQuantity *quantity = sample.quantity; + double value = [quantity doubleValueForUnit:unit]; + + NSMutableDictionary *response = [NSMutableDictionary dictionary]; + response[@"value"] = value ? @(value) : @"0"; + response[@"interval"] = interval ? interval : @""; + response[@"startDate"] = sample.startDate; + response[@"endDate"] = sample.endDate; + + [samplesOutput addObject:response]; + } + + NSMutableDictionary *groupedByInterval = [NSMutableDictionary new]; + + NSArray *distinctNames; + distinctNames = [samplesOutput valueForKeyPath:@"@distinctUnionOfObjects.interval"]; + for (NSString *name in distinctNames) { + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"interval = %@", name]; + NSArray *intervals = [samplesOutput filteredArrayUsingPredicate:predicate]; + [groupedByInterval setObject:intervals forKey:name]; + } + + NSMutableArray *resultWithSumForInterval = [NSMutableArray new]; + for (NSString* key in groupedByInterval) { + NSArray<__kindof NSDictionary *> *intervalValues = groupedByInterval[key]; + double intervalValue = 0; + double entriesCount = 0; + for (NSDictionary *intervalValueObj in intervalValues) { + intervalValue += [intervalValueObj[@"value"] doubleValue]; + entriesCount += 1; + } + + NSDate *startIntervalDate; + NSDate *endIntervalDate; + NSCalendar* calendar = [NSCalendar currentCalendar]; + if (intervalType == RCTIntervalDay) { + startIntervalDate = [calendar startOfDayForDate:intervalValues.firstObject[@"startDate"]]; + + NSDateComponents *dayComponent = [[NSDateComponents alloc] init]; + dayComponent.day = 1; + endIntervalDate = [calendar dateByAddingComponents:dayComponent toDate:startIntervalDate options:0]; + } else { + NSDateComponents *componentsStartDate = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:intervalValues.firstObject[@"startDate"]]; + [componentsStartDate setDay:1]; + startIntervalDate = [calendar dateFromComponents: componentsStartDate]; + + NSDateComponents* componentsEndDate = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:intervalValues.lastObject[@"endDate"]]; + [componentsEndDate setMonth:[componentsEndDate month]+1]; + [componentsEndDate setDay:0]; + endIntervalDate = [calendar dateFromComponents:componentsEndDate]; + } + + NSString *startDateString = [RCTAppleHealthKit buildStringFromDateForStatistics:startIntervalDate]; + NSString *endDateString = [RCTAppleHealthKit buildStringFromDateForStatistics:endIntervalDate]; + + NSMutableDictionary *resultForInterval = [NSMutableDictionary new]; + resultForInterval[@"startDate"] = startDateString; + resultForInterval[@"endDate"] = endDateString; + + double averageValue = 0; + if (entriesCount != 0) { + averageValue = intervalValue / entriesCount; + } + resultForInterval[@"value"] = @(averageValue); + + NSString *json = [RCTAppleHealthKit stringFromObject:resultForInterval]; + NSString *hashInput = [[NSString alloc] initWithFormat:@"%@:%@:%@", quantity, @"average", json]; + NSString *hash = [RCTAppleHealthKit md5HashString:hashInput]; + NSString *identifier = [RCTAppleHealthKit formattingStringHash:hash]; + + resultForInterval[@"id"] = identifier; + + resultForInterval[@"interval"] = intervalValues.firstObject[@"interval"]; + [resultWithSumForInterval addObject:resultForInterval]; + } + + NSSortDescriptor *dateDescriptor = [NSSortDescriptor + sortDescriptorWithKey:@"interval" + ascending:YES]; + NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor]; + NSArray *sortedResult = [resultWithSumForInterval + sortedArrayUsingDescriptors:sortDescriptors]; + + callback(@[[NSNull null], sortedResult]); +} + @end From 1f79881523c6d39f8f3e0c7a540d09368b14fd78 Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:09:09 +0300 Subject: [PATCH 11/16] dietary statistics requests interface updated --- index.d.ts | 70 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0b1c2395..20e32689 100644 --- a/index.d.ts +++ b/index.d.ts @@ -528,175 +528,175 @@ declare module 'react-native-health' { // Macronutrients getStatisticDietaryEnergyConsumed( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryCarbohydrates( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFiber( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietarySugar( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryTotalFat( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatMonounsaturated( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatPolyunsaturated( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFatSaturated( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryCholesterol( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryProtein( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void // Vitamins getStatisticDietaryVitaminA( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryThiamin( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryRiboflavin( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryNiacin( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPantothenicAcid( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminB6( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryBiotin( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminB12( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminC( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminD( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminE( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryVitaminK( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryFolate( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void // Minerals getStatisticDietaryCalcium( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryChloride( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryIron( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryMagnesium( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPhosphorus( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryPotassium( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietarySodium( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticDietaryZinc( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void // Hydration getStatisticDietaryWater( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void // Caffeination getStatisticDietaryCaffeine( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void @@ -728,12 +728,12 @@ declare module 'react-native-health' { ): void getStatisticDietarySelenium( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void getStatisticInsulinDelivery( - options: HealthStatisticsCumulativeInputOptions, + options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void From 2c0816bbced85ebe6bcd33f70b0ecff9294ed31f Mon Sep 17 00:00:00 2001 From: mobileapps23 <40164951+mobileapps23@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:09:37 +0300 Subject: [PATCH 12/16] dietary statistics documentation updated --- docs/statistics.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/statistics.md b/docs/statistics.md index 7485f829..15d8ce7d 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -84,7 +84,6 @@ Query statistic (aggregated) biomarkers. let options = { aggregator: HealthStatisticsCommonAggregatorType.AVERAGE, interval: HealthStatisticsIntervalType.DAY, // optional; default HealthStatisticsIntervalType.MONTH - unit: 'pound', // optional; startDate: new Date(2021, 0, 0).toISOString(), // optional endDate: new Date().toISOString(), // optional; default now } @@ -103,7 +102,7 @@ AppleHealthKit.getStatisticBodyMass( }, ) ``` - +For dietary biomarkers (Macronutrients, Vitamins, Minerals, Hydration, Caffeination, Ultratrace Minerals types) could be calculated average or cumulative values. ## Request payload From 1d612399cdb793e481d614f28600349f4397f049 Mon Sep 17 00:00:00 2001 From: Dmitry Kondratyev Date: Fri, 5 Apr 2024 14:25:56 +0200 Subject: [PATCH 13/16] MON-5942: lint & prettier --- index.d.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/index.d.ts b/index.d.ts index 20e32689..0b6880f7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,3 @@ -import { HealthInputOptions } from 'react-native-health' - declare module 'react-native-health' { export interface HealthKitPermissions { permissions: { @@ -541,41 +539,41 @@ declare module 'react-native-health' { options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietarySugar( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryTotalFat( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryFatMonounsaturated( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryFatPolyunsaturated( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryFatSaturated( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryCholesterol( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, ): void - + getStatisticDietaryProtein( options: HealthStatisticsCommonInputOptions, callback: (err: string, results: Array) => void, - ): void + ): void // Vitamins @@ -737,7 +735,7 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void - // Activity + // Activity getStatisticDistanceWheelchair( options: HealthStatisticsCumulativeInputOptions, @@ -749,7 +747,7 @@ declare module 'react-native-health' { callback: (err: string, results: Array) => void, ): void - // Body Measurments + // Body Measurments getStatisticAppleSleepingWristTemperature( options: HealthStatisticsCommonInputOptions, @@ -906,8 +904,8 @@ declare module 'react-native-health' { startDate: string eventTypeInt: number eventType: EventType - } - + } + enum GenericAggregatorsType { MIN = 0, MAX = 1, @@ -934,7 +932,7 @@ declare module 'react-native-health' { export enum HealthStatisticsIntervalType { MONTH = 0, DAY = 1, - } + } export interface HealthStatisticsCommonInputOptions extends HealthUnitOptions { From f30791efc41dbd61bd83ab2463f52340b8e6b2ae Mon Sep 17 00:00:00 2001 From: Dmitry Kondratyev Date: Fri, 5 Apr 2024 17:20:34 +0200 Subject: [PATCH 14/16] MON-5942: beauty --- RCTAppleHealthKit/RCTAppleHealthKit.m | 72 ++++----- .../RTCAppleHealthKit+Methods_Statistics.h | 6 +- .../RTCAppleHealthKit+Methods_Statistics.m | 20 +-- RNAppleHealthKit.podspec | 7 +- docs/statistics.md | 152 +++++++++--------- 5 files changed, 132 insertions(+), 125 deletions(-) diff --git a/RCTAppleHealthKit/RCTAppleHealthKit.m b/RCTAppleHealthKit/RCTAppleHealthKit.m index 6afa2a35..9efffdd6 100644 --- a/RCTAppleHealthKit/RCTAppleHealthKit.m +++ b/RCTAppleHealthKit/RCTAppleHealthKit.m @@ -677,10 +677,10 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryEnergyConsumed:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; + [self statistics_getStatisticDietaryProtein:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -689,16 +689,22 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryFiber:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietarySugar:input callback:callback]; + [self statistics_getStatisticDietaryTotalFat:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryTotalFat:input callback:callback]; + [self statistics_getStatisticDietaryWater:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietarySugar:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -725,16 +731,10 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryCholesterol:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryProtein:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminA:input callback:callback]; + [self statistics_getStatisticDietaryCarbohydrates:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryThiamin:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -779,18 +779,6 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietaryVitaminB12:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminC:input callback:callback]; -} - -RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) -{ - [self _initializeHealthStore]; - [self statistics_getStatisticDietaryVitaminD:input callback:callback]; -} - RCT_EXPORT_METHOD(getStatisticDietaryVitaminE:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; @@ -851,16 +839,28 @@ + (BOOL)requiresMainQueueSetup [self statistics_getStatisticDietarySodium:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryVitaminA:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryZinc:input callback:callback]; + [self statistics_getStatisticDietaryVitaminA:input callback:callback]; } -RCT_EXPORT_METHOD(getStatisticDietaryWater:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +RCT_EXPORT_METHOD(getStatisticDietaryVitaminC:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) { [self _initializeHealthStore]; - [self statistics_getStatisticDietaryWater:input callback:callback]; + [self statistics_getStatisticDietaryVitaminC:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryVitaminD:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryVitaminD:input callback:callback]; +} + +RCT_EXPORT_METHOD(getStatisticDietaryZinc:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) +{ + [self _initializeHealthStore]; + [self statistics_getStatisticDietaryZinc:input callback:callback]; } RCT_EXPORT_METHOD(getStatisticDietaryCaffeine:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback) @@ -1068,9 +1068,9 @@ - (void)initializeHealthKit:(NSDictionary *)input callback:(RCTResponseSenderBlo @"SleepAnalysis", @"InsulinDelivery" ]; - + NSArray *templates = @[@"healthKit:%@:new", @"healthKit:%@:failure", @"healthKit:%@:enabled", @"healthKit:%@:sample", @"healthKit:%@:setup:success", @"healthKit:%@:setup:failure"]; - + NSMutableArray *supportedEvents = [[NSMutableArray alloc] init]; for(NSString * type in types) { @@ -1096,7 +1096,7 @@ - (void)getModuleInfo:(NSDictionary *)input callback:(RCTResponseSenderBlock)cal - (void)getAuthorizationStatus:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { - + [self _initializeHealthStore]; if ([HKHealthStore isHealthDataAvailable]) { @@ -1169,7 +1169,7 @@ - (void)initializeBackgroundObservers:(RCTBridge *)bridge for(NSString * type in fitnessObservers) { [self fitness_registerObserver:type bridge:bridge hasListeners:hasListeners]; } - + NSArray *clinicalObservers = @[ @"AllergyRecord", @"ConditionRecord", @@ -1180,11 +1180,11 @@ - (void)initializeBackgroundObservers:(RCTBridge *)bridge @"ProcedureRecord", @"VitalSignRecord" ]; - + for(NSString * type in clinicalObservers) { [self clinical_registerObserver:type bridge:bridge hasListeners:hasListeners]; } - + [self results_registerObservers:bridge hasListeners:hasListeners]; NSLog(@"[HealthKit] Background observers added to the app"); diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h index 85ed1ae7..641afc0e 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h @@ -27,15 +27,15 @@ // MARK: - Macronutrients - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFatPolyunsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryFatSaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; -- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; // MARK: - Vitamins diff --git a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m index 651f3113..0ff49933 100644 --- a/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m +++ b/RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m @@ -114,11 +114,11 @@ - (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callb unit:unit]; } -- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = HKUnit.gramUnit; [self basicDietaryStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryCarbohydrates + quantity:HKQuantityTypeIdentifierDietaryProtein unit:unit]; } @@ -130,27 +130,27 @@ - (void)statistics_getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTR unit:unit]; } -- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = HKUnit.gramUnit; [self basicDietaryStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietarySugar + quantity:HKQuantityTypeIdentifierDietaryFatTotal unit:unit]; } -- (void)statistics_getStatisticDietaryTotalFat:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = HKUnit.gramUnit; [self basicDietaryStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryFatTotal + quantity:HKQuantityTypeIdentifierDietaryFatMonounsaturated unit:unit]; } -- (void)statistics_getStatisticDietaryFatMonounsaturated:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietarySugar:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = HKUnit.gramUnit; [self basicDietaryStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryFatMonounsaturated + quantity:HKQuantityTypeIdentifierDietarySugar unit:unit]; } @@ -178,11 +178,11 @@ - (void)statistics_getStatisticDietaryCholesterol:(NSDictionary *)input callback unit:unit]; } -- (void)statistics_getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { +- (void)statistics_getStatisticDietaryCarbohydrates:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback { HKUnit *unit = HKUnit.gramUnit; [self basicDietaryStatisticsRequest:input callback:callback - quantity:HKQuantityTypeIdentifierDietaryProtein + quantity:HKQuantityTypeIdentifierDietaryCarbohydrates unit:unit]; } diff --git a/RNAppleHealthKit.podspec b/RNAppleHealthKit.podspec index 86b92062..d3e11bbc 100644 --- a/RNAppleHealthKit.podspec +++ b/RNAppleHealthKit.podspec @@ -5,11 +5,14 @@ # Any lines starting with a # are optional, but their use is encouraged # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html # +require 'json' + +package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) Pod::Spec.new do |s| s.name = 'RNAppleHealthKit' - s.version = '1.19.2' - s.summary = 'A React Native package to interact with Apple HealthKit' + s.version = package['version'] + s.summary = package['description'] # This description is used to generate tags and improve search results. # * Think: What does it do? Why did you write it? What is the focus? diff --git a/docs/statistics.md b/docs/statistics.md index 15d8ce7d..c07da52a 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -2,80 +2,84 @@ Query statistic (aggregated) biomarkers. -|Value|Methods| -|---|---| -|bodyMass (вес)|getStatisticBodyMass| -|bloodPressureSystolic (систолическое давление)|getStatisticBloodPressureSystolic| -|bloodPressureDiastolic (диастолическое давление)|getStatisticBloodPressureDiastolic| -|bloodGlucose (глюкоза в крови)|getStatisticBloodGlucose| -|bodyMassIndex (индекс массы тела)|getStatisticBodyMassIndex| -|height (рост)|getStatisticHeight| -|stepCount (количество шагов)|getStatisticStepCount| -|heartRate (пульс)|getStatisticHeartRate| -|bodyTemperature (температура тела)|getStatisticBodyTemperature| -|oxygenSaturation (насыщение кислородом)|getStatisticOxygenSaturation| -|restingHeartRate (пульс в покое)|getStatisticRestingHeartRate| -|Dietary| | -|Macronutrients| | -|EnergyConsumed|getStatisticDietaryEnergyConsumed| -|Carbohydrates|geStatisticDietaryCarbohydrates| -|Fiber|getStatisticDietaryFiber| -|Sugar|getStatisticDietarySugar| -|TotalFat|getStatisticDietaryTotalFat| -|FatMonounsaturated|getStatisticDietaryFatMonounsaturated| -|FatPolyunsaturated|getStatisticDietaryFatPolyunsaturated| -|FatSaturated|getStatisticDietaryFatSaturated| -|Cholesterol|getStatisticDietaryCholesterol| -|Protein|getStatisticDietaryProtein| -|Vitamins| | -|VitaminA|getStatisticDietaryVitaminA| -|Thiamin|getStatisticDietaryThiamin| -|Riboflavin|getStatisticDietaryRiboflavin| -|Niacin|getStatisticDietaryNiacin| -|PantothenicAcid|getStatisticDietaryPantothenicAcid| -|VitaminB6|getStatisticDietaryVitaminB6| -|Biotin|getStatisticDietaryBiotin| -|VitaminB12|getStatisticDietaryVitaminB12| -|VitaminC|getStatisticDietaryVitaminC| -|VitaminD|getStatisticDietaryVitaminD| -|VitaminE|getStatisticDietaryVitaminE| -|VitaminK|getStatisticDietaryVitaminK| -|Folate|getStatisticDietaryFolate| -|Minerals| | -|Calcium|getStatisticDietaryCalcium| -|Chloride|getStatisticDietaryChloride| -|Iron|getStatisticDietaryIron| -|Magnesium|getStatisticDietaryMagnesium| -|Phosphorus|getStatisticDietaryPhosphorus| -|Potassium|getStatisticDietaryPotassium| -|Sodium|getStatisticDietarySodium| -|Zinc|getStatisticDietaryZinc| -|Hydration| | -|Water|getStatisticDietaryWater| -|Caffeination| | -|Caffeine|getStatisticDietaryCaffeine| -|Ultratrace Minerals| | -|Chromium|getStatisticDietaryChromium| -|Copper|getStatisticDietaryCopper| -|Iodine|getStatisticDietaryIodine| -|Manganese|getStatisticDietaryManganese| -|Molybdenum|getStatisticDietaryMolybdenum| -|Selenium|getStatisticDietarySelenium| -|Lab and Test Results|| -|insulinDelivery (подача инсулина)|getStatisticInsulinDelivery| -|number Of Times Fallen|getStatisticNumberOfTimesFallen| -|Peak Expiratory Flow Rate|getStatisticPeakExpiratoryFlowRate| -|Peripheral Perfusion Index|getStatisticPeripheralPerfusionIndex| -|Activity|| -|Distance Wheelchair|getStatisticDistanceWheelchair| -|Apple Exercise Time|getStatisticAppleExerciseTime| -|Body Measurments|| -|Apple Sleeping Wrist Temperature|getStatisticAppleSleepingWristTemperature| -|Vital Signs|| -|Heart Rate Recovery One Minute|getStatisticHeartRateRecoveryOneMinute| -|Atrial Fibrillation Burden|getStatisticAtrialFibrillationBurden| -|UV Exposure|| -|UV Exposure|getStatisticUvExposure| +| Value | Methods | +|--------------------------|-------------------------------------------| +| bodyMass (body weight) | getStatisticBodyMass | +| bloodPressureSystolic (systolic pressure) | getStatisticBloodPressureSystolic | +| bloodPressureDiastolic (diastolic pressure) | getStatisticBloodPressureDiastolic | +| bloodGlucose (blood glucose) | getStatisticBloodGlucose | +| bodyMassIndex (body mass index) | getStatisticBodyMassIndex | +| height (body height) | getStatisticHeight | +| stepCount (number of steps) | getStatisticStepCount | +| heartRate (pulse) | getStatisticHeartRate | +| bodyTemperature (body temperature) | getStatisticBodyTemperature | +| oxygenSaturation (oxygen saturation) | getStatisticOxygenSaturation | +| restingHeartRate (resting heart rate) | getStatisticRestingHeartRate | +| Dietary | | +| Macronutrients | | +| energyConsumed (energy value) | getStatisticDietaryEnergyConsumed | +| protein (protein) | getStatisticDietaryProtein | +| fiber (cellulose) | getStatisticDietaryFiber | +| totalFat (fats) | getStatisticDietaryTotalFat | +| sugar | getStatisticDietarySugar (sugar) | +| fatSaturated | getStatisticDietaryFatSaturated | +| fatMonounsaturated | getStatisticDietaryFatMonounsaturated | +| fatPolyunsaturated | getStatisticDietaryFatPolyunsaturated | +| cholesterol | getStatisticDietaryCholesterol | +| carbohydrates | getStatisticDietaryCarbohydrates | +| Vitamins | | +| vitaminA | getStatisticDietaryVitaminA | +| vitaminC | getStatisticDietaryVitaminC | +| vitaminD | getStatisticDietaryVitaminD | +| thiamin | getStatisticDietaryThiamin | +| riboflavin | getStatisticDietaryRiboflavin | +| niacin | getStatisticDietaryNiacin | +| pantothenicAcid | getStatisticDietaryPantothenicAcid | +| vitaminB6 | getStatisticDietaryVitaminB6 | +| biotin | getStatisticDietaryBiotin | +| vitaminB12 | getStatisticDietaryVitaminB12 | +| vitaminE | getStatisticDietaryVitaminE | +| vitaminK | getStatisticDietaryVitaminK | +| folate | getStatisticDietaryFolate | +| calcium | getStatisticDietaryCalcium | +| iron | getStatisticDietaryIron | +| potassium | getStatisticDietaryPotassium | +| sodium | getStatisticDietarySodium | +| Minerals | | +| calcium | getStatisticDietaryCalcium | +| chloride | getStatisticDietaryChloride | +| iron | getStatisticDietaryIron | +| magnesium | getStatisticDietaryMagnesium | +| phosphorus | getStatisticDietaryPhosphorus | +| potassium | getStatisticDietaryPotassium | +| sodium | getStatisticDietarySodium | +| zinc | getStatisticDietaryZinc | +| Hydration | | +| water | getStatisticDietaryWater | +| Caffeination | | +| caffeine | getStatisticDietaryCaffeine | +| Ultratrace Minerals | | +| chromium | getStatisticDietaryChromium | +| copper | getStatisticDietaryCopper | +| iodine | getStatisticDietaryIodine | +| manganese | getStatisticDietaryManganese | +| molybdenum | getStatisticDietaryMolybdenum | +| selenium | getStatisticDietarySelenium | +| Lab and Test Results | | +| insulinDelivery (insulin delivery) | getStatisticInsulinDelivery | +| numberOfTimesFallen | getStatisticNumberOfTimesFallen | +| peakExpiratoryFlowRate | getStatisticPeakExpiratoryFlowRate | +| peripheralPerfusionIndex | getStatisticPeripheralPerfusionIndex | +| Activity | | +| distanceWheelchair | getStatisticDistanceWheelchair | +| appleExerciseTime | getStatisticAppleExerciseTime | +| Body Measurments | | +| appleSleepingWristTemperature | getStatisticAppleSleepingWristTemperature | +| Vital Signs | | +| heartRateRecoveryOneMinute | getStatisticHeartRateRecoveryOneMinute | +| atrialFibrillationBurden | getStatisticAtrialFibrillationBurden | +| UV Exposure | | +| uvExposure | getStatisticUvExposure | ## Example call From a01cba4a5d61bcfdcc9855a2b90ca2e983c27466 Mon Sep 17 00:00:00 2001 From: Dmitry Kondratyev Date: Fri, 5 Apr 2024 17:23:40 +0200 Subject: [PATCH 15/16] MON-5942: change package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 64ddd1e7..79d8c52a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-health", - "version": "1.19.2", + "version": "1.20.0", "description": "A React Native package to interact with Apple HealthKit", "main": "index.js", "repository": { From 4597c63cfe29256cbb0c6df2bd4f57c255552862 Mon Sep 17 00:00:00 2001 From: Dmitry Kondratyev Date: Fri, 5 Apr 2024 17:27:47 +0200 Subject: [PATCH 16/16] MON-5942: beauty --- docs/statistics.md | 154 ++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/docs/statistics.md b/docs/statistics.md index c07da52a..a21dd2c0 100644 --- a/docs/statistics.md +++ b/docs/statistics.md @@ -2,84 +2,84 @@ Query statistic (aggregated) biomarkers. -| Value | Methods | -|--------------------------|-------------------------------------------| -| bodyMass (body weight) | getStatisticBodyMass | -| bloodPressureSystolic (systolic pressure) | getStatisticBloodPressureSystolic | +| Value | Methods | +|---------------------------------------------|-------------------------------------------| +| bodyMass (body weight) | getStatisticBodyMass | +| bloodPressureSystolic (systolic pressure) | getStatisticBloodPressureSystolic | | bloodPressureDiastolic (diastolic pressure) | getStatisticBloodPressureDiastolic | -| bloodGlucose (blood glucose) | getStatisticBloodGlucose | -| bodyMassIndex (body mass index) | getStatisticBodyMassIndex | -| height (body height) | getStatisticHeight | -| stepCount (number of steps) | getStatisticStepCount | -| heartRate (pulse) | getStatisticHeartRate | -| bodyTemperature (body temperature) | getStatisticBodyTemperature | -| oxygenSaturation (oxygen saturation) | getStatisticOxygenSaturation | -| restingHeartRate (resting heart rate) | getStatisticRestingHeartRate | -| Dietary | | -| Macronutrients | | -| energyConsumed (energy value) | getStatisticDietaryEnergyConsumed | -| protein (protein) | getStatisticDietaryProtein | -| fiber (cellulose) | getStatisticDietaryFiber | -| totalFat (fats) | getStatisticDietaryTotalFat | -| sugar | getStatisticDietarySugar (sugar) | -| fatSaturated | getStatisticDietaryFatSaturated | -| fatMonounsaturated | getStatisticDietaryFatMonounsaturated | -| fatPolyunsaturated | getStatisticDietaryFatPolyunsaturated | -| cholesterol | getStatisticDietaryCholesterol | -| carbohydrates | getStatisticDietaryCarbohydrates | -| Vitamins | | -| vitaminA | getStatisticDietaryVitaminA | -| vitaminC | getStatisticDietaryVitaminC | -| vitaminD | getStatisticDietaryVitaminD | -| thiamin | getStatisticDietaryThiamin | -| riboflavin | getStatisticDietaryRiboflavin | -| niacin | getStatisticDietaryNiacin | -| pantothenicAcid | getStatisticDietaryPantothenicAcid | -| vitaminB6 | getStatisticDietaryVitaminB6 | -| biotin | getStatisticDietaryBiotin | -| vitaminB12 | getStatisticDietaryVitaminB12 | -| vitaminE | getStatisticDietaryVitaminE | -| vitaminK | getStatisticDietaryVitaminK | -| folate | getStatisticDietaryFolate | -| calcium | getStatisticDietaryCalcium | -| iron | getStatisticDietaryIron | -| potassium | getStatisticDietaryPotassium | -| sodium | getStatisticDietarySodium | -| Minerals | | -| calcium | getStatisticDietaryCalcium | -| chloride | getStatisticDietaryChloride | -| iron | getStatisticDietaryIron | -| magnesium | getStatisticDietaryMagnesium | -| phosphorus | getStatisticDietaryPhosphorus | -| potassium | getStatisticDietaryPotassium | -| sodium | getStatisticDietarySodium | -| zinc | getStatisticDietaryZinc | -| Hydration | | -| water | getStatisticDietaryWater | -| Caffeination | | -| caffeine | getStatisticDietaryCaffeine | -| Ultratrace Minerals | | -| chromium | getStatisticDietaryChromium | -| copper | getStatisticDietaryCopper | -| iodine | getStatisticDietaryIodine | -| manganese | getStatisticDietaryManganese | -| molybdenum | getStatisticDietaryMolybdenum | -| selenium | getStatisticDietarySelenium | -| Lab and Test Results | | -| insulinDelivery (insulin delivery) | getStatisticInsulinDelivery | -| numberOfTimesFallen | getStatisticNumberOfTimesFallen | -| peakExpiratoryFlowRate | getStatisticPeakExpiratoryFlowRate | -| peripheralPerfusionIndex | getStatisticPeripheralPerfusionIndex | -| Activity | | -| distanceWheelchair | getStatisticDistanceWheelchair | -| appleExerciseTime | getStatisticAppleExerciseTime | -| Body Measurments | | -| appleSleepingWristTemperature | getStatisticAppleSleepingWristTemperature | -| Vital Signs | | -| heartRateRecoveryOneMinute | getStatisticHeartRateRecoveryOneMinute | -| atrialFibrillationBurden | getStatisticAtrialFibrillationBurden | -| UV Exposure | | -| uvExposure | getStatisticUvExposure | +| bloodGlucose (blood glucose) | getStatisticBloodGlucose | +| bodyMassIndex (body mass index) | getStatisticBodyMassIndex | +| height (body height) | getStatisticHeight | +| stepCount (number of steps) | getStatisticStepCount | +| heartRate (pulse) | getStatisticHeartRate | +| bodyTemperature (body temperature) | getStatisticBodyTemperature | +| oxygenSaturation (oxygen saturation) | getStatisticOxygenSaturation | +| restingHeartRate (resting heart rate) | getStatisticRestingHeartRate | +| Dietary | | +| Macronutrients | | +| energyConsumed (energy value) | getStatisticDietaryEnergyConsumed | +| protein (protein) | getStatisticDietaryProtein | +| fiber (cellulose) | getStatisticDietaryFiber | +| totalFat (fats) | getStatisticDietaryTotalFat | +| sugar | getStatisticDietarySugar (sugar) | +| fatSaturated | getStatisticDietaryFatSaturated | +| fatMonounsaturated | getStatisticDietaryFatMonounsaturated | +| fatPolyunsaturated | getStatisticDietaryFatPolyunsaturated | +| cholesterol | getStatisticDietaryCholesterol | +| carbohydrates | getStatisticDietaryCarbohydrates | +| Vitamins | | +| vitaminA | getStatisticDietaryVitaminA | +| vitaminC | getStatisticDietaryVitaminC | +| vitaminD | getStatisticDietaryVitaminD | +| thiamin | getStatisticDietaryThiamin | +| riboflavin | getStatisticDietaryRiboflavin | +| niacin | getStatisticDietaryNiacin | +| pantothenicAcid | getStatisticDietaryPantothenicAcid | +| vitaminB6 | getStatisticDietaryVitaminB6 | +| biotin | getStatisticDietaryBiotin | +| vitaminB12 | getStatisticDietaryVitaminB12 | +| vitaminE | getStatisticDietaryVitaminE | +| vitaminK | getStatisticDietaryVitaminK | +| folate | getStatisticDietaryFolate | +| calcium | getStatisticDietaryCalcium | +| iron | getStatisticDietaryIron | +| potassium | getStatisticDietaryPotassium | +| sodium | getStatisticDietarySodium | +| Minerals | | +| calcium | getStatisticDietaryCalcium | +| chloride | getStatisticDietaryChloride | +| iron | getStatisticDietaryIron | +| magnesium | getStatisticDietaryMagnesium | +| phosphorus | getStatisticDietaryPhosphorus | +| potassium | getStatisticDietaryPotassium | +| sodium | getStatisticDietarySodium | +| zinc | getStatisticDietaryZinc | +| Hydration | | +| water | getStatisticDietaryWater | +| Caffeination | | +| caffeine | getStatisticDietaryCaffeine | +| Ultratrace Minerals | | +| chromium | getStatisticDietaryChromium | +| copper | getStatisticDietaryCopper | +| iodine | getStatisticDietaryIodine | +| manganese | getStatisticDietaryManganese | +| molybdenum | getStatisticDietaryMolybdenum | +| selenium | getStatisticDietarySelenium | +| Lab and Test Results | | +| insulinDelivery (insulin delivery) | getStatisticInsulinDelivery | +| numberOfTimesFallen | getStatisticNumberOfTimesFallen | +| peakExpiratoryFlowRate | getStatisticPeakExpiratoryFlowRate | +| peripheralPerfusionIndex | getStatisticPeripheralPerfusionIndex | +| Activity | | +| distanceWheelchair | getStatisticDistanceWheelchair | +| appleExerciseTime | getStatisticAppleExerciseTime | +| Body Measurments | | +| appleSleepingWristTemperature | getStatisticAppleSleepingWristTemperature | +| Vital Signs | | +| heartRateRecoveryOneMinute | getStatisticHeartRateRecoveryOneMinute | +| atrialFibrillationBurden | getStatisticAtrialFibrillationBurden | +| UV Exposure | | +| uvExposure | getStatisticUvExposure | ## Example call