Search in sources :

Example 16 with Value

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

the class DynamicStockImageRadioButtonSingleQuestionView method onCheckedChanged.

@Override
public void onCheckedChanged(ImageRadioButtonOption imageRadioButton, boolean value) {
    if (value == false)
        return;
    for (int i = 0; i < answersContainer.getChildCount(); i++) {
        ImageRadioButtonOption optionView = (ImageRadioButtonOption) answersContainer.getChildAt(i);
        if (imageRadioButton != optionView && optionView.isChecked()) {
            optionView.setChecked(false);
            Question question = (Question) optionView.getTag();
            if (!question.isOutStockQuestion()) {
                notifyAnswerChanged(optionView, String.valueOf(-1));
            } else {
                List<Option> options = question.getAnswer().getOptions();
                for (Option option : options) {
                    if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.false_option_id))) {
                        notifyAnsweOptionChange(optionView, option);
                    }
                }
            }
        }
    }
    Question question = (Question) imageRadioButton.getTag();
    if (!question.isOutStockQuestion()) {
        notifyAnswerChanged(imageRadioButton, String.valueOf(optionDose.get(imageRadioButton.getOption().getId_option())));
    } else {
        List<Option> options = question.getAnswer().getOptions();
        for (Option option : options) {
            if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.true_option_id))) {
                notifyAnsweOptionChange(imageRadioButton, option);
            }
        }
    }
    //Setting a value for the stock question to get max total question correct
    View stockHideView = new View(context);
    stockHideView.setTag(Treatment.getDynamicStockQuestion());
    Question pqHideQuestion = Question.findByUID(context.getString(R.string.stockPqQuestionUID));
    Option falseOption = Option.findById(41l);
    Value valuePq = pqHideQuestion.getValueBySession();
    if (valuePq != null) {
        falseOption = valuePq.getOption();
    }
    notifyAnsweOptionChange(stockHideView, falseOption);
}
Also used : ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) AKeyboardQuestionView(org.eyeseetea.malariacare.views.question.AKeyboardQuestionView) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) View(android.view.View) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView)

Example 17 with Value

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

the class NumberRadioButtonMultiquestionView method changeTotalQuestions.

/**
     * Changing the total questions of the alternative pq questions depending on the answer provided
     */
private void changeTotalQuestions() {
    Question pqQuestion = Question.findByUID(context.getString(R.string.pqQuestionUID));
    Question actQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
    Question alternativePqQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
    Value actValue = null;
    Value pqValue = null;
    List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
    for (Value sValue : values) {
        if (sValue.getQuestion() == null) {
            continue;
        }
        if (sValue.getQuestion().equals(actQuestion)) {
            actValue = sValue;
            break;
        }
        if (sValue.getQuestion().getUid().equals(pqQuestion.getUid())) {
            pqValue = sValue;
            break;
        }
    }
    if ((actValue == null || actValue.getOption().getName().equals(PreferencesState.getInstance().getContext().getString(R.string.yes_option_identifier))) || (pqValue == null || Float.parseFloat(pqValue.getValue()) > 0)) {
        alternativePqQuestion.setTotalQuestions(8);
    } else {
        alternativePqQuestion.setTotalQuestions(9);
    }
    alternativePqQuestion.save();
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 18 with Value

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

the class NavigationController method isNextAllowed.

/**
     * Tells if you can move forward:
     * - Not even started: true
     * -
     * Cann
     */
public boolean isNextAllowed() {
    if (isMovingToForward) {
        return false;
    }
    QuestionNode currentQuestionNode = getCurrentNode();
    //not even start
    if (currentQuestionNode == null) {
        return true;
    }
    //Get value for current
    Question currentQuestion = getCurrentQuestion();
    Value currentValue = currentQuestion.getValueBySession();
    //Cannot move without answer
    if (currentValue == null) {
        Log.d(TAG, "isNextAllowed()->You must answer first");
        return false;
    }
    Option currentOption = currentValue == null ? null : currentValue.getOption();
    //Find next node with current option
    boolean isAllowed = findNext(currentOption) != null;
    Log.d(TAG, String.format("isNextAllowed()->%b", isAllowed));
    return isAllowed;
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 19 with Value

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

the class WarningStatusChecker method isEnabled.

@Override
public boolean isEnabled() {
    //Warning not built yet -> false
    if (questionThreshold == null || questionOption == null) {
        return false;
    }
    //Get current values in DB
    Question questionWithOption = questionOption.getQuestion();
    Value optionValue = questionWithOption.getValueBySession();
    Value intValue = questionThreshold.getQuestion().getValueBySession();
    //A question is not answered yet -> false
    if (optionValue == null || optionValue.getOption() == null || intValue == null) {
        return false;
    }
    //The option for this warning has not been selected
    if (optionValue.getId_option() != questionOption.getOption().getId_option()) {
        return false;
    }
    //If current int value NOT in threshold -> the warning is activated
    return !questionThreshold.isInThreshold(intValue.getValue());
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 20 with Value

use of org.eyeseetea.malariacare.data.database.model.Value 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

Value (org.eyeseetea.malariacare.data.database.model.Value)21 Question (org.eyeseetea.malariacare.data.database.model.Question)15 Survey (org.eyeseetea.malariacare.data.database.model.Survey)6 Option (org.eyeseetea.malariacare.data.database.model.Option)5 ArrayList (java.util.ArrayList)3 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)3 TableRow (android.widget.TableRow)2 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)2 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)2 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)2 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)2 Handler (android.os.Handler)1 View (android.view.View)1 Calendar (java.util.Calendar)1 CompositeScore (org.eyeseetea.malariacare.data.database.model.CompositeScore)1 Match (org.eyeseetea.malariacare.data.database.model.Match)1 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)1 Session.getMalariaSurvey (org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 Treatment (org.eyeseetea.malariacare.domain.entity.Treatment)1