Last active
March 18, 2019 05:50
-
-
Save NSAmit/86e0afeebf6ce1d581a95b613ed5f0d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getRecordUsingPredicateForAllergyType(recordReadCompletionHandler:@escaping ([HKClinicalRecord]?) -> Void) { | |
guard let healthRecordAllergyType = HKObjectType.clinicalType(forIdentifier: .allergyRecord) else { | |
fatalError("*** Unable to create the Allergy type ***") | |
} | |
let healthRecordPredicate = HKQuery.predicateForClinicalRecords(withFHIRResourceType: .allergyIntolerance) | |
let sampleQuery = HKSampleQuery(sampleType: healthRecordAllergyType, predicate: healthRecordPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, samples, error) in | |
guard let actualSamples = samples else { | |
// Handle the error here. | |
print("*** An error occurred: \(error?.localizedDescription ?? "nil") ***") | |
recordReadCompletionHandler(nil) | |
return | |
} | |
let healthRecordSamples = actualSamples as? [HKClinicalRecord] | |
recordReadCompletionHandler(healthRecordSamples) | |
} | |
healthStore.execute(sampleQuery) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment