use of de.symeda.sormas.api.utils.criteria.CriteriaDateType in project SORMAS-Project by hzi-braunschweig.
the class EventService method createEventDateFilter.
private Predicate createEventDateFilter(CriteriaQuery<?> cq, CriteriaBuilder cb, From<?, Event> from, EventCriteria eventCriteria) {
Predicate filter = null;
CriteriaDateType eventDateType = eventCriteria.getEventDateType();
Date eventDateFrom = eventCriteria.getEventDateFrom();
Date eventDateTo = eventCriteria.getEventDateTo();
if (eventDateType == null || eventDateType == EventCriteriaDateType.EVENT_DATE) {
Predicate eventDateFilter = null;
if (eventDateFrom != null && eventDateTo != null) {
eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.END_DATE)), cb.between(from.get(Event.START_DATE), eventDateFrom, eventDateTo)), cb.and(cb.isNull(from.get(Event.START_DATE)), cb.between(from.get(Event.END_DATE), eventDateFrom, eventDateTo)), cb.and(cb.greaterThanOrEqualTo(from.get(Event.END_DATE), eventDateFrom), cb.lessThanOrEqualTo(from.get(Event.START_DATE), eventDateTo)));
} else if (eventDateFrom != null) {
eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.END_DATE)), cb.greaterThanOrEqualTo(from.get(Event.START_DATE), eventDateFrom)), cb.and(cb.isNull(from.get(Event.START_DATE)), cb.greaterThanOrEqualTo(from.get(Event.END_DATE), eventDateFrom)));
} else if (eventDateTo != null) {
eventDateFilter = cb.or(cb.and(cb.isNull(from.get(Event.START_DATE)), cb.lessThanOrEqualTo(from.get(Event.END_DATE), eventDateTo)), cb.and(cb.isNull(from.get(Event.END_DATE)), cb.lessThanOrEqualTo(from.get(Event.START_DATE), eventDateTo)));
}
if (eventDateFrom != null || eventDateTo != null) {
filter = CriteriaBuilderHelper.and(cb, filter, eventDateFilter);
}
} else if (eventDateType == EventCriteriaDateType.REPORT_DATE) {
Predicate eventDateFilter = null;
if (eventDateFrom != null && eventDateTo != null) {
eventDateFilter = cb.between(from.get(Event.REPORT_DATE_TIME), eventDateFrom, eventDateTo);
} else if (eventDateFrom != null) {
eventDateFilter = cb.greaterThanOrEqualTo(from.get(Event.REPORT_DATE_TIME), eventDateFrom);
} else if (eventDateTo != null) {
eventDateFilter = cb.lessThanOrEqualTo(from.get(Event.REPORT_DATE_TIME), eventDateTo);
}
if (eventDateFrom != null || eventDateTo != null) {
filter = CriteriaBuilderHelper.and(cb, filter, eventDateFilter);
}
} else if (eventDateType == ExternalShareDateType.LAST_EXTERNAL_SURVEILLANCE_TOOL_SHARE) {
filter = externalShareInfoService.buildLatestSurvToolShareDateFilter(cq, cb, from, ExternalShareInfo.EVENT, (latestShareDate) -> {
if (eventDateFrom != null && eventDateTo != null) {
return cb.between(latestShareDate, eventDateFrom, eventDateTo);
} else if (eventDateFrom != null) {
return cb.greaterThanOrEqualTo(latestShareDate, eventDateFrom);
} else {
return cb.lessThanOrEqualTo(latestShareDate, eventDateTo);
}
});
}
return filter;
}
use of de.symeda.sormas.api.utils.criteria.CriteriaDateType in project SORMAS-Project by hzi-braunschweig.
the class CaseFilterForm method buildWeekAndDateFilter.
private HorizontalLayout buildWeekAndDateFilter(boolean isExternalShareEnabled) {
EpiWeekAndDateFilterComponent<CriteriaDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, I18nProperties.getString(Strings.infoCaseDate), CriteriaDateTypeHelper.getTypes(NewCaseDateType.class, isExternalShareEnabled), I18nProperties.getString(Strings.promptNewCaseDateType), null, this);
weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekFrom));
weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekTo));
weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptCasesDateFrom));
weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptDateTo));
addApplyHandler(e -> onApplyClick(weekAndDateFilter));
HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
dateFilterRowLayout.setSpacing(true);
dateFilterRowLayout.setSizeUndefined();
dateFilterRowLayout.addComponent(weekAndDateFilter);
return dateFilterRowLayout;
}
use of de.symeda.sormas.api.utils.criteria.CriteriaDateType in project SORMAS-Project by hzi-braunschweig.
the class CaseFilterForm method onApplyClick.
private void onApplyClick(EpiWeekAndDateFilterComponent<CriteriaDateType> weekAndDateFilter) {
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
Date fromDate, toDate;
if (dateFilterOption == DateFilterOption.DATE) {
Date dateFrom = weekAndDateFilter.getDateFromFilter().getValue();
fromDate = dateFrom != null ? DateHelper.getStartOfDay(dateFrom) : null;
Date dateTo = weekAndDateFilter.getDateToFilter().getValue();
toDate = dateFrom != null ? DateHelper.getEndOfDay(dateTo) : null;
} else {
fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
}
if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
CaseCriteria criteria = getValue();
CriteriaDateType newCaseDateType = (CriteriaDateType) weekAndDateFilter.getDateTypeSelector().getValue();
criteria.newCaseDateBetween(fromDate, toDate, newCaseDateType != null ? newCaseDateType : NewCaseDateType.MOST_RELEVANT);
criteria.dateFilterOption(dateFilterOption);
} else {
weekAndDateFilter.setNotificationsForMissingFilters();
}
}
use of de.symeda.sormas.api.utils.criteria.CriteriaDateType in project SORMAS-Project by hzi-braunschweig.
the class DashboardFacadeEjb method getDiseaseBurden.
@Override
@RolesAllowed({ UserRight._DASHBOARD_SURVEILLANCE_VIEW, UserRight._DASHBOARD_CONTACT_VIEW })
public List<DiseaseBurdenDto> getDiseaseBurden(RegionReferenceDto region, DistrictReferenceDto district, Date fromDate, Date toDate, Date previousFromDate, Date previousToDate, CriteriaDateType newCaseDateType) {
// diseases
List<Disease> diseases = diseaseConfigurationFacade.getAllDiseases(true, true, true);
// new cases
DashboardCriteria dashboardCriteria = new DashboardCriteria().region(region).district(district).newCaseDateType(newCaseDateType).dateBetween(fromDate, toDate);
Map<Disease, Long> newCases = dashboardService.getCaseCountByDisease(dashboardCriteria);
// events
Map<Disease, Long> events = eventFacade.getEventCountByDisease(new EventCriteria().region(region).district(district).eventDateType(null).eventDateBetween(fromDate, toDate));
// outbreaks
Map<Disease, Long> outbreakDistrictsCount;
if (featureConfigurationFacade.isFeatureEnabled(FeatureType.OUTBREAKS)) {
outbreakDistrictsCount = outbreakFacade.getOutbreakDistrictCountByDisease(new OutbreakCriteria().region(region).district(district).reportedBetween(fromDate, toDate));
} else {
outbreakDistrictsCount = new HashMap<>();
}
// last report district
Map<Disease, District> lastReportedDistricts = dashboardService.getLastReportedDistrictByDisease(dashboardCriteria);
// case fatalities
Map<Disease, Long> caseFatalities = dashboardService.getDeathCountByDisease(dashboardCriteria);
// previous cases
dashboardCriteria.dateBetween(previousFromDate, previousToDate);
Map<Disease, Long> previousCases = dashboardService.getCaseCountByDisease(dashboardCriteria);
// build diseasesBurden
List<DiseaseBurdenDto> diseasesBurden = diseases.stream().map(disease -> {
Long caseCount = newCases.getOrDefault(disease, 0L);
Long previousCaseCount = previousCases.getOrDefault(disease, 0L);
Long eventCount = events.getOrDefault(disease, 0L);
Long outbreakDistrictCount = outbreakDistrictsCount.getOrDefault(disease, 0L);
Long caseFatalityCount = caseFatalities.getOrDefault(disease, 0L);
District lastReportedDistrict = lastReportedDistricts.getOrDefault(disease, null);
String lastReportedDistrictName = lastReportedDistrict == null ? "" : lastReportedDistrict.getName();
return new DiseaseBurdenDto(disease, caseCount, previousCaseCount, eventCount, outbreakDistrictCount, caseFatalityCount, lastReportedDistrictName);
}).collect(Collectors.toList());
return diseasesBurden;
}
use of de.symeda.sormas.api.utils.criteria.CriteriaDateType in project SORMAS-Project by hzi-braunschweig.
the class EventsFilterForm method onApplyClick.
private void onApplyClick(EpiWeekAndDateFilterComponent<?> weekAndDateFilter, EventCriteria.DateType dateType) {
EventCriteria criteria = getValue();
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
CriteriaDateType eventDateType = (CriteriaDateType) weekAndDateFilter.getDateTypeSelector().getValue();
Date fromDate, toDate;
if (dateFilterOption == DateFilterOption.DATE) {
Date dateFrom = weekAndDateFilter.getDateFromFilter().getValue();
fromDate = dateFrom != null ? DateHelper.getStartOfDay(dateFrom) : null;
Date dateTo = weekAndDateFilter.getDateToFilter().getValue();
toDate = dateTo != null ? DateHelper.getEndOfDay(dateTo) : null;
} else {
fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
}
if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
criteria.dateBetween(dateType, fromDate, toDate, eventDateType, dateFilterOption);
} else {
weekAndDateFilter.setNotificationsForMissingFilters();
}
}
Aggregations