Search in sources :

Example 1 with District

use of de.symeda.sormas.backend.infrastructure.district.District in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method getContactsForMap.

@Override
public List<MapContactDto> getContactsForMap(RegionReferenceDto regionRef, DistrictReferenceDto districtRef, Disease disease, Date from, Date to) {
    Region region = regionService.getByReferenceDto(regionRef);
    District district = districtService.getByReferenceDto(districtRef);
    return service.getContactsForMap(region, district, disease, from, to);
}
Also used : Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District)

Example 2 with District

use of de.symeda.sormas.backend.infrastructure.district.District in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method createDefaultInfrastructureData.

private void createDefaultInfrastructureData() {
    if (!configFacade.isCreateDefaultEntities()) {
        // return if isCreateDefaultEntities() is false
        logger.info("Skipping the creation of default infrastructure data");
        return;
    }
    // Region
    Region region = null;
    if (regionService.count() == 0) {
        region = defaultEntitiesCreator.createDefaultRegion(false);
        regionService.ensurePersisted(region);
    }
    // District
    District district = null;
    if (districtService.count() == 0) {
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        district = defaultEntitiesCreator.createDefaultDistrict(region, false);
        districtService.ensurePersisted(district);
        region.getDistricts().add(district);
    }
    // Community
    Community community = null;
    if (communityService.count() == 0) {
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        community = defaultEntitiesCreator.createDefaultCommunity(district, false);
        communityService.ensurePersisted(community);
        district.getCommunities().add(community);
    }
    // Facility
    Facility facility;
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    if (facilityFacade.count(facilityCriteria) == 0) {
        if (community == null) {
            community = communityService.getAll().get(0);
        }
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        facility = defaultEntitiesCreator.createDefaultFacility(region, district, community);
        facilityService.ensurePersisted(facility);
    }
    // Laboratory
    Facility laboratory;
    facilityCriteria.type(FacilityType.LABORATORY);
    if (facilityFacade.count(facilityCriteria) == 0) {
        if (community == null) {
            community = communityService.getAll().get(0);
        }
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        laboratory = defaultEntitiesCreator.createDefaultLaboratory(region, district, community);
        facilityService.ensurePersisted(laboratory);
    }
    // Point of Entry
    PointOfEntry pointOfEntry;
    if (pointOfEntryService.count() == 0) {
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        pointOfEntry = defaultEntitiesCreator.createDefaultPointOfEntry(region, district);
        pointOfEntryService.ensurePersisted(pointOfEntry);
    }
}
Also used : Region(de.symeda.sormas.backend.infrastructure.region.Region) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 3 with District

use of de.symeda.sormas.backend.infrastructure.district.District in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method getIndexList.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<PersonIndexDto> getIndexList(PersonCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    long startTime = DateHelper.startTime();
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<PersonIndexDto> cq = cb.createQuery(PersonIndexDto.class);
    final Root<Person> person = cq.from(Person.class);
    final PersonQueryContext personQueryContext = new PersonQueryContext(cb, cq, person);
    final PersonJoins personJoins = (PersonJoins) personQueryContext.getJoins();
    personJoins.configure(criteria);
    final Join<Person, Location> location = personJoins.getAddress();
    final Join<Location, District> district = personJoins.getAddressJoins().getDistrict();
    final Subquery<String> phoneSubQuery = cq.subquery(String.class);
    final Root<PersonContactDetail> phoneRoot = phoneSubQuery.from(PersonContactDetail.class);
    phoneSubQuery.where(cb.and(cb.equal(phoneRoot.get(PersonContactDetail.PERSON), person), cb.isTrue(phoneRoot.get(PersonContactDetail.PRIMARY_CONTACT)), cb.equal(phoneRoot.get(PersonContactDetail.PERSON_CONTACT_DETAIL_TYPE), PersonContactDetailType.PHONE)));
    phoneSubQuery.select(phoneRoot.get(PersonContactDetail.CONTACT_INFORMATION));
    final Subquery<String> emailSubQuery = cq.subquery(String.class);
    final Root<PersonContactDetail> emailRoot = emailSubQuery.from(PersonContactDetail.class);
    emailSubQuery.where(cb.and(cb.equal(emailRoot.get(PersonContactDetail.PERSON), person), cb.isTrue(emailRoot.get(PersonContactDetail.PRIMARY_CONTACT)), cb.equal(emailRoot.get(PersonContactDetail.PERSON_CONTACT_DETAIL_TYPE), PersonContactDetailType.EMAIL)));
    emailSubQuery.select(emailRoot.get(PersonContactDetail.CONTACT_INFORMATION));
    // make sure to check the sorting by the multi-select order if you extend the selections here
    cq.multiselect(person.get(Person.UUID), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), person.get(Person.BIRTHDATE_DD), person.get(Person.BIRTHDATE_MM), person.get(Person.BIRTHDATE_YYYY), person.get(Person.SEX), district.get(District.NAME), location.get(Location.STREET), location.get(Location.HOUSE_NUMBER), location.get(Location.POSTAL_CODE), location.get(Location.CITY), phoneSubQuery.alias(PersonIndexDto.PHONE), emailSubQuery.alias(PersonIndexDto.EMAIL_ADDRESS), person.get(Person.CHANGE_DATE), JurisdictionHelper.booleanSelector(cb, personService.inJurisdictionOrOwned(personQueryContext)));
    Predicate filter = createIndexListFilter(criteria, personQueryContext);
    if (filter != null) {
        cq.where(filter);
    }
    cq.distinct(true);
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<Order>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case PersonIndexDto.UUID:
                case PersonIndexDto.FIRST_NAME:
                case PersonIndexDto.LAST_NAME:
                case PersonIndexDto.SEX:
                    expression = person.get(sortProperty.propertyName);
                    break;
                case PersonIndexDto.PHONE:
                    // order in the multiselect - Postgres limitation - needed to make sure it uses the same expression for ordering
                    expression = cb.literal(15);
                    break;
                case PersonIndexDto.EMAIL_ADDRESS:
                    // order in the multiselect - Postgres limitation - needed to make sure it uses the same expression for ordering
                    expression = cb.literal(16);
                    break;
                case PersonIndexDto.AGE_AND_BIRTH_DATE:
                    expression = person.get(Person.APPROXIMATE_AGE);
                    break;
                case PersonIndexDto.DISTRICT:
                    expression = district.get(District.NAME);
                    break;
                case PersonIndexDto.STREET:
                case PersonIndexDto.HOUSE_NUMBER:
                case PersonIndexDto.POSTAL_CODE:
                case PersonIndexDto.CITY:
                    expression = location.get(sortProperty.propertyName);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.desc(person.get(Person.CHANGE_DATE)));
    }
    List<PersonIndexDto> persons = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(PersonIndexDto.class, persons, p -> p.getInJurisdiction(), (p, isInJurisdiction) -> pseudonymizer.pseudonymizeDto(AgeAndBirthDateDto.class, p.getAgeAndBirthDate(), isInJurisdiction, null));
    logger.debug("getIndexList() finished. association={}, count={}, {}ms", Optional.ofNullable(criteria).orElse(new PersonCriteria()).getPersonAssociation().name(), persons.size(), DateHelper.durationMillies(startTime));
    return persons;
}
Also used : AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) District(de.symeda.sormas.backend.infrastructure.district.District) Location(de.symeda.sormas.backend.location.Location)

Example 4 with District

use of de.symeda.sormas.backend.infrastructure.district.District in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method getDeathsBetween.

@Override
public List<PersonDto> getDeathsBetween(Date fromDate, Date toDate, DistrictReferenceDto districtRef, Disease disease) {
    final User user = userService.getCurrentUser();
    if (user == null) {
        return Collections.emptyList();
    }
    final District district = districtService.getByReferenceDto(districtRef);
    return toPseudonymizedDtos(personService.getDeathsBetween(fromDate, toDate, district, disease, user));
}
Also used : User(de.symeda.sormas.backend.user.User) District(de.symeda.sormas.backend.infrastructure.district.District)

Example 5 with District

use of de.symeda.sormas.backend.infrastructure.district.District in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method countCasesForMap.

public Long countCasesForMap(RegionReferenceDto regionRef, DistrictReferenceDto districtRef, Disease disease, Date from, Date to, NewCaseDateType dateType) {
    Region region = regionService.getByReferenceDto(regionRef);
    District district = districtService.getByReferenceDto(districtRef);
    return service.countCasesForMap(region, district, disease, from, to, dateType);
}
Also used : Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District)

Aggregations

District (de.symeda.sormas.backend.infrastructure.district.District)87 Region (de.symeda.sormas.backend.infrastructure.region.Region)60 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)36 Predicate (javax.persistence.criteria.Predicate)34 Community (de.symeda.sormas.backend.infrastructure.community.Community)32 ArrayList (java.util.ArrayList)24 Facility (de.symeda.sormas.backend.infrastructure.facility.Facility)21 Test (org.junit.Test)20 Order (javax.persistence.criteria.Order)19 SortProperty (de.symeda.sormas.api.utils.SortProperty)18 User (de.symeda.sormas.backend.user.User)18 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)16 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)16 Date (java.util.Date)16 Location (de.symeda.sormas.backend.location.Location)14 List (java.util.List)12 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)11 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)11 Case (de.symeda.sormas.backend.caze.Case)11 Collectors (java.util.stream.Collectors)11