use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class NavigationBuilder method buildController.
/**
* Returns a navigation controller so you can navigate through questions according to answers
*/
public NavigationController buildController(Tab tab) {
//No tab -> nothing to build
if (tab == null) {
return null;
}
warningsXQuestion.clear();
Log.d(TAG, String.format("build(%s)", tab.getName()));
Question rootQuestion = Question.findRootQuestion(tab);
//NO first question -> nothing to build
if (rootQuestion == null) {
return null;
}
//init steps counter
step = 0;
QuestionNode rootNode = buildNode(rootQuestion);
return new NavigationController(rootNode);
}
use of org.eyeseetea.malariacare.data.database.model.Question 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.Question 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);
}
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method goToQuestion.
/**
* When the user click in a value in the review fragment the navigationController should go to
* related question
*/
private void goToQuestion(Question isMoveToQuestion) {
navigationController.first();
Question currentQuestion;
boolean isQuestionFound = false;
// question.
while (!isQuestionFound) {
currentQuestion = navigationController.getCurrentQuestion();
int tabType = currentQuestion.getHeader().getTab().getType();
if (Tab.isMultiQuestionTab(tabType)) {
List<Question> screenQuestions = currentQuestion.getQuestionsByTab(currentQuestion.getHeader().getTab());
for (Question question : screenQuestions) {
if (isMoveToQuestion.getUid().equals(question.getUid())) {
isQuestionFound = true;
}
}
} else {
if (isMoveToQuestion.getUid().equals(currentQuestion.getUid())) {
isQuestionFound = true;
}
}
if (!isQuestionFound) {
next();
skipReminder();
}
}
notifyDataSetChanged();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class CompletionSurveyUseCase method updateRDTStockQuestion.
private void updateRDTStockQuestion(Survey survey) {
if (survey.getStatus() == Constants.SURVEY_COMPLETED || survey.getStatus() == Constants.SURVEY_SENT) {
org.eyeseetea.malariacare.data.database.model.Survey surveyDBMalaria = org.eyeseetea.malariacare.data.database.model.Survey.findById(survey.getId());
List<Value> surveyValues = surveyDBMalaria.getValuesFromDB();
org.eyeseetea.malariacare.data.database.model.Survey surveyDBStock = org.eyeseetea.malariacare.data.database.model.Survey.getLastSurveyWithType(Constants.SURVEY_ISSUE);
Value rdtStockValue = Question.getStockRDTQuestion().insertValue("1", surveyDBStock);
rdtStockValue.setValue(Integer.toString(rdtUsed(surveyValues)));
rdtStockValue.save();
for (Question propagateQuestion : Question.getStockRDTQuestion().getPropagationQuestions()) {
propagateQuestion.insertValue(rdtStockValue.getValue(), Session.getMalariaSurvey()).save();
}
}
}
Aggregations