Search in sources :

Example 16 with EpiWeek

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;
}
Also used : Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 17 with EpiWeek

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;
}
Also used : DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) Button(com.vaadin.ui.Button) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 18 with EpiWeek

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();
    }
}
Also used : EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 19 with EpiWeek

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();
        }
    });
}
Also used : ValueChangeListener(de.symeda.sormas.app.component.controls.ValueChangeListener) ControlPropertyField(de.symeda.sormas.app.component.controls.ControlPropertyField) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 20 with EpiWeek

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());
}
Also used : EpiWeekFilterOption(de.symeda.sormas.app.report.EpiWeekFilterOption) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Aggregations

EpiWeek (de.symeda.sormas.api.utils.EpiWeek)34 Date (java.util.Date)24 DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)9 WeeklyReportOfficerSummaryDto (de.symeda.sormas.api.report.WeeklyReportOfficerSummaryDto)4 Test (org.junit.Test)4 Button (com.vaadin.ui.Button)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 MonthOfYear (de.symeda.sormas.api.MonthOfYear)3 QuarterOfYear (de.symeda.sormas.api.QuarterOfYear)3 WeeklyReportDto (de.symeda.sormas.api.report.WeeklyReportDto)3 WeeklyReportRegionSummaryDto (de.symeda.sormas.api.report.WeeklyReportRegionSummaryDto)3 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 RolesAllowed (javax.annotation.security.RolesAllowed)3 Month (de.symeda.sormas.api.Month)2 Quarter (de.symeda.sormas.api.Quarter)2 Year (de.symeda.sormas.api.Year)2 EventCriteria (de.symeda.sormas.api.event.EventCriteria)2