use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class UpdateDB method updateQuestionOption.
public static void updateQuestionOption(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_OPTIONS_CSV);
}
List<QuestionOption> questionOptions = QuestionOption.listAll();
HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
HashMap<Long, Question> questionsIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
HashMap<Long, Option> optionsIds = RelationsIdCsvDB.getOptionIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < questionOptions.size()) {
PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, questionOptions.get(i)).save();
} else {
QuestionOption questionOption = PopulateRow.populateQuestionOption(line, questionsIds, optionsIds, matchIds, null);
questionOption.insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class UpdateDB method updateQuestionRelation.
public static void updateQuestionRelation(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.QUESTION_RELATIONS_CSV);
List<QuestionRelation> questionRelations = QuestionRelation.listAll();
HashMap<Long, Question> questionIds = RelationsIdCsvDB.getQuestionIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_RELATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
boolean added = false;
if (i < questionRelations.size()) {
populateQuestionRelation(line, questionIds, questionRelations.get(i)).save();
} else {
QuestionRelation questionRelation = populateQuestionRelation(line, questionIds, null);
questionRelation.insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class Treatment method getNoTreatmentQuestions.
public List<Question> getNoTreatmentQuestions() {
List<Question> questions = new ArrayList<>();
Question treatmentQuestion = new Question();
treatmentQuestion.setOutput(Constants.QUESTION_LABEL);
treatmentQuestion.setForm_name("");
treatmentQuestion.setHelp_text(getContext().getResources().getResourceName(R.string.error_no_treatment));
treatmentQuestion.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
treatmentQuestion.setHeader(Header.DYNAMIC_TREATMENT_HEADER_ID);
questions.add(treatmentQuestion);
return questions;
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class Treatment method putACTDefaultYes.
private void putACTDefaultYes() {
Question actHiddenQuestion = Question.findByUID(getContext().getString(R.string.dynamicTreatmentHideQuestionUID));
List<Value> values = Session.getMalariaSurvey().getValuesFromDB();
Value actValue = null;
for (Value value : values) {
if (value.getQuestion().equals(actHiddenQuestion)) {
actValue = value;
}
}
if (actValue == null) {
actValue = new Value(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)), actHiddenQuestion, Session.getMalariaSurvey());
} else {
actValue.setOption(Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)));
}
actValue.save();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class Treatment method saveTreatmentInTreatmentQuestion.
private void saveTreatmentInTreatmentQuestion(org.eyeseetea.malariacare.data.database.model.Treatment treatment) {
Question treatmentQuestionSend = Question.findByUID(getContext().getResources().getString(R.string.dynamicTreatmentQuestionUID));
Question treatmentQuestionShow = Question.findByUID(getContext().getResources().getString(R.string.treatmentDiagnosisVisibleQuestion));
Survey malariaSurvey = Session.getMalariaSurvey();
List<Value> values = //this values should be get from memory because the
malariaSurvey.getValues();
// treatment options are in memory
boolean questionInSurvey = false;
boolean questionShowInSurvey = false;
String diagnosisMessage = Utils.getInternationalizedString(String.valueOf(treatment.getDiagnosis()));
String defaultDiagnosisMessage = Translation.getLocalizedString(treatment.getDiagnosis(), Translation.DEFAULT_LANGUAGE);
for (Value value : values) {
if (value.getQuestion() == null) {
continue;
}
if (value.getQuestion().equals(treatmentQuestionSend)) {
value.setValue(defaultDiagnosisMessage);
questionInSurvey = true;
value.save();
}
if (value.getQuestion().equals(treatmentQuestionShow)) {
value.setValue(diagnosisMessage);
questionShowInSurvey = true;
value.save();
}
}
if (!questionShowInSurvey) {
Value value = new Value(diagnosisMessage, treatmentQuestionShow, malariaSurvey);
value.insert();
}
if (!questionInSurvey) {
Value value = new Value(defaultDiagnosisMessage, treatmentQuestionSend, malariaSurvey);
value.insert();
}
}
Aggregations