use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class DynamicStockImageRadioButtonSingleQuestionView method onCheckedChanged.
@Override
public void onCheckedChanged(ImageRadioButtonOption imageRadioButton, boolean value) {
if (value == false)
return;
for (int i = 0; i < answersContainer.getChildCount(); i++) {
ImageRadioButtonOption optionView = (ImageRadioButtonOption) answersContainer.getChildAt(i);
if (imageRadioButton != optionView && optionView.isChecked()) {
optionView.setChecked(false);
Question question = (Question) optionView.getTag();
if (!question.isOutStockQuestion()) {
notifyAnswerChanged(optionView, String.valueOf(-1));
} else {
List<Option> options = question.getAnswer().getOptions();
for (Option option : options) {
if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.false_option_id))) {
notifyAnsweOptionChange(optionView, option);
}
}
}
}
}
Question question = (Question) imageRadioButton.getTag();
if (!question.isOutStockQuestion()) {
notifyAnswerChanged(imageRadioButton, String.valueOf(optionDose.get(imageRadioButton.getOption().getId_option())));
} else {
List<Option> options = question.getAnswer().getOptions();
for (Option option : options) {
if (option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.true_option_id))) {
notifyAnsweOptionChange(imageRadioButton, option);
}
}
}
//Setting a value for the stock question to get max total question correct
View stockHideView = new View(context);
stockHideView.setTag(Treatment.getDynamicStockQuestion());
Question pqHideQuestion = Question.findByUID(context.getString(R.string.stockPqQuestionUID));
Option falseOption = Option.findById(41l);
Value valuePq = pqHideQuestion.getValueBySession();
if (valuePq != null) {
falseOption = valuePq.getOption();
}
notifyAnsweOptionChange(stockHideView, falseOption);
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class NumberRadioButtonMultiquestionView method changeTotalQuestions.
/**
* Changing the total questions of the alternative pq questions depending on the answer provided
*/
private void changeTotalQuestions() {
Question pqQuestion = Question.findByUID(context.getString(R.string.pqQuestionUID));
Question actQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
Question alternativePqQuestion = Question.findByUID(context.getString(R.string.alternativePqQuestionUID));
Value actValue = null;
Value pqValue = null;
List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
for (Value sValue : values) {
if (sValue.getQuestion() == null) {
continue;
}
if (sValue.getQuestion().equals(actQuestion)) {
actValue = sValue;
break;
}
if (sValue.getQuestion().getUid().equals(pqQuestion.getUid())) {
pqValue = sValue;
break;
}
}
if ((actValue == null || actValue.getOption().getName().equals(PreferencesState.getInstance().getContext().getString(R.string.yes_option_identifier))) || (pqValue == null || Float.parseFloat(pqValue.getValue()) > 0)) {
alternativePqQuestion.setTotalQuestions(8);
} else {
alternativePqQuestion.setTotalQuestions(9);
}
alternativePqQuestion.save();
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class NavigationController method isNextAllowed.
/**
* Tells if you can move forward:
* - Not even started: true
* -
* Cann
*/
public boolean isNextAllowed() {
if (isMovingToForward) {
return false;
}
QuestionNode currentQuestionNode = getCurrentNode();
//not even start
if (currentQuestionNode == null) {
return true;
}
//Get value for current
Question currentQuestion = getCurrentQuestion();
Value currentValue = currentQuestion.getValueBySession();
//Cannot move without answer
if (currentValue == null) {
Log.d(TAG, "isNextAllowed()->You must answer first");
return false;
}
Option currentOption = currentValue == null ? null : currentValue.getOption();
//Find next node with current option
boolean isAllowed = findNext(currentOption) != null;
Log.d(TAG, String.format("isNextAllowed()->%b", isAllowed));
return isAllowed;
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class WarningStatusChecker method isEnabled.
@Override
public boolean isEnabled() {
//Warning not built yet -> false
if (questionThreshold == null || questionOption == null) {
return false;
}
//Get current values in DB
Question questionWithOption = questionOption.getQuestion();
Value optionValue = questionWithOption.getValueBySession();
Value intValue = questionThreshold.getQuestion().getValueBySession();
//A question is not answered yet -> false
if (optionValue == null || optionValue.getOption() == null || intValue == null) {
return false;
}
//The option for this warning has not been selected
if (optionValue.getId_option() != questionOption.getOption().getId_option()) {
return false;
}
//If current int value NOT in threshold -> the warning is activated
return !questionThreshold.isInThreshold(intValue.getValue());
}
use of org.eyeseetea.malariacare.data.database.model.Value 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