use of org.eyeseetea.malariacare.data.database.utils.populatedb.FileCsvs in project pictureapp by EyeSeeTea.
the class Migration4RenameOrganisationToPartner method migrate.
@Override
public void migrate(DatabaseWrapper database) {
String sqlCopy = "INSERT INTO Partner (id_partner, uid_partner, name)" + " SELECT id_organisation, uid_organisation, name" + " FROM Organisation;";
database.execSQL(sqlCopy);
String sqlDelete = "DROP TABLE IF EXISTS Organisation;";
database.execSQL(sqlDelete);
String sqlUserTemp = "CREATE TABLE UserTemp(id_user INTEGER PRIMARY KEY, uid_user TEXT, name TEXT, " + "partner_fk INTEGER, supervisor_fk INTEGER)";
database.execSQL(sqlUserTemp);
String sqlCopyUser = "INSERT INTO UserTemp (id_user, uid_user, name, partner_fk, supervisor_fk)" + " SELECT id_user, uid_user, name ,organisation_fk ,supervisor_fk" + " FROM User;";
database.execSQL(sqlCopyUser);
String sqlDeleteUser = "DROP TABLE IF EXISTS User;";
database.execSQL(sqlDeleteUser);
String renameUser = "ALTER TABLE UserTemp RENAME TO User";
database.execSQL(renameUser);
String sqlTreatmentTemp = "CREATE TABLE TreatmentTemp(id_treatment INTEGER PRIMARY KEY, " + "id_partner_fk INTEGER, diagnosis INTEGER, message INTEGER, type " + "INTEGER)";
database.execSQL(sqlTreatmentTemp);
String sqlCopyTreatment = "INSERT INTO TreatmentTemp (id_treatment, id_partner_fk, diagnosis, message, type)" + " SELECT id_treatment, id_organisation_fk, diagnosis, message, type" + " FROM Treatment;";
database.execSQL(sqlCopyTreatment);
String sqlDeleteTreatment = "DROP TABLE IF EXISTS Treatment;";
database.execSQL(sqlDeleteTreatment);
String renameTreatment = "ALTER TABLE TreatmentTemp RENAME TO Treatment";
database.execSQL(renameTreatment);
FileCsvs fileCsvs = new FileCsvs();
try {
fileCsvs.copyCsvFile("Organisations.csv", PopulateDB.PARTNER_CSV);
} catch (IOException e) {
new MigrateMigrationException(e);
}
}
use of org.eyeseetea.malariacare.data.database.utils.populatedb.FileCsvs in project pictureapp by EyeSeeTea.
the class PopulateDBStrategy method updateOptions.
public static void updateOptions(Context context) throws IOException {
List<Option> optionToDelete = Question.getOptions(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID));
for (Option option : optionToDelete) {
if (!option.getCode().equals(PreferencesState.getInstance().getContext().getString(R.string.patientResidenceVillageOtherCode))) {
option.delete();
}
}
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
List<Option> options = Option.getAllOptions();
HashMap<Long, Answer> answersIds = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
HashMap<Long, OptionAttribute> optionAttributeIds = RelationsIdCsvDB.getOptionAttributeIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < options.size()) {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, options.get(i)).save();
} else {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, null).insert();
}
i++;
}
List<OrgUnit> orgUnits = OrgUnit.getAllOrgUnit();
for (OrgUnit orgUnit : orgUnits) {
Option option = new Option();
option.setCode(orgUnit.getName());
option.setName(orgUnit.getUid());
option.setFactor((float) 0);
option.setId_option((long) 0);
option.setAnswer(Question.getAnswer(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID)));
option.save();
}
}
use of org.eyeseetea.malariacare.data.database.utils.populatedb.FileCsvs in project pictureapp by EyeSeeTea.
the class PopulateDBStrategy method init.
@Override
public void init() throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvsInFileIfNeeded();
TreatmentTableOperations treatmentTable = new TreatmentTableOperations();
treatmentTable.generateTreatmentMatrixIFNeeded();
}
use of org.eyeseetea.malariacare.data.database.utils.populatedb.FileCsvs in project pictureapp by EyeSeeTea.
the class UpdateDBStrategy method updateOptions.
public static void updateOptions(Context context) throws IOException {
List<Option> optionToDelete = Question.getOptions(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID));
for (Option option : optionToDelete) {
if (!option.getName().equals(PreferencesState.getInstance().getContext().getString(R.string.patientResidenceVillageOtherCode))) {
option.delete();
}
}
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.OPTIONS_CSV);
List<Option> options = Option.getAllOptions();
HashMap<Long, Answer> answersIds = RelationsIdCsvDB.getAnswerFKRelationCsvDB(context);
HashMap<Long, OptionAttribute> optionAttributeIds = RelationsIdCsvDB.getOptionAttributeIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.OPTIONS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < options.size()) {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, options.get(i)).save();
} else {
PopulateRow.populateOption(line, answersIds, optionAttributeIds, null).insert();
}
i++;
}
List<OrgUnit> orgUnits = OrgUnit.getAllOrgUnit();
for (OrgUnit orgUnit : orgUnits) {
Option option = new Option();
option.setName(orgUnit.getName());
option.setCode(orgUnit.getUid());
option.setFactor((float) 0);
option.setId_option((long) 0);
option.setAnswer(Question.getAnswer(PreferencesState.getInstance().getContext().getString(R.string.residenceVillageUID)));
option.save();
}
}
Aggregations