Closed federicatopazio closed 1 year ago
Hi! Addressing your first question, are you looking to pull sleep analysis data from HealthKit? Unfortunately that's a category type and at the moment CareKit only supports linking to quantity types in HealthKit. If there are use cases for linking to category types we can look into how that might fit into the API. It does seem like there are use cases, say if a user has a task to "sleep 8 hours a night".
Given that limitation, I would recommend using HealthKit APIs to read the sleep analysis data and map it to a CareKit chart. The HKAnchoredObjectQuery is a great API to start with. You could also consider mapping the data to a Swift Chart if you want a more custom visualization.
Hi, I was following the recover app tutorials from WWDC21, and I was wondering if there was a way of taking the sleep data directly from the healthApp (HealthKit). However, I'm unable to understand how to integrate this data automatically into the "barChart" he creates where he compares sleep data and pain data, the user manually puts by answering the daily forms:
`let painSeries = OCKDataSeriesConfiguration( taskID: TaskIDs.checkIn, legendTitle: "Pain (1-10)", gradientStartColor: #colorLiteral(red: 1, green: 0.462745098, blue: 0.368627451, alpha: 1), gradientEndColor: #colorLiteral(red: 1, green: 0.462745098, blue: 0.368627451, alpha: 1), markerSize: 10, eventAggregator: .custom({ events in events .first? .answer(kind: Surveys.checkInPainItemIdentifier) ?? 0 }) )
Furthermore, if there was also a way of displaying the sleep form only if the user did not register any sleep data into the health application, and so how to change the code here: `let sleepAnswerFormat = ORKAnswerFormat.scale( withMaximumValue: 12, minimumValue: 0, defaultValue: 0, step: 1, vertical: false, maximumValueDescription: nil, minimumValueDescription: nil ) let sleepItem = ORKFormItem( identifier: checkInSleepItemIdentifier, text: "How many hours of sleep did you get last night?", answerFormat: sleepAnswerFormat ) sleepItem.isOptional = false
but the main focus of my question is if there is a way to integrate sleep data into the barChart, using an OCKCartesianChartViewController.