I am attempting to query HealthKit for Vision Prescriptions.
The query below is able to return results back that I have saved to HealthKit, however, I am having trouble accessing the HKVisionPrescription
metadata such as the HKGlassesLensSpecification
for both the Right and Left Eye. I am only able to access properties like prescriptionType
and dateIssued
.
I created these record programmatically so I know the values I am looking for exist and I am able to confirm their existence in the Health app.
How can I modify this code so I can access the finer details of each prescription?
func getPrescriptions() async -> [HKVisionPrescription] {
let datePredicate = HKQuery.predicateForSamples(withStart: start, end: end)
// Predicate that matches vision prescriptions samples
let predicate = HKSamplePredicate.visionPrescription(datePredicate)
let descriptor = HKSampleQueryDescriptor(
predicates:[predicate],
sortDescriptors: [],
limit: 10)
do {
let results = try await descriptor.result(for: store)
if results.isEmpty {
await requestPermission()
return []
}
results.forEach { prescription in
// How to access prescription metadata here?
}
return results
} catch {
print("no error from query")
return []
}
}