Search in sources :

Example 11 with CSVReader

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

the class RelationsIdCsvDB method getIdRelationCsvDB.

static HashMap<Long, Object> getIdRelationCsvDB(Context context, String CsvName, List<Object> allDBObjects) throws IOException {
    HashMap<Long, Object> objectFK = new HashMap<>();
    List<Long> csvIds = new ArrayList<>();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(CsvName)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] idToAdd;
    while ((idToAdd = reader.readNext()) != null) {
        csvIds.add(Long.parseLong(idToAdd[0]));
    }
    for (int i = 0; i < allDBObjects.size() && i < csvIds.size(); i++) {
        objectFK.put(csvIds.get(i), allDBObjects.get(i));
    }
    return objectFK;
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList)

Example 12 with CSVReader

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

the class RelationsIdCsvDB method getDrugIdRelationCsvDB.

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

Example 13 with CSVReader

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

the class RelationsIdCsvDB method getProgramIdRelationCsvDB.

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

Example 14 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 15 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)

Aggregations

CSVReader (com.opencsv.CSVReader)57 InputStreamReader (java.io.InputStreamReader)50 ArrayList (java.util.ArrayList)23 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 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 IOException (java.io.IOException)5 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)5 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)5 Drug (org.eyeseetea.malariacare.data.database.model.Drug)4 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