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();
}
}
}
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();
}
}
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++;
}
}
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++;
}
}
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++;
}
}
Aggregations