Search in sources :

Example 16 with Survey

use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.

the class PushUseCase method callPushBySDK.

private void callPushBySDK() {
    List<Survey> filteredSurveys = new ArrayList<>();
    List<Survey> surveys = Survey.getAllMalariaSurveysToBeSent();
    //Check surveys not in progress
    for (Survey survey : surveys) {
        if (survey.isCompleted(survey.getId_survey()) && survey.getValues().size() > 0) {
            Log.d("DpBlank", "Survey is completed" + survey.getId_survey());
            filteredSurveys.add(survey);
        } else {
            Log.d("DpBlank", "Survey is sent" + survey.getId_survey());
        }
    }
    if (filteredSurveys.size() == 0) {
        stopProgress();
        PreferencesState.getInstance().setPushInProgress(false);
        return;
    }
    //Login successful start reload
    PushController.getInstance().push(context, filteredSurveys);
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) ArrayList(java.util.ArrayList)

Example 17 with Survey

use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.

the class NewReceiptBalanceFragment method createNewSurvey.

private void createNewSurvey() {
    Survey survey = new Survey(null, Program.getStockProgram(), Session.getUser(), type);
    Calendar surveyDate;
    if (date.getText().toString().isEmpty()) {
        surveyDate = Calendar.getInstance();
    } else {
        surveyDate = Utils.parseStringToCalendar(date.getText().toString(), "yyyy/MM/dd");
    }
    survey.setEventDate(surveyDate.getTime());
    survey.setStatus(Constants.SURVEY_COMPLETED);
    survey.save();
    new Value(rdt.getText().toString().isEmpty() ? rdt.getHint().toString() : rdt.getText().toString(), Question.getStockRDTQuestion(), survey).save();
    new Value(act6.getText().toString().isEmpty() ? act6.getHint().toString() : act6.getText().toString(), Question.getACT6Question(), survey).save();
    new Value(act12.getText().toString().isEmpty() ? act12.getHint().toString() : act12.getText().toString(), Question.getACT12Question(), survey).save();
    new Value(act18.getText().toString().isEmpty() ? act18.getHint().toString() : act18.getText().toString(), Question.getACT18Question(), survey).save();
    new Value(act24.getText().toString().isEmpty() ? act24.getHint().toString() : act24.getText().toString(), Question.getACT24Question(), survey).save();
    new Value(pq.getText().toString().isEmpty() ? pq.getHint().toString() : pq.getText().toString(), Question.getPqQuestion(), survey).save();
    new Value(cq.getText().toString().isEmpty() ? cq.getHint().toString() : cq.getText().toString(), Question.getCqQuestion(), survey).save();
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) Calendar(java.util.Calendar) Value(org.eyeseetea.malariacare.data.database.model.Value)

Example 18 with Survey

use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.

the class SurveyService method reloadDashboard.

private void reloadDashboard() {
    Log.i(TAG, "reloadDashboard");
    List<Survey> surveys = Survey.getAllSurveys();
    List<Survey> unsentSurveys = Survey.getAllUnsentMalariaSurveys();
    List<Survey> sentSurveys = Survey.getAllSentMalariaSurveys();
    //Since intents does NOT admit NON serializable as values we use Session instead
    Session.putServiceValue(ALL_UNSENT_SURVEYS_ACTION, unsentSurveys);
    Session.putServiceValue(ALL_SENT_SURVEYS_ACTION, sentSurveys);
    //Returning result to anyone listening
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ALL_UNSENT_SURVEYS_ACTION));
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ALL_SENT_SURVEYS_ACTION));
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) Intent(android.content.Intent)

Example 19 with Survey

use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.

the class SurveyService method getAllUnsentSurveys.

/**
     * Selects all pending surveys from database
     */
private void getAllUnsentSurveys() {
    Log.d(TAG, "getAllUnsentMalariaSurveys (Thread:" + Thread.currentThread().getId() + ")");
    //Select surveys from sql
    List<Survey> surveys = Survey.getAllUnsentMalariaSurveys();
    List<Survey> unsentSurveys = new ArrayList<Survey>();
    //Load %completion in every survey (it takes a while so it can NOT be done in UI Thread)
    for (Survey survey : surveys) {
        if (!survey.isSent() && !survey.isHide() && !survey.isConflict()) {
            survey.getAnsweredQuestionRatio();
            unsentSurveys.add(survey);
        }
    }
    //Since intents does NOT admit NON serializable as values we use Session instead
    Session.putServiceValue(ALL_UNSENT_SURVEYS_ACTION, unsentSurveys);
    //Returning result to anyone listening
    Intent resultIntent = new Intent(ALL_UNSENT_SURVEYS_ACTION);
    LocalBroadcastManager.getInstance(this).sendBroadcast(resultIntent);
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 20 with Survey

use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.

the class PushController method push.

public void push(final IPushControllerCallback callback) {
    if (!ServerAPIController.isNetworkAvailable()) {
        Log.d(TAG, "No network");
        callback.onError(new NetworkException());
    } else {
        Log.d(TAG, "Network connected");
        List<Survey> surveys = Survey.getAllCompletedSurveysNoReceiptReset();
        //Fixme Check if is necessary other conditions
        if (surveys == null || surveys.size() == 0) {
            Log.d("DpBlank", "Sets of Surveys to push");
            callback.onError(new SurveysToPushNotFoundException());
        } else {
            for (Survey srv : surveys) {
                Log.d("DpBlank", "Survey to push " + srv.toString());
                for (Value dv : srv.getValuesFromDB()) {
                    Log.d("DpBlank", "Values to push " + dv.toString());
                }
            }
            mPushDhisSDKDataSource.wipeEvents();
            try {
                convertToSDK(surveys);
            } catch (Exception ex) {
                callback.onError(new ConversionException(ex));
            }
            if (EventExtended.getAllEvents().size() == 0) {
                callback.onError(new ConversionException());
            } else {
                pushData(callback);
            }
        }
    }
}
Also used : ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException) Survey(org.eyeseetea.malariacare.data.database.model.Survey) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) Value(org.eyeseetea.malariacare.data.database.model.Value) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) ImportSummaryErrorException(org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException)

Aggregations

Survey (org.eyeseetea.malariacare.data.database.model.Survey)39 Date (java.util.Date)8 Intent (android.content.Intent)7 Value (org.eyeseetea.malariacare.data.database.model.Value)6 ArrayList (java.util.ArrayList)4 Program (org.eyeseetea.malariacare.data.database.model.Program)3 Question (org.eyeseetea.malariacare.data.database.model.Question)3 Session.getMalariaSurvey (org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey)3 Option (org.eyeseetea.malariacare.data.database.model.Option)2 OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)2 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)2 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ListView (android.widget.ListView)1 TableRow (android.widget.TableRow)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 CompositeScore (org.eyeseetea.malariacare.data.database.model.CompositeScore)1