use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class EventSelectionField method forSubordinateEvent.
public static EventSelectionField forSubordinateEvent(EventDto eventDto, Set<String> excludedUuids) {
EventSelectionField eventSelectionField = new EventSelectionField(eventDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateSuperordinateEventForEvent), eventCriteria -> {
eventCriteria.setExcludedUuids(excludedUuids);
eventCriteria.eventDateBetween(EventHelper.getStartOrEndDate(eventDto.getStartDate(), eventDto.getEndDate()), null, null, DateFilterOption.DATE);
eventCriteria.setHasNoSuperordinateEvent(Boolean.TRUE);
});
eventSelectionField.weekAndDateFilter.getDateFromFilter().addValueChangeListener(valueChangeEvent -> {
Date selectedFromDate = eventSelectionField.weekAndDateFilter.getDateFromFilter().getValue();
prepareSubordinateFilters(eventDto, eventSelectionField, selectedFromDate, eventSelectionField.weekAndDateFilter.getDateFromFilter());
});
eventSelectionField.weekAndDateFilter.getWeekFromFilter().addValueChangeListener(valueChangeEvent -> {
EpiWeek epiWeek = (EpiWeek) eventSelectionField.weekAndDateFilter.getWeekFromFilter().getValue();
Date epiWeekStartDate = DateHelper.getEpiWeekStart(epiWeek);
prepareSubordinateFilters(eventDto, eventSelectionField, epiWeekStartDate, eventSelectionField.weekAndDateFilter.getWeekFromFilter());
});
return eventSelectionField;
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class EventSelectionField method buildWeekAndDateFilter.
public HorizontalLayout buildWeekAndDateFilter() {
applyButton = ButtonHelper.createButton(Captions.actionApplyDateFilter, null);
weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, null);
weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekFrom));
weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekTo));
weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateFrom));
weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateTo));
applyButton.addClickListener(e -> {
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
Date fromDate = null;
Date toDate = null;
if (dateFilterOption == DateFilterOption.DATE) {
if (weekAndDateFilter.getDateFromFilter().getValue() != null) {
fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue());
}
if (weekAndDateFilter.getDateToFilter().getValue() != null) {
toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue());
}
} else {
fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
}
if (setDefaultFilters != null) {
EventCriteria defaultCriteria = new EventCriteria();
setDefaultFilters.accept(defaultCriteria);
fromDate = fromDate == null ? defaultCriteria.getEventDateFrom() : fromDate;
toDate = toDate == null ? defaultCriteria.getEventDateTo() : toDate;
}
applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY);
criteria.eventDateBetween(fromDate, toDate, EventCriteriaDateType.EVENT_DATE, dateFilterOption);
eventGrid.setCriteria(criteria);
eventGrid.getSelectedItems();
});
Button resetButton = ButtonHelper.createButton(Captions.caseEventsResetDateFilter, null);
resetButton.addClickListener(e -> {
weekAndDateFilter.getDateFromFilter().setValue(null);
weekAndDateFilter.getDateToFilter().setValue(null);
weekAndDateFilter.getWeekFromFilter().setValue(null);
weekAndDateFilter.getWeekToFilter().setValue(null);
criteria.freeText(null);
if (setDefaultFilters != null) {
setDefaultFilters.accept(criteria);
} else {
criteria.eventDateBetween(null, null, null, DateFilterOption.DATE);
}
eventGrid.setCriteria(criteria);
eventGrid.getSelectedItems();
});
HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
dateFilterRowLayout.setSpacing(true);
dateFilterRowLayout.setSizeUndefined();
dateFilterRowLayout.addComponent(weekAndDateFilter);
dateFilterRowLayout.addComponent(applyButton);
dateFilterRowLayout.addComponent(resetButton);
return dateFilterRowLayout;
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class ReportFragment method onAfterLayoutBinding.
@Override
protected void onAfterLayoutBinding(FragmentReportWeeklyLayoutBinding contentBinding) {
super.onAfterLayoutBinding(contentBinding);
EpiWeek epiWeek = ((ReportActivity) getActivity()).getEpiWeek();
if (epiWeek == null) {
contentBinding.reportSelector.setValue(EpiWeekFilterOption.LAST_WEEK);
} else {
setEpiWeek(epiWeek);
updateByEpiWeek();
}
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class ReportFragment method setupControls.
private void setupControls() {
EpiWeek epiWeek = DateHelper.getPreviousEpiWeek(new Date());
contentBinding.weeklyReportYear.initializeSpinner(yearList, epiWeek.getYear(), new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
Integer year = (Integer) field.getValue();
if (year != null) {
contentBinding.weeklyReportEpiWeek.setSpinnerData(DataUtils.toItems(DateHelper.createEpiWeekList(year)));
} else {
contentBinding.weeklyReportEpiWeek.setSpinnerData(null);
}
}
});
contentBinding.weeklyReportEpiWeek.initializeSpinner(DataUtils.toItems(DateHelper.createEpiWeekList(epiWeek.getYear())), epiWeek, new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
((ReportActivity) getActivity()).setEpiWeek((EpiWeek) field.getValue());
updateByEpiWeek();
}
});
contentBinding.reportSelector.addValueChangedListener(new ValueChangeListener() {
@Override
public void onChange(ControlPropertyField field) {
EpiWeekFilterOption filter = (EpiWeekFilterOption) field.getValue();
if (filter != null) {
switch(filter) {
case LAST_WEEK:
setEpiWeek(DateHelper.getPreviousEpiWeek(new Date()));
contentBinding.weeklyReportYear.setEnabled(false);
contentBinding.weeklyReportEpiWeek.setEnabled(false);
break;
case THIS_WEEK:
setEpiWeek(DateHelper.getEpiWeek(new Date()));
contentBinding.weeklyReportYear.setEnabled(false);
contentBinding.weeklyReportEpiWeek.setEnabled(false);
break;
case SPECIFY_WEEK:
contentBinding.weeklyReportYear.setEnabled(true);
contentBinding.weeklyReportEpiWeek.setEnabled(true);
break;
default:
throw new IllegalArgumentException(filter.toString());
}
}
}
});
contentBinding.addMissingCase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CaseNewActivity.startActivityWithEmptyReportDate(getContext());
}
});
contentBinding.submitReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSubmitReportConfirmationDialog();
}
});
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class AggregateReportsFragment method setupControls.
private void setupControls() {
EpiWeek epiWeek = DateHelper.getPreviousEpiWeek(new Date());
contentBinding.aggregateReportsYear.initializeSpinner(DataUtils.toItems(DateHelper.getYearsToNow()), epiWeek.getYear(), field -> {
Integer year = (Integer) field.getValue();
if (year != null) {
contentBinding.aggregateReportsWeek.setSpinnerData(DataUtils.toItems(DateHelper.createEpiWeekList(year)));
} else {
contentBinding.aggregateReportsWeek.setSpinnerData(null);
}
});
contentBinding.aggregateReportsWeek.initializeSpinner(DataUtils.toItems(DateHelper.createEpiWeekList(epiWeek.getYear())), epiWeek, field -> {
updateByEpiWeek();
});
contentBinding.reportSelector.addValueChangedListener(field -> {
EpiWeekFilterOption filter = (EpiWeekFilterOption) field.getValue();
if (filter != null) {
switch(filter) {
case LAST_WEEK:
setEpiWeek(DateHelper.getPreviousEpiWeek(new Date()));
contentBinding.aggregateReportsYear.setEnabled(false);
contentBinding.aggregateReportsWeek.setEnabled(false);
break;
case THIS_WEEK:
setEpiWeek(DateHelper.getEpiWeek(new Date()));
contentBinding.aggregateReportsYear.setEnabled(false);
contentBinding.aggregateReportsWeek.setEnabled(false);
break;
case SPECIFY_WEEK:
contentBinding.aggregateReportsYear.setEnabled(true);
contentBinding.aggregateReportsWeek.setEnabled(true);
break;
default:
throw new IllegalArgumentException(filter.toString());
}
}
});
contentBinding.submitReport.setOnClickListener(view -> showSubmitCaseNumbersConfirmationDialog());
}
Aggregations