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);
}
}
}
}
}
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();
}
}
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);
}
}
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);
}
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();
}
Aggregations