Search in sources :

Example 26 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class TreatmentTable method getNotTreatmentLines.

private List<String[]> getNotTreatmentLines(String filename) throws IOException {
    List<String[]> lines = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(mContext.openFileInput(filename)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    while ((line = reader.readNext()) != null) {
        lines.add(line);
    }
    return lines;
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList)

Example 27 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method updateTranslations.

public static void updateTranslations(Context context, boolean updateCsv) throws IOException {
    if (updateCsv) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TRANSLATION_CSV);
    }
    List<Translation> translations = Translation.getAllTranslations();
    HashMap<Long, StringKey> stringKeyFK = RelationsIdCsvDB.getStringKeyIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TRANSLATION_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < translations.size()) {
            PopulateRow.populateTranslation(line, stringKeyFK, translations.get(i)).save();
        } else {
            PopulateRow.populateTranslation(line, stringKeyFK, null).insert();
        }
        i++;
    }
}
Also used : Translation(org.eyeseetea.malariacare.data.database.model.Translation) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) StringKey(org.eyeseetea.malariacare.data.database.model.StringKey)

Example 28 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method updateAnswers.

/**
     * Method to update the old answers and add new ones.
     *
     * @param context Needed to open the csv with the answers.
     * @throws IOException If there is a problem opening the csv.
     */
public static void updateAnswers(Context context) throws IOException {
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.ANSWERS_CSV);
    List<Answer> answers = Answer.getAllAnswers();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    //Save new answers
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < answers.size()) {
            PopulateRow.populateAnswer(line, answers.get(i)).save();
        } else {
            PopulateRow.populateAnswer(line, null).insert();
        }
        i++;
    }
}
Also used : Answer(org.eyeseetea.malariacare.data.database.model.Answer) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader)

Example 29 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method updateTreatments.

/**
     * Method to update treatments from csvs.
     *
     * @param context Needed to open the csvs.
     * @throws IOException If there is a problem opening the csv.
     */
public static void updateTreatments(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TREATMENT_CSV);
    }
    List<Treatment> treatments = Treatment.getAllTreatments();
    HashMap<Long, Organisation> organisationIds = RelationsIdCsvDB.getOrganisationIdRelationCsvDB(context);
    HashMap<Long, StringKey> stringKeyIds = RelationsIdCsvDB.getStringKeyIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TREATMENT_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < treatments.size()) {
            PopulateRow.populateTreatments(line, organisationIds, stringKeyIds, treatments.get(i)).save();
        } else {
            PopulateRow.populateTreatments(line, organisationIds, stringKeyIds, null).insert();
        }
        i++;
    }
}
Also used : Organisation(org.eyeseetea.malariacare.data.database.model.Organisation) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) StringKey(org.eyeseetea.malariacare.data.database.model.StringKey) Treatment(org.eyeseetea.malariacare.data.database.model.Treatment)

Example 30 with CSVReader

use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.

the class UpdateDB method insertLastLines.

public static void insertLastLines(int numeberLines, Context context) throws IOException {
    HashMap<Long, Answer> answersIds = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
    HashMap<Long, OptionAttribute> optionAttributeIds = RelationsIdCsvDB.getOptionAttributeIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    List<String[]> lines = reader.readAll();
    for (int i = lines.size() - numeberLines - 1; i < lines.size(); i++) {
        PopulateRow.populateOption(lines.get(i), answersIds, optionAttributeIds, null).insert();
    }
}
Also used : Answer(org.eyeseetea.malariacare.data.database.model.Answer) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) OptionAttribute(org.eyeseetea.malariacare.data.database.model.OptionAttribute)

Aggregations

CSVReader (com.opencsv.CSVReader)59 InputStreamReader (java.io.InputStreamReader)51 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)18 Question (org.eyeseetea.malariacare.data.database.model.Question)11 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)9 Match (org.eyeseetea.malariacare.data.database.model.Match)8 Option (org.eyeseetea.malariacare.data.database.model.Option)8 IOException (java.io.IOException)6 Answer (org.eyeseetea.malariacare.data.database.model.Answer)6 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)6 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)6 FileReader (java.io.FileReader)5 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)5 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)5 Organisation (org.eyeseetea.malariacare.data.database.model.Organisation)4 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)4 PopulateRow.populateMatch (org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch)4 File (java.io.File)3 Drug (org.eyeseetea.malariacare.data.database.model.Drug)3