Skip to content

Commit aacf222

Browse files
committed
- Added InsulinDelivery getter method
1 parent c30c529 commit aacf222

6 files changed

+56
-0
lines changed

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1313
- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
14+
- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1415
- (void)results_saveBloodGlucoseSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1516
- (void)results_saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
1617
- (void)results_deleteBloodGlucoseSample:(NSString *)oid callback:(RCTResponseSenderBlock)callback;

RCTAppleHealthKit/RCTAppleHealthKit+Methods_Results.m

+34
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ - (void)results_getBloodGlucoseSamples:(NSDictionary *)input callback:(RCTRespon
4646
}];
4747
}
4848

49+
- (void)results_getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
50+
{
51+
HKQuantityType *insulinDeliveryType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierInsulinDelivery];
52+
53+
HKUnit *unit = [HKUnit internationalUnit];
54+
55+
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
56+
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
57+
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil];
58+
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
59+
if(startDate == nil){
60+
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
61+
return;
62+
}
63+
64+
NSPredicate * predicate = [RCTAppleHealthKit predicateForSamplesBetweenDates:startDate endDate:endDate];
65+
66+
[self fetchQuantitySamplesOfType:insulinDeliveryType
67+
unit:unit
68+
predicate:predicate
69+
ascending:ascending
70+
limit:limit
71+
completion:^(NSArray *results, NSError *error) {
72+
if(results){
73+
callback(@[[NSNull null], results]);
74+
return;
75+
} else {
76+
NSLog(@"An error occured while retrieving the glucose sample %@. The error was: ", error);
77+
callback(@[RCTMakeError(@"An error occured while retrieving the glucose sample", error, nil)]);
78+
return;
79+
}
80+
}];
81+
}
82+
4983
- (void)results_getCarbohydratesSamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
5084
{
5185
HKQuantityType *carbohydratesType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCarbohydrates];

RCTAppleHealthKit/RCTAppleHealthKit+TypesAndPermissions.m

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ - (nullable HKObjectType *)getReadPermFromText:(nonnull NSString*)key {
158158
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryWater];
159159
} else if ([@"BloodGlucose" isEqualToString:key]) {
160160
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose];
161+
} else if ([@"InsulinDelivery" isEqualToString:key]) {
162+
return [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierInsulinDelivery];
161163
}
162164

163165
// Vital Signs Identifiers

RCTAppleHealthKit/RCTAppleHealthKit.m

+6
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ + (BOOL)requiresMainQueueSetup
472472
[self results_getCarbohydratesSamples:input callback:callback];
473473
}
474474

475+
RCT_EXPORT_METHOD(getInsulinDeliverySamples:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
476+
{
477+
[self _initializeHealthStore];
478+
[self results_getInsulinDeliverySamples:input callback:callback];
479+
}
480+
475481
RCT_EXPORT_METHOD(saveCarbohydratesSample:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
476482
{
477483
[self _initializeHealthStore];

index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ declare module 'react-native-health' {
437437
callback: (err: string, results: Array<HealthActivitySummary>) => void,
438438
): void
439439

440+
getInsulinDeliverySamples(
441+
options: HealthInputOptions,
442+
callback: (err: string, results: Array<HealthValue>) => void,
443+
): void
444+
445+
440446
Constants: Constants
441447
}
442448

@@ -708,6 +714,7 @@ declare module 'react-native-health' {
708714
Folate = 'Folate',
709715
HeadphoneAudioExposure = 'HeadphoneAudioExposure',
710716
ImmunizationRecord = 'ImmunizationRecord',
717+
InsulinDelivery = 'InsulinDelivery',
711718
Iodine = 'Iodine',
712719
Iron = 'Iron',
713720
LabResultRecord = 'LabResultRecord',
@@ -845,6 +852,11 @@ declare module 'react-native-health' {
845852
Postprandial = 2,
846853
}
847854

855+
export enum InsulinDeliveryReason {
856+
Basal = 1,
857+
Bolus = 2,
858+
}
859+
848860
const appleHealthKit: AppleHealthKit
849861

850862
export default appleHealthKit

src/constants/Permissions.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const Permissions = {
4040
Folate: 'Folate',
4141
HeadphoneAudioExposure: 'HeadphoneAudioExposure',
4242
ImmunizationRecord: 'ImmunizationRecord',
43+
InsulinDelivery: 'InsulinDelivery',
4344
Iodine: 'Iodine',
4445
Iron: 'Iron',
4546
LabResultRecord: 'LabResultRecord',

0 commit comments

Comments
 (0)