use of org.eyeseetea.malariacare.data.database.model.Treatment in project pictureapp by EyeSeeTea.
the class PopulateRow method populateTreatments.
/**
* Method to populate each row of Treatment.csv, execute after populateOrganisations.
*
* @param line The row of the csv to populate.
* @param stringKeyList
*/
static Treatment populateTreatments(String[] line, HashMap<Long, Organisation> organisationFK, HashMap<Long, StringKey> stringKeyList, @Nullable Treatment treatment) {
if (treatment == null) {
treatment = new Treatment();
}
treatment.setOrganisation(organisationFK.get(Long.parseLong(line[1])));
treatment.setDiagnosis(stringKeyList.get(Long.valueOf(line[2])).getId_string_key());
treatment.setMessage(stringKeyList.get(Long.valueOf(line[3])).getId_string_key());
treatment.setType(Integer.parseInt(line[4]));
return treatment;
}
use of org.eyeseetea.malariacare.data.database.model.Treatment 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)), SEPARATOR, 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();
}
}
}
use of org.eyeseetea.malariacare.data.database.model.Treatment 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)), SEPARATOR, 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.Treatment in project pictureapp by EyeSeeTea.
the class TreatmentTableOperations 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();
}
}
Aggregations