Search in sources :

Example 1 with OrgUnit

use of org.eyeseetea.malariacare.data.database.model.OrgUnit in project pictureapp by EyeSeeTea.

the class SurveyChecker method checkAllQuarantineSurveys.

/**
     * Download the related events. and checks all the quarantine surveys.
     * If a survey is in the server, the survey should be set as sent. Else, the survey should be
     * set as completed and it will be resend.
     */
public static void checkAllQuarantineSurveys() {
    List<Program> programs = Program.getAllPrograms();
    for (Program program : programs) {
        for (OrgUnit orgUnit : Survey.getQuarantineOrgUnits(program.getId_program())) {
            List<Survey> quarantineSurveys = Survey.getAllQuarantineSurveysByProgramAndOrgUnit(program, orgUnit);
            if (quarantineSurveys.size() == 0) {
                continue;
            }
            Date minDate = Survey.getMinQuarantineCompletionDateByProgramAndOrgUnit(program, orgUnit);
            Date maxDate = Survey.getMaxQuarantineEventDateByProgramAndOrgUnit(program, orgUnit);
            List<EventExtended> events = getEvents(program.getUid(), orgUnit.getUid(), minDate, maxDate);
            if (events != null && events.size() > 0) {
                for (Survey survey : quarantineSurveys) {
                    updateQuarantineSurveysStatus(events, 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) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) Date(java.util.Date)

Example 2 with OrgUnit

use of org.eyeseetea.malariacare.data.database.model.OrgUnit in project pictureapp by EyeSeeTea.

the class UpdateDB 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();
    }
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) OptionAttribute(org.eyeseetea.malariacare.data.database.model.OptionAttribute) Answer(org.eyeseetea.malariacare.data.database.model.Answer) QuestionOption(org.eyeseetea.malariacare.data.database.model.QuestionOption) Option(org.eyeseetea.malariacare.data.database.model.Option)

Example 3 with OrgUnit

use of org.eyeseetea.malariacare.data.database.model.OrgUnit in project pictureapp by EyeSeeTea.

the class DynamicTabAdapter method OnOptionAnswered.

public void OnOptionAnswered(View view, Option selectedOption, boolean moveToNextQuestion) {
    if (moveToNextQuestion) {
        navigationController.isMovingToForward = true;
    }
    Question question = (Question) view.getTag();
    if (!selectedOption.getName().isEmpty() && question.getOutput() == Constants.DROPDOWN_OU_LIST) {
        OrgUnit orgUnit = OrgUnit.findByUID(selectedOption.getName());
        assignOrgUnitToSurvey(Session.getMalariaSurvey(), orgUnit);
        assignOrgUnitToSurvey(Session.getStockSurvey(), orgUnit);
    }
    Question counterQuestion = question.findCounterByOption(selectedOption);
    if (counterQuestion == null) {
        saveOptionValue(view, selectedOption, question, moveToNextQuestion);
    } else if (!(view instanceof ImageRadioButtonSingleQuestionView)) {
        showConfirmCounter(view, selectedOption, question, counterQuestion);
    }
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Question(org.eyeseetea.malariacare.data.database.model.Question) ImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView) DynamicStockImageRadioButtonSingleQuestionView(org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)

Example 4 with OrgUnit

use of org.eyeseetea.malariacare.data.database.model.OrgUnit in project pictureapp by EyeSeeTea.

the class ConvertFromSDKVisitor method visit.

/**
     * Turns a sdk organisationUnit into an app OrgUnit
     */
@Override
public void visit(OrganisationUnitExtended sdkOrganisationUnitExtended) {
    OrgUnit appOrgUnit = new OrgUnit();
    appOrgUnit.setName(sdkOrganisationUnitExtended.getLabel());
    appOrgUnit.setUid(sdkOrganisationUnitExtended.getId());
    appOrgUnit.save();
    orgUnits.add(appOrgUnit);
    appMapObjects.put(sdkOrganisationUnitExtended.getId(), appOrgUnit);
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit)

Example 5 with OrgUnit

use of org.eyeseetea.malariacare.data.database.model.OrgUnit in project pictureapp by EyeSeeTea.

the class PopulateDB method populateDummyData.

public static void populateDummyData(Context context) throws IOException {
    //Reset inner references
    cleanDummyLists();
    for (String table : tables2populateDummy) {
        Log.i(TAG, "Loading csv: " + table);
        CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(table)), SEPARATOR, QUOTECHAR);
        String[] line;
        while ((line = reader.readNext()) != null) {
            switch(table) {
                case ORG_UNIT_LEVEL_CSV:
                    OrgUnitLevel orgUnitLevel = new OrgUnitLevel();
                    orgUnitLevel.setName(line[1]);
                    orgUnitLevel.save();
                    orgUnitLevelList.put(Integer.valueOf(line[0]), orgUnitLevel);
                    break;
                case ORG_UNIT_CSV:
                    OrgUnit orgUnit = new OrgUnit();
                    orgUnit.setUid(line[1]);
                    orgUnit.setName(line[2]);
                    orgUnit.setOrgUnit(Long.valueOf(line[3]));
                    orgUnit.setOrgUnitLevel(orgUnitLevelList.get(Integer.valueOf(line[4])));
                    orgUnit.save();
                    orgUnitList.put(Integer.valueOf(line[0]), orgUnit);
                    break;
            }
        }
        reader.close();
    }
    //Free references since the maps are static
    cleanDummyLists();
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) OrgUnitLevel(org.eyeseetea.malariacare.data.database.model.OrgUnitLevel) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader)

Aggregations

OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)8 Program (org.eyeseetea.malariacare.data.database.model.Program)3 CSVReader (com.opencsv.CSVReader)2 InputStreamReader (java.io.InputStreamReader)2 Question (org.eyeseetea.malariacare.data.database.model.Question)2 Survey (org.eyeseetea.malariacare.data.database.model.Survey)2 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)2 Date (java.util.Date)1 Answer (org.eyeseetea.malariacare.data.database.model.Answer)1 Option (org.eyeseetea.malariacare.data.database.model.Option)1 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)1 OrgUnitLevel (org.eyeseetea.malariacare.data.database.model.OrgUnitLevel)1 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)1 DataValueExtended (org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)1 QuestionNotFoundException (org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException)1 DynamicStockImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.DynamicStockImageRadioButtonSingleQuestionView)1 ImageRadioButtonSingleQuestionView (org.eyeseetea.malariacare.views.question.singlequestion.ImageRadioButtonSingleQuestionView)1