use of org.eyeseetea.malariacare.data.database.model.Match in project pictureapp by EyeSeeTea.
the class PopulateDB method createMissingRelationInLao.
/**
* Migration used to add a new parent-child relation in lao
*/
public static void createMissingRelationInLao() {
//new match relation in csv
//29;29
//new QuestionOption in csv
//45;5;13;29
//new QuestionRelation in csv
//29;1;6
Long childId = 6l;
Long parentId = 5l;
Long optionId = 13l;
QuestionRelation questionRelation = new QuestionRelation(Question.findByID(childId), QuestionRelation.PARENT_CHILD);
questionRelation.save();
Match match = new Match(questionRelation);
match.save();
QuestionOption questionOption = new QuestionOption(Option.findById(optionId), Question.findByID(parentId), match);
questionOption.save();
}
use of org.eyeseetea.malariacare.data.database.model.Match 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++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Match in project pictureapp by EyeSeeTea.
the class UpdateDB method updateQuestionOption.
public static void updateQuestionOption(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_OPTIONS_CSV);
}
List<QuestionOption> questionOptions = QuestionOption.listAll();
HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
HashMap<Long, Option> optionsIds = RelationsIdCsvDB.getOptionIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < questionOptions.size()) {
PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, questionOptions.get(i)).save();
} else {
QuestionOption questionOption = PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, null);
questionOption.insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Match in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getMatchIdRelationCsvDB.
static HashMap<Long, Match> getMatchIdRelationCsvDB(Context context) throws IOException {
HashMap<Long, Match> 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(csvIds.get(i), matches.get(i));
}
return matchesFK;
}
use of org.eyeseetea.malariacare.data.database.model.Match 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;
}
Aggregations