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
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Work With StoreManager Next episode: 11. Make an ActiveTask Using ResearchKit.

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 10. Make a Follow-Up Vaccination Task

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

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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