use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class PopulateDB method addVisibleQuestions.
public static void addVisibleQuestions(Context context, List<Question> questions) throws IOException {
//Reset inner references
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (question.getUid().equals(line[5])) {
question.setVisible(Integer.valueOf(line[14]));
question.save();
break;
}
}
}
reader.close();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class PopulateDB method addTotalQuestions.
public static void addTotalQuestions(Context context, List<Question> questions) throws IOException {
//Reset inner references
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (question.getUid().equals(line[5])) {
question.setTotalQuestions(Integer.valueOf(line[13]));
question.save();
break;
}
}
}
reader.close();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class PopulateDB method updateQuestions.
public static void updateQuestions(Context context) throws IOException {
List<Question> questions = Question.getAllQuestions();
//Reset inner references
cleanInnerLists();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
//Save new option name for each option
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (String.valueOf(question.getId_question()).equals((line[0]))) {
question.setCode(line[1]);
question.setDe_name(line[2]);
question.setHelp_text(line[3]);
question.setForm_name(line[4]);
//Update necessary from migration22 in myanmar
question.setOutput(Integer.valueOf(line[12]));
//Update necessary from migration3
question.setTotalQuestions(Integer.valueOf(line[13]));
//Update necessary from migration4
question.setVisible(Integer.valueOf(line[14]));
//Update necessary from migration7
if (line.length > 15 && !line[15].equals("")) {
question.setPath(line[15]);
}
if (line.length > 16 && !line[16].equals("")) {
question.setCompulsory(Integer.valueOf(line[16]));
} else {
question.setCompulsory(Question.QUESTION_NOT_COMPULSORY);
}
question.save();
break;
}
}
}
reader.close();
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class ConvertFromSDKVisitor method visit.
@Override
public void visit(DataValueExtended sdkDataValueExtended) {
Survey survey = (Survey) appMapObjects.get(sdkDataValueExtended.getEvent());
String questionUID = sdkDataValueExtended.getDataElement();
//Data value is a value from compositeScore -> ignore
if (appMapObjects.get(questionUID) instanceof CompositeScore) {
return;
}
//Phone metadata -> ignore
if (PreferencesState.getInstance().getContext().getString(R.string.control_data_element_phone_metadata).equals(questionUID)) {
return;
}
//Datavalue is a value from a question
Question question = Question.findByUID(questionUID);
if (question == null) {
Log.e(TAG, "Question not found with dataelement uid " + questionUID);
}
Value value = new Value();
value.setQuestion(question);
value.setSurvey(survey);
Option option = sdkDataValueExtended.findOptionByQuestion(question);
value.setOption(option);
//No option -> text question (straight value)
if (option == null) {
value.setValue(sdkDataValueExtended.getValue());
} else {
//Option -> extract value from code
value.setValue(sdkDataValueExtended.getDataValue().getValue());
}
values.add(value);
}
use of org.eyeseetea.malariacare.data.database.model.Question in project pictureapp by EyeSeeTea.
the class OrgUnitToOptionConverter method addOUOptionToQuestions.
public static void addOUOptionToQuestions(List<Question> questions, OrgUnit orgUnit) {
for (Question question : questions) {
if (!existsOrgUnitAsOptionInQuestion(orgUnit, question)) {
Option option = new Option();
option.setAnswer(question.getAnswer());
option.setName(orgUnit.getUid());
option.setCode(orgUnit.getName());
option.save();
}
}
}
Aggregations