Search in sources :

Example 1 with Survey

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

the class SurveyChecker method checkAllQuarantineSurveys.

/**
     * Download the related events. and checks all the quarantine surveys.
     * If a survey is in the server, the survey should be set as sent. Else, the survey should be
     * set as completed and it will be resend.
     */
public static void checkAllQuarantineSurveys() {
    List<Program> programs = Program.getAllPrograms();
    for (Program program : programs) {
        for (OrgUnit orgUnit : Survey.getQuarantineOrgUnits(program.getId_program())) {
            List<Survey> quarantineSurveys = Survey.getAllQuarantineSurveysByProgramAndOrgUnit(program, orgUnit);
            if (quarantineSurveys.size() == 0) {
                continue;
            }
            Date minDate = Survey.getMinQuarantineCompletionDateByProgramAndOrgUnit(program, orgUnit);
            Date maxDate = Survey.getMaxQuarantineEventDateByProgramAndOrgUnit(program, orgUnit);
            List<EventExtended> events = getEvents(program.getUid(), orgUnit.getUid(), minDate, maxDate);
            if (events != null && events.size() > 0) {
                for (Survey survey : quarantineSurveys) {
                    updateQuarantineSurveysStatus(events, survey);
                }
            }
        }
    }
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Survey(org.eyeseetea.malariacare.data.database.model.Survey) Program(org.eyeseetea.malariacare.data.database.model.Program) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) Date(java.util.Date)

Example 2 with Survey

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

the class DynamicTabAdapter method toggleChild.

/**
     * find and toggle the child question
     *
     * @param row           is the child question view
     * @param rowQuestion   is the question in the view
     * @param childQuestion is the posible child
     */
private boolean toggleChild(TableRow row, Question rowQuestion, Question childQuestion) {
    if (childQuestion.getId_question().equals(rowQuestion.getId_question())) {
        Survey survey = (rowQuestion.isStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
        if (rowQuestion.isHiddenBySurveyAndHeader(survey)) {
            row.setVisibility(View.GONE);
            hideDefaultValue(rowQuestion);
        } else {
            row.setVisibility(View.VISIBLE);
            showDefaultValue(row, rowQuestion);
        }
        return true;
    }
    return false;
}
Also used : Session.getMalariaSurvey(org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey) Survey(org.eyeseetea.malariacare.data.database.model.Survey)

Example 3 with Survey

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

the class PushDhisSDKDataSource method getEventUidToBePushed.

@NonNull
private Set<String> getEventUidToBePushed() {
    final Set<String> eventUids = new HashSet<>();
    final Set<String> sendingEventUids = new HashSet<>();
    List<Survey> surveys = Survey.getAllSendingSurveys();
    for (Survey survey : surveys) {
        sendingEventUids.add(survey.getEventUid());
    }
    List<EventFlow> eventsFlows = SdkQueries.getEvents();
    Log.d(TAG, "Size of events " + eventsFlows.size() + "size of surveys" + sendingEventUids.size());
    if (sendingEventUids.size() != eventsFlows.size()) {
        Log.d(TAG, "Error in size of events");
    }
    for (EventFlow eventFlow : eventsFlows) {
        if (eventFlow.getEventDate() != null && sendingEventUids.contains(eventFlow.getUId())) {
            eventUids.add(eventFlow.getUId());
        } else {
            Log.d(TAG, "Error pushing events. The event uid: " + eventFlow.getUId() + "haven't eventDate or is not listed to send");
        }
    }
    Log.d(TAG, "Size of valid events " + eventsFlows.size());
    return eventUids;
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) EventFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow) HashSet(java.util.HashSet) NonNull(android.support.annotation.NonNull)

Example 4 with Survey

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

the class AssessmentAdapter method onClick.

/**
     * Checks if the given position points to a real survey and open it.
     */
public void onClick(ListView l, int position, List<Survey> surveys) {
    //Discard clicks on header|footer (which is attended on newSurvey via super)
    if (!isPositionASurvey(l, surveys, position)) {
        return;
    }
    //fixed the position in the list if the adapter have a header.
    int fixedPosition = getFixedPosition(l);
    //Put selected survey in session
    Survey malariaSurvey = surveys.get(position - fixedPosition);
    Session.setMalariaSurvey(malariaSurvey);
    if (mDashboardAdapterStrategy.hasAllComplementarySurveys(malariaSurvey)) {
        // Go to SurveyActivity
        DashboardActivity.dashboardActivity.openSentSurvey();
    }
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey)

Example 5 with Survey

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

the class DynamicTabAdapter method renderQuestion.

public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
    TableRow tableRow;
    IQuestionViewFactory questionViewFactory;
    questionViewFactory = (Tab.isMultiQuestionTab(tabType) || Tab.isDynamicTreatmentTab(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
    // Se get the value from Session
    int visibility = View.GONE;
    Survey survey = (screenQuestion.isStockQuestion() || screenQuestion.isDynamicStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
    if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
        visibility = View.VISIBLE;
    }
    Value value = screenQuestion.getValueBySession();
    tableRow = new TableRow(context);
    IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
    if (questionView != null) {
        if (questionView instanceof IMultiQuestionView) {
            mMultiQuestionViews.add((IMultiQuestionView) questionView);
            ((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
        }
        addTagQuestion(screenQuestion, (View) questionView);
        configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
        questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
        questionView.setEnabled(!readOnly);
        if (questionView instanceof IImageQuestionView) {
            ((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
        }
        if (screenQuestion.isDynamicStockQuestion()) {
            Treatment treatment = new Treatment(getMalariaSurvey(), Session.getStockSurvey());
            if (treatment.hasTreatment()) {
                org.eyeseetea.malariacare.data.database.model.Treatment dbTreatment = treatment.getTreatment();
                Question actAnsweredNo = treatment.getACTQuestionAnsweredNo();
                screenQuestion.setAnswer(treatment.getACTOptions(dbTreatment));
                ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptionDose(treatment.getOptionDose(dbTreatment));
            }
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setQuestion(screenQuestion);
            ((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
            //Getting the question to put the correct values on it
            ArrayList<Question> questions = new ArrayList<>();
            for (Option option : screenQuestion.getAnswer().getOptions()) {
                Question question = Question.findByID(option.getId_option());
                if (question != null) {
                    questions.add(question);
                }
            }
            survey.getValuesFromDB();
            for (Question question : questions) {
                Value valueStock = question.getValueBySession();
                questionView.setValue(valueStock);
            }
        }
        if (questionView instanceof AOptionQuestionView) {
            ((AOptionQuestionView) questionView).setQuestion(screenQuestion);
            List<Option> options = screenQuestion.getAnswer().getOptions();
            ((AOptionQuestionView) questionView).setOptions(options);
        }
        if (questionView instanceof NumberRadioButtonMultiquestionView) {
            if (doseByQuestion != null) {
                ((NumberRadioButtonMultiquestionView) questionView).setDose(doseByQuestion.get(screenQuestion.getId_question()));
            }
            ((NumberRadioButtonMultiquestionView) questionView).setQuestion(screenQuestion);
            ((NumberRadioButtonMultiquestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
        }
        if (!readOnly) {
            configureAnswerChangedListener(questionView);
        }
        if (reloadingQuestionFromInvalidOption) {
            reloadingQuestionFromInvalidOption = false;
        } else {
            questionView.setValue(value);
        }
        setupNavigationByQuestionView(rowView.getRootView(), questionView);
        tableRow.addView((View) questionView);
        swipeTouchListener.addClickableView(tableRow);
        setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
    }
}
Also used : SingleQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.SingleQuestionViewFactory) IQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.IQuestionViewFactory) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) ArrayList(java.util.ArrayList) MultiQuestionViewFactory(org.eyeseetea.malariacare.presentation.factory.MultiQuestionViewFactory) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) Session.getMalariaSurvey(org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey) Survey(org.eyeseetea.malariacare.data.database.model.Survey) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) Treatment(org.eyeseetea.malariacare.domain.entity.Treatment) TableRow(android.widget.TableRow) Value(org.eyeseetea.malariacare.data.database.model.Value) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) Question(org.eyeseetea.malariacare.data.database.model.Question) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Option(org.eyeseetea.malariacare.data.database.model.Option) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView)

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