use of org.eyeseetea.malariacare.data.database.model.OptionAttribute in project pictureapp by EyeSeeTea.
the class PopulateDB method addOptionTextSize.
public static void addOptionTextSize(Context context) throws IOException {
List<Option> options = Option.getAllOptions();
// Reset inner references
cleanInnerLists();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(OPTION_ATTRIBUTES_CSV)), SEPARATOR, QUOTECHAR);
CSVReader readerOptions = new CSVReader(new InputStreamReader(context.openFileInput(OPTIONS_CSV)), SEPARATOR, QUOTECHAR);
// Remove bad optionAttributes.
Delete.tables(OptionAttribute.class);
String[] line;
// save new optionattributes
while ((line = reader.readNext()) != null) {
OptionAttribute optionAttribute = new OptionAttribute();
optionAttribute.setBackground_colour(line[1]);
optionAttribute.setPath(line[2]);
if (line.length > 3 && !line[3].equals("")) {
optionAttribute.setHorizontal_alignment(Integer.valueOf(line[3]));
} else {
optionAttribute.setHorizontal_alignment(OptionAttribute.DEFAULT_HORIZONTAL_ALIGNMENT);
}
if (line.length > 4 && !line[4].equals("")) {
optionAttribute.setVertical_alignment(Integer.valueOf(line[4]));
} else {
optionAttribute.setVertical_alignment(OptionAttribute.DEFAULT_VERTICAL_ALIGNMENT);
}
if (line.length > 5 && !line[5].equals("")) {
optionAttribute.setText_size(Integer.valueOf(line[5]));
} else {
optionAttribute.setText_size(Integer.parseInt(PreferencesState.getInstance().getContext().getResources().getString(R.string.default_option_text_size)));
}
if (line.length > 6 && !line[6].equals("")) {
optionAttribute.setDefaultOption(Integer.valueOf(line[6]));
} else {
optionAttribute.setDefaultOption(0);
}
optionAttribute.save();
optionAttributeList.put(Integer.valueOf(line[0]), optionAttribute);
}
line = null;
// Save new optionattributes for each question
while ((line = readerOptions.readNext()) != null) {
for (Option option : options) {
if (String.valueOf(option.getId_option()).equals(line[0])) {
if (!line[5].equals("")) {
option.setOptionAttribute(optionAttributeList.get(Integer.valueOf(line[5])));
option.save();
}
break;
}
}
}
reader.close();
}
use of org.eyeseetea.malariacare.data.database.model.OptionAttribute in project pictureapp by EyeSeeTea.
the class PopulateDBStrategy method updateOptions.
public static void updateOptions(Context context) throws IOException {
List<Option> optionToDelete = Question.getOptions(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID));
for (Option option : optionToDelete) {
if (!option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.patientResidenceVillageOtherCode))) {
option.delete();
}
}
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
List<Option> options = Option.getAllOptions();
HashMap<Long, Answer> answersIds = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
HashMap<Long, OptionAttribute> optionAttributeIds = RelationsIdCsvDB.getOptionAttributeIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < options.size()) {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, options.get(i)).save();
} else {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, null).insert();
}
i++;
}
List<OrgUnit> orgUnits = OrgUnit.getAllOrgUnit();
for (OrgUnit orgUnit : orgUnits) {
Option option = new Option();
option.setCode(orgUnit.getName());
option.setName(orgUnit.getUid());
option.setFactor((float) 0);
option.setId_option((long) 0);
option.setAnswer(Question.getAnswer(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID)));
option.save();
}
}
use of org.eyeseetea.malariacare.data.database.model.OptionAttribute in project pictureapp by EyeSeeTea.
the class UpdateDB method updateOptionAttributes.
public static void updateOptionAttributes(Context context) throws IOException {
List<OptionAttribute> optionsAttributes = OptionAttribute.getAllOptionAttributes();
CSVReader reader = new CSVReader(new InputStreamReader(new PopulateDBStrategy().openFile(context, OPTION_ATTRIBUTES_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
for (OptionAttribute optionsAttribute : optionsAttributes) {
if (optionsAttribute.getId_option_attribute() == Integer.valueOf(line[0])) {
optionsAttribute.setBackground_colour(line[1]);
optionsAttribute.save();
}
}
}
}
use of org.eyeseetea.malariacare.data.database.model.OptionAttribute in project pictureapp by EyeSeeTea.
the class PopulateDB method addOptionAttributes.
public static void addOptionAttributes(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTION_ATTRIBUTES_CSV);
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
List<Option> options = Option.getAllOptions();
// Reset inner references
cleanInnerLists();
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(OPTION_ATTRIBUTES_CSV)), SEPARATOR, QUOTECHAR);
CSVReader readerOptions = new CSVReader(new InputStreamReader(context.openFileInput(OPTIONS_CSV)), SEPARATOR, QUOTECHAR);
// Remove bad optionAttributes.
Delete.tables(OptionAttribute.class);
String[] line;
// save new optionattributes
while ((line = reader.readNext()) != null) {
OptionAttribute optionAttribute = new OptionAttribute();
optionAttribute.setBackground_colour(line[1]);
optionAttribute.setPath(line[2]);
if (line.length > 3 && !line[3].equals("")) {
optionAttribute.setHorizontal_alignment(Integer.valueOf(line[3]));
} else {
optionAttribute.setHorizontal_alignment(OptionAttribute.DEFAULT_HORIZONTAL_ALIGNMENT);
}
if (line.length > 4 && !line[4].equals("")) {
optionAttribute.setVertical_alignment(Integer.valueOf(line[4]));
} else {
optionAttribute.setVertical_alignment(OptionAttribute.DEFAULT_VERTICAL_ALIGNMENT);
}
if (line.length > 5 && !line[5].equals("")) {
optionAttribute.setText_size(Integer.valueOf(line[5]));
} else {
optionAttribute.setText_size(Integer.parseInt(PreferencesState.getInstance().getContext().getResources().getString(R.string.default_option_text_size)));
}
if (line.length > 6 && !line[6].equals("")) {
optionAttribute.setDefaultOption(Integer.valueOf(line[6]));
} else {
optionAttribute.setDefaultOption(0);
}
optionAttribute.save();
optionAttributeList.put(Integer.valueOf(line[0]), optionAttribute);
}
line = null;
// Save new optionattributes for each question
while ((line = readerOptions.readNext()) != null) {
for (Option option : options) {
if (String.valueOf(option.getId_option()).equals(line[0])) {
if (!line[5].equals("")) {
option.setOptionAttribute(optionAttributeList.get(Integer.valueOf(line[5])));
option.save();
}
break;
}
}
}
reader.close();
}
use of org.eyeseetea.malariacare.data.database.model.OptionAttribute 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(TreatmentQueries.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(TreatmentQueries.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(TreatmentQueries.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(TreatmentQueries.getACT18Question().getId_question());
optionACT18.setOptionAttribute(new OptionAttribute("c8b8c7", "question_images/p5_actx18.png"));
Question outStockQuestion = TreatmentQueries.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 (TreatmentQueries.isACT24(drug.getQuestion_code())) {
optionACT24.setName(treatment.getMessage().toString());
options.add(optionACT24);
} else if (TreatmentQueries.isACT18(drug.getQuestion_code())) {
optionACT18.setName(treatment.getMessage().toString());
options.add(optionACT18);
} else if (TreatmentQueries.isACT12(drug.getQuestion_code())) {
optionACT12.setName(treatment.getMessage().toString());
options.add(optionACT12);
} else if (TreatmentQueries.isACT6(drug.getQuestion_code())) {
optionACT6.setName(treatment.getMessage().toString());
options.add(optionACT6);
}
}
}
options.add(optionOutStock);
answer.setOptions(options);
return answer;
}
Aggregations