Search in sources :

Example 6 with QuestionOption

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

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

the class PopulateRow method populateQuestionOption.

static QuestionOption populateQuestionOption(String[] line, HashMap<Long, Question> questionFK, HashMap<Long, Option> optionFK, HashMap<Long, Match> matchFK, @Nullable QuestionOption questionOption) {
    if (questionOption == null) {
        questionOption = new QuestionOption();
    }
    questionOption.setQuestion(questionFK.get(Long.valueOf(line[1])));
    questionOption.setOption(optionFK.get(Long.valueOf(line[2])));
    if (!line[3].equals("")) {
        questionOption.setMatch(matchFK.get(Long.valueOf(line[3])));
    }
    return questionOption;
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption)

Example 8 with QuestionOption

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

the class RelationsIdCsvDB method getQuestionOptionIdRelationDBCsv.

static HashMap<Long, Long> getQuestionOptionIdRelationDBCsv(Context context) throws IOException {
    HashMap<Long, Long> questionOptionFK = new HashMap<>();
    List<QuestionOption> questionOptions = QuestionOption.listAll();
    List<Long> csvIds = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] idToAdd;
    while ((idToAdd = reader.readNext()) != null) {
        csvIds.add(Long.parseLong(idToAdd[0]));
    }
    for (int i = 0; i < questionOptions.size() && i < csvIds.size(); i++) {
        questionOptionFK.put(questionOptions.get(i).getId_question_option(), csvIds.get(i));
    }
    return questionOptionFK;
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList)

Example 9 with QuestionOption

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

the class TreatmentTable method deleteRelatedTablesLines.

/**
     * Deleting the matches, questionOption and questionThresholds related with the treatment
     * table.
     */
private void deleteRelatedTablesLines(TreatmentMatch treatmentMatch) throws IOException {
    Match match = treatmentMatch.getMatch();
    List<QuestionOption> questionOptions = QuestionOption.getQuestionOptionsWithMatchId(match.getId_match());
    for (QuestionOption questionOption : questionOptions) {
        questionOption.delete();
    }
    List<QuestionThreshold> questionThresholds = QuestionThreshold.getQuestionThresholdsWithMatch(match.getId_match());
    for (QuestionThreshold questionThreshold : questionThresholds) {
        questionThreshold.delete();
    }
    match.delete();
}
Also used : QuestionThreshold(org.eyeseetea.malariacare.data.database.model.QuestionThreshold) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch)

Example 10 with QuestionOption

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

the class ReminderStatusChecker method initRemainderTriggers.

private void initRemainderTriggers(Question reminderQuestion) {
    this.reminderTriggers = new ArrayList<>();
    //Look for a REMINDER relation which origin questionOption is activated
    for (QuestionRelation questionRelation : reminderQuestion.getQuestionRelations()) {
        if (!questionRelation.isAReminder()) {
            continue;
        }
        //Find QuestionOption for this relation
        QuestionOption questionOption = findQuestionOption(questionRelation);
        if (questionOption == null) {
            continue;
        }
        //Annotate questionOption to check
        this.reminderTriggers.add(questionOption);
    }
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation)

Aggregations

QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)10 Match (org.eyeseetea.malariacare.data.database.model.Match)5 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)5 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)5 CSVReader (com.opencsv.CSVReader)4 InputStreamReader (java.io.InputStreamReader)4 Option (org.eyeseetea.malariacare.data.database.model.Option)4 Question (org.eyeseetea.malariacare.data.database.model.Question)4 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)2 QuestionThreshold (org.eyeseetea.malariacare.data.database.model.QuestionThreshold)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Answer (org.eyeseetea.malariacare.data.database.model.Answer)1 Drug (org.eyeseetea.malariacare.data.database.model.Drug)1 Header (org.eyeseetea.malariacare.data.database.model.Header)1 Organisation (org.eyeseetea.malariacare.data.database.model.Organisation)1 Program (org.eyeseetea.malariacare.data.database.model.Program)1 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)1 Tab (org.eyeseetea.malariacare.data.database.model.Tab)1