Search in sources :

Example 1 with TreatmentMatch

use of org.eyeseetea.malariacare.data.database.model.TreatmentMatch 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 TreatmentMatch

use of org.eyeseetea.malariacare.data.database.model.TreatmentMatch in project pictureapp by EyeSeeTea.

the class PopulateRow method populateTreatmentMatches.

/**
     * Method to populate each row of TreatmentMatches.csv, execute after populateTreatments and
     * populateMatches.
     *
     * @param line The row of the csv to populate.
     */
static TreatmentMatch populateTreatmentMatches(String[] line, HashMap<Long, Treatment> treatmentIds, HashMap<Long, Match> matchesIds, TreatmentMatch treatmentMatch) {
    if (treatmentMatch == null) {
        treatmentMatch = new TreatmentMatch();
    }
    treatmentMatch.setTreatment(treatmentIds.get(Long.parseLong(line[1])));
    treatmentMatch.setMatch(matchesIds.get(Long.parseLong(line[2])));
    return treatmentMatch;
}
Also used : TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch)

Example 3 with TreatmentMatch

use of org.eyeseetea.malariacare.data.database.model.TreatmentMatch in project pictureapp by EyeSeeTea.

the class UpdateDB method updateTreatmentMatches.

/**
     * Method to update treatmentMatches from csvs.
     *
     * @param context Needed to open the csvs.
     * @throws IOException If there is a problem opening the csv.
     */
public static void updateTreatmentMatches(Context context, boolean updateCSV) throws IOException {
    if (updateCSV) {
        FileCsvs fileCsvs = new FileCsvs();
        fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TREATMENT_MATCHES_CSV);
    }
    List<TreatmentMatch> treatmentMatches = TreatmentMatch.getAllTreatmentMatches();
    HashMap<Long, Treatment> treatmentIds = RelationsIdCsvDB.getTreatmentIdRelationCsvDB(context);
    HashMap<Long, Match> matchIds = RelationsIdCsvDB.getMatchIdRelationCsvDB(context);
    CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TREATMENT_MATCHES_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
    String[] line;
    int i = 0;
    while ((line = reader.readNext()) != null) {
        if (i < treatmentMatches.size()) {
            PopulateRow.populateTreatmentMatches(line, treatmentIds, matchIds, treatmentMatches.get(i)).save();
        } else {
            PopulateRow.populateTreatmentMatches(line, treatmentIds, matchIds, null).insert();
        }
        i++;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) CSVReader(com.opencsv.CSVReader) PopulateRow.populateMatch(org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch) Treatment(org.eyeseetea.malariacare.data.database.model.Treatment)

Example 4 with TreatmentMatch

use of org.eyeseetea.malariacare.data.database.model.TreatmentMatch in project pictureapp by EyeSeeTea.

the class TreatmentTable method deleteRelatedTablesLines.

/**
     * Deleting the matches, questionOption and questionThresholds related with the treatment
     * table.
     */
private void deleteRelatedTablesLines(TreatmentMatch treatmentMatch) throws IOException {
    Match match = treatmentMatch.getMatch();
    List<QuestionOption> questionOptions = QuestionOption.getQuestionOptionsWithMatchId(match.getId_match());
    for (QuestionOption questionOption : questionOptions) {
        questionOption.delete();
    }
    List<QuestionThreshold> questionThresholds = QuestionThreshold.getQuestionThresholdsWithMatch(match.getId_match());
    for (QuestionThreshold questionThreshold : questionThresholds) {
        questionThreshold.delete();
    }
    match.delete();
}
Also used : QuestionThreshold(org.eyeseetea.malariacare.data.database.model.QuestionThreshold) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Match(org.eyeseetea.malariacare.data.database.model.Match) TreatmentMatch(org.eyeseetea.malariacare.data.database.model.TreatmentMatch)

Aggregations

TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)4 Match (org.eyeseetea.malariacare.data.database.model.Match)2 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)2 CSVReader (com.opencsv.CSVReader)1 InputStreamReader (java.io.InputStreamReader)1 DrugCombination (org.eyeseetea.malariacare.data.database.model.DrugCombination)1 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)1 QuestionThreshold (org.eyeseetea.malariacare.data.database.model.QuestionThreshold)1 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)1 Translation (org.eyeseetea.malariacare.data.database.model.Translation)1 PopulateRow.populateMatch (org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch)1