Skip to content
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

feat: Add startDate and endDate to OCKOutcomeValue #719

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Rodrigox30
Copy link

@Rodrigox30 Rodrigox30 commented Aug 6, 2024

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. At @netreconlab, we plan on creating graphs to display user's health data over time and with the newly added startDate and endDate to OCKOutcomeValue, we can provide this functionality.

These are the proposed changes to CareKit:

  • Updated CareKitStore2.1 to CareKitStore3.0 by adding startDate and endDate attributes to OCKCDOutcomeValue
  • Reflected these changes in OCKCDOutcomeValue.swift and OCKOutcomeValue.swift (this allows the startDate and endDate to be accessed for HealthKit samples but also allows developers to store/retrieve their own dates for these values)
  • Converting a sample to an outcome value and storing it on the event's outcome now has startDate and endDate sample values
  • Test to confirm that these changes were made
  • 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

Rodrigox30 and others added 3 commits August 6, 2024 10:05
* 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]>
@Rodrigox30 Rodrigox30 marked this pull request as draft August 6, 2024 17:43
@Rodrigox30 Rodrigox30 marked this pull request as ready for review August 6, 2024 19:40
Copy link
Author

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

Copy link
Author

@Rodrigox30 Rodrigox30 Aug 7, 2024

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated schema version

Copy link
Author

@Rodrigox30 Rodrigox30 Aug 7, 2024

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

@@ -35,6 +35,8 @@ class OCKCDOutcomeValue: NSManagedObject {
@NSManaged var kind: String? // blood sugar, body weight, etc.
@NSManaged var units: String?
@NSManaged var createdDate: Date
@NSManaged var startDate: Date?
@NSManaged var endDate: Date?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added startDate and endDate

doubleValue,
units: event.task.healthKitLinkage.unit.unitString
)

outcomeValue.startDate = sample.dateInterval.start
outcomeValue.endDate = sample.dateInterval.end
Copy link
Author

@Rodrigox30 Rodrigox30 Aug 7, 2024

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

Copy link
Author

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)

@@ -48,14 +48,15 @@ class TestCoreDataSchemaMigrations: XCTestCase {
/// Tasks: 3
/// Outcomes: 3
/// OutcomeValues: 3
func testMigrationFrom2_0to2_1() throws {
func testMigrationFrom2_0to3_0() throws {
Copy link
Author

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.

Copy link
Author

@Rodrigox30 Rodrigox30 Aug 7, 2024

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

@@ -129,6 +130,8 @@ class TestHealthKitPassthroughStoreEvents: XCTestCase {
case heartRateTask.id:
XCTAssertEqual(outcomeValues.count, 2)
XCTAssertEqual(outcomeValues.first?.doubleValue, 70)
XCTAssertEqual(outcomeValues.first?.startDate, heartRateStart)
XCTAssertEqual(outcomeValues.first?.endDate, heartRateEnd)
Copy link
Author

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?

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant