Search in sources :

Example 16 with Question

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

the class Treatment method getTreatmentFromSurvey.

private org.eyeseetea.malariacare.data.database.model.Treatment getTreatmentFromSurvey() {
    List<Value> values = mMalariaSurvey.getValuesFromDB();
    List<Match> ageMatches = new ArrayList<>();
    List<Match> pregnantMatches = new ArrayList<>();
    List<Match> severeMatches = new ArrayList<>();
    List<Match> rdtMatches = new ArrayList<>();
    for (Value value : values) {
        Question question = value.getQuestion();
        //Getting matches for questions of age, pregnant, severe and rdt.
        if (question == null) {
            continue;
        }
        if (question.getUid().equals(getContext().getString(R.string.ageQuestionUID))) {
            ageMatches = QuestionThreshold.getMatchesWithQuestionValue(question.getId_question(), Integer.parseInt(value.getValue()));
            Log.d(TAG, "age size: " + ageMatches.size());
        } else if (question.getUid().equals(getContext().getString(R.string.sexPregnantQuestionUID))) {
            pregnantMatches = QuestionOption.getMatchesWithQuestionOption(question.getId_question(), value.getId_option());
            Log.d(TAG, "pregnant size: " + pregnantMatches.size());
        } else if (question.getUid().equals(getContext().getString(R.string.severeSymtomsQuestionUID))) {
            severeMatches = QuestionOption.getMatchesWithQuestionOption(question.getId_question(), value.getId_option());
            Log.d(TAG, "severe size: " + severeMatches.size());
        } else if (question.getUid().equals(getContext().getString(R.string.rdtQuestionUID))) {
            rdtMatches = QuestionOption.getMatchesWithQuestionOption(question.getId_question(), value.getId_option());
            Log.d(TAG, "rdt size: " + rdtMatches.size());
        }
    }
    Log.d(TAG, "matches obtained");
    List<Match> treatmentMatches = new ArrayList<>();
    for (Match match : ageMatches) {
        if (pregnantMatches.contains(match) && severeMatches.contains(match) && rdtMatches.contains(match)) {
            treatmentMatches.add(match);
        }
    }
    org.eyeseetea.malariacare.data.database.model.Treatment treatment = null;
    for (Match treatmentMatch : treatmentMatches) {
        if (Session.getCredentials().isDemoCredentials()) {
            return treatmentMatch.getTreatment();
        }
        if (treatmentMatch.getTreatment().getOrganisation().getId_organisation() == Session.getUser().getOrganisation()) {
            Log.d(TAG, "match: " + treatmentMatch.toString());
            treatment = treatmentMatch.getTreatment();
            Log.d(TAG, "treatment: " + treatment.toString());
            break;
        }
    }
    return treatment;
}
Also used : Value(org.eyeseetea.malariacare.data.database.model.Value) ArrayList(java.util.ArrayList) Question(org.eyeseetea.malariacare.data.database.model.Question) Match(org.eyeseetea.malariacare.data.database.model.Match)

Example 17 with Question

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

the class DataConverterStrategy method convertPatientSexPregnancyDataValue.

private void convertPatientSexPregnancyDataValue(ConvertFromSDKVisitor converter, EventExtended event) throws QuestionNotFoundException {
    if (event.getProgramUId().equals(mContext.getString(R.string.stockProgramUID))) {
        return;
    }
    Question sexPregnancyQuestion = Question.findByUID(SEX_PREGNANCY_QUESTION_UID);
    if (sexPregnancyQuestion == null) {
        Log.d(TAG, event.getUid() + "With invalid sexPregnancy question");
        return;
    }
    List<DataValueExtended> dataValues = DataValueExtended.getExtendedList(SdkQueries.getDataValues(event.getUid()));
    DataValueExtended sexDataValue = getDataValue(dataValues, SEX_QUESTION_UID);
    DataValueExtended pregnancyDataValue = getDataValue(dataValues, PREGNANT_QUESTION_UID);
    if (sexDataValue == null || pregnancyDataValue == null) {
        Log.d(TAG, event.getUid() + "With invalid sexPregnancy question");
        return;
    }
    DataValueExtended OrgUnitDataValue = new DataValueExtended();
    OrgUnitDataValue.setEvent(event.getEvent());
    OrgUnitDataValue.setDataElement(sexPregnancyQuestion.getUid());
    if (sexDataValue.getValue().equals("F")) {
        if (pregnancyDataValue.getValue().equals("true")) {
            OrgUnitDataValue.setValue(SEX_PREGNANCY_PREGNANT_VALUE);
        } else {
            OrgUnitDataValue.setValue(SEX_PREGNANCY_FEMALE_VALUE);
        }
    } else {
        OrgUnitDataValue.setValue(SEX_PREGNANCY_MALE_VALUE);
    }
    OrgUnitDataValue.accept(converter);
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 18 with Question

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

the class DataConverterStrategy method convertOrgUnitDataValue.

private void convertOrgUnitDataValue(ConvertFromSDKVisitor converter, EventExtended event) throws QuestionNotFoundException {
    if (event.getProgramUId().equals(mContext.getString(R.string.stockProgramUID))) {
        return;
    }
    Question orgUnitQuestion = Question.findByUID(ORG_UNIT_QUESTION_UID);
    if (orgUnitQuestion == null) {
        throw new QuestionNotFoundException(String.format("Question with uid %s not found", ORG_UNIT_QUESTION_UID));
    }
    DataValueExtended OrgUnitDataValue = new DataValueExtended();
    OrgUnitDataValue.setEvent(event.getEvent());
    OrgUnitDataValue.setDataElement(orgUnitQuestion.getUid());
    OrgUnitDataValue.setValue(event.getOrganisationUnitId());
    OrgUnitDataValue.accept(converter);
}
Also used : QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) Question(org.eyeseetea.malariacare.data.database.model.Question) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 19 with Question

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

the class DynamicStockImageRadioButtonSingleQuestionView method setValue.

@Override
public void setValue(Value value) {
    if (value == null || value.getValue() == null) {
        return;
    }
    for (int i = 0; i < answersContainer.getChildCount(); i++) {
        ImageRadioButtonOption imageRadioButtonOption = (ImageRadioButtonOption) answersContainer.getChildAt(i);
        Question question = (Question) imageRadioButtonOption.getTag();
        if (!question.isOutStockQuestion() && question.getId_question().equals(value.getQuestion().getId_question()) && Float.parseFloat(value.getValue()) > 0) {
            imageRadioButtonOption.setChecked(true);
        } else if (question.getId_question().equals(value.getQuestion().getId_question())) {
            List<Option> options = question.getAnswer().getOptions();
            for (Option option : options) {
                if ((option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.true_option_id))) && option.getId_option().equals(value.getId_option())) {
                    imageRadioButtonOption.setChecked(true);
                }
            }
        }
    }
}
Also used : ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption) Question(org.eyeseetea.malariacare.data.database.model.Question) List(java.util.List) Option(org.eyeseetea.malariacare.data.database.model.Option) ImageRadioButtonOption(org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)

Example 20 with Question

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

the class ImageRadioButtonOption method setCounter.

public void setCounter(Question question) {
    Question optionCounter = question.findCounterByOption(mOption);
    if (optionCounter == null) {
        return;
    }
    String counterValue = optionCounter.getQuestionValueBySession();
    if (counterValue == null || counterValue.isEmpty()) {
        return;
    }
    String counterTextValue = getContext().getResources().getString(R.string.option_counter);
    mCounter.setText(counterTextValue + counterValue);
    mCounter.setVisibility(View.VISIBLE);
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question)

Aggregations

Question (org.eyeseetea.malariacare.data.database.model.Question)58 Option (org.eyeseetea.malariacare.data.database.model.Option)15 Value (org.eyeseetea.malariacare.data.database.model.Value)15 CSVReader (com.opencsv.CSVReader)11 InputStreamReader (java.io.InputStreamReader)11 ArrayList (java.util.ArrayList)7 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)7 View (android.view.View)6 Answer (org.eyeseetea.malariacare.data.database.model.Answer)5 Match (org.eyeseetea.malariacare.data.database.model.Match)5 ImageRadioButtonOption (org.eyeseetea.malariacare.views.option.ImageRadioButtonOption)5 AOptionQuestionView (org.eyeseetea.malariacare.views.question.AOptionQuestionView)5 IQuestionView (org.eyeseetea.malariacare.views.question.IQuestionView)5 DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)5 TableRow (android.widget.TableRow)4 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)4 IImageQuestionView (org.eyeseetea.malariacare.views.question.IImageQuestionView)4 IMultiQuestionView (org.eyeseetea.malariacare.views.question.IMultiQuestionView)4 NumberRadioButtonMultiquestionView (org.eyeseetea.malariacare.views.question.multiquestion.NumberRadioButtonMultiquestionView)4 ImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)4