Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigable Tasks #1542

Open
InfuriatingYetti opened this issue Feb 19, 2023 · 0 comments
Open

Navigable Tasks #1542

InfuriatingYetti opened this issue Feb 19, 2023 · 0 comments

Comments

@InfuriatingYetti
Copy link

InfuriatingYetti commented Feb 19, 2023

Hello everyone!

I was hoping to get some help in understanding a ResearchKit concept.

Navigable Task Question
I was looking at different things one can do with Research Kit and came across the Navigable Task based on the various answer responses; for example, ORKPredicateStepNavigationRule. The first information for ORKPredicateStepNavigationRule I found though uses a method in which each individual question for an ORKTextChoice is its own steps += [], as opposed to the code I have below called Choices1 where the steps are contained within a single form (as seen with the ORKTextChoice):

//Choices1

static let choiceIdentifier = "choice"
static let choiceFormIdentifier = "choice.form"
static let ChoiceQuestion1Step = "checkin.form.choicequestion1"
static let ChoiceQuestionStep = "checkin.form.Choice"

  static func Choices1() -> ORKTask {
      
      let Choices = [
          ORKTextChoice(text: "None", value: 0 as NSNumber),
          ORKTextChoice(text: "Slight", value: 1 as NSNumber),
          ORKTextChoice(text: "Mild", value: 2 as NSNumber),
          ORKTextChoice(text: "Severe", value: 3 as NSNumber),
   
      ]
      let choiceAnswerFormat =  ORKAnswerFormat.choiceAnswerFormat(
          with: .singleChoice,
          textChoices: Choices
      )
             
      
      let choiceStep = ORKFormItem(
          identifier: ChoiceQuestion1Step,
          text: "Text question goes here",
          answerFormat: choiceAnswerFormat
      )
      choiceStep.isOptional = false
      
      
      let formStep = ORKFormStep(
          identifier: choiceFormIdentifier,
          title: "Choice Question",
          text: "Instructions for questions"
      )
      formStep.formItems = [choiceStep]
      formStep.isOptional = false
      
      let choiceTask = ORKOrderedTask(
          identifier: choiceIdentifier,
          steps: [formStep]
      )
      
      return choiceTask
  } 

What I am trying to understand is in the absence of having steps += for each individual question (not as a form), is it possible to use the ORKPredicateStepNavigationRule within the above Choices1 form and depending on the question response to an ORKTextChoice in the Choices1 the user will be redirected to another form (Choices2 below)?

For example, looking at the modified code below, you see that I have added Choices2 as an additional form to the original code from above. What I am looking to do is make it so when a person where to select ORKTextChoice(text: "None", value: 0 as NSNumber), they will be sent automatically to the Choices2 form and could fill out an additional series of questions.

//Choices1

static let choiceIdentifier = "choice"
static let choiceFormIdentifier = "choice.form"
static let ChoiceQuestion1Step = "checkin.form.choicequestion1"
static let ChoiceQuestionStep = "checkin.form.Choice"

  static func Choices1() -> ORKTask {
      
      let Choices = [
          ORKTextChoice(text: "None", value: 0 as NSNumber),
          ORKTextChoice(text: "Slight", value: 1 as NSNumber),
          ORKTextChoice(text: "Mild", value: 2 as NSNumber),
          ORKTextChoice(text: "Severe", value: 3 as NSNumber),
   
      ]
      let choiceAnswerFormat =  ORKAnswerFormat.choiceAnswerFormat(
          with: .singleChoice,
          textChoices: Choices
      )
             
      
      let choiceStep = ORKFormItem(
          identifier: ChoiceQuestion1Step,
          text: "Text question goes here",
          answerFormat: choiceAnswerFormat
      )
      choiceStep.isOptional = false
      
      
      let formStep = ORKFormStep(
          identifier: choiceFormIdentifier,
          title: "Choice Question",
          text: "Instructions for questions"
      )
      formStep.formItems = [choiceStep]
      formStep.isOptional = false
      
      let choiceTask = ORKOrderedTask(
          identifier: choiceIdentifier,
          steps: [formStep]
      )
      
      return choiceTask
  } 

// Choices2

static let choice2Identifier = "choice2"
static let choice2FormIdentifier = "choice2.form"
static let Choice2Question1Step = "checkin.form.choice2question1"
static let Choice2QuestionStep = "checkin.form.Choice2"

  static func Choices2() -> ORKTask {
      
      let Choices2 = [
          ORKTextChoice(text: "None", value: 0 as NSNumber),
          ORKTextChoice(text: "Slight", value: 1 as NSNumber),
          ORKTextChoice(text: "Mild", value: 2 as NSNumber),
          ORKTextChoice(text: "Severe", value: 3 as NSNumber),
   
      ]
      let choiceAnswerFormat2 =  ORKAnswerFormat.choiceAnswerFormat(
          with: .singleChoice,
          textChoices: Choices2
      )
             
      
      let choice2Step = ORKFormItem(
          identifier: Choice2Question1Step,
          text: "Text question goes here",
          answerFormat: choiceAnswerFormat2
      )
      choice2Step.isOptional = false
      
      
      let form2Step = ORKFormStep(
          identifier: choice2FormIdentifier,
          title: "Choice Question",
          text: "Instructions for questions"
      )
      form2Step.formItems = [choices2Step]
      form2Step.isOptional = false
      
      let choice2Task = ORKOrderedTask(
          identifier: choice2Identifier,
          steps: [form2Step]
      )
      
      return choiceTask
  } 

I thought that doing something like this inside of the Choices1 code would work, but doesn't seem to be:

let choicePredicate = ORKResultPredicate.predicateForBooleanQuestionResult(with: ORKResultSelector(resultIdentifier: ChoiceQuestion1Step), expectedAnswer: (0 != 0))
            
let predicatedNavigationRule = ORKPredicateStepNavigationRule(resultPredicates: [choicePredicate], destinationStepIdentifiers: [choice2Task])

task.setNavigationRule(predicatedNavigationRule, forTriggerStepIdentifier: ChoiceQuestion1Step)

I have a feeling that because I am working with two forms and if I put the ORKResultPredicate.predicateForBooleanQuestionResult inside Choices1, for whatever reason cannot see the form of Choices2.

Am I close and on the right track? Can someone help me better understand how this works, please? I hope this makes sense, please let me know if you need any clarification - I'd be grateful for any direction!

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant