Search in sources :

Example 11 with Value

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

Example 12 with Value

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);
}
Also used : CompositeScore(org.eyeseetea.malariacare.data.database.model.CompositeScore) Survey(org.eyeseetea.malariacare.data.database.model.Survey) Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 13 with 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;
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 14 with Value

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();
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Example 15 with Value

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();
    }
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) Value(org.eyeseetea.malariacare.data.database.model.Value) Question(org.eyeseetea.malariacare.data.database.model.Question)

Aggregations

Value (org.eyeseetea.malariacare.data.database.model.Value)21 Question (org.eyeseetea.malariacare.data.database.model.Question)15 Survey (org.eyeseetea.malariacare.data.database.model.Survey)6 Option (org.eyeseetea.malariacare.data.database.model.Option)5 ArrayList (java.util.ArrayList)3 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)3 TableRow (android.widget.TableRow)2 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)2 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)2 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)2 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)2 Handler (android.os.Handler)1 View (android.view.View)1 Calendar (java.util.Calendar)1 CompositeScore (org.eyeseetea.malariacare.data.database.model.CompositeScore)1 Match (org.eyeseetea.malariacare.data.database.model.Match)1 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)1 Session.getMalariaSurvey (org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 Treatment (org.eyeseetea.malariacare.domain.entity.Treatment)1