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