Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CareKit & ResearchKit - An introduction

CareKit & ResearchKit - An introduction

iOSCon 2016 - London

Matteo Crippa

May 26, 2016
Tweet

More Decks by Matteo Crippa

Other Decks in Programming

Transcript

  1. api

  2. limited participation subjective information infrequent data one-way communications wider reach

    driven data continuous stream of data feedback for participants vs
  3. public var surveyTask: ORKOrderedTask { let questions: [Question] = [

    Question( image: UIImage(named: "duck"), answers: [ Answer(text: "A cat", value: 0), Answer(text: "A duck", value: 1), Answer(text: "Nothing", value: 0) ] ), Question( image: UIImage(named: "dog"), answers: [ Answer(text: "An airplane", value: 0), Answer(text: "Nothing", value: 0), Answer(text: "A dog", value: 1) ] ), Question( image: UIImage(named: "butterfly"), answers: [ Answer(text: "A goat", value: 0), Answer(text: "A butterfly", value: 1), Answer(text: "Nothing", value: 0) ] ) ] let steps = generateSteps(questions) return ORKOrderedTask(identifier: "Survey", steps: steps) }
  4. What do you recognize? Step 2 of 6 A cat

    A duck Nothing Next Cancel
  5. func generateSteps(questions: [Question]) -> [ORKStep] { var steps = [ORKStep]()

    var index = 0 for q in questions { let stepImage = ORKInstructionStep(identifier: "stepImage\(index)") stepImage.text = "Please look at this image for 10 seconds" stepImage.image = q.image steps += [stepImage] var answers = [ORKTextChoice]() for a in q.answers { answers.append(ORKTextChoice(text: a.text, value: a.value)) } let colorBlindAnswerFormat = ORKTextChoiceAnswerFormat( style: .SingleChoice, textChoices: answers ) let colorBlindStep = ORKQuestionStep( identifier: "stepQuestion\(index)", title: "What do you recognize?", text: "", answer: colorBlindAnswerFormat ) colorBlindStep.optional = false steps = steps + [colorBlindStep] index = index + 1 } return steps }
  6. extension ViewController: ORKTaskViewControllerDelegate { func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason,

    error: NSError?) { var total = 0 let taskResult = taskViewController.result // this should be a ORKTaskResult // swiftlint:disable force_cast let results = taskResult.results as! [ORKStepResult] for thisStepResult in results { // swiftlint:disable force_cast let stepResults = thisStepResult.results as! [ORKQuestionResult] for item in stepResults { if let answer = item as? ORKChoiceQuestionResult { // cast it to the right subclass let arr = answer.answer as! [Int] let value = arr[0] total = total + value } } } NSUserDefaults.standardUserDefaults().setInteger(total, forKey: "blindTotal") NSUserDefaults.standardUserDefaults().synchronize() taskViewController.dismissViewControllerAnimated(true, completion: nil) } }
  7. care card Ibuprofen 200mg Hamstring Stretch 5 mins Outdoor walk

    15 mins Care Completion April 22, 2016 25% S S M T T F W Care Card Today
  8. symptom Weight Early morning Blood Glucose After dinner Mood Pain

    Lower Back out of 10 5 Activity Completion April 22, 2016 25% S S M T T F W Symptom Tracker Today
  9. insight dashboard Fri Sat Sun Mon Tue Wed Thu 4/15

    4/16 4/17 4/18 4/19 4/20 4/21 N/A 7 7 6 5 5 8 100% 100% 50% 50% 100% 100% 8 Back Pain Pain Medication Adherence Medication Adherence Your medication adherence was 21% last week. Weekly Charts Insights
  10. connect Manages contacts of the care team and friends/family members.

    Allows easily to share reports and insights.
  11. care plan store Stores all the data displayed by Care

    Card and Progress Card. It provides reactive information to UI. It is encrypted by default.
  12. document exporter Allows you to export data in HTML or

    PDF format, creating custom template based documents with graphs.
  13. Dog

  14. let vet = OCKContact( contactType: .CareTeam, name: "John Doe", relation:

    "Vet", tintColor: Colors.Blue.color, phoneNumber: CNPhoneNumber(stringValue: "00 39 123 456"), messageNumber: CNPhoneNumber(stringValue: "00 39 234 567”), emailAddress: "[email protected]", monogram: "JD", image: nil )
  15. struct DogWalk: Activity { // set activity type according enum

    let type: ActivityType = .DogWalk func carePlanActivity() -> OCKCarePlanActivity { // define early starting date let startDate = NSDateComponents(year: 2016, month: 1, day: 1) // set weekly scheduling let schedule = OCKCareSchedule.weeklyScheduleWithStartDate( startDate, occurrencesOnEachDay: [3, 2, 2, 2, 2, 2, 3] ) // set details for this activity let title = "Outdoor walk" let summary = "at least 10 minutes" let instructions = "Take a break and have a nice walk with your dog." // generate activity return OCKCarePlanActivity.interventionWithIdentifier( type.rawValue, groupIdentifier: nil, title: title, text: summary, tintColor: Colors.Purple.color, instructions: instructions, imageURL: nil, schedule: schedule, userInfo: nil ) } }
  16. struct DogMood: Assessment { // set activity type according enum

    let type: ActivityType = .DogMood func carePlanActivity() -> OCKCarePlanActivity { // define early starting date let startDate = NSDateComponents(year: 2016, month: 1, day: 1) // set weekly scheduling let schedule = OCKCareSchedule.weeklyScheduleWithStartDate( startDate, occurrencesOnEachDay: [1, 1, 1, 1, 1, 1, 1] ) // set details for this activity let title = "Mood" // generate activity return OCKCarePlanActivity.assessmentWithIdentifier( type.rawValue, groupIdentifier: nil, title: title, text: nil, tintColor: Colors.Green.color, resultResettable: false, schedule: schedule, userInfo: nil ) } // set task func task() -> ORKTask { let question = NSLocalizedString("On a scale from 1 to 10, how would you rate your dog mood today?", comment: "") let maximumValueDescription = NSLocalizedString("Good", comment: "") let minimumValueDescription = NSLocalizedString("Bad", comment: "") let answerFormat = ORKScaleAnswerFormat( maximumValue: 10, minimumValue: 1, defaultValue: -1, step: 1, vertical: false, maximumValueDescription: maximumValueDescription, minimumValueDescription: minimumValueDescription ) let questionStep = ORKQuestionStep(identifier: type.rawValue, title: question, answer: answerFormat) questionStep.optional = false let task = ORKOrderedTask(identifier: type.rawValue, steps: [questionStep]) return task } }
  17. private var connectVC: OCKConnectViewController! = { var contacts = [OCKContact]()

    let vc = OCKConnectViewController(contacts: contacts) vc.title = "Contacts" vc.tabBarItem = UITabBarItem( title: vc.title, image: UIImage(named: "alarm"), selectedImage: UIImage(named: "alarm select") ) vc.view.tintColor = Colors.AppColor.color vc.navigationController?.navigationBar.tintColor = Colors.AppColor.color return vc }()