use of org.eyeseetea.malariacare.data.database.model.Program in project pictureapp by EyeSeeTea.
the class ConvertFromSDKVisitor method visit.
/**
* Turns an event into a sent survey
*/
@Override
public void visit(EventExtended sdkEventExtended) {
OrgUnit orgUnit = (OrgUnit) appMapObjects.get(sdkEventExtended.getOrganisationUnitId());
Program program = Program.getProgram(sdkEventExtended.getProgramUId());
Survey survey = new Survey();
//Any survey that comes from the pull has been sent
survey.setStatus(Constants.SURVEY_SENT);
//Set dates
survey.setCreationDate(sdkEventExtended.getCreationDate());
survey.setCompletionDate(sdkEventExtended.getEventDate());
survey.setEventDate(sdkEventExtended.getEventDate());
survey.setScheduledDate(sdkEventExtended.getScheduledDate());
//Set fks
survey.setOrgUnit(orgUnit);
survey.setProgram(program);
survey.setEventUid(sdkEventExtended.getUid());
mConvertFromSDKVisitorStrategy.visit(sdkEventExtended, survey);
surveys.add(survey);
//Annotate object in map
appMapObjects.put(sdkEventExtended.getUid(), survey);
}
use of org.eyeseetea.malariacare.data.database.model.Program in project pictureapp by EyeSeeTea.
the class DataConverter method convert.
public void convert(IPullController.Callback callback, ConvertFromSDKVisitor converter) {
String orgUnitName = PreferencesState.getInstance().getOrgUnit();
List<OrgUnit> orgUnits = converter.getOrgUnits();
for (OrgUnit orgUnit : orgUnits) {
//Only events for the right ORGUNIT are loaded
if (!orgUnitName.isEmpty() && orgUnit.getName() != null && !orgUnit.getName().equals(orgUnitName)) {
continue;
}
List<Program> programs = Program.getAllPrograms();
for (Program program : programs) {
List<EventExtended> events = EventExtended.getExtendedList(SdkQueries.getEvents(orgUnit.getUid(), program.getUid()));
callback.onStep(BUILDING_SURVEYS);
for (EventExtended event : events) {
event.accept(converter);
}
callback.onStep(BUILDING_VALUES);
for (EventExtended event : events) {
List<DataValueExtended> dataValues = DataValueExtended.getExtendedList(SdkQueries.getDataValues(event.getUid()));
for (DataValueExtended dataValueExtended : dataValues) {
dataValueExtended.accept(converter);
}
try {
dataConverterStrategy.convert(converter, event);
} catch (QuestionNotFoundException e) {
callback.onError(e);
}
}
}
}
saveConvertedSurveys(callback, converter);
}
use of org.eyeseetea.malariacare.data.database.model.Program in project pictureapp by EyeSeeTea.
the class UpdateDB method updateTabs.
/**
* Method to update the old tabs and add new ones from the csv. Use before insert all programs.
*
* @param context Needed to open the csv with the tabs.
* @throws IOException If there is a problem opening the csv.
*/
public static void updateTabs(Context context) throws IOException {
FileCsvs fileCsvs = new FileCsvs();
fileCsvs.saveCsvFromAssetsToFile(PopulateDB.TABS_CSV);
List<Tab> tabs = Tab.getAllTabs();
HashMap<Long, Program> programIds = RelationsIdCsvDB.getProgramIdRelationCsvDB(context);
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(PopulateDB.TABS_CSV)), PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] line;
int i = 0;
while ((line = reader.readNext()) != null) {
if (i < tabs.size()) {
PopulateRow.populateTab(line, programIds, tabs.get(i)).save();
} else {
PopulateRow.populateTab(line, programIds, null).insert();
}
i++;
}
}
use of org.eyeseetea.malariacare.data.database.model.Program in project pictureapp by EyeSeeTea.
the class BaseActivity method createActionBar.
/**
* Adds actionbar to the activity
*/
public void createActionBar() {
Program program = Program.getFirstProgram();
if (program != null) {
android.support.v7.app.ActionBar actionBar = this.getSupportActionBar();
LayoutUtils.setActionBarLogo(actionBar);
LayoutUtils.setActionBarText(actionBar, PreferencesState.getInstance().getOrgUnit(), this.getResources().getString(R.string.malaria_case_based_reporting));
}
}
use of org.eyeseetea.malariacare.data.database.model.Program in project pictureapp by EyeSeeTea.
the class DashboardActivityStrategy method newSurvey.
@Override
public void newSurvey(Activity activity) {
Program myanmarProgram = Program.findByUID(activity.getString(R.string.malariaProgramUID));
Program stockProgram = Program.findByUID(activity.getString(R.string.stockProgramUID));
// Put new survey in session
Survey survey = new Survey(null, myanmarProgram, Session.getUser());
survey.save();
Session.setMalariaSurvey(survey);
Survey stockSurvey = new Survey(null, stockProgram, Session.getUser(), Constants.SURVEY_ISSUE);
stockSurvey.setEventDate(//asociate the malaria survey to the stock survey
survey.getEventDate());
stockSurvey.save();
Session.setStockSurvey(stockSurvey);
prepareLocationListener(activity, survey);
}
Aggregations