Search in sources :

Example 1 with Treatment

use of org.eyeseetea.malariacare.domain.entity.Treatment 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)

Example 2 with Treatment

use of org.eyeseetea.malariacare.domain.entity.Treatment in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    mMultiQuestionViews.clear();
    Validation.init();
    //init validation control(used only in multiquestions tabs)
    failedValidations = 0;
    //Inflate the layout
    View rowView = lInflater.inflate(R.layout.dynamic_tab_grid_question, parent, false);
    rowView.getLayoutParams().height = parent.getHeight();
    rowView.requestLayout();
    Question questionItem = (Question) this.getItem(position);
    // We get values from DB and put them in Session
    if (getMalariaSurvey() != null) {
        if (Session.getStockSurvey() != null) {
            Session.getStockSurvey().getValuesFromDB();
        }
        getMalariaSurvey().getValuesFromDB();
    } else {
        // getView is called.
        return convertView;
    }
    //Question
    CustomTextView headerView = (CustomTextView) rowView.findViewById(question);
    //Load a font which support Khmer character
    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/" + context.getString(R.string.specific_language_font));
    headerView.setTypeface(tf);
    int tabType = questionItem.getHeader().getTab().getType();
    if (Tab.isMultiQuestionTab(tabType)) {
        headerView.setText(questionItem.getHeader().getTab().getInternationalizedName());
    } else if (Tab.isDynamicTreatmentTab(tabType)) {
        headerView.setText(questionItem.getHeader().getTab().getInternationalizedName());
    } else {
        headerView.setText(questionItem.getInternationalizedForm_name());
    }
    //question image
    if (questionItem.getPath() != null && !questionItem.getPath().equals("") && mDynamicTabAdapterStrategy.HasQuestionImageVisibleInHeader(questionItem.getOutput())) {
        ImageView imageView = (ImageView) rowView.findViewById(R.id.questionImage);
        BaseLayoutUtils.putImageInImageView(questionItem.getInternationalizedPath(), imageView);
        imageView.setVisibility(View.VISIBLE);
    }
    //Progress
    ProgressUtils.updateProgressBarStatus(rowView, navigationController.getCurrentPage(), navigationController.getCurrentTotalPages());
    List<Question> screenQuestions = new ArrayList<>();
    if (isTabScrollable(questionItem, tabType)) {
        tableLayout = (TableLayout) rowView.findViewById(R.id.multi_question_options_table);
        (rowView.findViewById(R.id.scrolled_table)).setVisibility(View.VISIBLE);
        (rowView.findViewById(R.id.no_scrolled_table)).setVisibility(View.GONE);
        if (tabType == Constants.TAB_DYNAMIC_TREATMENT) {
            Treatment treatment = new Treatment(Session.getMalariaSurvey(), Session.getStockSurvey());
            if (treatment.hasTreatment()) {
                screenQuestions = treatment.getQuestions();
                doseByQuestion = treatment.getDoseByQuestion();
            } else {
                screenQuestions = treatment.getNoTreatmentQuestions();
            }
        } else if (Tab.isMultiQuestionTab(tabType)) {
            screenQuestions = questionItem.getQuestionsByTab(questionItem.getHeader().getTab());
        } else {
            screenQuestions.add(questionItem);
        }
        swipeTouchListener.addScrollView((ScrollView) (rowView.findViewById(R.id.scrolled_table)).findViewById(R.id.table_scroll));
    } else {
        tableLayout = (TableLayout) rowView.findViewById(R.id.dynamic_tab_options_table);
        (rowView.findViewById(R.id.no_scrolled_table)).setVisibility(View.VISIBLE);
        (rowView.findViewById(R.id.scrolled_table)).setVisibility(View.GONE);
        screenQuestions.add(questionItem);
    }
    navigationButtonHolder = rowView.findViewById(R.id.snackbar);
    if (GradleVariantConfig.isButtonNavigationActive()) {
        initializeNavigationButtons(navigationButtonHolder);
        isClicked = false;
    }
    Log.d(TAG, "Questions in actual tab: " + screenQuestions.size());
    swipeTouchListener.clearClickableViews();
    for (Question screenQuestion : screenQuestions) {
        renderQuestion(rowView, tabType, screenQuestion);
    }
    rowView.requestLayout();
    reloadingQuestionFromInvalidOption = false;
    //FIXME: 09/03/2017  Refactor: This is used to prevent multiple open and close surveys crash
    Session.setIsLoadingSurvey(false);
    if (Session.shouldPressBackOnLoadSurvey()) {
        DashboardActivity.dashboardActivity.runOnUiThread(new Runnable() {

            public void run() {
                DashboardActivity.dashboardActivity.onBackPressed();
            }
        });
    }
    return rowView;
}
Also used : CustomTextView(org.eyeseetea.sdk.presentation.views.CustomTextView) Treatment(org.eyeseetea.malariacare.domain.entity.Treatment) Typeface(android.graphics.Typeface) ArrayList(java.util.ArrayList) Question(org.eyeseetea.malariacare.data.database.model.Question) ImageView(android.widget.ImageView) AKeyboardQuestionView(org.eyeseetea.malariacare.views.question.AKeyboardQuestionView) ImageView(android.widget.ImageView) AOptionQuestionView(org.eyeseetea.malariacare.views.question.AOptionQuestionView) View(android.view.View) INavigationQuestionView(org.eyeseetea.malariacare.views.question.INavigationQuestionView) IQuestionView(org.eyeseetea.malariacare.views.question.IQuestionView) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView) CustomTextView(org.eyeseetea.sdk.presentation.views.CustomTextView) ListView(android.widget.ListView) IMultiQuestionView(org.eyeseetea.malariacare.views.question.IMultiQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView) IImageQuestionView(org.eyeseetea.malariacare.views.question.IImageQuestionView) NumberRadioButtonMultiquestionView(org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView) ScrollView(android.widget.ScrollView)

Aggregations

ArrayList (java.util.ArrayList)2 Question (org.eyeseetea.malariacare.data.database.model.Question)2 Treatment (org.eyeseetea.malariacare.domain.entity.Treatment)2 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)2 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)2 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)2 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)2 NumberRadioButtonMultiquestionView (org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView)2 DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)2 Typeface (android.graphics.Typeface)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 ScrollView (android.widget.ScrollView)1 TableRow (android.widget.TableRow)1 Option (org.eyeseetea.malariacare.data.database.model.Option)1 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)1 Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 Value (org.eyeseetea.malariacare.data.database.model.Value)1 Session.getMalariaSurvey (org.eyeseetea.malariacare.data.database.utils.Session.getMalariaSurvey)1