use of org.eyeseetea.malariacare.data.database.model.QuestionOption 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.QuestionOption in project pictureapp by EyeSeeTea.
the class PopulateRow method populateQuestionOption.
static QuestionOption populateQuestionOption(String[] line, HashMap<Long, Question> questionFK, HashMap<Long, Option> optionFK, HashMap<Long, Match> matchFK, @Nullable QuestionOption questionOption) {
if (questionOption == null) {
questionOption = new QuestionOption();
}
questionOption.setQuestion(questionFK.get(Long.valueOf(line[1])));
questionOption.setOption(optionFK.get(Long.valueOf(line[2])));
if (!line[3].equals("")) {
questionOption.setMatch(matchFK.get(Long.valueOf(line[3])));
}
return questionOption;
}
use of org.eyeseetea.malariacare.data.database.model.QuestionOption in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getQuestionOptionIdRelationDBCsv.
static HashMap<Long, Long> getQuestionOptionIdRelationDBCsv(Context context) throws IOException {
HashMap<Long, Long> questionOptionFK = new HashMap<>();
List<QuestionOption> questionOptions = QuestionOption.listAll();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < questionOptions.size() && i < csvIds.size(); i++) {
questionOptionFK.put(questionOptions.get(i).getId_question_option(), csvIds.get(i));
}
return questionOptionFK;
}
use of org.eyeseetea.malariacare.data.database.model.QuestionOption in project pictureapp by EyeSeeTea.
the class TreatmentTable method deleteRelatedTablesLines.
/**
* Deleting the matches, questionOption and questionThresholds related with the treatment
* table.
*/
private void deleteRelatedTablesLines(TreatmentMatch treatmentMatch) throws IOException {
Match match = treatmentMatch.getMatch();
List<QuestionOption> questionOptions = QuestionOption.getQuestionOptionsWithMatchId(match.getId_match());
for (QuestionOption questionOption : questionOptions) {
questionOption.delete();
}
List<QuestionThreshold> questionThresholds = QuestionThreshold.getQuestionThresholdsWithMatch(match.getId_match());
for (QuestionThreshold questionThreshold : questionThresholds) {
questionThreshold.delete();
}
match.delete();
}
use of org.eyeseetea.malariacare.data.database.model.QuestionOption in project pictureapp by EyeSeeTea.
the class ReminderStatusChecker method initRemainderTriggers.
private void initRemainderTriggers(Question reminderQuestion) {
this.reminderTriggers = new ArrayList<>();
//Look for a REMINDER relation which origin questionOption is activated
for (QuestionRelation questionRelation : reminderQuestion.getQuestionRelations()) {
if (!questionRelation.isAReminder()) {
continue;
}
//Find QuestionOption for this relation
QuestionOption questionOption = findQuestionOption(questionRelation);
if (questionOption == null) {
continue;
}
//Annotate questionOption to check
this.reminderTriggers.add(questionOption);
}
}
Aggregations