Humza Ali
Humza Ali

Reputation: 96

Apple HealthKit health records

Can I add Patients health records like lab reports etc. to apple health app using health kit in swift? So far what i understand is that you can only read the health record data but you can not write it from your own health app. So what will I have to do to be able to add data in health section in apple's health app.

I have tried to look on the apple's documentation but there is no way to add health records.

Upvotes: 0

Views: 601

Answers (2)

Pascal
Pascal

Reputation: 16941

The Health Records feature is read-only from a 3rd party API perspective. This data can only be added as a direct download from supported health systems. See here for more information: https://www.apple.com/healthcare/health-records/

Upvotes: 1

lancylot2004
lancylot2004

Reputation: 307

I might be misunderstanding what you want to do, but you want to add data using HealthKit right?

Here's a bit of sample code I found for step data.

let healthStore = HKHealthStore()

// Request authorization to write step count data
let stepCountType = HKQuantityType.quantityType(forIdentifier: .stepCount)!
healthStore.requestAuthorization(toShare: [stepCountType]) { (success, error) in
    if success {
        // Create a new HKQuantitySample with the step count data
        let quantity = HKQuantity(unit: HKUnit.count(), doubleValue: 1000)
        let sample = HKQuantitySample(type: stepCountType, quantity: quantity, start: Date(), end: Date())

        // Save the new HKQuantitySample to the Health app
        healthStore.save(sample) { (success, error) in
            if success {
                print("Step count saved to Health app.")
            } else {
                print("Error saving step count to Health app: \(error!.localizedDescription)")
            }
        }
    } else {
        print("Error requesting authorization to write step count data: \(error!.localizedDescription)")
    }
}

More docs at Apple.

Upvotes: -1

Related Questions