Search in sources :

Example 51 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationBuilder method buildController.

/**
     * Returns a navigation controller so you can navigate through questions according to answers
     */
public NavigationController buildController(Tab tab) {
    //No tab -> nothing to build
    if (tab == null) {
        return null;
    }
    warningsXQuestion.clear();
    Log.d(TAG, String.format("build(%s)", tab.getName()));
    Question rootQuestion = Question.findRootQuestion(tab);
    //NO first question -> nothing to build
    if (rootQuestion == null) {
        return null;
    }
    //init steps counter
    step = 0;
    QuestionNode rootNode = buildNode(rootQuestion);
    return new NavigationController(rootNode);
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 52 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationBuilder method buildChildren.

/**
     * Adds navigation options according to answers (children questions)
     */
private void buildChildren(QuestionNode currentNode) {
    //precondition: options and some relations
    if (!withOptionsAndRelations(currentNode)) {
        return;
    }
    Question currentQuestion = currentNode.getQuestion();
    Answer currentAnswer = currentQuestion.getAnswer();
    for (Option option : currentAnswer.getOptions()) {
        Question firstChildrenQuestion = currentQuestion.findFirstChildrenByOption(option);
        //No child question for this option -> next
        if (firstChildrenQuestion == null) {
            continue;
        }
        Log.d(TAG, String.format("'%s' + '%s' --> '%s'", currentQuestion.getCode(), option.getName(), firstChildrenQuestion.getCode()));
        //Build navigation from there
        QuestionNode childNode;
        //Option that references self
        if (currentNode.getQuestion().getId_question() == firstChildrenQuestion.getId_question()) {
            childNode = currentNode;
        } else {
            //Any other child question
            childNode = buildNode(firstChildrenQuestion);
        }
        //Add navigation by option to current node
        currentNode.addNavigation(option, childNode);
    }
}
Also used : Answer(org.eyeseetea.malariacare.data.database.model.Answer) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 53 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class NavigationBuilder method buildCounters.

/**
     * Adds counters to this node
     */
private void buildCounters(QuestionNode currentNode) {
    //precondition: options and some relations
    if (!withOptionsAndRelations(currentNode)) {
        return;
    }
    Question currentQuestion = currentNode.getQuestion();
    Answer currentAnswer = currentQuestion.getAnswer();
    for (Option option : currentAnswer.getOptions()) {
        Question optionCounter = currentQuestion.findCounterByOption(option);
        //no counter -> try next option
        if (optionCounter == null) {
            continue;
        }
        //found a counter -> annotate it
        currentNode.addCounter(option, optionCounter);
    }
}
Also used : Answer(org.eyeseetea.malariacare.data.database.model.Answer) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 54 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method goToQuestion.

/**
     * When the user click in a value in the review fragment the navigationController should go to
     * related question
     */
private void goToQuestion(Question isMoveToQuestion) {
    navigationController.first();
    Question currentQuestion;
    boolean isQuestionFound = false;
    // question.
    while (!isQuestionFound) {
        currentQuestion = navigationController.getCurrentQuestion();
        int tabType = currentQuestion.getHeader().getTab().getType();
        if (Tab.isMultiQuestionTab(tabType)) {
            List<Question> screenQuestions = currentQuestion.getQuestionsByTab(currentQuestion.getHeader().getTab());
            for (Question question : screenQuestions) {
                if (isMoveToQuestion.getUid().equals(question.getUid())) {
                    isQuestionFound = true;
                }
            }
        } else {
            if (isMoveToQuestion.getUid().equals(currentQuestion.getUid())) {
                isQuestionFound = true;
            }
        }
        if (!isQuestionFound) {
            next();
            skipReminder();
        }
    }
    notifyDataSetChanged();
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 55 with Question

use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.

the class CompletionSurveyUseCase method updateRDTStockQuestion.

private void updateRDTStockQuestion(Survey survey) {
    if (survey.getStatus() == Constants.SURVEY_COMPLETED || survey.getStatus() == Constants.SURVEY_SENT) {
        org.eyeseetea.malariacare.data.database.model.Survey surveyDBMalaria = org.eyeseetea.malariacare.data.database.model.Survey.findById(survey.getId());
        List<Value> surveyValues = surveyDBMalaria.getValuesFromDB();
        org.eyeseetea.malariacare.data.database.model.Survey surveyDBStock = org.eyeseetea.malariacare.data.database.model.Survey.getLastSurveyWithType(Constants.SURVEY_ISSUE);
        Value rdtStockValue = Question.getStockRDTQuestion().insertValue("1", surveyDBStock);
        rdtStockValue.setValue(Integer.toString(rdtUsed(surveyValues)));
        rdtStockValue.save();
        for (Question propagateQuestion : Question.getStockRDTQuestion().getPropagationQuestions()) {
            propagateQuestion.insertValue(rdtStockValue.getValue(), Session.getMalariaSurvey()).save();
        }
    }
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Aggregations

Question (org.eyeseetea.malariacare.data.database.model.Question)58 Option (org.eyeseetea.malariacare.data.database.model.Option)15 Value (org.eyeseetea.malariacare.data.database.model.Value)15 CSVReader (com.opencsv.CSVReader)11 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)7 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)7 View (android.view.View)6 Answer (org.eyeseetea.malariacare.data.database.model.Answer)5 Match (org.eyeseetea.malariacare.data.database.model.Match)5 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)5 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)5 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)5 DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)5 TableRow (android.widget.TableRow)4 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)4 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)4 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)4 NumberRadioButtonMultiquestionView (org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView)4 ImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)4