Search in sources :

Example 1 with ProgramLocalDataSource

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;
}
Also used : IProgramRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository) ProgramLocalDataSource(org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource) SurveyAnsweredRatio(org.eyeseetea.malariacare.domain.entity.SurveyAnsweredRatio)

Example 2 with ProgramLocalDataSource

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);
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) IProgramRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository) ProgramLocalDataSource(org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Example 3 with ProgramLocalDataSource

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");
            }
        });
    }
}
Also used : IProgramRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository) GetUserProgramUIDUseCase(org.eyeseetea.malariacare.domain.usecase.GetUserProgramUIDUseCase) ProgramLocalDataSource(org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)

Aggregations

ProgramLocalDataSource (org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource)3 IProgramRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository)3 CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)1 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)1 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)1 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)1 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)1 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)1 SurveyAnsweredRatio (org.eyeseetea.malariacare.domain.entity.SurveyAnsweredRatio)1 GetUserProgramUIDUseCase (org.eyeseetea.malariacare.domain.usecase.GetUserProgramUIDUseCase)1 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)1 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)1