Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dietary statistics #14

Merged
merged 7 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,108 @@ + (BOOL)requiresMainQueueSetup
[self statistics_getStatisticRestingHeartRate:input callback:callback];
}

RCT_EXPORT_METHOD(getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self _initializeHealthStore];
[self statistics_getStatisticDietaryEnergyConsumed:input callback:callback];
}

RCT_EXPORT_METHOD(getStatisticDietaryProtein:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self _initializeHealthStore];
[self statistics_getStatisticDietaryProtein:input callback:callback];
}

RCT_EXPORT_METHOD(getStatisticDietaryFiber:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self _initializeHealthStore];
[self statistics_getStatisticDietaryFiber: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)
{
[self _initializeHealthStore];
[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];
[self statistics_getStatisticInsulinDelivery:input callback:callback];
}

RCT_EXPORT_METHOD(getMedianStatistic:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self _initializeHealthStore];
Expand Down
21 changes: 21 additions & 0 deletions RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@
- (void)statistics_getStatisticOxygenSaturation:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)statistics_getStatisticRestingHeartRate:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;

// Dietary

- (void)statistics_getStatisticDietaryEnergyConsumed:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)statistics_getStatisticDietaryProtein:(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_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;

@end
224 changes: 224 additions & 0 deletions RCTAppleHealthKit/RTCAppleHealthKit+Methods_Statistics.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,230 @@ - (void)statistics_getStatisticRestingHeartRate:(NSDictionary *)input callback:(
unit:unit];
}

// MARK: - Dietary

- (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
callback:callback
quantity:HKQuantityTypeIdentifierDietaryEnergyConsumed
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
callback:callback
quantity:HKQuantityTypeIdentifierDietaryProtein
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
callback:callback
quantity:HKQuantityTypeIdentifierDietaryFiber
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
callback:callback
quantity:HKQuantityTypeIdentifierDietaryFatTotal
unit:unit];
}

- (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];
}

- (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) {
callback(@[RCTMakeError(@"aggregator should be CUMULATIVE_SUM = 3", nil, nil)]);
return;
}
HKUnit *unit = HKUnit.internationalUnit;
[self basicStatisticsRequest:input
callback:callback
quantity:HKQuantityTypeIdentifierInsulinDelivery
unit:unit];
}

// MARK: - Private

- (void)basicStatisticsRequest:(NSDictionary *)input
Expand Down
Loading