use of de.symeda.sormas.api.caze.CaseFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFollowUpGrid method setVisitColumns.
public void setVisitColumns(CaseCriteria criteria) {
Date referenceDate = criteria.getFollowUpVisitsTo();
int interval = criteria.getFollowUpVisitsInterval();
setDataProvider(referenceDate, interval - 1);
setCriteria(criteria);
dates.forEach(date -> removeColumn(DateFormatHelper.formatDate(date)));
setDates(referenceDate, interval);
for (int i = 0; i < interval; i++) {
String columnId = DateFormatHelper.formatDate(dates.get(i));
addComponentColumn(followUpDto -> new Label("")).setId(columnId);
final int index = i;
getColumn(columnId).setCaption(columnId).setSortable(false).setStyleGenerator((StyleGenerator<CaseFollowUpDto>) item -> {
final VisitResultDto visitResult = item.getVisitResults()[index];
final Date date = dates.get(index);
return getVisitResultCssStyle(visitResult, date, item.getReportDate(), item.getFollowUpUntil());
}).setDescriptionGenerator((DescriptionGenerator<CaseFollowUpDto>) item -> {
final VisitResultDto visitResult = item.getVisitResults()[index];
final Date date = dates.get(index);
return getVisitResultDescription(visitResult, date, item.getReportDate(), item.getFollowUpUntil());
});
}
}
use of de.symeda.sormas.api.caze.CaseFollowUpDto 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.caze.CaseFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFollowUpGrid method setDataProvider.
public void setDataProvider(Date referenceDate, int interval) {
DataProvider<CaseFollowUpDto, CaseCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getCaseFacade().getCaseFollowUpList(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.getCaseFacade().count(query.getFilter().orElse(null)));
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
}
use of de.symeda.sormas.api.caze.CaseFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjbPseudonymizationTest method testPseudonymizeGetFollowupList.
@Test
public void testPseudonymizeGetFollowupList() {
CaseDataDto caze1 = createCase(rdcf1, user1);
ContactDto contact1 = createContact(user2, caze1, rdcf1);
ContactDto contact2 = createContact(user2, caze1, rdcf1);
assertThat(contact1.getUuid(), not(is(contact2.getUuid())));
// case in other jurisdiction, but visible since linked via contacts reported by user
// --> should be pseudonymized
CaseDataDto caze2 = createCase(rdcf2, user2);
CaseDataDto caze3 = createCase(rdcf2, user1);
CaseCriteria caseCriteria = new CaseCriteria();
caseCriteria.setIncludeCasesFromOtherJurisdictions(true);
List<CaseFollowUpDto> caseFollowUpList = getCaseFacade().getCaseFollowUpList(caseCriteria, new Date(), 10, 0, 100, Collections.emptyList());
assertThat(caseFollowUpList.size(), is(3));
CaseFollowUpDto followup1 = caseFollowUpList.stream().filter(c -> c.getUuid().equals(caze1.getUuid())).findFirst().get();
assertThat(followup1.getFirstName(), is("Confidential"));
assertThat(followup1.getLastName(), is("Confidential"));
CaseFollowUpDto followup2 = caseFollowUpList.stream().filter(c -> c.getUuid().equals(caze2.getUuid())).findFirst().get();
assertThat(followup2.getFirstName(), is("James"));
assertThat(followup2.getLastName(), is("Smith"));
CaseFollowUpDto followup3 = caseFollowUpList.stream().filter(c -> c.getUuid().equals(caze3.getUuid())).findFirst().get();
assertThat(followup3.getFirstName(), is("James"));
assertThat(followup3.getLastName(), is("Smith"));
}
Aggregations