use of de.symeda.sormas.api.utils.SortProperty 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.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class AdditionalTestService method getIndexList.
public List<AdditionalTest> getIndexList(AdditionalTestCriteria additionalTestCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<AdditionalTest> cq = cb.createQuery(getElementClass());
Root<AdditionalTest> from = cq.from(getElementClass());
Predicate filter = null;
if (additionalTestCriteria != null) {
filter = buildCriteriaFilter(additionalTestCriteria, cb, from);
}
if (filter != null) {
cq.where(filter);
}
cq.orderBy(cb.desc(from.get(AdditionalTest.CHANGE_DATE)));
cq.distinct(true);
List<Order> order = new ArrayList<>();
if (sortProperties != null && sortProperties.size() > 0) {
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case AdditionalTest.UUID:
case AdditionalTest.SAMPLE:
case AdditionalTest.TEST_DATE_TIME:
expression = from.get(sortProperty.propertyName);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
}
order.add(cb.desc(from.get(AdditionalTest.UUID)));
cq.orderBy(order);
return QueryHelper.getResultList(em, cq, first, max);
}
use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class PathogenTestService method getIndexList.
public List<PathogenTest> getIndexList(PathogenTestCriteria pathogenTestCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PathogenTest> cq = cb.createQuery(getElementClass());
Root<PathogenTest> from = cq.from(getElementClass());
Predicate filter = null;
if (pathogenTestCriteria != null) {
filter = buildCriteriaFilter(pathogenTestCriteria, cb, from);
}
if (filter != null) {
cq.where(filter);
}
cq.orderBy(cb.desc(from.get(PathogenTest.CHANGE_DATE)));
cq.distinct(true);
List<Order> order = new ArrayList<>();
if (sortProperties != null && sortProperties.size() > 0) {
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case PathogenTest.UUID:
case PathogenTest.SAMPLE:
case PathogenTest.TEST_DATE_TIME:
expression = from.get(sortProperty.propertyName);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
}
order.add(cb.desc(from.get(PathogenTest.UUID)));
cq.orderBy(order);
return QueryHelper.getResultList(em, cq, first, max);
}
use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationGrid method setLazyDataProvider.
private void setLazyDataProvider() {
DataProvider<ImmunizationIndexDto, ImmunizationCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getImmunizationFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getImmunizationFacade().count(query.getFilter().orElse(null)));
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
}
use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class ClinicalVisitFacadeEjb method getIndexList.
@Override
public List<ClinicalVisitIndexDto> getIndexList(ClinicalVisitCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ClinicalVisitIndexDto> cq = cb.createQuery(ClinicalVisitIndexDto.class);
Root<ClinicalVisit> visit = cq.from(ClinicalVisit.class);
ClinicalVisitJoins joins = new ClinicalVisitJoins(visit);
cq.multiselect(visit.get(ClinicalVisit.UUID), visit.get(ClinicalVisit.VISIT_DATE_TIME), visit.get(ClinicalVisit.VISITING_PERSON), visit.get(ClinicalVisit.VISIT_REMARKS), joins.getSymptoms().get(Symptoms.TEMPERATURE), joins.getSymptoms().get(Symptoms.TEMPERATURE_SOURCE), joins.getSymptoms().get(Symptoms.BLOOD_PRESSURE_SYSTOLIC), joins.getSymptoms().get(Symptoms.BLOOD_PRESSURE_DIASTOLIC), joins.getSymptoms().get(Symptoms.HEART_RATE), joins.getSymptoms().get(Symptoms.ID), JurisdictionHelper.booleanSelector(cb, caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, cq, joins.getCaze()))));
if (criteria != null) {
cq.where(service.buildCriteriaFilter(criteria, cb, visit));
}
if (CollectionUtils.isNotEmpty(sortProperties)) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case ClinicalVisitDto.UUID:
case ClinicalVisitDto.DISEASE:
case ClinicalVisitDto.VISIT_DATE_TIME:
case ClinicalVisitDto.CLINICAL_COURSE:
expression = visit.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(visit.get(ClinicalVisit.VISIT_DATE_TIME)));
}
List<ClinicalVisitIndexDto> results = QueryHelper.getResultList(em, cq, first, max);
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
pseudonymizer.pseudonymizeDtoCollection(ClinicalVisitIndexDto.class, results, v -> v.getInJurisdiction(), null);
return results;
}
Aggregations