use of org.eyeseetea.malariacare.domain.entity.SurveyAnsweredRatio in project pictureapp by EyeSeeTea.
the class Survey method updateSurveyStatus.
/**
* Updates ratios, status and completion date depending on the question and answer (text)
*/
public void updateSurveyStatus() {
// Sent surveys are not updated
if (this.isSent() || this.isHide() || this.isConflict()) {
return;
}
SurveyAnsweredRatio answeredRatio = this.reloadSurveyAnsweredRatio();
// Update status & completionDate
if (answeredRatio.isCompleted()) {
complete();
} else {
setStatus(Constants.SURVEY_IN_PROGRESS);
setCompletionDate(this.event_date);
save();
}
}
use of org.eyeseetea.malariacare.domain.entity.SurveyAnsweredRatio in project pictureapp by EyeSeeTea.
the class Survey method reloadSurveyAnsweredRatio.
/**
* Calculates the current ratio of completion for this survey
*
* @return SurveyAnsweredRatio that hold the total & answered questions.
*/
public SurveyAnsweredRatio reloadSurveyAnsweredRatio() {
SurveyAnsweredRatio surveyAnsweredRatio;
// First parent is always required and not calculated.
int numRequired = 1;
int numAnswered = 0;
IProgramRepository programLocalDataSource = new ProgramLocalDataSource();
Program program = Program.findByUID(programLocalDataSource.getUserProgram().getId());
Tab tab = program.getTabs().get(0);
Question rootQuestion = Question.findRootQuestion(tab);
Question localQuestion = rootQuestion;
numRequired = SurveyFragmentStrategy.getNumRequired(numRequired, localQuestion);
// Add children required by each parent (value+question)
Survey survey = Survey.findById(id_survey);
for (Value value : survey.getValuesFromDB()) {
if (value.getQuestion().isCompulsory() && value.getId_option() != null) {
numRequired += Question.countChildrenByOptionValue(value.getId_option());
}
}
numAnswered += countCompulsoryBySurvey(this);
Log.d("survey answered", "num required: " + numRequired + " num answered: " + numAnswered);
surveyAnsweredRatio = new SurveyAnsweredRatio(numRequired, numAnswered);
SurveyAnsweredRatioCache.put(this.id_survey, surveyAnsweredRatio);
return surveyAnsweredRatio;
}
Aggregations