use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class OrgUnitToOptionConverter method convert.
public static void convert() {
List<Question> questions = Question.getAllQuestionsWithOrgUnitDropdownList();
if (questions.size() == 0) {
return;
}
List<OrgUnit> orgUnits = OrgUnit.getAllOrgUnit();
for (OrgUnit orgUnit : orgUnits) {
addOUOptionToQuestions(questions, orgUnit);
}
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class Treatment method getACTOptions.
public Answer getACTOptions(org.eyeseetea.malariacare.data.database.model.Treatment mainTreatment) {
List<Option> options = new ArrayList<>();
Answer answer = new Answer("stock");
answer.setId_answer(Answer.DYNAMIC_STOCK_ANSWER_ID);
//this options are never saved
Option optionACT24 = new Option("ACT_x_24", "ACT_x_24", 0f, answer);
optionACT24.setId_option(Question.getACT24Question().getId_question());
optionACT24.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx24.png"));
Option optionACT12 = new Option("ACT_x_12", "ACT_x_12", 0f, answer);
optionACT12.setId_option(Question.getACT12Question().getId_question());
optionACT12.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx12.png"));
Option optionACT6 = new Option("ACT_x_6", "ACT_x_6", 0f, answer);
optionACT6.setId_option(Question.getACT6Question().getId_question());
optionACT6.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx6.png"));
Option optionACT18 = new Option("ACT_x_18", "ACT_x_18", 0f, answer);
optionACT18.setId_option(Question.getACT18Question().getId_question());
optionACT18.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx18.png"));
Question outStockQuestion = Question.getOutOfStockQuestion();
Option optionOutStock = new Option("out_stock_option", "out_stock_option", 0f, outStockQuestion.getAnswer());
optionOutStock.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p6_stockout.png"));
optionOutStock.setId_option(outStockQuestion.getId_question());
List<org.eyeseetea.malariacare.data.database.model.Treatment> treatments = mainTreatment.getAlternativeTreatments();
for (org.eyeseetea.malariacare.data.database.model.Treatment treatment : treatments) {
List<Drug> alternativeDrugs = treatment.getDrugsForTreatment();
for (Drug drug : alternativeDrugs) {
if (drug.isACT24()) {
optionACT24.setCode(treatment.getMessage().toString());
options.add(optionACT24);
} else if (drug.isACT18()) {
optionACT18.setCode(treatment.getMessage().toString());
options.add(optionACT18);
} else if (drug.isACT12()) {
optionACT12.setCode(treatment.getMessage().toString());
options.add(optionACT12);
} else if (drug.isACT6()) {
optionACT6.setCode(treatment.getMessage().toString());
options.add(optionACT6);
}
}
}
options.add(optionOutStock);
answer.setOptions(options);
return answer;
}
use of org.eyeseetea.malariacare.data.database.model.Question 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;
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class Treatment method getQuestionsForTreatment.
private List<Question> getQuestionsForTreatment(org.eyeseetea.malariacare.data.database.model.Treatment treatment) {
List<Question> questions = new ArrayList<>();
List<Drug> drugs = treatment.getDrugsForTreatment();
Question treatmentQuestion = new Question();
treatmentQuestion.setOutput(Constants.QUESTION_LABEL);
treatmentQuestion.setForm_name(treatment.getDiagnosis().toString());
treatmentQuestion.setHelp_text(treatment.getMessage().toString());
treatmentQuestion.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
treatmentQuestion.setHeader(Header.DYNAMIC_TREATMENT_HEADER_ID);
questions.add(treatmentQuestion);
for (Drug drug : drugs) {
Question question = Question.findByUID(drug.getQuestion_code());
if (question != null) {
if (isPq(question)) {
question.setForm_name(getPqTitleDose(DrugCombination.getDose(treatment, drug)));
} else if (isCq(question)) {
question.setForm_name(getCqTitleDose(DrugCombination.getDose(treatment, drug)));
}
doseByQuestion.put(question.getId_question(), DrugCombination.getDose(treatment, drug));
questions.add(question);
}
if (!questions.isEmpty()) {
Log.d(TAG, "Question: " + questions.get(questions.size() - 1) + "\n");
}
}
return questions;
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class UpdateDB method updateAndAddQuestions.
public static void updateAndAddQuestions(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTIONS_CSV);
List<Question> questionsDB = Question.getAllQuestions();
HashMap<Long, Header> headerHashMap = RelationsIdCsvDB.getHeaderFKRelationCsvDB(context);
HashMap<Long, Answer> answerHashMap = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
//Save new option name for each option
while ((line = reader.readNext()) != null) {
if (i < questionsDB.size()) {
PopulateRow.populateQuestion(line, headerHashMap, answerHashMap, questionsDB.get(i)).save();
} else {
PopulateRow.populateQuestion(line, headerHashMap, answerHashMap, null).insert();
}
i++;
}
}
Aggregations