Search in sources :

Example 6 with Program

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);
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Survey(org.eyeseetea.malariacare.data.database.model.Survey) Program(org.eyeseetea.malariacare.data.database.model.Program)

Example 7 with Program

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);
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Program(org.eyeseetea.malariacare.data.database.model.Program) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 8 with Program

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++;
    }
}
Also used : Program(org.eyeseetea.malariacare.data.database.model.Program) Tab(org.eyeseetea.malariacare.data.database.model.Tab) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader)

Example 9 with Program

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));
    }
}
Also used : Program(org.eyeseetea.malariacare.data.database.model.Program)

Example 10 with Program

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);
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) Program(org.eyeseetea.malariacare.data.database.model.Program)

Aggregations

Program (org.eyeseetea.malariacare.data.database.model.Program)10 CSVReader (com.opencsv.CSVReader)4 InputStreamReader (java.io.InputStreamReader)4 OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)3 Survey (org.eyeseetea.malariacare.data.database.model.Survey)3 Tab (org.eyeseetea.malariacare.data.database.model.Tab)2 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Answer (org.eyeseetea.malariacare.data.database.model.Answer)1 Drug (org.eyeseetea.malariacare.data.database.model.Drug)1 Header (org.eyeseetea.malariacare.data.database.model.Header)1 Match (org.eyeseetea.malariacare.data.database.model.Match)1 Option (org.eyeseetea.malariacare.data.database.model.Option)1 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)1 Organisation (org.eyeseetea.malariacare.data.database.model.Organisation)1 Question (org.eyeseetea.malariacare.data.database.model.Question)1 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)1 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)1