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