Apple Health Frameworks

Nov 29 2022 Swift 5, iOS 15, Xcode 13

Part 3: Take Advantage of CareKit & ResearchKit

10. Make a Follow-Up Vaccination Task

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 9. Work With StoreManager Next episode: 11. Make an ActiveTask Using ResearchKit.

Please check your local health authorities for guidance and find out when you are able to get vaccinated.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Part 3, Episode 11, Make a follow-up Vaccination Task

In this episode, I want to show you how to add a new task by using an output of other tasks, for example, extracting the date of the first dose of vaccine and adding the follow-up reminder to inject the second dose after a month.

  case secondVaccinationCheck
  static func makeNextVaccination(date: Date) -> OCKTask {
    let thisMorning = Calendar.current.startOfDay(for: date)
    let nextMonth = Calendar.current.date(
      byAdding: .month,
      value: 1,
      to: thisMorning)
    let schedule = OCKSchedule.dailyAtTime(
      hour: 0,
      minutes: 0,
      start: nextMonth ?? Date(),
      end: nil,
      text: nil,
      duration: .allDay)
    var task = OCKTask(
      id: TaskModel.secondVaccinationCheck.rawValue,
      title: "Vaccination Task",
      carePlanUUID: nil,
      schedule: schedule)
    task.instructions =
      "Please check your local health authorities for guidance and find out when you are able to get a vaccination."
    task.impactsAdherence = false
    return task
  }
    case .vaccinationCheck, .secondVaccinationCheck:
{ result in
              if let survey = result.results?.first(where: { $0.identifier == "vaccination.date" }) as? ORKStepResult,
              let dateResult = survey.results?.first as? ORKDateQuestionResult,
              let answer = dateResult.dateAnswer {
                TaskViewModel.prepareTasks(
                  storeManager: storeManager,
                  tasksList: [
                    TaskManager.makeNextVaccination(date: answer)
                  ])
              }
              return [OCKOutcomeValue(Date())] }
if id == TaskModel.checkIn || id == TaskModel.secondVaccinationCheck