Search in sources :

Example 51 with CSVReader

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

the class RelationsIdCsvDB method getQuestionThresholdIdRelationDBCsv.

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

Example 52 with CSVReader

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

the class RelationsIdCsvDB method getMatchIdRelationDBCsv.

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

Example 53 with CSVReader

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

the class RelationsIdCsvDB method getQuestionOptionIdRelationDBCsv.

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

Example 54 with CSVReader

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

the class RelationsIdCsvDB method getHeaderFKRelationCsvDB.

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

Example 55 with CSVReader

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

the class RelationsIdCsvDB method getTabsIdRelationsCsvDB.

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

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