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

Unable to find outcome of HealthKitTask #640

Open
zhang-bo-lilly opened this issue Feb 2, 2022 · 2 comments
Open

Unable to find outcome of HealthKitTask #640

zhang-bo-lilly opened this issue Feb 2, 2022 · 2 comments

Comments

@zhang-bo-lilly
Copy link

I am working on a CareKit app where I use ParseCareKit developed by @cbaker6 for remote synchronization and his parse-hipaa for the server. Within the app, I defined three tasks: an onboarding task similar to the demo shown in WWDC, a daily stretch task, and a walking task. The onboarding and stretch tasks are created using OCKTask and the walking task is created as an OCKHealthKitTask. Here are the code snippets related to the creation and display of the HealthKit task.

let schedule = OCKSchedule.dailyAtTime(
            hour: 15, minutes: 50, start: Date(), end: nil, text: nil,
            duration: .minutes(15), targetValues: [OCKOutcomeValue(200.0, units: "Steps")])

var steps = OCKHealthKitTask(
    id: "Steps",
    title: "Steps",
    carePlanUUID: carePlanUUID,
    schedule: schedule,
    healthKitLinkage: OCKHealthKitLinkage(
        quantityIdentifier: .stepCount,
        quantityType: .cumulative,
        unit: HKUnit.count()))
let view = NumericProgressTaskView(
    task: task,
    eventQuery: OCKEventQuery(for: date),
    storeManager: self.storeManager)

image

Above is a screenshot of the app in the simulator. In the simulator, I manually add step data to the Health app and can observe the cumulative values being updated at the same time.

Back to the server side. On the Parse dashboard, I am able to observe (1) all three tasks are successfully added to the data store and sync'ed to the server. (2) The outcomes of the OCKTasks are also saved to the data store after completion and sync'ed to the server.

However, I am unable to observe any outcome related to the HealthKitTask ever sync'ed to the remote, even past the schedule time (16:05 in the screenshot). Assuming ParseCareKit correctly synchronizes data from the device to the server, I am not sure if the outcome of this HealthKitTask is saved anywhere to the data store on the device. Am I missing something here?

@erik-apple
Copy link
Collaborator

That behavior is correct. The outcomes you add into HealthKit are stored within your device’s HealthKit store, not inside of your app. CareKit reads those values from HealthKit and shows them along side the data it owns, but it doesn’t synchronize them.

This is a shortcoming that we’d like to address someday. @cbaker6 might be able to compensate for it within his plugin somehow, but ideally CareKit would do the book keeping.

@zhang-bo-lilly
Copy link
Author

@erik-apple, thank you for the reply. If you don't mind, I would like to double check my interpretation to make sure I get this correct.

I understand that the step count outcomes I added are stored within the device's HealthKit store and the app is simply reading from it. In fact, based on #569, I only ask for read permission of step count from the HealthKit with no intention to write back to it.

I set up breakpoints in all methods of the OCKHealthKitStore+Outcomes file and observe the breakpoint is only triggered in the fetchOutcomes method after I add data to HealthKit store and prepare to go back to the view.

private func fetchOutcomes(task: OCKHealthKitTask, dateRange: DateInterval,

In the debugger, I noticed that isOwnedByApp is always false. I guess this means even the addOutcomes method in this file is called somewhere (and I am not sure whether this method is ever called), the following line leaves samples empty


As a result, even if I want to save something (which I don't), there is nothing to save at this line.

It seems to me the outcome of the HealthKitTask is properly displayed to the UI when needed, but not saved to the OCKStore. Is this interpretation correct?

For my case, if I want to know the outcome of the OCKHealthKitTask and sync it to a remote server, it seems that I need to execute a query past the end of the underlying schedule (e.g., execute the query after 16:05). Is this the correct way to handle this?

Lastly, I notice that both OCKHealthKitPassthroughStore and OCKHealthKitProxy call HKHealthStore(). The developer documentation, however, states one need only a single HealthKit store per app. May I know the reasons why two are created here? Thanks.


private let store = HKHealthStore()

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

No branches or pull requests

2 participants