ios – Entry Imaginative and prescient Prescription metadata from HKSampleQueryDescription


I need to question HealthKit for Imaginative and prescient Prescriptions.

I’ve created these imaginative and prescient prescriptions programmatically and I’m making an attempt to jot down a question for HealthKit in order that I can retrieve them.

I’m able to question the prescription data, however not in a position to entry all of the metadata in regards to the prescription such because the HKGlassesLensSpecification for each eyes.

I created these document programmatically so I do know the values I’m in search of exist and I’m able to verify their existence within the Well being app.

The question beneath is ready to return outcomes again that I’ve saved to HealthKit, nevertheless, I’m having hassle accessing the HKVisionPrescription metadata such because the HKGlassesLensSpecification for each the Proper and Left Eye. I’m solely in a position to entry properties like prescriptionType and dateIssued.

func getPrescriptions() async -> [HKVisionPrescription] {
        let datePredicate = HKQuery.predicateForSamples(withStart: begin, finish: finish)

        // Predicate that matches imaginative and prescient prescriptions samples
        let predicate = HKSamplePredicate.visionPrescription(datePredicate)

        let descriptor = HKSampleQueryDescriptor(
            predicates:[predicate],
            sortDescriptors: [],
            restrict: 10)
        
        do {
            let outcomes = strive await descriptor.outcome(for: retailer)
            
            if outcomes.isEmpty {
                return []
            }
            
            outcomes.forEach { prescription in
                // Easy methods to entry prescription metadata right here?
            }
            return outcomes
            
        } catch {
            return []
        }
    }

Edit: I observed a metadata property on the HKVisionPrescription… is that this a spot the place I can retailer the properties for every prescription?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles