public Step getStepAfterStep()

in Android/app/src/main/java/com/harvard/studyappmodule/activitybuilder/ActivityBuilder.java [62:235]


  public Step getStepAfterStep(Step previousStep, TaskResult taskResult) {

    if (branching) {
      Steps stepsData = null;
      for (int i = 0; i < activityQuestionStep.size(); i++) {
        if (previousStep == null) {
          return steps.get(0);
        } else if (previousStep
            .getIdentifier()
            .equalsIgnoreCase(activityQuestionStep.get(i).getKey())) {
          stepsData = activityQuestionStep.get(i);
        }
      }

      if (stepsData.getResultType().equalsIgnoreCase("textScale")
          || stepsData.getResultType().equalsIgnoreCase("imageChoice")
          || stepsData.getResultType().equalsIgnoreCase("textChoice")
          || stepsData.getResultType().equalsIgnoreCase("boolean")) {

        if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase("")
            && stepsData.getDestinations().get(0).getDestination().equalsIgnoreCase("")) {
          return null;
        } else if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && (stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase(""))) {
          for (int i = 0; i < steps.size(); i++) {
            if (steps
                .get(i)
                .getIdentifier()
                .equalsIgnoreCase(stepsData.getDestinations().get(0).getDestination())) {
              return steps.get(i);
            }
          }
        } else if (stepsData != null) {
          Map<String, StepResult> map = taskResult.getResults();
          String destination = "";
          String answer = getAnswerForResultTypeSet1(map, stepsData);

          for (int j = 0; j < stepsData.getDestinations().size(); j++) {
            if (stepsData.getDestinations().get(j).getCondition().equalsIgnoreCase(answer)) {
              destination = stepsData.getDestinations().get(j).getDestination();
            }
          }
          for (int k = 0; k < steps.size(); k++) {
            if (steps.get(k).getIdentifier().equalsIgnoreCase(destination)) {
              return steps.get(k);
            }
          }

          // if destination doesn't satisfy
          if (previousStep == null) {
            return steps.get(0);
          }

          if (destination.equalsIgnoreCase("")) {
            return null;
          }

          int nextIndex = steps.indexOf(previousStep) + 1;

          if (nextIndex < steps.size()) {
            return steps.get(nextIndex);
          }
        }
      } else if (stepsData.getResultType().equalsIgnoreCase("scale")
          || stepsData.getResultType().equalsIgnoreCase("continuousScale")
          || stepsData.getResultType().equalsIgnoreCase("numeric")
          || stepsData.getResultType().equalsIgnoreCase("timeInterval")
          || stepsData.getResultType().equalsIgnoreCase("height")) {
        if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase("")
            && stepsData.getDestinations().get(0).getDestination().equalsIgnoreCase("")) {
          return null;
        } else if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && (stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase(""))) {
          for (int i = 0; i < steps.size(); i++) {
            if (steps
                .get(i)
                .getIdentifier()
                .equalsIgnoreCase(stepsData.getDestinations().get(0).getDestination())) {
              return steps.get(i);
            }
          }
        } else if (stepsData != null) {
          Map<String, StepResult> map = taskResult.getResults();
          String destination = "";
          String answer = getAnswerForResultTypeSet2(map, stepsData);
          for (int j = 0; j < stepsData.getDestinations().size(); j++) {
            if (answer.equalsIgnoreCase("")) {
              if (stepsData.getDestinations().get(j).getCondition().equalsIgnoreCase(answer)) {
                destination = stepsData.getDestinations().get(j).getDestination();
              }
            } else if (!stepsData.getDestinations().get(j).getCondition().equalsIgnoreCase("")) {
              double condition =
                  Double.parseDouble(stepsData.getDestinations().get(j).getCondition());
              if (stepsData.getResultType().equalsIgnoreCase("timeInterval")) {
                condition =
                    Double.parseDouble(stepsData.getDestinations().get(j).getCondition()) / 3600d;
              }
              double answerDouble = Double.parseDouble(answer);
              destination = getDestination(condition, answerDouble, stepsData, j, destination);
            }
          }
          for (int k = 0; k < steps.size(); k++) {
            if (steps.get(k).getIdentifier().equalsIgnoreCase(destination)) {
              return steps.get(k);
            }
          }

          // if destination doesn't satisfy
          if (previousStep == null) {
            return steps.get(0);
          }

          if (destination.equalsIgnoreCase("")) {
            return null;
          }

          int nextIndex = steps.indexOf(previousStep) + 1;

          if (nextIndex < steps.size()) {
            return steps.get(nextIndex);
          }
        }
      } else {

        if (previousStep == null) {
          return steps.get(0);
        }

        if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && (stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase(""))
            && stepsData.getDestinations().get(0).getDestination().equalsIgnoreCase("")) {
          return null;
        } else if (stepsData != null
            && stepsData.getDestinations().size() == 1
            && (stepsData.getDestinations().get(0).getCondition().equalsIgnoreCase(""))) {
          for (int i = 0; i < steps.size(); i++) {
            if (steps
                .get(i)
                .getIdentifier()
                .equalsIgnoreCase(stepsData.getDestinations().get(0).getDestination())) {
              return steps.get(i);
            }
          }
        } else {

          int nextIndex = steps.indexOf(previousStep) + 1;

          if (nextIndex < steps.size()) {
            return steps.get(nextIndex);
          }
        }
      }

    } else {
      if (previousStep == null) {
        return steps.get(0);
      }

      int nextIndex = steps.indexOf(previousStep) + 1;

      if (nextIndex < steps.size()) {
        return steps.get(nextIndex);
      }
    }

    return null;
  }