- 
                Notifications
    
You must be signed in to change notification settings  - Fork 457
 
feat: Add endDate to OCKOutcomeValue #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* feat: date acesses for created date to end date to task outcomes * endDate documentation update * Updated OCKOutcomeValue startDate and endDate documentation to HealthKit documentation. * Added 2.0 to 3.0 CoreData mapping and adjusted OCKOutcomeValue members * nits * Test added for Outcome Value * CareKitStore3.0 mapping update * Succesful migration from CareKitStore 2.1 to CareKitStore 3.0. * Add file to Package.swift * add files to Xcode project * fix coredata in project * nits * fix absolute path for coredata * deleted files --------- Co-authored-by: Corey Baker <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This CareKitStore only adds two new attributes to OCKCDOutcomeValue, startDate and endDate, to CareKitStore 2.1. Nothing else has changed from the 2.1 store
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same custom migration policy from CareKitStore 2.0 to CareKitStore 2.1 updated to migrate CKS 2.0 to CKS 3.0. The only change that occurred was updating the schema version to 3.0.0.
| 
               | 
          ||
| // Update the schema version to 3.0 | ||
| if key == "schemaVersion" { | ||
| dInstance.setValue("3.0.0", forKey: key) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated schema version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping is one-to-one for CKS 2.1 to CKS 3.0. I need to hardcode the schemaVersion to 3.0.0 since $source.schemaVersion would not be correct, and I do not want to introduce a new custom migration policy for one change.
Changes occurred to:
- OCKCDOutcomeToOCKCDOutcome
 - OCKCDCarePlanToOCKCDCarePlan
 - OCKCDTaskToOCKCDTask
 - OCKCDContactToOCKCDContact
 - OCKCDPatientToOCKCDPatient
 
| @NSManaged var units: String? | ||
| @NSManaged var createdDate: Date | ||
| @NSManaged var startDate: Date? | ||
| @NSManaged var endDate: Date? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added startDate and endDate
| ) | ||
| 
               | 
          ||
| outcomeValue.startDate = sample.dateInterval.start | ||
| outcomeValue.endDate = sample.dateInterval.end | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we add the sample's startDate and endDate to its OCKOutcomeValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files were added to test migration from CareKitStore2.1 to CareKitStore3.0 (used in testMigrationFrom2_1to3_0)
| /// Outcomes: 3 | ||
| /// OutcomeValues: 3 | ||
| func testMigrationFrom2_0to2_1() throws { | ||
| func testMigrationFrom2_0to3_0() throws { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed testMigrationFrom2_0to2_1 because we are not using CareKitStore 2.1. Created new tests for the previous stores to check if their migration was successfull.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of how this updated OCKOutcomeValue allows developers to store/retrieve their own dates for these values
| XCTAssertEqual(outcomeValues.count, 2) | ||
| XCTAssertEqual(outcomeValues.first?.doubleValue, 70) | ||
| XCTAssertEqual(outcomeValues.first?.startDate, heartRateStart) | ||
| XCTAssertEqual(outcomeValues.first?.endDate, heartRateEnd) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test to check if the sample's startDate and endDate were successfully saved in their OCKOutcomeValue
| 
               | 
          ||
| /// The value's end date. | ||
| public var endDate: Date? | ||
| 
               | 
          
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added startDate and endDate to OCKOutcomeValue
| 
           @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  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: cbaker6#23, cbaker6@79c88ab, cbaker6#26 
  | 
    
Currently, when querying
OCKHealthKitTaskfrom the CareStore, the captured dates of samples are not accessible by developers from their respectiveOCKOutcomeValues. 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 thecreatedDatecan only be accessed on anOCKOutcomeValuewhich for a HealthKit sample is incorrect because thecreatedDateis 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:
@gavirawson-apple please let me know if you want me to make any additional updates
Collaborators: @cbaker6