Search in sources :

Example 1 with PersonAssociation

use of de.symeda.sormas.api.person.PersonAssociation in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method count.

@Override
public long count(PersonCriteria criteria) {
    long startTime = DateHelper.startTime();
    final PersonCriteria nullSafeCriteria = Optional.ofNullable(criteria).orElse(new PersonCriteria());
    final long count;
    if (nullSafeCriteria.getPersonAssociation() == PersonAssociation.ALL) {
        // Fetch Person.id per association and find the distinct count.
        Set<Long> distinctPersonIds = new HashSet<>();
        boolean immunizationModuleReduced = featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED);
        Arrays.stream(PersonAssociation.getSingleAssociations()).filter(e -> !(immunizationModuleReduced && e == PersonAssociation.IMMUNIZATION)).map(e -> getPersonIds(SerializationUtils.clone(nullSafeCriteria).personAssociation(e))).forEach(distinctPersonIds::addAll);
        count = distinctPersonIds.size();
    } else {
        // Directly fetch the count for the only required association
        count = getPersonIds(criteria).size();
    }
    logger.debug("count() finished. association={}, count={}, {}ms", nullSafeCriteria.getPersonAssociation().name(), count, DateHelper.durationMillies(startTime));
    return count;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) Valid(javax.validation.Valid) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) PersonContext(de.symeda.sormas.api.person.PersonContext) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) LocationFacadeEjbLocal(de.symeda.sormas.backend.location.LocationFacadeEjb.LocationFacadeEjbLocal) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) DistrictFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb.DistrictFacadeEjbLocal) UserService(de.symeda.sormas.backend.user.UserService) Stream(java.util.stream.Stream) User(de.symeda.sormas.backend.user.User) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SymptomJournalStatus(de.symeda.sormas.api.person.SymptomJournalStatus) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) PersonFacade(de.symeda.sormas.api.person.PersonFacade) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) SerializationUtils(org.apache.commons.lang3.SerializationUtils) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) LocalBean(javax.ejb.LocalBean) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) DataHelper(de.symeda.sormas.api.utils.DataHelper) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) SormasToSormasOriginInfoService(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoService) UserFacadeEjbLocal(de.symeda.sormas.backend.user.UserFacadeEjb.UserFacadeEjbLocal) Collectors.maxBy(java.util.stream.Collectors.maxBy) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) Disease(de.symeda.sormas.api.Disease) ContactService(de.symeda.sormas.backend.contact.ContactService) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) SormasToSormasOriginInfo(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfo) FeatureType(de.symeda.sormas.api.feature.FeatureType) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) Join(javax.persistence.criteria.Join) FollowUpStatusDto(de.symeda.sormas.api.contact.FollowUpStatusDto) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) CauseOfDeath(de.symeda.sormas.api.person.CauseOfDeath) CommunityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb.CommunityFacadeEjbLocal) CountryService(de.symeda.sormas.backend.infrastructure.country.CountryService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) EventFacadeEjbLocal(de.symeda.sormas.backend.event.EventFacadeEjb.EventFacadeEjbLocal) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CaseService(de.symeda.sormas.backend.caze.CaseService) CountryFacadeEjb(de.symeda.sormas.backend.infrastructure.country.CountryFacadeEjb) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) PersonHelper(de.symeda.sormas.api.person.PersonHelper) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) ImmunizationFacadeEjb(de.symeda.sormas.backend.immunization.ImmunizationFacadeEjb) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) Objects(java.util.Objects) List(java.util.List) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) Order(javax.persistence.criteria.Order) Optional(java.util.Optional) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) Location(de.symeda.sormas.backend.location.Location) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) ApproximateAgeHelper(de.symeda.sormas.api.person.ApproximateAgeType.ApproximateAgeHelper) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) HashSet(java.util.HashSet) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionAttribute(javax.ejb.TransactionAttribute) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) FacilityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb.FacilityFacadeEjbLocal) Comparator.comparing(java.util.Comparator.comparing) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) LocationDto(de.symeda.sormas.api.location.LocationDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Logger(org.slf4j.Logger) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Validations(de.symeda.sormas.api.i18n.Validations) LocationFacadeEjb(de.symeda.sormas.backend.location.LocationFacadeEjb) Pair(de.symeda.sormas.api.utils.DataHelper.Pair) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Country(de.symeda.sormas.backend.infrastructure.country.Country) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) Comparator(java.util.Comparator) Collections(java.util.Collections) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) HashSet(java.util.HashSet)

Example 2 with PersonAssociation

use of de.symeda.sormas.api.person.PersonAssociation in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testCountAndGetIndexListWithAssociations.

/**
 * Test all {@link PersonAssociation} variants if they work. Also serves to review the generated SQL.
 */
@Test
public void testCountAndGetIndexListWithAssociations() {
    PersonFacade cut = getPersonFacade();
    Integer offset = null;
    Integer limit = null;
    List<SortProperty> sortProperties = null;
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf.region.getUuid(), null, null, null, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    loginWith(user);
    // 1a. Test for all available PersonAssociations
    for (PersonAssociation pa : PersonAssociation.values()) {
        PersonCriteria criteria = new PersonCriteria().personAssociation(pa);
        assertThat("Failed for testing association on count: " + pa.name(), cut.count(criteria), equalTo(0L));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
        assertThat("Failed for testing association on getIndexList: " + pa.name(), cut.getIndexList(criteria, offset, limit, sortProperties), is(empty()));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
    }
    // 1b. Test that calling with "null" as criteria also works
    assertThat(cut.count(null), equalTo(0L));
    assertThat(cut.getIndexList(null, offset, limit, sortProperties), is(empty()));
    // 2. Test paging windows
    final PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1920, 1, 1);
    final CaseDataDto case1 = creator.createCase(user.toReference(), person1.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    final PersonDto person2 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1920, 1, 1);
    final ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), person2.toReference(), null, new Date(), new Date(), Disease.EVD, rdcf);
    // 2a. count
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.ALL)), equalTo(2L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CASE)), equalTo(1L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CONTACT)), equalTo(1L));
    // 2b. getIndexList with all persons in the paging window
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 2;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 1;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    // 2c. getIndexList [PersonAssociation.ALL] with only the contact person in the paging window (default sorting by changeDate)
    offset = 1;
    limit = 2;
    assertPersonsFound(null, null, Arrays.asList(contact2.getPerson()), cut, offset, limit, sortProperties);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) PersonFacade(de.symeda.sormas.api.person.PersonFacade) UserDto(de.symeda.sormas.api.user.UserDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with PersonAssociation

use of de.symeda.sormas.api.person.PersonAssociation in project SORMAS-Project by hzi-braunschweig.

the class PersonService method createUserFilter.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate createUserFilter(PersonQueryContext personQueryContext, PersonCriteria personCriteria) {
    final CriteriaBuilder cb = personQueryContext.getCriteriaBuilder();
    final CriteriaQuery cq = personQueryContext.getQuery();
    final PersonJoins joins = (PersonJoins) personQueryContext.getJoins();
    final boolean fullImmunizationModuleUsed = !featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED);
    // 1. Define filters per association lazy to avoid superfluous joins
    final Supplier<Predicate> caseFilter = () -> CriteriaBuilderHelper.and(cb, caseService.createUserFilter(cb, cq, joins.getCaze(), new CaseUserFilterCriteria()), caseService.createDefaultFilter(cb, joins.getCaze()));
    final Supplier<Predicate> contactFilter = () -> {
        final Predicate contactUserFilter = contactService.createUserFilterForJoin(new ContactQueryContext(cb, cq, joins.getContact()), new ContactCriteria().includeContactsFromOtherJurisdictions(false));
        return CriteriaBuilderHelper.and(cb, contactUserFilter, contactService.createDefaultFilter(cb, joins.getContact()));
    };
    final Supplier<Predicate> eventParticipantFilter = () -> CriteriaBuilderHelper.and(cb, eventParticipantService.createUserFilterForJoin(cb, cq, joins.getEventParticipant(), new EventUserFilterCriteria().includeUserCaseAndEventParticipantFilter(false).forceRegionJurisdiction(true)), eventParticipantService.createDefaultFilter(cb, joins.getEventParticipant()));
    final Supplier<Predicate> immunizationFilter = fullImmunizationModuleUsed ? () -> CriteriaBuilderHelper.and(cb, immunizationService.createUserFilter(cb, cq, joins.getImmunization()), immunizationService.createDefaultFilter(cb, joins.getImmunization())) : () -> null;
    final Supplier<Predicate> travelEntryFilter = () -> CriteriaBuilderHelper.and(cb, travelEntryService.createUserFilter(cb, cq, joins.getTravelEntry()), travelEntryService.createDefaultFilter(cb, joins.getTravelEntry()));
    // 2. Define the Joins on associations where needed
    PersonAssociation personAssociation = Optional.ofNullable(personCriteria).map(e -> e.getPersonAssociation()).orElse(PersonCriteria.DEFAULT_ASSOCIATION);
    switch(personAssociation) {
        case ALL:
            return CriteriaBuilderHelper.or(cb, caseFilter.get(), contactFilter.get(), eventParticipantFilter.get(), fullImmunizationModuleUsed ? immunizationFilter.get() : null, travelEntryFilter.get());
        case CASE:
            return caseFilter.get();
        case CONTACT:
            return contactFilter.get();
        case EVENT_PARTICIPANT:
            return eventParticipantFilter.get();
        case IMMUNIZATION:
            if (!fullImmunizationModuleUsed) {
                throw new UnsupportedOperationException("Filtering persons by immunizations is not supported when the reduced immunization module is used.");
            }
            return immunizationFilter.get();
        case TRAVEL_ENTRY:
            return travelEntryFilter.get();
        default:
            throw new IllegalArgumentException(personAssociation.toString());
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FeatureType(de.symeda.sormas.api.feature.FeatureType) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Arrays(java.util.Arrays) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) GeocodingService(de.symeda.sormas.backend.geocoding.GeocodingService) Join(javax.persistence.criteria.Join) SIMILARITY_OPERATOR(de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect.SIMILARITY_OPERATOR) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) CriteriaBuilderHelper.andEquals(de.symeda.sormas.backend.common.CriteriaBuilderHelper.andEquals) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) EventUserFilterCriteria(de.symeda.sormas.backend.event.EventUserFilterCriteria) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) From(javax.persistence.criteria.From) CriteriaBuilderHelper.andEqualsReferenceDto(de.symeda.sormas.backend.common.CriteriaBuilderHelper.andEqualsReferenceDto) Path(javax.persistence.criteria.Path) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) CaseService(de.symeda.sormas.backend.caze.CaseService) Transactional(javax.transaction.Transactional) Timestamp(java.sql.Timestamp) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) Sex(de.symeda.sormas.api.person.Sex) Region(de.symeda.sormas.backend.infrastructure.region.Region) PersonHelper(de.symeda.sormas.api.person.PersonHelper) District(de.symeda.sormas.backend.infrastructure.district.District) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) List(java.util.List) Query(javax.persistence.Query) UserService(de.symeda.sormas.backend.user.UserService) Stream(java.util.stream.Stream) User(de.symeda.sormas.backend.user.User) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Location(de.symeda.sormas.backend.location.Location) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DateHelper(de.symeda.sormas.api.utils.DateHelper) Supplier(java.util.function.Supplier) TypedQuery(javax.persistence.TypedQuery) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) CollectionUtils(org.apache.commons.collections.CollectionUtils) AdoServiceWithUserFilter(de.symeda.sormas.backend.common.AdoServiceWithUserFilter) ChangeDateUuidComparator(de.symeda.sormas.backend.util.ChangeDateUuidComparator) TransactionAttribute(javax.ejb.TransactionAttribute) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CriteriaBuilderHelper.and(de.symeda.sormas.backend.common.CriteriaBuilderHelper.and) LocalBean(javax.ejb.LocalBean) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Disease(de.symeda.sormas.api.Disease) ContactService(de.symeda.sormas.backend.contact.ContactService) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) Collections(java.util.Collections) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) EventUserFilterCriteria(de.symeda.sormas.backend.event.EventUserFilterCriteria) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) Predicate(javax.persistence.criteria.Predicate) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation)

Example 4 with PersonAssociation

use of de.symeda.sormas.api.person.PersonAssociation in project SORMAS-Project by hzi-braunschweig.

the class PersonsView method createAssociationFilterBar.

public HorizontalLayout createAssociationFilterBar() {
    HorizontalLayout associationFilterLayout = new HorizontalLayout();
    associationFilterLayout.setSpacing(true);
    associationFilterLayout.setMargin(false);
    associationFilterLayout.setWidth(100, Unit.PERCENTAGE);
    associationFilterLayout.addStyleName(CssStyles.VSPACE_3);
    associationButtons = new HashMap<>();
    for (PersonAssociation association : PersonAssociation.values()) {
        if (association == PersonAssociation.IMMUNIZATION && (FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(FeatureType.IMMUNIZATION_MANAGEMENT) || FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) || association == PersonAssociation.TRAVEL_ENTRY && (FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(FeatureType.TRAVEL_ENTRIES) || !FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) || association == PersonAssociation.CONTACT && FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(FeatureType.CONTACT_TRACING) || association == PersonAssociation.CASE && FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(FeatureType.CASE_SURVEILANCE) || association == PersonAssociation.EVENT_PARTICIPANT && FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(FeatureType.EVENT_SURVEILLANCE)) {
            continue;
        }
        Button associationButton = ButtonHelper.createButton(association.toString(), e -> {
            if (!UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_USER) && association == PersonAssociation.ALL) {
                Label contentLabel = new Label(I18nProperties.getString(Strings.confirmationSeeAllPersons));
                VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingSeeAllPersons), contentLabel, I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, ee -> {
                    if (ee.booleanValue() == true) {
                        criteria.personAssociation(association);
                        navigateTo(criteria);
                    }
                });
            } else {
                criteria.personAssociation(association);
                navigateTo(criteria);
            }
        }, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER, CssStyles.BUTTON_FILTER_LIGHT);
        associationButton.setData(association);
        associationButton.setCaptionAsHtml(true);
        associationFilterLayout.addComponent(associationButton);
        associationFilterLayout.setComponentAlignment(associationButton, Alignment.MIDDLE_LEFT);
        associationButtons.put(associationButton, association.toString());
    }
    Label emptyLabel = new Label("");
    associationFilterLayout.addComponent(emptyLabel);
    associationFilterLayout.setComponentAlignment(emptyLabel, Alignment.MIDDLE_RIGHT);
    associationFilterLayout.setExpandRatio(emptyLabel, 1);
    return associationFilterLayout;
}
Also used : PopupButton(org.vaadin.hene.popupbutton.PopupButton) Button(com.vaadin.ui.Button) Label(com.vaadin.ui.Label) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

PersonAssociation (de.symeda.sormas.api.person.PersonAssociation)4 PersonCriteria (de.symeda.sormas.api.person.PersonCriteria)3 Disease (de.symeda.sormas.api.Disease)2 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)2 ExternalDataDto (de.symeda.sormas.api.externaldata.ExternalDataDto)2 ExternalDataUpdateException (de.symeda.sormas.api.externaldata.ExternalDataUpdateException)2 FeatureType (de.symeda.sormas.api.feature.FeatureType)2 FeatureTypeProperty (de.symeda.sormas.api.feature.FeatureTypeProperty)2 ApproximateAgeType (de.symeda.sormas.api.person.ApproximateAgeType)2 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)2 PersonDto (de.symeda.sormas.api.person.PersonDto)2 PersonFacade (de.symeda.sormas.api.person.PersonFacade)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 Date (java.util.Date)2 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)1 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)1 Phonenumber (com.google.i18n.phonenumbers.Phonenumber)1 Button (com.vaadin.ui.Button)1