Search in sources :

Example 6 with QuestionRelation

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

the class ReviewFragment method getReviewValues.

private List<Value> getReviewValues() {
    List<Value> reviewValues = new ArrayList<>();
    Survey survey = Session.getMalariaSurvey();
    List<Value> allValues = survey.getValuesFromDB();
    for (Value value : allValues) {
        boolean isReviewValue = true;
        if (value.getQuestion() == null) {
            continue;
        }
        for (QuestionRelation questionRelation : value.getQuestion().getQuestionRelations()) {
            if (questionRelation.isACounter() || questionRelation.isAReminder() || questionRelation.isAWarning() || questionRelation.isAMatch()) {
                isReviewValue = false;
            }
        }
        int output = value.getQuestion().getOutput();
        if (output == Constants.HIDDEN || output == Constants.DYNAMIC_STOCK_IMAGE_RADIO_BUTTON) {
            isReviewValue = false;
        }
        if (isReviewValue) {
            if (value.getQuestion() != null) {
                reviewValues.add(value);
            }
        }
    }
    return reviewValues;
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) Value(org.eyeseetea.malariacare.data.database.model.Value) ArrayList(java.util.ArrayList)

Example 7 with QuestionRelation

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

the class PopulateRow method populateQuestionRelation.

static QuestionRelation populateQuestionRelation(String[] line, HashMap<Long, Question> questionFK, @Nullable QuestionRelation questionRelation) {
    if (questionRelation == null) {
        questionRelation = new QuestionRelation();
    }
    questionRelation.setOperation(Integer.valueOf(line[1]));
    questionRelation.setQuestion(questionFK.get(Long.valueOf(line[2])));
    return questionRelation;
}
Also used : QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation)

Example 8 with QuestionRelation

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

the class RelationsIdCsvDB method getQuestionRelationIdRelationCsvDB.

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

Example 9 with QuestionRelation

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

Example 10 with QuestionRelation

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

the class PopulateDB method createMissingRelationInLao.

/**
 * Migration used to add a new parent-child relation in lao
 */
public static void createMissingRelationInLao() {
    // new match relation in csv
    // 29;29
    // new QuestionOption in csv
    // 45;5;13;29
    // new QuestionRelation in csv
    // 29;1;6
    Long childId = 6l;
    Long parentId = 5l;
    Long optionId = 13l;
    QuestionRelation questionRelation = new QuestionRelation(Question.findByID(childId), QuestionRelation.PARENT_CHILD);
    questionRelation.save();
    Match match = new Match(questionRelation);
    match.save();
    QuestionOption questionOption = new QuestionOption(Option.findById(optionId), Question.findByID(parentId), match);
    questionOption.save();
}
Also used : QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch)

Aggregations

QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)11 CSVReader (com.opencsv.CSVReader)5 InputStreamReader (java.io.InputStreamReader)5 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)5 Match (org.eyeseetea.malariacare.data.database.model.Match)4 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)4 Question (org.eyeseetea.malariacare.data.database.model.Question)3 ArrayList (java.util.ArrayList)2 Option (org.eyeseetea.malariacare.data.database.model.Option)2 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)2 PopulateRow.populateQuestionRelation (org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateQuestionRelation)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)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 Partner (org.eyeseetea.malariacare.data.database.model.Partner)1 Program (org.eyeseetea.malariacare.data.database.model.Program)1