-
Notifications
You must be signed in to change notification settings - Fork 465
fix: Query HealthKit samples over specified date interval #723
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?
Changes from all commits
c4037df
b085481
957c213
2ad0695
83f4d2d
e9be043
981cb22
150122b
ec7b381
f6923b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -530,12 +530,23 @@ extension OCKHealthKitPassthroughStore { | |||||||||||||||||
|
|
||||||||||||||||||
| func makeTaskQuery(from outcomeQuery: OCKOutcomeQuery) -> OCKTaskQuery { | ||||||||||||||||||
|
|
||||||||||||||||||
| let dateInterval = Calendar.current.dateInterval(of: .day, for: Date())! | ||||||||||||||||||
| // Search over the interval provided by OCKOutcomeQuery if present | ||||||||||||||||||
| // or else constrain sample query over the current day. | ||||||||||||||||||
| let dateInterval = outcomeQuery.dateInterval ?? | ||||||||||||||||||
| Calendar.current.dateInterval(of: .day, for: Date())! | ||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to CareKit/CareKitStore/CareKitStore/Protocols/Events/OCKReadOnlyEventStore+VersioningUtilities.swift Lines 225 to 232 in b16d15c
|
||||||||||||||||||
|
|
||||||||||||||||||
| var taskQuery = OCKTaskQuery(dateInterval: dateInterval) | ||||||||||||||||||
| taskQuery.ids = outcomeQuery.taskIDs | ||||||||||||||||||
| taskQuery.remoteIDs = outcomeQuery.taskRemoteIDs | ||||||||||||||||||
| taskQuery.uuids = outcomeQuery.taskUUIDs | ||||||||||||||||||
| taskQuery.sortDescriptors = outcomeQuery.sortDescriptors.map { descriptor in | ||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass relevant sort criteria to the task query. |
||||||||||||||||||
| switch descriptor { | ||||||||||||||||||
| case .effectiveDate(ascending: let ascending): | ||||||||||||||||||
| return OCKTaskQuery.SortDescriptor.effectiveDate(ascending: ascending) | ||||||||||||||||||
| case .groupIdentifier(ascending: let ascending): | ||||||||||||||||||
| return OCKTaskQuery.SortDescriptor.groupIdentifier(ascending: ascending) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return taskQuery | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ public extension OCKAnyReadOnlyCarePlanStore { | |
| completion: @escaping OCKResultClosure<OCKAnyCarePlan>) { | ||
| var query = OCKCarePlanQuery(for: Date()) | ||
| query.limit = 1 | ||
| query.sortDescriptors = [.effectiveDate(ascending: true)] | ||
| query.sortDescriptors = [.effectiveDate(ascending: false)] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these should be false to always get the newest version related to today, similar to how the fetching task was set up. |
||
| query.ids = [id] | ||
|
|
||
| fetchAnyCarePlans(query: query, callbackQueue: callbackQueue, completion: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,7 @@ public protocol OCKAnyTaskStore: OCKAnyReadOnlyTaskStore { | |
|
|
||
| public extension OCKAnyReadOnlyTaskStore { | ||
| func fetchAnyTask(withID id: String, callbackQueue: DispatchQueue = .main, completion: @escaping OCKResultClosure<OCKAnyTask>) { | ||
| var query = OCKTaskQuery(id: id) | ||
| var query = OCKTaskQuery(for: Date()) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched this so it's aligned with the other Entity fetches. It was setting the |
||
| query.sortDescriptors = [.effectiveDate(ascending: false)] | ||
| query.ids = [id] | ||
| query.limit = 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,11 +374,27 @@ class TestStoreTasks: XCTestCase { | |
|
|
||
| var taskV2 = taskV1 | ||
| taskV2.title = "V2" | ||
| taskV2.effectiveDate = Calendar.current.date(byAdding: .year, value: 1, to: Date())! | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted this test based on #723 (comment). This |
||
| taskV2 = try await store.updateTask(taskV2) | ||
|
|
||
| let task = try await store.fetchTask(withID: "task") | ||
| XCTAssertEqual(task.title, taskV2.title) | ||
| } | ||
|
|
||
| func testFetchAnyTaskByIdConvenienceMethodReturnsNewestVersionOfTask() async throws { | ||
| let coordinator = OCKStoreCoordinator() | ||
| let store = OCKStore(name: "test", type: .inMemory) | ||
| coordinator.attach(store: store) | ||
|
|
||
| let schedule = OCKSchedule.dailyAtTime(hour: 0, minutes: 0, start: Date(), end: nil, text: nil) | ||
| var taskV1 = OCKTask(id: "task", title: "V1", carePlanUUID: nil, schedule: schedule) | ||
| taskV1 = try await store.addTask(taskV1) | ||
|
|
||
| var taskV2 = taskV1 | ||
| taskV2.title = "V2" | ||
| taskV2 = try await store.updateTask(taskV2) | ||
|
|
||
| let fetchedTask = try await store.fetchAnyTask(withID: "task") | ||
| XCTAssertEqual(fetchedTask.title, "V2") | ||
| XCTAssertEqual(fetchedTask.title, taskV2.title) | ||
| } | ||
|
|
||
| func testTaskQueryStartingExactlyOnEffectiveDateOfNewVersion() async 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.
Added groupIdentifier sort to all that was missing