use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method getCaseFollowUpList.
@Override
public List<CaseFollowUpDto> getCaseFollowUpList(CaseCriteria caseCriteria, Date referenceDate, int interval, Integer first, Integer max, List<SortProperty> sortProperties) {
Date end = DateHelper.getEndOfDay(referenceDate);
Date start = DateHelper.getStartOfDay(DateHelper.subtractDays(end, interval));
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<CaseFollowUpDto> cq = cb.createQuery(CaseFollowUpDto.class);
Root<Case> caze = cq.from(Case.class);
final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, caze);
final CaseJoins joins = caseQueryContext.getJoins();
cq.multiselect(caze.get(Case.UUID), caze.get(Case.CHANGE_DATE), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), caze.get(Case.REPORT_DATE), joins.getSymptoms().get(Symptoms.ONSET_DATE), caze.get(Case.FOLLOW_UP_UNTIL), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), caze.get(Case.DISEASE), JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(caseQueryContext)));
Predicate filter = CriteriaBuilderHelper.and(cb, service.createUserFilter(caseQueryContext), service.createCriteriaFilter(caseCriteria, caseQueryContext));
if (filter != null) {
cq.where(filter);
}
cq.distinct(true);
if (sortProperties != null && !sortProperties.isEmpty()) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case FollowUpDto.UUID:
case FollowUpDto.REPORT_DATE:
case FollowUpDto.FOLLOW_UP_UNTIL:
expression = caze.get(sortProperty.propertyName);
break;
case FollowUpDto.FIRST_NAME:
expression = joins.getPerson().get(Person.FIRST_NAME);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
break;
case FollowUpDto.SYMPTOM_JOURNAL_STATUS:
expression = joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS);
break;
case FollowUpDto.LAST_NAME:
expression = joins.getPerson().get(Person.LAST_NAME);
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));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.desc(caze.get(Case.CHANGE_DATE)));
}
List<CaseFollowUpDto> resultList = QueryHelper.getResultList(em, cq, first, max);
if (!resultList.isEmpty()) {
List<String> caseUuids = resultList.stream().map(FollowUpDto::getUuid).collect(Collectors.toList());
CriteriaQuery<Object[]> visitsCq = cb.createQuery(Object[].class);
Root<Case> visitsCqRoot = visitsCq.from(Case.class);
Join<Case, Visit> visitsJoin = visitsCqRoot.join(Case.VISITS, JoinType.LEFT);
Join<Visit, Symptoms> visitSymptomsJoin = visitsJoin.join(Visit.SYMPTOMS, JoinType.LEFT);
visitsCq.where(CriteriaBuilderHelper.and(cb, caze.get(AbstractDomainObject.UUID).in(caseUuids), cb.isNotEmpty(visitsCqRoot.get(Case.VISITS)), cb.between(visitsJoin.get(Visit.VISIT_DATE_TIME), start, end)));
visitsCq.multiselect(visitsCqRoot.get(Case.UUID), visitsJoin.get(Visit.VISIT_DATE_TIME), visitsJoin.get(Visit.VISIT_STATUS), visitsJoin.get(Visit.ORIGIN), visitSymptomsJoin.get(Symptoms.SYMPTOMATIC));
// Sort by visit date so that we'll have the latest visit of each day
visitsCq.orderBy(cb.asc(visitsJoin.get(Visit.VISIT_DATE_TIME)));
visitsCq.orderBy(cb.asc(visitsJoin.get(Visit.VISIT_DATE_TIME)), cb.asc(visitsJoin.get(Visit.CREATION_DATE)));
List<Object[]> visits = em.createQuery(visitsCq).getResultList();
Map<String, CaseFollowUpDto> resultMap = resultList.stream().collect(Collectors.toMap(CaseFollowUpDto::getUuid, Function.identity()));
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
for (CaseFollowUpDto caseFollowUpDto : resultMap.values()) {
caseFollowUpDto.initVisitSize(interval + 1);
pseudonymizer.pseudonymizeDto(CaseFollowUpDto.class, caseFollowUpDto, caseFollowUpDto.getInJurisdiction(), null);
}
for (Object[] v : visits) {
int day = DateHelper.getDaysBetween(start, (Date) v[1]);
VisitResultDto result = getVisitResult((VisitStatus) v[2], (VisitOrigin) v[3], (Boolean) v[4]);
resultMap.get(v[0]).getVisitResults()[day - 1] = result;
}
}
return resultList;
}
use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class CampaignFacadeEjb method getIndexList.
@Override
public List<CampaignIndexDto> getIndexList(CampaignCriteria campaignCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<CampaignIndexDto> cq = cb.createQuery(CampaignIndexDto.class);
Root<Campaign> campaign = cq.from(Campaign.class);
CampaignQueryContext queryContext = new CampaignQueryContext(cb, cq, campaign);
cq.multiselect(campaign.get(Campaign.UUID), campaign.get(Campaign.NAME), campaign.get(Campaign.START_DATE), campaign.get(Campaign.END_DATE));
Predicate filter = service.createUserFilter(queryContext);
if (campaignCriteria != null) {
Predicate criteriaFilter = service.buildCriteriaFilter(queryContext, campaignCriteria);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
}
cq.where(filter);
if (sortProperties != null && sortProperties.size() > 0) {
List<Order> order = new ArrayList<Order>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case CampaignIndexDto.UUID:
case CampaignIndexDto.NAME:
case CampaignIndexDto.START_DATE:
case CampaignIndexDto.END_DATE:
expression = campaign.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(campaign.get(Campaign.CHANGE_DATE)));
}
return QueryHelper.getResultList(em, cq, first, max);
}
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.getCaseJoins()))));
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;
}
use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.
the class ContactFollowUpGrid method setDataProvider.
public void setDataProvider(Date referenceDate, int interval) {
DataProvider<ContactFollowUpDto, ContactCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getContactFacade().getContactFollowUpList(query.getFilter().orElse(null), referenceDate, interval, query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getContactFacade().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 PointsOfEntryGrid method setLazyDataProvider.
public void setLazyDataProvider() {
DataProvider<PointOfEntryDto, PointOfEntryCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getPointOfEntryFacade().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 -> {
return (int) FacadeProvider.getPointOfEntryFacade().count(query.getFilter().orElse(null));
});
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
}
Aggregations