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);
}
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();
}
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));
}
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);
}
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);
}
}
}
}
Aggregations