Search in sources :

Example 1 with CriteriaDateType

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;
}
Also used : Arrays(java.util.Arrays) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) SampleJurisdictionPredicateValidator(de.symeda.sormas.backend.sample.SampleJurisdictionPredicateValidator) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) EventCriteriaDateType(de.symeda.sormas.api.event.EventCriteriaDateType) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Predicate(javax.persistence.criteria.Predicate) ActionService(de.symeda.sormas.backend.action.ActionService) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) From(javax.persistence.criteria.From) Path(javax.persistence.criteria.Path) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Action(de.symeda.sormas.backend.action.Action) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) Transactional(javax.transaction.Transactional) Timestamp(java.sql.Timestamp) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) EditPermissionType(de.symeda.sormas.api.EditPermissionType) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) PersonQueryContext(de.symeda.sormas.backend.person.PersonQueryContext) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) Optional(java.util.Optional) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) Sample(de.symeda.sormas.backend.sample.Sample) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) EventCriteria(de.symeda.sormas.api.event.EventCriteria) CollectionUtils(org.apache.commons.collections.CollectionUtils) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) Disease(de.symeda.sormas.api.Disease) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) Subquery(javax.persistence.criteria.Subquery) Collections(java.util.Collections) EventCriteriaDateType(de.symeda.sormas.api.event.EventCriteriaDateType) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 2 with CriteriaDateType

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;
}
Also used : NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with CriteriaDateType

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

Example 4 with CriteriaDateType

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;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) FeatureType(de.symeda.sormas.api.feature.FeatureType) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) DashboardCaseMeasureDto(de.symeda.sormas.api.dashboard.DashboardCaseMeasureDto) RolesAllowed(javax.annotation.security.RolesAllowed) Date(java.util.Date) DashboardContactStoppedFollowUpDto(de.symeda.sormas.api.dashboard.DashboardContactStoppedFollowUpDto) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) BigDecimal(java.math.BigDecimal) Map(java.util.Map) FeatureConfigurationFacadeEjb(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) OutbreakCriteria(de.symeda.sormas.api.outbreak.OutbreakCriteria) Stateless(javax.ejb.Stateless) EnumMap(java.util.EnumMap) Predicate(java.util.function.Predicate) District(de.symeda.sormas.backend.infrastructure.district.District) DiseaseBurdenDto(de.symeda.sormas.api.disease.DiseaseBurdenDto) Collectors(java.util.stream.Collectors) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) PREVIOUS_CONTACTS(de.symeda.sormas.api.dashboard.DashboardContactStatisticDto.PREVIOUS_CONTACTS) DashboardContactDto(de.symeda.sormas.api.dashboard.DashboardContactDto) DashboardFacade(de.symeda.sormas.api.dashboard.DashboardFacade) List(java.util.List) DashboardQuarantineDataDto(de.symeda.sormas.api.dashboard.DashboardQuarantineDataDto) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) DashboardContactStatisticDto(de.symeda.sormas.api.dashboard.DashboardContactStatisticDto) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) Optional(java.util.Optional) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) OutbreakFacadeEjb(de.symeda.sormas.backend.outbreak.OutbreakFacadeEjb) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseMeasure(de.symeda.sormas.api.CaseMeasure) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DateHelper(de.symeda.sormas.api.utils.DateHelper) HashMap(java.util.HashMap) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DashboardContactVisitDto(de.symeda.sormas.api.dashboard.DashboardContactVisitDto) CURRENT_CONTACTS(de.symeda.sormas.api.dashboard.DashboardContactStatisticDto.CURRENT_CONTACTS) EventCriteria(de.symeda.sormas.api.event.EventCriteria) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) DashboardContactFollowUpDto(de.symeda.sormas.api.dashboard.DashboardContactFollowUpDto) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) EpiCurveGrouping(de.symeda.sormas.api.dashboard.EpiCurveGrouping) EJB(javax.ejb.EJB) DataHelper(de.symeda.sormas.api.utils.DataHelper) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) DateUtils(org.apache.commons.lang3.time.DateUtils) DashboardCaseStatisticDto(de.symeda.sormas.api.dashboard.DashboardCaseStatisticDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) UserRight(de.symeda.sormas.api.user.UserRight) Disease(de.symeda.sormas.api.Disease) TreeMap(java.util.TreeMap) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) Disease(de.symeda.sormas.api.Disease) DiseaseBurdenDto(de.symeda.sormas.api.disease.DiseaseBurdenDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) OutbreakCriteria(de.symeda.sormas.api.outbreak.OutbreakCriteria) District(de.symeda.sormas.backend.infrastructure.district.District) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 5 with CriteriaDateType

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

Aggregations

CriteriaDateType (de.symeda.sormas.api.utils.criteria.CriteriaDateType)5 EventCriteria (de.symeda.sormas.api.event.EventCriteria)3 Date (java.util.Date)3 Disease (de.symeda.sormas.api.Disease)2 EventCriteriaDateType (de.symeda.sormas.api.event.EventCriteriaDateType)2 DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)2 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 CaseMeasure (de.symeda.sormas.api.CaseMeasure)1 EditPermissionType (de.symeda.sormas.api.EditPermissionType)1 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)1 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseReferenceDefinition (de.symeda.sormas.api.caze.CaseReferenceDefinition)1 NewCaseDateType (de.symeda.sormas.api.caze.NewCaseDateType)1 DeletionDetails (de.symeda.sormas.api.common.DeletionDetails)1 ContactClassification (de.symeda.sormas.api.contact.ContactClassification)1 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)1 ContactStatus (de.symeda.sormas.api.contact.ContactStatus)1 FollowUpStatus (de.symeda.sormas.api.contact.FollowUpStatus)1