Skip to content

Commit

Permalink
- Added InsulinDelivery getter method
Browse files Browse the repository at this point in the history
  • Loading branch information
GGGava committed Jun 29, 2023
1 parent c30c529 commit aacf222
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_saveBloodGlucoseSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)results_deleteBloodGlucoseSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;
Expand Down
34 changes: 34 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ - (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTRespon
}];
}

- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *insulinDeliveryType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierInsulinDelivery];

HKUnit *unit = [HKUnit internationalUnit];

NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}

NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];

[self fetchQuantitySamplesOfType:insulinDeliveryType
unit:unit
predicate:predicate
ascending:ascending
limit:limit
completion:^(NSArray *results, NSError *error) {
if(results){
callback(@[[NSNull null], results]);
return;
} else {
NSLog(@"An error occured while retrieving the glucose sample %@. The error was: ", error);
callback(@[RCTMakeError(@"An error occured while retrieving the glucose sample", error, nil)]);
return;
}
}];
}

- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
HKQuantityType *carbohydratesType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCarbohydrates];
Expand Down
2 changes: 2 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key {
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryWater];
} else if ([@"BloodGlucose" isEqualToString:key]) {
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose];
} else if ([@"InsulinDelivery" isEqualToString:key]) {
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierInsulinDelivery];
}

// Vital Signs Identifiers
Expand Down
6 changes: 6 additions & 0 deletions RCTAppleHealthKit/RCTAppleHealthKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ + (BOOL)requiresMainQueueSetup
[self results_getCarbohydratesSamples:input callback:callback];
}

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

RCT_EXPORT_METHOD(saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self _initializeHealthStore];
Expand Down
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ declare module 'react-native-health' {
callback: (err: string, results: Array<HealthActivitySummary>) => void,
): void

getInsulinDeliverySamples(
options: HealthInputOptions,
callback: (err: string, results: Array<HealthValue>) => void,
): void


Constants: Constants
}

Expand Down Expand Up @@ -708,6 +714,7 @@ declare module 'react-native-health' {
Folate = 'Folate',
HeadphoneAudioExposure = 'HeadphoneAudioExposure',
ImmunizationRecord = 'ImmunizationRecord',
InsulinDelivery = 'InsulinDelivery',
Iodine = 'Iodine',
Iron = 'Iron',
LabResultRecord = 'LabResultRecord',
Expand Down Expand Up @@ -845,6 +852,11 @@ declare module 'react-native-health' {
Postprandial = 2,
}

export enum InsulinDeliveryReason {
Basal = 1,
Bolus = 2,
}

const appleHealthKit: AppleHealthKit

export default appleHealthKit
Expand Down
1 change: 1 addition & 0 deletions src/constants/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Permissions = {
Folate: 'Folate',
HeadphoneAudioExposure: 'HeadphoneAudioExposure',
ImmunizationRecord: 'ImmunizationRecord',
InsulinDelivery: 'InsulinDelivery',
Iodine: 'Iodine',
Iron: 'Iron',
LabResultRecord: 'LabResultRecord',
Expand Down

0 comments on commit aacf222

Please sign in to comment.