use of org.eyeseetea.malariacare.data.database.model.Drug 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.Drug 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.Drug in project pictureapp by EyeSeeTea.
the class UpdateDB method updateDrugCombination.
/**
* Method to Update drugCombination from csvs.
*
* @param context Needed to open the csvs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateDrugCombination(Context context, boolean updateCSV) throws IOException {
if (updateCSV) {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.DRUG_COMBINATIONS_CSV);
}
List<DrugCombination> drugCombinations = DrugCombination.getAllDrugCombination();
HashMap<Long, Drug> drugIds = RelationsIdCsvDB.getDrugIdRelationCsvDB(context);
HashMap<Long, Treatment> treatmentIds = RelationsIdCsvDB.getTreatmentIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.DRUG_COMBINATIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < drugCombinations.size()) {
PopulateRow.populateDrugCombinations(line, drugIds, treatmentIds, drugCombinations.get(i)).save();
} else {
PopulateRow.populateDrugCombinations(line, drugIds, treatmentIds, null).insert();
}
}
}
Aggregations