Search in sources :

Example 21 with Question

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

the class PopulateDB method addVisibleQuestions.

public static void addVisibleQuestions(Context context, List<Question> questions) throws IOException {
    //Reset inner references
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
    String[] line;
    while ((line = reader.readNext()) != null) {
        for (Question question : questions) {
            if (question.getUid().equals(line[5])) {
                question.setVisible(Integer.valueOf(line[14]));
                question.save();
                break;
            }
        }
    }
    reader.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 22 with Question

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

the class PopulateDB method addTotalQuestions.

public static void addTotalQuestions(Context context, List<Question> questions) throws IOException {
    //Reset inner references
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
    String[] line;
    while ((line = reader.readNext()) != null) {
        for (Question question : questions) {
            if (question.getUid().equals(line[5])) {
                question.setTotalQuestions(Integer.valueOf(line[13]));
                question.save();
                break;
            }
        }
    }
    reader.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 23 with Question

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

the class PopulateDB method updateQuestions.

public static void updateQuestions(Context context) throws IOException {
    List<Question> questions = Question.getAllQuestions();
    //Reset inner references
    cleanInnerLists();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
    String[] line;
    //Save new option name for each option
    while ((line = reader.readNext()) != null) {
        for (Question question : questions) {
            if (String.valueOf(question.getId_question()).equals((line[0]))) {
                question.setCode(line[1]);
                question.setDe_name(line[2]);
                question.setHelp_text(line[3]);
                question.setForm_name(line[4]);
                //Update necessary from migration22 in myanmar
                question.setOutput(Integer.valueOf(line[12]));
                //Update necessary from migration3
                question.setTotalQuestions(Integer.valueOf(line[13]));
                //Update necessary from migration4
                question.setVisible(Integer.valueOf(line[14]));
                //Update necessary from migration7
                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);
                }
                question.save();
                break;
            }
        }
    }
    reader.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 24 with Question

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

the class ConvertFromSDKVisitor method visit.

@Override
public void visit(DataValueExtended sdkDataValueExtended) {
    Survey survey = (Survey) appMapObjects.get(sdkDataValueExtended.getEvent());
    String questionUID = sdkDataValueExtended.getDataElement();
    //Data value is a value from compositeScore -> ignore
    if (appMapObjects.get(questionUID) instanceof CompositeScore) {
        return;
    }
    //Phone metadata -> ignore
    if (PreferencesState.getInstance().getContext().getString(R.string.control_data_element_phone_metadata).equals(questionUID)) {
        return;
    }
    //Datavalue is a value from a question
    Question question = Question.findByUID(questionUID);
    if (question == null) {
        Log.e(TAG, "Question not found with dataelement uid " + questionUID);
    }
    Value value = new Value();
    value.setQuestion(question);
    value.setSurvey(survey);
    Option option = sdkDataValueExtended.findOptionByQuestion(question);
    value.setOption(option);
    //No option -> text question (straight value)
    if (option == null) {
        value.setValue(sdkDataValueExtended.getValue());
    } else {
        //Option -> extract value from code
        value.setValue(sdkDataValueExtended.getDataValue().getValue());
    }
    values.add(value);
}
Also used : CompositeScore(org.eyeseetea.malariacare.data.database.model.CompositeScore) Survey(org.eyeseetea.malariacare.data.database.model.Survey) 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 25 with Question

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

the class OrgUnitToOptionConverter method addOUOptionToQuestions.

public static void addOUOptionToQuestions(List<Question> questions, OrgUnit orgUnit) {
    for (Question question : questions) {
        if (!existsOrgUnitAsOptionInQuestion(orgUnit, question)) {
            Option option = new Option();
            option.setAnswer(question.getAnswer());
            option.setName(orgUnit.getUid());
            option.setCode(orgUnit.getName());
            option.save();
        }
    }
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

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