Almost ten years ago, Apple introduced the HealthKit. It provides an elegant way of getting users’ medical data. It covers integration with 3rd party wearables and even hospitals which could provide you with personal health records via FHIR API. It is 100% production ready, but you should use it wisely. Today I am going to share the lessons we learned.
Let’s see what issues you will encounter while loading hospital data. Apple Health loads the medical data into the smartphone in FHIR format. For security reasons, Apple doesn’t have access to the data. So they can’t validate it. The hospital is self-declaring that data is stored in FHIR format, but there is no way to check that the data is correct. So you can get incorrect FHIR resources. Some required fields may be missing. You can even get FHIR resources with typos in attribute names. The references may point to FHIR resources you don’t have access to. It could be Practitioner, Organization, or any other resources used in the clinic internally. Finally, there are multiple versions of the FHIR standard so that you can get data from the old version. In this case, you have to normalize and transform the data. To sum up, please keep in mind that you can’t use this data as it is. You have to implement the validation and normalization before using the data.
Let’s keep digging deeper and see how integration with wearables works. Apple HealthKit data may be gathered across different sources and contain duplications. HealthKit provides granular access to the data. You will get all metrics from all devices that will be a massive amount of data you may not need. Also, this data could contain duplications you would like to eliminate. Likely, HealthKit provides aggregation API, but it is limited. You can aggregate by a period of time and data type and apply ordering on top of it. In some cases, the same data type could be loaded from different sources. You can’t do such aggregation with the API. So, you need to load the data into your app runtime and implement aggregation on your own. It is not obvious and may cause different errors.