use of org.eyeseetea.malariacare.data.database.model.Answer in project pictureapp by EyeSeeTea.
the class Treatment method getACTOptions.
public Answer getACTOptions(org.eyeseetea.malariacare.data.database.model.Treatment mainTreatment) {
List<Option> options = new ArrayList<>();
Answer answer = new Answer("stock");
answer.setId_answer(Answer.DYNAMIC_STOCK_ANSWER_ID);
//this options are never saved
Option optionACT24 = new Option("ACT_x_24", "ACT_x_24", 0f, answer);
optionACT24.setId_option(Question.getACT24Question().getId_question());
optionACT24.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx24.png"));
Option optionACT12 = new Option("ACT_x_12", "ACT_x_12", 0f, answer);
optionACT12.setId_option(Question.getACT12Question().getId_question());
optionACT12.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx12.png"));
Option optionACT6 = new Option("ACT_x_6", "ACT_x_6", 0f, answer);
optionACT6.setId_option(Question.getACT6Question().getId_question());
optionACT6.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx6.png"));
Option optionACT18 = new Option("ACT_x_18", "ACT_x_18", 0f, answer);
optionACT18.setId_option(Question.getACT18Question().getId_question());
optionACT18.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx18.png"));
Question outStockQuestion = Question.getOutOfStockQuestion();
Option optionOutStock = new Option("out_stock_option", "out_stock_option", 0f, outStockQuestion.getAnswer());
optionOutStock.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p6_stockout.png"));
optionOutStock.setId_option(outStockQuestion.getId_question());
List<org.eyeseetea.malariacare.data.database.model.Treatment> treatments = mainTreatment.getAlternativeTreatments();
for (org.eyeseetea.malariacare.data.database.model.Treatment treatment : treatments) {
List<Drug> alternativeDrugs = treatment.getDrugsForTreatment();
for (Drug drug : alternativeDrugs) {
if (drug.isACT24()) {
optionACT24.setCode(treatment.getMessage().toString());
options.add(optionACT24);
} else if (drug.isACT18()) {
optionACT18.setCode(treatment.getMessage().toString());
options.add(optionACT18);
} else if (drug.isACT12()) {
optionACT12.setCode(treatment.getMessage().toString());
options.add(optionACT12);
} else if (drug.isACT6()) {
optionACT6.setCode(treatment.getMessage().toString());
options.add(optionACT6);
}
}
}
options.add(optionOutStock);
answer.setOptions(options);
return answer;
}
use of org.eyeseetea.malariacare.data.database.model.Answer 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 org.eyeseetea.malariacare.data.database.model.Answer in project pictureapp by EyeSeeTea.
the class RelationsIdCsvDB method getAnswerFKRelationCsvDB.
static HashMap<Long, Answer> getAnswerFKRelationCsvDB(Context context) throws IOException {
HashMap<Long, Answer> answerFK = new HashMap<>();
List<Answer> answers = Answer.getAllAnswers();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < answers.size() && i < csvIds.size(); i++) {
answerFK.put(csvIds.get(i), answers.get(i));
}
return answerFK;
}
use of org.eyeseetea.malariacare.data.database.model.Answer in project pictureapp by EyeSeeTea.
the class NavigationBuilder method buildChildren.
/**
* Adds navigation options according to answers (children questions)
*/
private void buildChildren(QuestionNode currentNode) {
//precondition: options and some relations
if (!withOptionsAndRelations(currentNode)) {
return;
}
Question currentQuestion = currentNode.getQuestion();
Answer currentAnswer = currentQuestion.getAnswer();
for (Option option : currentAnswer.getOptions()) {
Question firstChildrenQuestion = currentQuestion.findFirstChildrenByOption(option);
//No child question for this option -> next
if (firstChildrenQuestion == null) {
continue;
}
Log.d(TAG, String.format("'%s' + '%s' --> '%s'", currentQuestion.getCode(), option.getName(), firstChildrenQuestion.getCode()));
//Build navigation from there
QuestionNode childNode;
//Option that references self
if (currentNode.getQuestion().getId_question() == firstChildrenQuestion.getId_question()) {
childNode = currentNode;
} else {
//Any other child question
childNode = buildNode(firstChildrenQuestion);
}
//Add navigation by option to current node
currentNode.addNavigation(option, childNode);
}
}
use of org.eyeseetea.malariacare.data.database.model.Answer in project pictureapp by EyeSeeTea.
the class NavigationBuilder method buildCounters.
/**
* Adds counters to this node
*/
private void buildCounters(QuestionNode currentNode) {
//precondition: options and some relations
if (!withOptionsAndRelations(currentNode)) {
return;
}
Question currentQuestion = currentNode.getQuestion();
Answer currentAnswer = currentQuestion.getAnswer();
for (Option option : currentAnswer.getOptions()) {
Question optionCounter = currentQuestion.findCounterByOption(option);
//no counter -> try next option
if (optionCounter == null) {
continue;
}
//found a counter -> annotate it
currentNode.addCounter(option, optionCounter);
}
}
Aggregations