CareKit
CareKit copied to clipboard
feat: Add endDate to OCKOutcomeValue
Currently, when querying OCKHealthKitTask from the CareStore, the captured dates of samples are not accessible by developers from their respective OCKOutcomeValues. Adding this information to OCKOutcomeValue will allow developers to differentiate when samples were taken to provide insights into trends over time. The current problem is the createdDate can only be accessed on an OCKOutcomeValue which for a HealthKit sample is incorrect because the createdDate is the date the sample was queried from HealthKit (see here) as opposed to the actual start/end dates of the HealthKit sample. To reflect HealthKit samples startDate and endDate in OCKOutcomeValues, OCKOutcomeValue.createdDate is now set to the start date of the sample, and the newly added endDate is set to the end date of the sample.
These are the proposed changes to CareKit:
- [x] Updated CareKitStore2.1 to CareKitStore3.0 by adding endDate attributes to OCKCDOutcomeValue
- [x] Reflected these changes in OCKCDOutcomeValue.swift and OCKOutcomeValue.swift (this allows the endDate to be accessed for HealthKit samples but also allows developers to store/retrieve their own dates for these values)
- [x] Converting a sample to an outcome value and storing it on the event's outcome now has endDate sample values, with startDate sample values stored in createdDate
- [x] Test to confirm that these changes were made
- [x] Provided migration for CareKitStore2.0->CareKtStore3.0 and CareKitStore2.1->CareKtStore3.0
@gavirawson-apple please let me know if you want me to make any additional updates
Collaborators: @cbaker6
@gavirawson-apple @aplummer-apple if this ends up getting merged after a successful review (🤞🏾) we plan to open up another PR that enables OCKOutcomeValue's to represent HKQuantity and HKCategory samples that consist of all valid HK properties in the Care Store and on OCKOutcomeValue. This will also allow CareKit to access HKCategory types using linkage:
public struct OCKHealthKitLinkage: Equatable, Codable {
/// Initialize by specifying HealthKit types.
///
/// - Parameter categoryIdentifier: A HealthKitCategoryIdentifier that describes the outcome's data type.
public init(categoryIdentifier: HKCategoryTypeIdentifier) {
self.sampleIdentifier = categoryIdentifier.rawValue
}
}
For details on the working implementation see: https://github.com/cbaker6/CareKit/pull/23, https://github.com/cbaker6/CareKit/commit/79c88ab8b475da531ea485ce3f05c75cbc62effc, https://github.com/cbaker6/CareKit/pull/26
HKQuantity and HKCategory samples can then be queried, graphed, saved to the OCKStore, etc. over any date interval using #723