use of de.symeda.sormas.api.contact.ContactFollowUpDto 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.contact.ContactFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFollowUpGrid method setVisitColumns.
public void setVisitColumns(ContactCriteria 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);
dateColumnIds.clear();
for (int i = 0; i < interval; i++) {
String columnId = DateFormatHelper.formatDate(dates.get(i));
dateColumnIds.add(columnId);
addComponentColumn(followUpDto -> new Label("")).setId(columnId);
final int index = i;
getColumn(columnId).setCaption(columnId).setSortable(false).setStyleGenerator((StyleGenerator<ContactFollowUpDto>) item -> {
final VisitResultDto visitResult = item.getVisitResults()[index];
final Date date = dates.get(index);
return getVisitResultCssStyle(visitResult, date, ContactLogic.getStartDate(item.getLastContactDate(), item.getReportDate()), item.getFollowUpUntil());
}).setDescriptionGenerator((DescriptionGenerator<ContactFollowUpDto>) item -> {
final VisitResultDto visitResult = item.getVisitResults()[index];
final Date date = dates.get(index);
return getVisitResultDescription(visitResult, date, ContactLogic.getStartDate(item.getLastContactDate(), item.getReportDate()), item.getFollowUpUntil());
});
}
}
use of de.symeda.sormas.api.contact.ContactFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method getContactFollowUpList.
@Override
public List<ContactFollowUpDto> getContactFollowUpList(ContactCriteria contactCriteria, 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<ContactFollowUpDto> cq = cb.createQuery(ContactFollowUpDto.class);
Root<Contact> contact = cq.from(Contact.class);
final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
final ContactJoins joins = contactQueryContext.getJoins();
cq.multiselect(contact.get(Contact.UUID), contact.get(Contact.CHANGE_DATE), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getContactOfficer().get(User.UUID), joins.getContactOfficer().get(User.FIRST_NAME), joins.getContactOfficer().get(User.LAST_NAME), contact.get(Contact.LAST_CONTACT_DATE), contact.get(Contact.REPORT_DATE_TIME), contact.get(Contact.FOLLOW_UP_UNTIL), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), contact.get(Contact.DISEASE), jurisdictionSelector(contactQueryContext));
// Only use user filter if no restricting case is specified
Predicate filter = listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext);
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 FollowUpDto.UUID:
case ContactFollowUpDto.LAST_CONTACT_DATE:
case FollowUpDto.FOLLOW_UP_UNTIL:
expression = contact.get(sortProperty.propertyName);
break;
case FollowUpDto.REPORT_DATE:
expression = contact.get(Contact.REPORT_DATE_TIME);
break;
case FollowUpDto.SYMPTOM_JOURNAL_STATUS:
expression = joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS);
break;
case FollowUpDto.FIRST_NAME:
expression = joins.getPerson().get(Person.FIRST_NAME);
break;
case FollowUpDto.LAST_NAME:
expression = joins.getPerson().get(Person.LAST_NAME);
break;
case ContactFollowUpDto.CONTACT_OFFICER:
expression = joins.getContactOfficer().get(User.FIRST_NAME);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
expression = joins.getContactOfficer().get(User.LAST_NAME);
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(contact.get(Contact.CHANGE_DATE)));
}
List<ContactFollowUpDto> resultList = QueryHelper.getResultList(em, cq, first, max);
if (!resultList.isEmpty()) {
List<String> contactUuids = resultList.stream().map(d -> d.getUuid()).collect(Collectors.toList());
CriteriaQuery<Object[]> visitsCq = cb.createQuery(Object[].class);
Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
Join<Contact, Visit> visitsJoin = visitsCqRoot.join(Contact.VISITS, JoinType.LEFT);
Join<Visit, Symptoms> visitSymptomsJoin = visitsJoin.join(Visit.SYMPTOMS, JoinType.LEFT);
visitsCq.where(CriteriaBuilderHelper.and(cb, contact.get(AbstractDomainObject.UUID).in(contactUuids), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS)), cb.between(visitsJoin.get(Visit.VISIT_DATE_TIME), start, end)));
visitsCq.multiselect(visitsCqRoot.get(Contact.UUID), visitsJoin.get(Visit.VISIT_DATE_TIME), visitsJoin.get(Visit.VISIT_STATUS), visitsJoin.get(Visit.ORIGIN), visitSymptomsJoin.get(Symptoms.SYMPTOMATIC));
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, ContactFollowUpDto> resultMap = resultList.stream().collect(Collectors.toMap(ContactFollowUpDto::getUuid, Function.identity()));
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
for (ContactFollowUpDto contactFollowUpDto : resultMap.values()) {
contactFollowUpDto.initVisitSize(interval + 1);
boolean isInJurisdiction = contactFollowUpDto.getInJurisdiction();
pseudonymizer.pseudonymizeDto(ContactFollowUpDto.class, contactFollowUpDto, isInJurisdiction, 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.contact.ContactFollowUpDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbPseudonymizationTest method testPseudonymizeGetFollowupList.
@Test
public void testPseudonymizeGetFollowupList() {
CaseDataDto caze = createCase(user1, rdcf1);
ContactDto contact1 = createContact(user2, caze, rdcf2);
// contact of case on other jurisdiction --> should be pseudonymized
ContactDto contact2 = creator.createContact(user1.toReference(), user1.toReference(), createPerson().toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
List<ContactFollowUpDto> matchingContacts = getContactFacade().getContactFollowUpList(contactCriteria, new Date(), 10, 0, 100, Collections.emptyList());
ContactFollowUpDto followup1 = matchingContacts.stream().filter(c -> c.getUuid().equals(contact1.getUuid())).findFirst().get();
assertThat(followup1.getFirstName(), is("James"));
assertThat(followup1.getLastName(), is("Smith"));
// sensitive data
assertThat(followup1.getContactOfficer(), is(user2));
ContactFollowUpDto followup2 = matchingContacts.stream().filter(c -> c.getUuid().equals(contact2.getUuid())).findFirst().get();
assertThat(followup2.getFirstName(), is("Confidential"));
assertThat(followup2.getLastName(), is("Confidential"));
// sensitive data
assertThat(followup2.getContactOfficer(), is(nullValue()));
}
Aggregations