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 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 forSuperordinateEvent.
public static EventSelectionField forSuperordinateEvent(EventDto eventDto, Set<String> excludedUuids) {
EventSelectionField eventSelectionField = new EventSelectionField(eventDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateSuperordinateEventForEvent), eventCriteria -> {
eventCriteria.setExcludedUuids(excludedUuids);
eventCriteria.eventDateBetween(null, EventHelper.getStartOrEndDate(eventDto.getStartDate(), eventDto.getEndDate()), null, DateFilterOption.DATE);
});
eventSelectionField.weekAndDateFilter.getDateToFilter().addValueChangeListener(valueChangeEvent -> {
Date selectedToDate = eventSelectionField.weekAndDateFilter.getDateToFilter().getValue();
prepareSuperordinateFilters(eventDto, eventSelectionField, selectedToDate, eventSelectionField.weekAndDateFilter.getDateToFilter());
});
eventSelectionField.weekAndDateFilter.getWeekToFilter().addValueChangeListener(valueChangeEvent -> {
EpiWeek epiWeek = (EpiWeek) eventSelectionField.weekAndDateFilter.getWeekToFilter().getValue();
Date epiWeekEndDate = DateHelper.getEpiWeekEnd(epiWeek);
prepareSuperordinateFilters(eventDto, eventSelectionField, epiWeekEndDate, eventSelectionField.weekAndDateFilter.getWeekToFilter());
});
return eventSelectionField;
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class StatisticsHelperTest method testBuildGroupingKey.
@Test
public void testBuildGroupingKey() {
EpiWeek epiWeek = (EpiWeek) StatisticsHelper.buildGroupingKey(1803, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.EPI_WEEK_OF_YEAR, null, null, null, null);
assertThat(epiWeek.getYear(), equalTo(18));
assertThat(epiWeek.getWeek(), equalTo(3));
MonthOfYear monthOfYear = (MonthOfYear) StatisticsHelper.buildGroupingKey(1811, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.MONTH_OF_YEAR, null, null, null, null);
assertThat(monthOfYear.getYear().getValue(), equalTo(18));
assertThat(monthOfYear.getMonth(), equalTo(Month.NOVEMBER));
QuarterOfYear quarterOfYear = (QuarterOfYear) StatisticsHelper.buildGroupingKey(182, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.QUARTER_OF_YEAR, null, null, null, null);
assertThat(quarterOfYear.getYear().getValue(), equalTo(18));
assertThat(quarterOfYear.getQuarter().getValue(), equalTo(2));
}
use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.
the class ReportsView method updateEpiWeeks.
private void updateEpiWeeks(int year, int week) {
List<EpiWeek> epiWeekList = DateHelper.createEpiWeekList(year);
for (EpiWeek epiWeek : epiWeekList) {
epiWeekFilter.addItem(epiWeek.getWeek());
epiWeekFilter.setItemCaption(epiWeek.getWeek(), epiWeek.toString());
}
epiWeekFilter.select(week);
}
Aggregations