Search in sources :

Example 21 with CSVReader

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

the class UpdateDB method updateQuestionThresholds.

public static void updateQuestionThresholds(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_THRESHOLDS_CSV);
    }
    List<QuestionThreshold> questionThresholds = QuestionThreshold.getAllQuestionThresholds();
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_THRESHOLDS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < questionThresholds.size()) {
            PopulateRow.populateQuestionThreshold(line, matchIds, questionsIds, questionThresholds.get(i)).save();
        } else {
            QuestionThreshold questionThreshold = PopulateRow.populateQuestionThreshold(line, matchIds, questionsIds, null);
            questionThreshold.insert();
        }
    }
}
Also used : QuestionThreshold(org.eyeseetea.malariacare.data.database.model.QuestionThreshold) InputStreamReader(java.io.InputStreamReader) 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) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 22 with CSVReader

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

the class UpdateDB method updateOptions.

public static void updateOptions(Context context) throws IOException {
    List<Option> optionToDelete = Question.getOptions(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID));
    for (Option option : optionToDelete) {
        if (!option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.patientResidenceVillageOtherCode))) {
            option.delete();
        }
    }
    FileCsvs fileCsvs = new FileCsvs();
    fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
    List<Option> options = Option.getAllOptions();
    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);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < options.size()) {
            PopulateRow.populateOption(line, answersIds, optionAttributeIds, options.get(i)).save();
        } else {
            PopulateRow.populateOption(line, answersIds, optionAttributeIds, null).insert();
        }
        i++;
    }
    List<OrgUnit> orgUnits = OrgUnit.getAllOrgUnit();
    for (OrgUnit orgUnit : orgUnits) {
        Option option = new Option();
        option.setCode(orgUnit.getName());
        option.setName(orgUnit.getUid());
        option.setFactor((float) 0);
        option.setId_option((long) 0);
        option.setAnswer(Question.getAnswer(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID)));
        option.save();
    }
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) OptionAttribute(org.eyeseetea.malariacare.data.database.model.OptionAttribute) Answer(org.eyeseetea.malariacare.data.database.model.Answer) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 23 with CSVReader

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

the class UpdateDB method updatePrograms.

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

Example 24 with CSVReader

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

the class UpdateDB method updateDrugs.

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

Example 25 with CSVReader

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

the class UpdateDB method updateMatches.

public static void updateMatches(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.MATCHES);
    }
    List<Match> matches = Match.listAll();
    HashMap<Long, QuestionRelation> questionsrelationIds = RelationsIdCsvDB.getQuestionRelationIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.MATCHES)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < matches.size()) {
            populateMatch(line, questionsrelationIds, matches.get(i)).save();
        } else {
            Match match = populateMatch(line, questionsrelationIds, null);
            match.insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) PopulateRow.populateQuestionRelation(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateQuestionRelation) QuestionRelation(org.eyeseetea.malariacare.data.database.model.QuestionRelation) 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)

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