-
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 4 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -562,12 +562,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 |
|---|---|---|
|
|
@@ -138,7 +138,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 | ||
|---|---|---|---|---|
|
|
@@ -44,14 +44,13 @@ extension OCKStoreCoordinator { | |||
| $0.anyOutcomes(matching: query) | ||||
| } | ||||
|
|
||||
| let sortDescriptor = NSSortDescriptor( | ||||
| keyPath: \OCKCDOutcome.id, | ||||
|
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. I'm assuming this is leftover from when the OCKCDOutcome.id had the the task occurrence appended to it:
|
||||
| ascending: true | ||||
| ) | ||||
| let sortDescriptors = query | ||||
| .sortDescriptors | ||||
| .map(\.nsSortDescriptor) | ||||
|
|
||||
| let outcomes = combineMany( | ||||
| sequences: outcomesStreams, | ||||
| sortingElementsUsing: [sortDescriptor] | ||||
| sortingElementsUsing: sortDescriptors | ||||
| ) | ||||
|
|
||||
| return outcomes | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,22 @@ import Foundation | |
| /// A query that limits which outcomes will be returned when fetching. | ||
| public struct OCKOutcomeQuery: Equatable, OCKQueryProtocol { | ||
|
|
||
| /// Specifies the order in which query results will be sorted. | ||
| public enum SortDescriptor: Equatable { | ||
|
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. Add a sort descriptor for OCKOutcomeQuery |
||
|
|
||
| case effectiveDate(ascending: Bool) | ||
| case groupIdentifier(ascending: Bool) | ||
|
|
||
| var nsSortDescriptor: NSSortDescriptor { | ||
| switch self { | ||
| case let .effectiveDate(ascending): | ||
| return NSSortDescriptor(keyPath: \OCKCDOutcome.effectiveDate, ascending: ascending) | ||
| case let .groupIdentifier(ascending): | ||
| return NSSortDescriptor(keyPath: \OCKCDOutcome.groupIdentifier, ascending: ascending) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// An array of task identifiers to match against. | ||
| public var taskIDs: [String] = [] | ||
|
|
||
|
|
@@ -42,6 +58,9 @@ public struct OCKOutcomeQuery: Equatable, OCKQueryProtocol { | |
| /// An array of remote IDs of tasks for which outcomes should be returned. | ||
| public var taskRemoteIDs: [String] = [] | ||
|
|
||
| /// The order in which the results will be sorted when returned from the query. | ||
| public var sortDescriptors: [SortDescriptor] = [] | ||
|
|
||
| // MARK: OCKQuery | ||
| public var ids: [String] = [] | ||
| public var uuids: [UUID] = [] | ||
|
|
||
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