Skip to content

Commit

Permalink
Merge pull request #100 from rossmartin/master
Browse files Browse the repository at this point in the history
Support reading clinical data (FHIR) from the HealthKit store in iOS 12
  • Loading branch information
EddyVerbruggen authored Sep 26, 2018
2 parents c6b15ea + 9492fac commit 80bb3a4
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/ios/HealthKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ + (HKObjectType *)getHKObjectType:(NSString *)elem {
return type;
}

if (@available(iOS 12.0, *)) {
type = [HKObjectType clinicalTypeForIdentifier:elem];
if (type != nil) {
return type;
}
}

// @TODO | The fall through here is inefficient.
// @TODO | It needs to be refactored so the same HK method isnt called twice
return [HealthKit getHKSampleType:elem];
Expand Down Expand Up @@ -238,6 +245,13 @@ + (HKSampleType *)getHKSampleType:(NSString *)elem {
}
}

if (@available(iOS 12.0, *)) {
type = [HKObjectType clinicalTypeForIdentifier:elem];
if (type != nil) {
return type;
}
}

// leave this here for if/when apple adds other sample types
return type;

Expand Down Expand Up @@ -1352,6 +1366,33 @@ - (void)querySampleType:(CDVInvokedUrlCommand *)command {
HKWorkout *wsample = (HKWorkout *) sample;
[entry setValue:@(wsample.duration) forKey:@"duration"];

} else {

if (@available(iOS 12.0, *)) {

if ([sample isKindOfClass:[HKClinicalRecord class]]) {
HKClinicalRecord *clinicalRecord = (HKClinicalRecord *) sample;
NSError *err = nil;
NSDictionary *fhirData = [NSJSONSerialization JSONObjectWithData:clinicalRecord.FHIRResource.data options:NSJSONReadingMutableContainers error:&err];

if (err != nil) {
dispatch_sync(dispatch_get_main_queue(), ^{
[HealthKit triggerErrorCallbackWithMessage:err.localizedDescription command:command delegate:bSelf.commandDelegate];
});
return;
} else {
NSDictionary *fhirResource = @{
@"identifier": clinicalRecord.FHIRResource.identifier,
@"sourceURL": clinicalRecord.FHIRResource.sourceURL.absoluteString,
@"displayName": clinicalRecord.displayName,
@"data": fhirData
};
entry[@"FHIRResource"] = fhirResource;
}
}

}

}

[finalResults addObject:entry];
Expand Down

0 comments on commit 80bb3a4

Please sign in to comment.