Search in sources :

Example 11 with Question

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

the class PopulateRow method populateQuestion.

static Question populateQuestion(String[] line, HashMap<Long, Header> headerFK, HashMap<Long, Answer> answerFK, @Nullable Question question) {
    if (question == null) {
        question = new Question();
    }
    question.setCode(line[1]);
    question.setDe_name(line[2]);
    question.setHelp_text(line[3]);
    question.setForm_name(line[4]);
    question.setUid(line[5]);
    question.setOrder_pos(Integer.valueOf(line[6]));
    question.setNumerator_w(Float.valueOf(line[7]));
    question.setDenominator_w(Float.valueOf(line[8]));
    question.setHeader(headerFK.get(Long.valueOf(line[9])));
    if (!line[10].equals("")) {
        question.setAnswer(answerFK.get(Long.valueOf(line[10])));
    }
    question.setOutput(Integer.valueOf(line[12]));
    question.setTotalQuestions(Integer.valueOf(line[13]));
    question.setVisible(Integer.valueOf(line[14]));
    if (line.length > 15 && !line[15].equals("")) {
        question.setPath((line[15]));
    }
    if (line.length > 16 && !line[16].equals("")) {
        question.setCompulsory(Integer.valueOf(line[16]));
    } else {
        question.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
    }
    return question;
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 12 with Question

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

the class UpdateDB method updateQuestionThresholds.

public static void updateQuestionThresholds(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_THRESHOLDS_CSV);
    }
    List<QuestionThreshold> questionThresholds = QuestionThreshold.getAllQuestionThresholds();
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_THRESHOLDS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < questionThresholds.size()) {
            PopulateRow.populateQuestionThreshold(line, matchIds, questionsIds, questionThresholds.get(i)).save();
        } else {
            QuestionThreshold questionThreshold = PopulateRow.populateQuestionThreshold(line, matchIds, questionsIds, null);
            questionThreshold.insert();
        }
    }
}
Also used : QuestionThreshold(org.eyeseetea.malariacare.data.database.model.QuestionThreshold) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) PopulateRow.populateMatch(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 13 with Question

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

the class DynamicTabAdapter method OnOptionAnswered.

public void OnOptionAnswered(View view, Option selectedOption, boolean moveToNextQuestion) {
    if (moveToNextQuestion) {
        navigationController.isMovingToForward = true;
    }
    Question question = (Question) view.getTag();
    if (!selectedOption.getName().isEmpty() && question.getOutput() == Constants.DROPDOWN_OU_LIST) {
        OrgUnit orgUnit = OrgUnit.findByUID(selectedOption.getName());
        assignOrgUnitToSurvey(Session.getMalariaSurvey(), orgUnit);
        assignOrgUnitToSurvey(Session.getStockSurvey(), orgUnit);
    }
    Question counterQuestion = question.findCounterByOption(selectedOption);
    if (counterQuestion == null) {
        saveOptionValue(view, selectedOption, question, moveToNextQuestion);
    } else if (!(view instanceof ImageRadioButtonSingleQuestionView)) {
        showConfirmCounter(view, selectedOption, question, counterQuestion);
    }
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Question(org.eyeseetea.malariacare.data.database.model.Question) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)

Example 14 with Question

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

the class DynamicTabAdapter method switchHiddenMatches.

/**
     * switch the matches of a no dataelement question with his hidden dataelements.
     * Only applies to question with options and matches the option position (0)/(1) Match position
     * 1 no match position 0
     */
public void switchHiddenMatches(Question question, Option option) {
    if (!question.hasOutputWithOptions() || (!question.getOutput().equals(Constants.IMAGE_3_NO_DATAELEMENT) && !question.getOutput().equals(Constants.IMAGE_RADIO_GROUP_NO_DATAELEMENT))) {
        return;
    }
    //Find QuestionOptions
    for (QuestionOption questionOption : question.getQuestionOption()) {
        if (questionOption.getMatch().getQuestionRelation().getOperation() != QuestionRelation.MATCH) {
            continue;
        }
        Option matchOption = questionOption.getOption();
        Question matchQuestion = questionOption.getMatch().getQuestionRelation().getQuestion();
        switchHiddenMatch(question, option, matchQuestion, matchOption);
    }
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Option(org.eyeseetea.malariacare.data.database.model.Option) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 15 with Question

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

the class DynamicTabAdapter method renderQuestion.

public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
    TableRow tableRow;
    IQuestionViewFactory questionViewFactory;
    questionViewFactory = (Tab.isMultiQuestionTab(tabType) || Tab.isDynamicTreatmentTab(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
    // Se get the value from Session
    int visibility = View.GONE;
    Survey survey = (screenQuestion.isStockQuestion() || screenQuestion.isDynamicStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
    if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
        visibility = View.VISIBLE;
    }
    Value value = screenQuestion.getValueBySession();
    tableRow = new TableRow(context);
    IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
    if (questionView != null) {
        if (questionView instanceof IMultiQuestionView) {
            mMultiQuestionViews.add((IMultiQuestionView) questionView);
            ((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
        }
        addTagQuestion(screenQuestion, (View) questionView);
        configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
        questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
        questionView.setEnabled(!readOnly);
        if (questionView instanceof IImageQuestionView) {
            ((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
        }
        if (screenQuestion.isDynamicStockQuestion()) {
            Treatment treatment = new Treatment(getMalariaSurvey(), Session.getStockSurvey());
            if (treatment.hasTreatment()) {
                org.eyeseetea.malariacare.data.database.model.Treatment dbTreatment = treatment.getTreatment();
                Question actAnsweredNo = treatment.getACTQuestionAnsweredNo();
                screenQuestion.setAnswer(treatment.getACTOptions(dbTreatment));
                ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptionDose(treatment.getOptionDose(dbTreatment));
            }
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setQuestion(screenQuestion);
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
            //Getting the question to put the correct values on it
            ArrayList<Question> questions = new ArrayList<>();
            for (Option option : screenQuestion.getAnswer().getOptions()) {
                Question question = Question.findByID(option.getId_option());
                if (question != null) {
                    questions.add(question);
                }
            }
            survey.getValuesFromDB();
            for (Question question : questions) {
                Value valueStock = question.getValueBySession();
                questionView.setValue(valueStock);
            }
        }
        if (questionView instanceof AOptionQuestionView) {
            ((AOptionQuestionView) questionView).setQuestion(screenQuestion);
            List<Option> options = screenQuestion.getAnswer().getOptions();
            ((AOptionQuestionView) questionView).setOptions(options);
        }
        if (questionView instanceof NumberRadioButtonMultiquestionView) {
            if (doseByQuestion != null) {
                ((NumberRadioButtonMultiquestionView) questionView).setDose(doseByQuestion.get(screenQuestion.getId_question()));
            }
            ((NumberRadioButtonMultiquestionView) questionView).setQuestion(screenQuestion);
            ((NumberRadioButtonMultiquestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
        }
        if (!readOnly) {
            configureAnswerChangedListener(questionView);
        }
        if (reloadingQuestionFromInvalidOption) {
            reloadingQuestionFromInvalidOption = false;
        } else {
            questionView.setValue(value);
        }
        setupNavigationByQuestionView(rowView.getRootView(), questionView);
        tableRow.addView((View) questionView);
        swipeTouchListener.addClickableView(tableRow);
        setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
    }
}
Also used : SingleQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.SingleQuestionViewFactory) IQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.IQuestionViewFactory) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) ArrayList(java.util.ArrayList) MultiQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.MultiQuestionViewFactory) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) Session.getMalariaSurvey(org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey) Survey(org.eyeseetea.malariacare.data.database.model.Survey) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) Treatment(org.eyeseetea.malariacare.domain.entity.Treatment) TableRow(android.widget.TableRow) Value(org.eyeseetea.malariacare.data.database.model.Value) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) Question(org.eyeseetea.malariacare.data.database.model.Question) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Option(org.eyeseetea.malariacare.data.database.model.Option) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView)

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