Search code examples
iosswift3healthkit

How to store ECG data on apple healthkit?


I am new to IOS app development. I have been trying to learn how to work with Apple HealthKit API. So far, as an experiment I have managed to build a simple app which could store and retrieve data from the HealthKit such as blood type, heart rate etc (i can furnish the code if anyone needs it-it is already available on the internet). I am able to do this functionality because healthkitStore exposes these typeIdentifiers for the app developers. However, I am a bit lost when I want to create a new typeIdentifier such for storing ECG/EKG on the healthKit? I want to feed ECG/EKG signals into my app and use the HealthKitStore to save these information. Am i missing something?I know I am slow, but i have searched a lot over the internet, but I could not find any specific solutions. Is this not possible? But the whole point of opening the API to the developers is to create new apps with different features. I have no specific requirement as far as storing and retrieving ECG data is concerned, as i simply want to create a PoC without any constraints but focusing on the functionality.

Will I be wrong If i want to create the above by using

struct HKClinicalTypeIdentifier

and then use Clinical Record type identifier

static let labResultRecord: HKClinicalTypeIdentifier

Is this the correct direction? Any direction, motivation or criticism is much welcomed.


Solution

  • I found an alternate solution to the above issue. I am writing this so that if anyone has similar issue can take a similar approach if needed. Basically at the time of writing this thread, there are no ECG typeIdentifier available for developers to use. However, the way around it is to create a HKQauntiySample object and pass the ECG values as metadata. But the only issue that i am facing with such an approach is to do with the rate at which the live/historical ECG can be saved into the healthkit.

    The sampling frequency for the ECG e.g is 200 Hz. I am not able to store the data with subsecond timestamp. It can only provide upto seconds of timestamp. Also, it seems, the maximum rate at which data can be stored using the above object is as low as 160Hz. Maybe this is a limitation of the interface, healtkitstore etc. I dont know. Hope this closes the issue.