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 an OCKAnyOutcome sorting extension #12

Merged
merged 3 commits into from
Jul 8, 2024
Merged

feat: Add an OCKAnyOutcome sorting extension #12

merged 3 commits into from
Jul 8, 2024

Conversation

cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Jul 8, 2024

Dealing with OCKAnyOutcome's is more complex than the other types. For example, OCKOutcome is versioned, but querying for an OCKOutcome doesn't necessarily follow CareKit's documentation (example1, example2). This seems done on purpose, but may require a developer to query for all OCKOutcome's and filter accordingly. The changes in this PR assists with that by sorting all returned OCKOutcome's with the first item in the array being the greatest for a particular max value.

Some examples are below:

let outcomes = [firstOutcome, secondOutcome]

// Replicates the other OCK versioned types by getting the latest versioned outcome as of today as the first element of the array, the oldest is last.
let sortedOutcomes = outcomes.sortedNewestToOldest(
                \.effectiveDate,
                 lessThanEqualTo: Date()
)

let sortedByCreatedDate = try outcomes.sortedNewestToOldest(
            \.createdDate
)
let sortedByCreatedDate2 = try outcomes.sortedNewestToOldest(
            \.createdDate,
             lessThanEqualTo: secondDate
)
let sortedByOccurrenceIndex = outcomes.sortedNewestToOldest(
            \.taskOccurrenceIndex
)
let sortedByOccurrenceIndex2 = outcomes.sortedNewestToOldest(
            \.taskOccurrenceIndex,
             lessThanEqualTo: firstIndex
)

@cbaker6 cbaker6 changed the title feat: Add an OCKOutcome sorting extension feat: Add an OCKAnyOutcome sorting extension Jul 8, 2024
@cbaker6 cbaker6 merged commit d810768 into main Jul 8, 2024
6 checks passed
@cbaker6 cbaker6 deleted the sortOutcomes branch July 8, 2024 02:23
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