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();
}
}
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;
}
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++;
}
}
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();
}
Aggregations