Search in sources :

Example 16 with CSVReader

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

the class RelationsIdCsvDB method getTreatmentIdRelationCsvDB.

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

Example 17 with CSVReader

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

the class RelationsIdCsvDB method getQuestionIdRelationCsvDB.

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

Example 18 with CSVReader

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

the class RelationsIdCsvDB method getOptionAttributeIdRelationCsvDB.

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

Example 19 with CSVReader

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

the class RelationsIdCsvDB method getStringKeyIdRelationCsvDB.

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

Example 20 with CSVReader

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

the class UpdateDB method updateOrganisations.

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

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