Search in sources :

Example 41 with CSVReader

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

the class UpdateDB method updateStringKeys.

public static void updateStringKeys(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.STRING_KEY_CSV);
    }
    List<StringKey> stringKeys = StringKey.getAllStringKeys();
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.STRING_KEY_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < stringKeys.size()) {
            PopulateRow.populateStringKey(line, stringKeys.get(i)).save();
        } else {
            PopulateRow.populateStringKey(line, null).insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) StringKey(org.eyeseetea.malariacare.data.database.model.StringKey)

Example 42 with CSVReader

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

the class TreatmentTable method splitTreatmentTableToCsvs.

private void splitTreatmentTableToCsvs() throws IOException {
    CSVReader reader = new CSVReader(new InputStreamReader(mContext.openFileInput(PopulateDB.TREATMENT_TABLE_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    initCSVQuestionOptionsIds();
    List<String[]> organisationLines = getNotTreatmentLines(PopulateDB.ORGANISATIONS_CSV);
    List<String[]> treatmentLines = new ArrayList<>();
    List<String[]> treatmentMatchLines = new ArrayList<>();
    List<String[]> drugsCombinationLines = new ArrayList<>();
    List<String[]> stringKeyLines = new ArrayList<>();
    List<String[]> translationLines = new ArrayList<>();
    List<String[]> messageLines = new ArrayList<>();
    List<String[]> diagnosisLines = new ArrayList<>();
    List<String[]> matchLines = getNotTreatmentLines(PopulateDB.MATCHES);
    List<String[]> questionThresholdLines = getNotTreatmentLines(PopulateDB.QUESTION_THRESHOLDS_CSV);
    List<String[]> questionOptionLines = getNotTreatmentLines(PopulateDB.QUESTION_OPTIONS_CSV);
    String[] line;
    while ((line = reader.readNext()) != null) {
        addDiagnosisAndMessageLine(line, stringKeyLines, messageLines, diagnosisLines, translationLines);
        addTreatment(line, treatmentLines, treatmentMatchLines, messageLines, diagnosisLines, organisationLines);
        addDrugCombinations(line, drugsCombinationLines, treatmentLines);
        if (line[5].equals("Y")) {
            addMatch(matchLines, treatmentQuestionRelationId);
            addTreatmentMatch(treatmentMatchLines, matchLines, treatmentLines);
            addQuestionOptionAge(line, questionThresholdLines, matchLines);
            addQuestionOptionPregnant(line, questionOptionLines, matchLines);
            addQuestionOptionSevere(line, questionOptionLines, matchLines);
            addQuestionOptionRDT(line, questionOptionLines, matchLines);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList)

Example 43 with CSVReader

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

the class UpdateDB method updateAndAddQuestions.

public static void updateAndAddQuestions(Context context) throws IOException {
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTIONS_CSV);
    List<Question> questionsDB = Question.getAllQuestions();
    HashMap<Long, Header> headerHashMap = RelationsIdCsvDB.getHeaderFKRelationCsvDB(context);
    HashMap<Long, Answer> answerHashMap = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    //Save new option name for each option
    while ((line = reader.readNext()) != null) {
        if (i < questionsDB.size()) {
            PopulateRow.populateQuestion(line, headerHashMap, answerHashMap, questionsDB.get(i)).save();
        } else {
            PopulateRow.populateQuestion(line, headerHashMap, answerHashMap, null).insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) Answer(org.eyeseetea.malariacare.data.database.model.Answer) Header(org.eyeseetea.malariacare.data.database.model.Header) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 44 with CSVReader

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

the class UpdateDB method updateHeaders.

/**
     * Method to update the old headers and add new ones from the csv. Use before inserting all
     * tabs.
     *
     * @param context Needed to open the csv with the headers.
     * @throws IOException If there is a problem opening the csv.
     */
public static void updateHeaders(Context context) throws IOException {
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.HEADERS_CSV);
    List<Header> headers = Header.getAllHeaders();
    HashMap<Long, Tab> tabIds = RelationsIdCsvDB.getTabsIdRelationsCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.HEADERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < headers.size()) {
            PopulateRow.populateHeader(line, tabIds, headers.get(i)).save();
        } else {
            PopulateRow.populateHeader(line, tabIds, null).insert();
        }
        i++;
    }
}
Also used : Header(org.eyeseetea.malariacare.data.database.model.Header) Tab(org.eyeseetea.malariacare.data.database.model.Tab) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader)

Example 45 with CSVReader

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

the class UpdateDB method updateTreatmentMatches.

/**
     * Method to update treatmentMatches from csvs.
     *
     * @param context Needed to open the csvs.
     * @throws IOException If there is a problem opening the csv.
     */
public static void updateTreatmentMatches(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TREATMENT_MATCHES_CSV);
    }
    List<TreatmentMatch> treatmentMatches = TreatmentMatch.getAllTreatmentMatches();
    HashMap<Long, Treatment> treatmentIds = RelationsIdCsvDB.getTreatmentIdRelationCsvDB(context);
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TREATMENT_MATCHES_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < treatmentMatches.size()) {
            PopulateRow.populateTreatmentMatches(line, treatmentIds, matchIds, treatmentMatches.get(i)).save();
        } else {
            PopulateRow.populateTreatmentMatches(line, treatmentIds, matchIds, null).insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) CSVReader(com.opencsv.CSVReader) PopulateRow.populateMatch(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) Treatment(org.eyeseetea.malariacare.data.database.model.Treatment)

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