use of org.eyeseetea.malariacare.data.database.model.DrugCombination in project pictureapp by EyeSeeTea.
the class TreatmentTable method deleteOldTreatmentTable.
private void deleteOldTreatmentTable() throws IOException {
List<TreatmentMatch> treatmentMatches = TreatmentMatch.getAllTreatmentMatches();
for (TreatmentMatch treatmentMatch : treatmentMatches) {
deleteRelatedTablesLines(treatmentMatch);
treatmentMatch.delete();
}
List<Treatment> treatments = Treatment.getAllTreatments();
for (Treatment treatment : treatments) {
treatment.delete();
}
List<DrugCombination> drugCombinations = DrugCombination.getAllDrugCombination();
for (DrugCombination drugCombination : drugCombinations) {
drugCombination.delete();
}
List<StringKey> stringKeys = StringKey.getAllStringKeys();
for (StringKey stringKey : stringKeys) {
stringKey.delete();
}
List<Translation> translations = Translation.getAllTranslations();
for (Translation translation : translations) {
translation.delete();
}
}
use of org.eyeseetea.malariacare.data.database.model.DrugCombination in project pictureapp by EyeSeeTea.
the class PopulateRow method populateDrugCombinations.
/**
* Method to populate each row of DrugCombinations.csv, execute after populateDrugs and
* populateTreatments.
*
* @param line The row of the csv to populate.
*/
static DrugCombination populateDrugCombinations(String[] line, HashMap<Long, Drug> drugsFK, HashMap<Long, Treatment> treatmentFK, @Nullable DrugCombination drugCombination) {
if (drugCombination == null) {
drugCombination = new DrugCombination();
}
drugCombination.setDrug(drugsFK.get(Long.parseLong(line[1])));
drugCombination.setTreatment(treatmentFK.get(Long.parseLong(line[2])));
drugCombination.setDose(Float.parseFloat(line[3]));
return drugCombination;
}
use of org.eyeseetea.malariacare.data.database.model.DrugCombination 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