use of org.eyeseetea.malariacare.data.database.model.Survey 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.Survey in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method toggleChild.
/**
* find and toggle the child question
*
* @param row is the child question view
* @param rowQuestion is the question in the view
* @param childQuestion is the posible child
*/
private boolean toggleChild(TableRow row, Question rowQuestion, Question childQuestion) {
if (childQuestion.getId_question().equals(rowQuestion.getId_question())) {
Survey survey = (rowQuestion.isStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
if (rowQuestion.isHiddenBySurveyAndHeader(survey)) {
row.setVisibility(View.GONE);
hideDefaultValue(rowQuestion);
} else {
row.setVisibility(View.VISIBLE);
showDefaultValue(row, rowQuestion);
}
return true;
}
return false;
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class PushDhisSDKDataSource method getEventUidToBePushed.
@NonNull
private Set<String> getEventUidToBePushed() {
final Set<String> eventUids = new HashSet<>();
final Set<String> sendingEventUids = new HashSet<>();
List<Survey> surveys = Survey.getAllSendingSurveys();
for (Survey survey : surveys) {
sendingEventUids.add(survey.getEventUid());
}
List<EventFlow> eventsFlows = SdkQueries.getEvents();
Log.d(TAG, "Size of events " + eventsFlows.size() + "size of surveys" + sendingEventUids.size());
if (sendingEventUids.size() != eventsFlows.size()) {
Log.d(TAG, "Error in size of events");
}
for (EventFlow eventFlow : eventsFlows) {
if (eventFlow.getEventDate() != null && sendingEventUids.contains(eventFlow.getUId())) {
eventUids.add(eventFlow.getUId());
} else {
Log.d(TAG, "Error pushing events. The event uid: " + eventFlow.getUId() + "haven't eventDate or is not listed to send");
}
}
Log.d(TAG, "Size of valid events " + eventsFlows.size());
return eventUids;
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class AssessmentAdapter method onClick.
/**
* Checks if the given position points to a real survey and open it.
*/
public void onClick(ListView l, int position, List<Survey> surveys) {
//Discard clicks on header|footer (which is attended on newSurvey via super)
if (!isPositionASurvey(l, surveys, position)) {
return;
}
//fixed the position in the list if the adapter have a header.
int fixedPosition = getFixedPosition(l);
//Put selected survey in session
Survey malariaSurvey = surveys.get(position - fixedPosition);
Session.setMalariaSurvey(malariaSurvey);
if (mDashboardAdapterStrategy.hasAllComplementarySurveys(malariaSurvey)) {
// Go to SurveyActivity
DashboardActivity.dashboardActivity.openSentSurvey();
}
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method renderQuestion.
public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
TableRow tableRow;
IQuestionViewFactory questionViewFactory;
questionViewFactory = (Tab.isMultiQuestionTab(tabType) || Tab.isDynamicTreatmentTab(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
// Se get the value from Session
int visibility = View.GONE;
Survey survey = (screenQuestion.isStockQuestion() || screenQuestion.isDynamicStockQuestion()) ? Session.getStockSurvey() : getMalariaSurvey();
if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
visibility = View.VISIBLE;
}
Value value = screenQuestion.getValueBySession();
tableRow = new TableRow(context);
IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
if (questionView != null) {
if (questionView instanceof IMultiQuestionView) {
mMultiQuestionViews.add((IMultiQuestionView) questionView);
((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
}
addTagQuestion(screenQuestion, (View) questionView);
configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
questionView.setEnabled(!readOnly);
if (questionView instanceof IImageQuestionView) {
((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
}
if (screenQuestion.isDynamicStockQuestion()) {
Treatment treatment = new Treatment(getMalariaSurvey(), Session.getStockSurvey());
if (treatment.hasTreatment()) {
org.eyeseetea.malariacare.data.database.model.Treatment dbTreatment = treatment.getTreatment();
Question actAnsweredNo = treatment.getACTQuestionAnsweredNo();
screenQuestion.setAnswer(treatment.getACTOptions(dbTreatment));
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptionDose(treatment.getOptionDose(dbTreatment));
}
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setQuestion(screenQuestion);
((DynamicStockImageRadioButtonSingleQuestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
//Getting the question to put the correct values on it
ArrayList<Question> questions = new ArrayList<>();
for (Option option : screenQuestion.getAnswer().getOptions()) {
Question question = Question.findByID(option.getId_option());
if (question != null) {
questions.add(question);
}
}
survey.getValuesFromDB();
for (Question question : questions) {
Value valueStock = question.getValueBySession();
questionView.setValue(valueStock);
}
}
if (questionView instanceof AOptionQuestionView) {
((AOptionQuestionView) questionView).setQuestion(screenQuestion);
List<Option> options = screenQuestion.getAnswer().getOptions();
((AOptionQuestionView) questionView).setOptions(options);
}
if (questionView instanceof NumberRadioButtonMultiquestionView) {
if (doseByQuestion != null) {
((NumberRadioButtonMultiquestionView) questionView).setDose(doseByQuestion.get(screenQuestion.getId_question()));
}
((NumberRadioButtonMultiquestionView) questionView).setQuestion(screenQuestion);
((NumberRadioButtonMultiquestionView) questionView).setOptions(screenQuestion.getAnswer().getOptions());
}
if (!readOnly) {
configureAnswerChangedListener(questionView);
}
if (reloadingQuestionFromInvalidOption) {
reloadingQuestionFromInvalidOption = false;
} else {
questionView.setValue(value);
}
setupNavigationByQuestionView(rowView.getRootView(), questionView);
tableRow.addView((View) questionView);
swipeTouchListener.addClickableView(tableRow);
setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
}
}
Aggregations