在继续在 ResearchKit 中进行调查之前需要征得同意



我目前正在创建一个想要利用ResearchKit的程序。在进入调查问题之前,我需要征得同意。我正在使用 Ray Wenderlich (https://www.raywenderlich.com/1820-researchkit-tutorial-with-swift-getting-started( 教程并设置了此代码。我已经尝试继续我的程序的调查部分,我甚至可以在未经同意的情况下访问它。

import ResearchKit
public var ConsentTask: ORKOrderedTask {
var ctr = 0
let Document = ORKConsentDocument()
Document.title = "Consent"
//section types
let sectionTypes: [ORKConsentSectionType] = [
.overview,
.dataGathering,
.privacy
]
let consentSections: [ORKConsentSection] = sectionTypes.map { contentSectionType in
let consentSection = ORKConsentSection(type: contentSectionType)
if ctr < sectionTypes.count {
if ctr == 0 { 
consentSection.summary = "Summary"
consentSection.content = "Content"
}
else if ctr == 1 { //Data Gathering
consentSection.summary = "Summary"
consentSection.content = "Content"
}
else if ctr == 2 { //Privacy
consentSection.summary = "Summary"
consentSection.content = "Content"
}
ctr = ctr + 1
}
return consentSection
}
Document.sections = consentSections
Document.addSignature(ORKConsentSignature(forPersonWithTitle: nil, dateFormatString: nil, identifier: "UserSignature"))
var steps = [ORKStep]()
let visualConsentStep = ORKVisualConsentStep(identifier: "VisualConsent", document: Document)
steps += [visualConsentStep]
let signature = Document.signatures!.first! as ORKConsentSignature
let reviewConsentStep = ORKConsentReviewStep(identifier: "Review", signature: signature, in: Document)
reviewConsentStep.text = "Review the consent"
reviewConsentStep.reasonForConsent = "I agree"
steps += [reviewConsentStep]
//Completion
let completionStep = ORKCompletionStep(identifier: "CompletionStep")
completionStep.title = "Welcome"
completionStep.text = "Thank you for helping!"
steps += [completionStep]
return ORKOrderedTask(identifier: "ConsentTask", steps: steps)
}

在我的视图控制器中,我有

@IBAction func consentTask(_ sender: Any) {
if consentDone == false {
let taskViewController = ORKTaskViewController(task: ConsentTask, taskRun: nil)
taskViewController.delegate = self
present(taskViewController, animated: true, completion: nil)
}
else if consentDone == true {
//would they like to leave the study
}
}

通过我的努力在这里放置一个同意完成标志。

func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
taskViewController.dismiss(animated: true, completion: {() in self.consentDone = true})
print(consentDone)
}

但是,发生的情况是,如果用户按右上角的取消或在同意的最后完成,它将始终触发此操作。有没有办法确保代码块仅在所有完成后执行?理想情况下,在此之后,我想将其作为用户已经完成同意的标志。之后,我每次都会将用户重定向到不同的页面,直到用户离开研究。

经过一番试验和错误,我在这里找到了答案:https://github.com/ResearchKit/ResearchKit/issues/919

通过知道用户的签名意味着用户已经完成了表单,我们可以做

if result.identifier == "UserSignature"{
print(result)
let consentDoneAnswerResult = result as! ORKConsentSignatureResult
let consentDone = consentDoneAnswerResult.consented
print(consentDone)
}

这给出了同意在表单完成时完成,而不是取消。

相关内容

  • 没有找到相关文章

最新更新