use of org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource 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;
}
use of org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource in project pictureapp by EyeSeeTea.
the class PullControllerStrategy method onPullDataComplete.
@Override
public void onPullDataComplete(final IPullController.Callback callback) {
ICredentialsRepository credentialsLocalDataSource = new CredentialsLocalDataSource();
IOrganisationUnitRepository orgUnitDataSource = new OrganisationUnitRepository();
IProgramRepository programLocalDataSource = new ProgramLocalDataSource();
try {
org.eyeseetea.malariacare.domain.entity.OrganisationUnit orgUnit = orgUnitDataSource.getUserOrgUnit(credentialsLocalDataSource.getOrganisationCredentials());
org.eyeseetea.malariacare.domain.entity.Program program = orgUnit.getProgram();
programLocalDataSource.saveUserProgramId(program);
} catch (Exception e) {
e.printStackTrace();
callback.onError(e);
}
mPullController.convertData(callback);
}
use of org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource in project pictureapp by EyeSeeTea.
the class SurveyService method getProgramUID.
private void getProgramUID(final Callback callback) {
if (mProgramUID != null) {
callback.onSuccess(mProgramUID);
} else {
IProgramRepository programLocalDataSource = new ProgramLocalDataSource();
IMainExecutor mainExecutor = new UIThreadExecutor();
IAsyncExecutor asyncExecutor = new AsyncExecutor();
GetUserProgramUIDUseCase getUserProgramUIDUseCase = new GetUserProgramUIDUseCase(programLocalDataSource, mainExecutor, asyncExecutor);
getUserProgramUIDUseCase.execute(new GetUserProgramUIDUseCase.Callback() {
@Override
public void onSuccess(String uid) {
mProgramUID = uid;
callback.onSuccess(uid);
}
@Override
public void onError() {
Log.e(TAG, "error getting user program");
}
});
}
}
Aggregations