Skip to content

Instantly share code, notes, and snippets.

@NSAmit
Last active March 18, 2019 05:50
Show Gist options
  • Save NSAmit/86e0afeebf6ce1d581a95b613ed5f0d0 to your computer and use it in GitHub Desktop.
Save NSAmit/86e0afeebf6ce1d581a95b613ed5f0d0 to your computer and use it in GitHub Desktop.
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