Search in sources :

Example 11 with QuestionRelation

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

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