Search in sources :

Example 1 with DrugCombination

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();
    }
}
Also used : Translation(org.eyeseetea.malariacare.data.database.model.Translation) Treatment(org.eyeseetea.malariacare.data.database.model.Treatment) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) StringKey(org.eyeseetea.malariacare.data.database.model.StringKey) DrugCombination(org.eyeseetea.malariacare.data.database.model.DrugCombination)

Example 2 with DrugCombination

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;
}
Also used : DrugCombination(org.eyeseetea.malariacare.data.database.model.DrugCombination)

Example 3 with 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();
        }
    }
}
Also used : Drug(org.eyeseetea.malariacare.data.database.model.Drug) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) DrugCombination(org.eyeseetea.malariacare.data.database.model.DrugCombination) Treatment(org.eyeseetea.malariacare.data.database.model.Treatment)

Aggregations

DrugCombination (org.eyeseetea.malariacare.data.database.model.DrugCombination)3 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)2 CSVReader (com.opencsv.CSVReader)1 InputStreamReader (java.io.InputStreamReader)1 Drug (org.eyeseetea.malariacare.data.database.model.Drug)1 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)1 Translation (org.eyeseetea.malariacare.data.database.model.Translation)1 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)1