Search in sources :

Example 1 with CaseFollowUpDto

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());
        });
    }
}
Also used : UuidRenderer(de.symeda.sormas.ui.utils.UuidRenderer) FollowUpUtils.getVisitResultDescription(de.symeda.sormas.ui.utils.FollowUpUtils.getVisitResultDescription) Date(java.util.Date) DescriptionGenerator(com.vaadin.ui.DescriptionGenerator) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) SortDirection(com.vaadin.shared.data.sort.SortDirection) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) ArrayList(java.util.ArrayList) FollowUpDto(de.symeda.sormas.api.followup.FollowUpDto) Label(com.vaadin.ui.Label) DataProvider(com.vaadin.data.provider.DataProvider) DateRenderer(com.vaadin.ui.renderers.DateRenderer) FilteredGrid(de.symeda.sormas.ui.utils.FilteredGrid) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) SortProperty(de.symeda.sormas.api.utils.SortProperty) Collectors(java.util.stream.Collectors) List(java.util.List) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) FollowUpUtils.getVisitResultCssStyle(de.symeda.sormas.ui.utils.FollowUpUtils.getVisitResultCssStyle) StyleGenerator(com.vaadin.ui.StyleGenerator) View(com.vaadin.navigator.View) StyleGenerator(com.vaadin.ui.StyleGenerator) Label(com.vaadin.ui.Label) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) Date(java.util.Date) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto)

Example 2 with CaseFollowUpDto

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;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Visit(de.symeda.sormas.backend.visit.Visit) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) ArrayList(java.util.ArrayList) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) Date(java.util.Date) LocalDate(java.time.LocalDate) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms)

Example 3 with CaseFollowUpDto

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);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto)

Example 4 with CaseFollowUpDto

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"));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseFollowUpDto(de.symeda.sormas.api.caze.CaseFollowUpDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseFollowUpDto (de.symeda.sormas.api.caze.CaseFollowUpDto)4 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)3 SortProperty (de.symeda.sormas.api.utils.SortProperty)3 Date (java.util.Date)3 VisitResultDto (de.symeda.sormas.api.visit.VisitResultDto)2 ArrayList (java.util.ArrayList)2 DataProvider (com.vaadin.data.provider.DataProvider)1 View (com.vaadin.navigator.View)1 SortDirection (com.vaadin.shared.data.sort.SortDirection)1 DescriptionGenerator (com.vaadin.ui.DescriptionGenerator)1 Label (com.vaadin.ui.Label)1 StyleGenerator (com.vaadin.ui.StyleGenerator)1 DateRenderer (com.vaadin.ui.renderers.DateRenderer)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 FollowUpDto (de.symeda.sormas.api.followup.FollowUpDto)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 DateHelper (de.symeda.sormas.api.utils.DateHelper)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1