Search in sources :

Example 1 with VisitIndexDto

use of de.symeda.sormas.api.visit.VisitIndexDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    UserDto user = creator.createUser(creator.createRDCF(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto person = creator.createPerson();
    PersonDto person2 = creator.createPerson();
    PersonDto person3 = creator.createPerson();
    PersonDto person4 = creator.createPerson();
    PersonDto person5 = creator.createPerson();
    ContactDto contact = creator.createContact(user.toReference(), person.toReference());
    creator.createContact(user.toReference(), person2.toReference());
    ContactDto contact2 = creator.createContact(user.toReference(), person3.toReference());
    CaseDataDto caze = creator.createCase(user.toReference(), person5.toReference(), creator.createRDCF());
    creator.createCase(user.toReference(), person4.toReference(), creator.createRDCF());
    CaseDataDto caze2 = creator.createCase(user.toReference(), person3.toReference(), creator.createRDCF());
    creator.createVisit(person.toReference());
    creator.createVisit(person.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person5.toReference());
    VisitDto otherVisit = creator.createVisit(person2.toReference());
    VisitDto otherVisit2 = creator.createVisit(person4.toReference());
    List<VisitIndexDto> indexVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(contact.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(2));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    indexVisits = getVisitFacade().getIndexList(new VisitCriteria().caze(caze.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(1));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    indexVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(contact2.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(3));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    List<VisitIndexDto> indexVisits2 = getVisitFacade().getIndexList(new VisitCriteria().caze(caze2.toReference()), null, null, null);
    assertEquals(indexVisits.size(), indexVisits2.size());
    for (int i = 0; i < indexVisits.size(); ++i) {
        assertEquals(indexVisits.get(i).getUuid(), indexVisits2.get(i).getUuid());
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with VisitIndexDto

use of de.symeda.sormas.api.visit.VisitIndexDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testCreateExternalVisit.

@Test
public void testCreateExternalVisit() {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Ext", "Vis", UserRole.REST_EXTERNAL_VISITS_USER);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    final ExternalVisitDto externalVisitDto = new ExternalVisitDto();
    externalVisitDto.setPersonUuid(contactPerson.getUuid());
    externalVisitDto.setDisease(contact.getDisease());
    externalVisitDto.setVisitDateTime(new Date());
    externalVisitDto.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks = "Everything good";
    externalVisitDto.setVisitRemarks(visitRemarks);
    final ExternalVisitDto externalVisitDto2 = new ExternalVisitDto();
    externalVisitDto2.setPersonUuid(cazePerson.getUuid());
    externalVisitDto2.setDisease(caze.getDisease());
    externalVisitDto2.setVisitDateTime(new Date());
    externalVisitDto2.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks2 = "Everything good 2";
    externalVisitDto2.setVisitRemarks(visitRemarks2);
    final VisitFacade visitFacade = getVisitFacade();
    visitFacade.saveExternalVisit(externalVisitDto);
    visitFacade.saveExternalVisit(externalVisitDto2);
    final VisitCriteria visitCriteria = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList = visitFacade.getIndexList(visitCriteria.contact(new ContactReferenceDto(contact.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList);
    assertEquals(1, visitIndexList.size());
    VisitIndexDto visitIndexDto = visitIndexList.get(0);
    assertNotNull(visitIndexDto.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto.getVisitStatus());
    assertEquals(visitRemarks, visitIndexDto.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
    final VisitCriteria visitCriteria2 = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList2 = visitFacade.getIndexList(visitCriteria2.caze(new CaseReferenceDto(caze.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList2);
    assertEquals(1, visitIndexList2.size());
    VisitIndexDto visitIndexDto2 = visitIndexList2.get(0);
    assertNotNull(visitIndexDto2.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto2.getVisitStatus());
    assertEquals(visitRemarks2, visitIndexDto2.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
}
Also used : ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) VisitFacade(de.symeda.sormas.api.visit.VisitFacade) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with VisitIndexDto

use of de.symeda.sormas.api.visit.VisitIndexDto in project SORMAS-Project by hzi-braunschweig.

the class ContactVisitsView method createTopBar.

public HorizontalLayout createTopBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);
    topLayout.setWidth(100, Unit.PERCENTAGE);
    topLayout.addStyleName(CssStyles.VSPACE_3);
    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        topLayout.setWidth(100, Unit.PERCENTAGE);
        MenuBar bulkOperationsDropdown = MenuBarHelper.createDropDown(Captions.bulkActions, new MenuBarHelper.MenuBarItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH, selectedItem -> {
            ControllerProvider.getVisitController().deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {

                public void run() {
                    navigateTo(criteria);
                }
            });
        }));
        topLayout.addComponent(bulkOperationsDropdown);
        topLayout.setComponentAlignment(bulkOperationsDropdown, Alignment.MIDDLE_RIGHT);
        topLayout.setExpandRatio(bulkOperationsDropdown, 1);
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.VISIT_EXPORT)) {
        Button exportButton = ButtonHelper.createIconButton(Captions.export, VaadinIcons.DOWNLOAD, null, ValoTheme.BUTTON_PRIMARY);
        {
            topLayout.addComponent(exportButton);
            topLayout.setComponentAlignment(exportButton, Alignment.MIDDLE_RIGHT);
            if (topLayout.getComponentCount() == 1) {
                topLayout.setExpandRatio(exportButton, 1);
            }
        }
        StreamResource exportStreamResource = DownloadUtil.createCsvExportStreamResource(VisitExportDto.class, VisitExportType.CONTACT_VISITS, (Integer start, Integer max) -> FacadeProvider.getVisitFacade().getVisitsExportList(grid.getCriteria(), grid.getSelectionModel() instanceof MultiSelectionModelImpl ? grid.asMultiSelect().getSelectedItems().stream().map(VisitIndexDto::getUuid).collect(Collectors.toSet()) : null, VisitExportType.CONTACT_VISITS, start, max, null), (propertyId, type) -> {
            String caption = findPrefixCaption(propertyId, VisitExportDto.I18N_PREFIX, VisitDto.I18N_PREFIX, PersonDto.I18N_PREFIX, SymptomsDto.I18N_PREFIX);
            if (Date.class.isAssignableFrom(type)) {
                caption += " (" + DateFormatHelper.getDateFormatPattern() + ")";
            }
            return caption;
        }, ExportEntityName.CONTACT_VISITS, null);
        new FileDownloader(exportStreamResource).extend(exportButton);
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.VISIT_CREATE)) {
        newButton = ButtonHelper.createIconButton(Captions.visitNewVisit, VaadinIcons.PLUS_CIRCLE, e -> ControllerProvider.getVisitController().createVisit(this.getContactRef(), r -> navigateTo(criteria)), ValoTheme.BUTTON_PRIMARY);
        topLayout.addComponent(newButton);
        topLayout.setComponentAlignment(newButton, Alignment.MIDDLE_RIGHT);
        final ContactDto contactDto = FacadeProvider.getContactFacade().getByUuid(this.getContactRef().getUuid());
        if (contactDto.getResultingCase() != null) {
            newButton.setEnabled(false);
            final Label label = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
            label.setDescription(I18nProperties.getString(Strings.infoContactAlreadyConvertedToCase));
            topLayout.addComponent(label);
            topLayout.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);
        }
    }
    return topLayout;
}
Also used : StreamResource(com.vaadin.server.StreamResource) VisitGrid(de.symeda.sormas.ui.visit.VisitGrid) Date(java.util.Date) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) Alignment(com.vaadin.ui.Alignment) VisitExportDto(de.symeda.sormas.api.visit.VisitExportDto) PersonDto(de.symeda.sormas.api.person.PersonDto) DetailSubComponentWrapper(de.symeda.sormas.ui.utils.DetailSubComponentWrapper) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) ExportEntityName(de.symeda.sormas.ui.utils.ExportEntityName) ViewModelProviders(de.symeda.sormas.ui.ViewModelProviders) CssStyles(de.symeda.sormas.ui.utils.CssStyles) MenuBarHelper(de.symeda.sormas.ui.utils.MenuBarHelper) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) UserProvider(de.symeda.sormas.ui.UserProvider) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) ContentMode(com.vaadin.shared.ui.ContentMode) DownloadUtil(de.symeda.sormas.ui.utils.DownloadUtil) VisitExportType(de.symeda.sormas.api.visit.VisitExportType) MenuBar(com.vaadin.ui.MenuBar) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) UserRight(de.symeda.sormas.api.user.UserRight) Button(com.vaadin.ui.Button) VisitDto(de.symeda.sormas.api.visit.VisitDto) MultiSelectionModelImpl(com.vaadin.ui.components.grid.MultiSelectionModelImpl) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ContactDto(de.symeda.sormas.api.contact.ContactDto) FileDownloader(com.vaadin.server.FileDownloader) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) Strings(de.symeda.sormas.api.i18n.Strings) Label(com.vaadin.ui.Label) MenuBar(com.vaadin.ui.MenuBar) HorizontalLayout(com.vaadin.ui.HorizontalLayout) MenuBarHelper(de.symeda.sormas.ui.utils.MenuBarHelper) StreamResource(com.vaadin.server.StreamResource) Button(com.vaadin.ui.Button) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) MultiSelectionModelImpl(com.vaadin.ui.components.grid.MultiSelectionModelImpl) ContactDto(de.symeda.sormas.api.contact.ContactDto) FileDownloader(com.vaadin.server.FileDownloader)

Example 4 with VisitIndexDto

use of de.symeda.sormas.api.visit.VisitIndexDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjb method getIndexList.

@Override
public List<VisitIndexDto> getIndexList(VisitCriteria visitCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    if (visitCriteria == null || visitCriteria.isEmpty()) {
        // Retrieving an index list independent of a contact/case is not possible
        return new ArrayList<>();
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<VisitIndexDto> cq = cb.createQuery(VisitIndexDto.class);
    Root<Visit> visit = cq.from(Visit.class);
    Join<Visit, Symptoms> symptoms = visit.join(Visit.SYMPTOMS, JoinType.LEFT);
    Join<Visit, Case> caseJoin = visit.join(Visit.CAZE, JoinType.LEFT);
    Join<Visit, Contact> contactJoin = visit.join(Visit.CONTACTS, JoinType.LEFT);
    Join<Visit, User> visitUser = visit.join(Visit.VISIT_USER, JoinType.LEFT);
    cq.multiselect(visit.get(Visit.ID), visit.get(Visit.UUID), visit.get(Visit.VISIT_DATE_TIME), visit.get(Visit.VISIT_STATUS), visit.get(Visit.VISIT_REMARKS), visit.get(Visit.DISEASE), symptoms.get(Symptoms.SYMPTOMATIC), symptoms.get(Symptoms.TEMPERATURE), symptoms.get(Symptoms.TEMPERATURE_SOURCE), visit.get(Visit.ORIGIN), visitUser.get(User.UUID), visitUser.get(User.FIRST_NAME), visitUser.get(User.LAST_NAME), jurisdictionSelector(cq, cb, caseJoin, contactJoin));
    cq.distinct(true);
    cq.where(visitService.buildCriteriaFilter(visitCriteria, cb, visit));
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case VisitIndexDto.VISIT_DATE_TIME:
                case VisitIndexDto.VISIT_STATUS:
                case VisitIndexDto.VISIT_REMARKS:
                case VisitIndexDto.DISEASE:
                case VisitIndexDto.ORIGIN:
                    expression = visit.get(sortProperty.propertyName);
                    break;
                case VisitIndexDto.SYMPTOMATIC:
                case VisitIndexDto.TEMPERATURE:
                    expression = symptoms.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(Visit.VISIT_DATE_TIME)));
    }
    List<VisitIndexDto> indexList = QueryHelper.getResultList(em, cq, first, max);
    if (indexList.size() > 0) {
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        indexList.forEach(visitIndex -> pseudonymizer.pseudonymizeDto(VisitIndexDto.class, visitIndex, visitIndex.getInJurisdiction(), null));
    }
    return indexList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) User(de.symeda.sormas.backend.user.User) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) Contact(de.symeda.sormas.backend.contact.Contact) SortProperty(de.symeda.sormas.api.utils.SortProperty) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms)

Example 5 with VisitIndexDto

use of de.symeda.sormas.api.visit.VisitIndexDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbPseudonymizationTest method testPseudonymizeIndexList.

@Test
public void testPseudonymizeIndexList() {
    PersonDto newPerson = creator.createPerson("First", "Last");
    ContactVisit contactVisit1 = createVisit(user1, newPerson);
    ContactVisit contactVisit2 = createVisit(user2, person);
    List<VisitIndexDto> indexList1 = getVisitFacade().getIndexList(new VisitCriteria().contact(contactVisit1.contact.toReference()), 0, 100, null);
    VisitIndexDto index1 = indexList1.get(0);
    assertThat(index1.getVisitRemarks(), is("Confidential"));
    List<VisitIndexDto> indexList2 = getVisitFacade().getIndexList(new VisitCriteria().contact(contactVisit2.contact.toReference()), 0, 100, null);
    VisitIndexDto index2 = indexList2.get(0);
    assertThat(index2.getVisitRemarks(), is("Test remarks"));
}
Also used : VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

VisitIndexDto (de.symeda.sormas.api.visit.VisitIndexDto)6 PersonDto (de.symeda.sormas.api.person.PersonDto)5 VisitCriteria (de.symeda.sormas.api.visit.VisitCriteria)5 ContactDto (de.symeda.sormas.api.contact.ContactDto)3 VisitDto (de.symeda.sormas.api.visit.VisitDto)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 Date (java.util.Date)3 VaadinIcons (com.vaadin.icons.VaadinIcons)2 FileDownloader (com.vaadin.server.FileDownloader)2 StreamResource (com.vaadin.server.StreamResource)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 MenuBar (com.vaadin.ui.MenuBar)2 MultiSelectionModelImpl (com.vaadin.ui.components.grid.MultiSelectionModelImpl)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 Captions (de.symeda.sormas.api.i18n.Captions)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2