CareKit 和 ResearchKit 冲突
Posted
技术标签:
【中文标题】CareKit 和 ResearchKit 冲突【英文标题】:CareKit and ResearchKit conflict 【发布时间】:2018-11-19 08:51:04 【问题描述】:我对结果表调查的类型有疑问。 如果我使用 CareKit / HealthKit 调查,一切都很好,当我想将它与 ResearchKit 调查混合使用时 - 我在以下方法中有错误:
func buildCarePlanResultFrom(taskResult: ORKTaskResult) -> OCKCarePlanEventResult
guard let firstResult = taskResult.firstResult as? ORKStepResult,
let stepResult = firstResult.results?.first else
fatalError("Unexepected task results")
if let numericResult = stepResult as? ORKNumericQuestionResult,
let answer = numericResult.numericAnswer
return OCKCarePlanEventResult(valueString: answer.stringValue, unitString: numericResult.unit, userInfo: nil)
else
fatalError("Unexpected task result type")
这是 - 我认为 - 因为我无法创建 OCKCarePlanEventResult 对象 [answer 和 numericResult 都是 nil]。
我在下面的扩展中更新症状跟踪器:
extension TabBarViewController: ORKTaskViewControllerDelegate
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith
reason: ORKTaskViewControllerFinishReason, error: Error?)
defer
dismiss(animated: true, completion: nil)
guard reason == .completed else return
guard let symptomTrackerViewController = symptomTrackerViewController,
let event = symptomTrackerViewController.lastSelectedAssessmentEvent else return
symptomTrackerViewController.progressRingTintColor = .lightGreen
symptomTrackerViewController.delegate = self
let carePlanResult = carePlanStoreManager.buildCarePlanResultFrom(taskResult: taskViewController.result)
carePlanStoreManager.store.update(event, with: carePlanResult, state: .completed)
success, _, error in
if !success
print(error?.localizedDescription)
有什么建议如何将 ResearchKit 的结果类型转换为 CareKit 或其他解决方案以更新视图?
可能会有帮助,任务示例:
let sleepHoursSurveyActivity = OCKCarePlanActivity.assessment(
withIdentifier: ActivityIdentifier.sleepHours.rawValue,
groupIdentifier: nil,
title: "Sleep Hours",
text: nil,
tintColor: .darkGreen,
resultResettable: true,
schedule: dailyScheduleRepeating(occurencesPerDay: 1),
userInfo: ["ORKTask" : AssessmentTaskFactory.sleepHoursSurveyAssessmentTask()])
static func sleepHoursSurveyAssessmentTask() -> ORKTask
var steps = [ORKQuestionStep]()
let question = NSLocalizedString("How many hours did you sleep?", comment: "")
let textChoices = [
ORKTextChoice(text: "1-3", value: "1-3" as NSString),
ORKTextChoice(text: "4-5", value: "4-5" as NSString),
ORKTextChoice(text: "6-7", value: "6-7" as NSString),
ORKTextChoice(text: "8", value: "8" as NSString),
ORKTextChoice(text: "more than 8", value: "more than 8" as NSString)
]
let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)
let sleepHoursSurvaySteps = ORKQuestionStep(identifier: "sleepHours", title: question, answer: questAnswerFormat)
sleepHoursSurvaySteps.isOptional = false
steps += [sleepHoursSurvaySteps]
return ORKOrderedTask(identifier: "sleepHoursSurveyTask", steps: [sleepHoursSurvaySteps])
【问题讨论】:
我不知道问题出在哪里,因为 firstResult 和 stepResult 对于 HK、CR 和 RK 来说都很好,它们都具有相同的类型。突然间 numericResult 和 answer 在 RK 中为零。为什么? 【参考方案1】:返回任务的函数sleepHoursSurveyAssessmentTask
没有数字答案格式。您正在使用 ORKTextChoiceAnswerFormat
,您可以使用 ORKChoiceQuestionResult
从 ORKTaskResult
中提取它。
【讨论】:
感谢您的回答。我改了格式,问题还是一样。以上是关于CareKit 和 ResearchKit 冲突的主要内容,如果未能解决你的问题,请参考以下文章
从字符串中的 ORKQuestionResult 数组中获取 Researchkit 中的结果?