use of org.eyeseetea.malariacare.data.database.model.Value 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);
}
}
}
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class ConvertFromSDKVisitor method visit.
@Override
public void visit(DataValueExtended sdkDataValueExtended) {
Survey survey = (Survey) appMapObjects.get(sdkDataValueExtended.getEvent());
String questionUID = sdkDataValueExtended.getDataElement();
//Data value is a value from compositeScore -> ignore
if (appMapObjects.get(questionUID) instanceof CompositeScore) {
return;
}
//Phone metadata -> ignore
if (PreferencesState.getInstance().getContext().getString(R.string.control_data_element_phone_metadata).equals(questionUID)) {
return;
}
//Datavalue is a value from a question
Question question = Question.findByUID(questionUID);
if (question == null) {
Log.e(TAG, "Question not found with dataelement uid " + questionUID);
}
Value value = new Value();
value.setQuestion(question);
value.setSurvey(survey);
Option option = sdkDataValueExtended.findOptionByQuestion(question);
value.setOption(option);
//No option -> text question (straight value)
if (option == null) {
value.setValue(sdkDataValueExtended.getValue());
} else {
//Option -> extract value from code
value.setValue(sdkDataValueExtended.getDataValue().getValue());
}
values.add(value);
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class Treatment method getACTQuestionAnsweredNo.
public Question getACTQuestionAnsweredNo() {
List<Question> questions = mStockSurvey.getQuestionsFromValues();
Question actQuestion = null;
for (Question question : questions) {
if (isACT24Question(question) || isACT18Question(question) || isACT12Question(question) || isACT6Question(question)) {
actQuestion = question;
List<Value> values = mStockSurvey.getValuesFromDB();
for (Value value : values) {
if (value.getQuestion() == null) {
continue;
}
if (value.getQuestion().getId_question().equals(actQuestion.getId_question())) {
if (Float.parseFloat(value.getValue()) == 0) {
return actQuestion;
}
}
}
}
}
return null;
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class Treatment method putACTDefaultYes.
private void putACTDefaultYes() {
Question actHiddenQuestion = Question.findByUID(getContext().getString(R.string.dynamicTreatmentHideQuestionUID));
List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
Value actValue = null;
for (Value value : values) {
if (value.getQuestion().equals(actHiddenQuestion)) {
actValue = value;
}
}
if (actValue == null) {
actValue = new Value(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)), actHiddenQuestion, Session.getMalariaSurvey());
} else {
actValue.setOption(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)));
}
actValue.save();
}
use of org.eyeseetea.malariacare.data.database.model.Value in project pictureapp by EyeSeeTea.
the class Treatment method saveTreatmentInTreatmentQuestion.
private void saveTreatmentInTreatmentQuestion(org.eyeseetea.malariacare.data.database.model.Treatment treatment) {
Question treatmentQuestionSend = Question.findByUID(getContext().getResources().getString(R.string.dynamicTreatmentQuestionUID));
Question treatmentQuestionShow = Question.findByUID(getContext().getResources().getString(R.string.treatmentDiagnosisVisibleQuestion));
Survey malariaSurvey = Session.getMalariaSurvey();
List<Value> values = //this values should be get from memory because the
malariaSurvey.getValues();
// treatment options are in memory
boolean questionInSurvey = false;
boolean questionShowInSurvey = false;
String diagnosisMessage = Utils.getInternationalizedString(String.valueOf(treatment.getDiagnosis()));
String defaultDiagnosisMessage = Translation.getLocalizedString(treatment.getDiagnosis(), Translation.DEFAULT_LANGUAGE);
for (Value value : values) {
if (value.getQuestion() == null) {
continue;
}
if (value.getQuestion().equals(treatmentQuestionSend)) {
value.setValue(defaultDiagnosisMessage);
questionInSurvey = true;
value.save();
}
if (value.getQuestion().equals(treatmentQuestionShow)) {
value.setValue(diagnosisMessage);
questionShowInSurvey = true;
value.save();
}
}
if (!questionShowInSurvey) {
Value value = new Value(diagnosisMessage, treatmentQuestionShow, malariaSurvey);
value.insert();
}
if (!questionInSurvey) {
Value value = new Value(defaultDiagnosisMessage, treatmentQuestionSend, malariaSurvey);
value.insert();
}
}
Aggregations