Search in sources :

Example 31 with Question

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

the class UpdateDB method updateQuestionOption.

public static void updateQuestionOption(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_OPTIONS_CSV);
    }
    List<QuestionOption> questionOptions = QuestionOption.listAll();
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    HashMap<Long, Option> optionsIds = RelationsIdCsvDB.getOptionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < questionOptions.size()) {
            PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, questionOptions.get(i)).save();
        } else {
            QuestionOption questionOption = PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, null);
            questionOption.insert();
        }
        i++;
    }
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) 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) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 32 with Question

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

the class UpdateDB method updateQuestionRelation.

public static void updateQuestionRelation(Context context) throws IOException {
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_RELATIONS_CSV);
    List<QuestionRelation> questionRelations = QuestionRelation.listAll();
    HashMap<Long, Question> questionIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        boolean added = false;
        if (i < questionRelations.size()) {
            populateQuestionRelation(line, questionIds, questionRelations.get(i)).save();
        } else {
            QuestionRelation questionRelation = populateQuestionRelation(line, questionIds, null);
            questionRelation.insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) PopulateRow.populateQuestionRelation(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateQuestionRelation) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 33 with Question

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

the class Treatment method getNoTreatmentQuestions.

public List<Question> getNoTreatmentQuestions() {
    List<Question> questions = new ArrayList<>();
    Question treatmentQuestion = new Question();
    treatmentQuestion.setOutput(Constants.QUESTION_LABEL);
    treatmentQuestion.setForm_name("");
    treatmentQuestion.setHelp_text(getContext().getResources().getResourceName(R.string.error_no_treatment));
    treatmentQuestion.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
    treatmentQuestion.setHeader(Header.DYNAMIC_TREATMENT_HEADER_ID);
    questions.add(treatmentQuestion);
    return questions;
}
Also used : ArrayList(java.util.ArrayList) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 34 with Question

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

the class Treatment method putACTDefaultYes.

private void putACTDefaultYes() {
    Question actHiddenQuestion = Question.findByUID(getContext().getString(R.string.dynamicTreatmentHideQuestionUID));
    List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
    Value actValue = null;
    for (Value value : values) {
        if (value.getQuestion().equals(actHiddenQuestion)) {
            actValue = value;
        }
    }
    if (actValue == null) {
        actValue = new Value(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)), actHiddenQuestion, Session.getMalariaSurvey());
    } else {
        actValue.setOption(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)));
    }
    actValue.save();
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 35 with Question

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

the class Treatment method saveTreatmentInTreatmentQuestion.

private void saveTreatmentInTreatmentQuestion(org.eyeseetea.malariacare.data.database.model.Treatment treatment) {
    Question treatmentQuestionSend = Question.findByUID(getContext().getResources().getString(R.string.dynamicTreatmentQuestionUID));
    Question treatmentQuestionShow = Question.findByUID(getContext().getResources().getString(R.string.treatmentDiagnosisVisibleQuestion));
    Survey malariaSurvey = Session.getMalariaSurvey();
    List<Value> values = //this values should be get from memory because the
    malariaSurvey.getValues();
    // treatment options are in memory
    boolean questionInSurvey = false;
    boolean questionShowInSurvey = false;
    String diagnosisMessage = Utils.getInternationalizedString(String.valueOf(treatment.getDiagnosis()));
    String defaultDiagnosisMessage = Translation.getLocalizedString(treatment.getDiagnosis(), Translation.DEFAULT_LANGUAGE);
    for (Value value : values) {
        if (value.getQuestion() == null) {
            continue;
        }
        if (value.getQuestion().equals(treatmentQuestionSend)) {
            value.setValue(defaultDiagnosisMessage);
            questionInSurvey = true;
            value.save();
        }
        if (value.getQuestion().equals(treatmentQuestionShow)) {
            value.setValue(diagnosisMessage);
            questionShowInSurvey = true;
            value.save();
        }
    }
    if (!questionShowInSurvey) {
        Value value = new Value(diagnosisMessage, treatmentQuestionShow, malariaSurvey);
        value.insert();
    }
    if (!questionInSurvey) {
        Value value = new Value(defaultDiagnosisMessage, treatmentQuestionSend, malariaSurvey);
        value.insert();
    }
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) 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