Commit c3b53243 authored by Evgenii Evstropov's avatar Evgenii Evstropov

update work around isTracked flag, to perfom only one quert for tracked and non-tracked samples

parent dd643582
...@@ -53,27 +53,11 @@ ...@@ -53,27 +53,11 @@
HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]]; HKUnit *unit = [RCTAppleHealthKit hkUnitFromOptions:input key:@"unit" withDefault:[HKUnit countUnit]];
NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit]; NSUInteger limit = [RCTAppleHealthKit uintFromOptions:input key:@"limit" withDefault:HKObjectQueryNoLimit];
BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false]; BOOL ascending = [RCTAppleHealthKit boolFromOptions:input key:@"ascending" withDefault:false];
BOOL isTracked = [RCTAppleHealthKit boolFromOptions:input key:@"isTracked" withDefault:true];
NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"]; NSString *type = [RCTAppleHealthKit stringFromOptions:input key:@"type" withDefault:@"Walking"];
NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:nil]; NSDate *startDate = [RCTAppleHealthKit dateFromOptions:input key:@"startDate" withDefault:[NSDate date]];
NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]]; NSDate *endDate = [RCTAppleHealthKit dateFromOptions:input key:@"endDate" withDefault:[NSDate date]];
if(startDate == nil){
callback(@[RCTMakeError(@"startDate is required in options", nil, nil)]);
return;
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
// no isTracked
NSArray *subPredicates = [[NSArray alloc] init];
NSMutableArray *subPredicatesAux = [[NSMutableArray alloc] init];
NSPredicate *predicateDate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
NSPredicate *predicateType = isTracked ? [NSPredicate predicateWithFormat:@"metadata.%K != YES", HKMetadataKeyWasUserEntered] : [NSPredicate predicateWithFormat:@"metadata.%K == YES", HKMetadataKeyWasUserEntered];
[subPredicatesAux addObject:predicateDate];
[subPredicatesAux addObject:predicateType];
subPredicates = [subPredicatesAux copy];
NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:predicateType, predicateDate, nil]]; NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]; HKSampleType *samplesType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
if ([type isEqual:@"Walking"]) { if ([type isEqual:@"Walking"]) {
...@@ -90,15 +74,11 @@ ...@@ -90,15 +74,11 @@
samplesType = [HKObjectType workoutType]; samplesType = [HKObjectType workoutType];
} }
NSString * paramName = @"isTracked"; [self fetchSamplesOfType:samplesType
[self fetchQuantitySamplesOfType:samplesType
unit:unit unit:unit
predicate:predicate predicate:predicate
ascending:ascending ascending:ascending
limit:limit limit:limit
additionalParamName:paramName
additionalParam:isTracked
completion:^(NSArray *results, NSError *error) { completion:^(NSArray *results, NSError *error) {
if(results){ if(results){
callback(@[[NSNull null], results]); callback(@[[NSNull null], results]);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
startDate:(NSDate *)startDate startDate:(NSDate *)startDate
endDate:(NSDate *)endDate endDate:(NSDate *)endDate
completion:(void (^)(NSArray *, NSError *))completionHandler; completion:(void (^)(NSArray *, NSError *))completionHandler;
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType - (void)fetchSamplesOfType:(HKSampleType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
ascending:(BOOL)asc ascending:(BOOL)asc
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
ascending:(BOOL)asc ascending:(BOOL)asc
limit:(NSUInteger)lim limit:(NSUInteger)lim
additionalParamName:(NSString *)paramName
additionalParam:(BOOL)param
completion:(void (^)(NSArray *, NSError *))completion; completion:(void (^)(NSArray *, NSError *))completion;
- (void)fetchCorrelationSamplesOfType:(HKQuantityType *)quantityType - (void)fetchCorrelationSamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType - (void)fetchQuantitySamplesOfType:(HKQuantityType *)quantityType
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
...@@ -105,13 +104,13 @@ ...@@ -105,13 +104,13 @@
[self.healthStore executeQuery:query]; [self.healthStore executeQuery:query];
} }
- (void)fetchQuantitySamplesOfType:(HKSampleType *)type
- (void)fetchSamplesOfType:(HKSampleType *)type
unit:(HKUnit *)unit unit:(HKUnit *)unit
predicate:(NSPredicate *)predicate predicate:(NSPredicate *)predicate
ascending:(BOOL)asc ascending:(BOOL)asc
limit:(NSUInteger)lim limit:(NSUInteger)lim
additionalParamName:(NSString *)paramName
additionalParam:(BOOL)param
completion:(void (^)(NSArray *, NSError *))completion { completion:(void (^)(NSArray *, NSError *))completion {
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate
ascending:asc]; ascending:asc];
...@@ -139,14 +138,19 @@ ...@@ -139,14 +138,19 @@
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate];
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate];
bool isTracked = true;
for(id key in [sample metadata])
if (key == HKMetadataKeyWasUserEntered ) {
isTracked = false;
}
NSDictionary *elem = @{ NSDictionary *elem = @{
@"type" : type, @"type" : type,
@"energy" : @(energy), @"energy" : @(energy),
@"isTracked" : @(isTracked),
@"distance" : @(distance), @"distance" : @(distance),
@"startDate" : startDateString, @"startDate" : startDateString,
@"endDate" : endDateString, @"endDate" : endDateString
paramName : @(param),
}; };
[data addObject:elem]; [data addObject:elem];
...@@ -159,11 +163,17 @@ ...@@ -159,11 +163,17 @@
NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate]; NSString *startDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.startDate];
NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate]; NSString *endDateString = [RCTAppleHealthKit buildISO8601StringFromDate:sample.endDate];
bool isTracked = true;
for(id key in [sample metadata])
if (key == HKMetadataKeyWasUserEntered ) {
isTracked = false;
}
NSDictionary *elem = @{ NSDictionary *elem = @{
@"value" : @(value), @"value" : @(value),
@"isTracked" : @(isTracked),
@"startDate" : startDateString, @"startDate" : startDateString,
@"endDate" : endDateString, @"endDate" : endDateString
paramName : @(param),
}; };
[data addObject:elem]; [data addObject:elem];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment