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);
}
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);
}
}
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;
}
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));
}
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);
}
Aggregations