Search in sources :

Example 1 with ContactFacade

use of de.symeda.sormas.api.contact.ContactFacade in project SORMAS-Project by hzi-braunschweig.

the class ContactController method showBulkContactDataEditComponent.

public void showBulkContactDataEditComponent(Collection<? extends ContactIndexDto> selectedContacts, String caseUuid) {
    if (selectedContacts.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected), I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
        return;
    }
    // Check if cases with multiple districts have been selected
    String districtUuid = null;
    for (ContactIndexDto selectedContact : selectedContacts) {
        String selectedDistrictUuid = selectedContact.getDistrictUuid();
        if (districtUuid == null) {
            districtUuid = selectedDistrictUuid;
        } else if (!districtUuid.equals(selectedDistrictUuid)) {
            districtUuid = null;
            break;
        }
    }
    DistrictReferenceDto district = districtUuid != null ? FacadeProvider.getDistrictFacade().getReferenceByUuid(districtUuid) : null;
    // Create a temporary contact in order to use the CommitDiscardWrapperComponent
    ContactBulkEditData bulkEditData = new ContactBulkEditData();
    BulkContactDataForm form = new BulkContactDataForm(district, selectedContacts);
    form.setValue(bulkEditData);
    final CommitDiscardWrapperComponent<BulkContactDataForm> editView = new CommitDiscardWrapperComponent<BulkContactDataForm>(form, form.getFieldGroup());
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingEditContacts));
    editView.addCommitListener(() -> {
        ContactBulkEditData updatedBulkEditData = form.getValue();
        ContactFacade contactFacade = FacadeProvider.getContactFacade();
        boolean classificationChange = form.getClassificationCheckBox().getValue();
        boolean contactOfficerChange = district != null ? form.getContactOfficerCheckBox().getValue() : false;
        int changedContacts = bulkEdit(selectedContacts, updatedBulkEditData, contactFacade, classificationChange, contactOfficerChange);
        popupWindow.close();
        if (caseUuid == null) {
            overview();
        } else {
            caseContactsOverview(caseUuid);
        }
        if (changedContacts == selectedContacts.size()) {
            Notification.show(I18nProperties.getString(Strings.messageContactsEdited), Type.HUMANIZED_MESSAGE);
        } else {
            NotificationHelper.showNotification(String.format(I18nProperties.getString(Strings.messageContactsEditedExceptArchived), changedContacts), Type.HUMANIZED_MESSAGE, -1);
        }
    });
    editView.addDiscardListener(() -> popupWindow.close());
}
Also used : Window(com.vaadin.ui.Window) ContactFacade(de.symeda.sormas.api.contact.ContactFacade) ContactBulkEditData(de.symeda.sormas.api.contact.ContactBulkEditData) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Notification(com.vaadin.ui.Notification) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto)

Example 2 with ContactFacade

use of de.symeda.sormas.api.contact.ContactFacade in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testGetNonSourceCaseCountForDashboard.

@Test
public void testGetNonSourceCaseCountForDashboard() {
    ContactFacade cut = getBean(ContactFacadeEjbLocal.class);
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto person = creator.createPerson("Case", "Person");
    Disease disease = Disease.OTHER;
    // 1. A case not resulted of a contact: 0
    CaseDataDto caseWithoutContact = creator.createCase(user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
    assertThat(cut.getNonSourceCaseCountForDashboard(Collections.singletonList(caseWithoutContact.getUuid())), equalTo(0));
    // 2. Another case, but created from a contact: 1
    ContactDto contact = creator.createContact(user.toReference(), person.toReference(), disease);
    CaseDataDto caseWithContact = creator.createCase(user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
    contact.setResultingCase(caseWithContact.toReference());
    contact = getContactFacade().save(contact);
    assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(caseWithoutContact.getUuid(), caseWithContact.getUuid())), equalTo(1));
    // 3. Some more cases
    {
        CaseDataDto caseWithoutContact2 = creator.createCase(user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
        ContactDto contact2 = creator.createContact(user.toReference(), person.toReference(), disease);
        CaseDataDto caseWithContact2 = creator.createCase(user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
        contact2.setResultingCase(caseWithContact2.toReference());
        contact2 = getContactFacade().save(contact2);
        ContactDto contact3 = creator.createContact(user.toReference(), person.toReference(), disease);
        CaseDataDto caseWithContact3 = creator.createCase(user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
        contact3.setResultingCase(caseWithContact3.toReference());
        contact3 = getContactFacade().save(contact3);
        assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(caseWithoutContact.getUuid(), caseWithContact.getUuid(), caseWithoutContact2.getUuid(), caseWithContact2.getUuid(), caseWithContact3.getUuid())), equalTo(3));
    }
}
Also used : ContactFacade(de.symeda.sormas.api.contact.ContactFacade) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) Disease(de.symeda.sormas.api.Disease) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with ContactFacade

use of de.symeda.sormas.api.contact.ContactFacade in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testGetNonSourceCaseCountForDashboardVariousInClauseCount.

@Test
public void testGetNonSourceCaseCountForDashboardVariousInClauseCount() {
    ContactFacade cut = getBean(ContactFacadeEjbLocal.class);
    // 0. Works for 0 cases
    assertThat(cut.getNonSourceCaseCountForDashboard(Collections.emptyList()), equalTo(0));
    assertThat(cut.getNonSourceCaseCountForDashboard(null), equalTo(0));
    // 1a. Works for 1 case
    assertThat(cut.getNonSourceCaseCountForDashboard(Collections.singletonList(DataHelper.createUuid())), equalTo(0));
    // 1b. Works for 2 cases
    assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(DataHelper.createUuid(), DataHelper.createUuid())), equalTo(0));
    // 1c. Works for 3 cases
    assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(DataHelper.createUuid(), DataHelper.createUuid(), DataHelper.createUuid())), equalTo(0));
    // 2a. Works for 1_000 cases
    assertThat(cut.getNonSourceCaseCountForDashboard(TestDataCreator.createValuesList(1_000, i -> DataHelper.createUuid())), equalTo(0));
    // 2b. Works for 100_000 cases
    assertThat(cut.getNonSourceCaseCountForDashboard(TestDataCreator.createValuesList(100_000, i -> DataHelper.createUuid())), equalTo(0));
}
Also used : ContactFacade(de.symeda.sormas.api.contact.ContactFacade) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

ContactFacade (de.symeda.sormas.api.contact.ContactFacade)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 Test (org.junit.Test)2 Notification (com.vaadin.ui.Notification)1 Window (com.vaadin.ui.Window)1 Disease (de.symeda.sormas.api.Disease)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 ContactBulkEditData (de.symeda.sormas.api.contact.ContactBulkEditData)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 ContactIndexDto (de.symeda.sormas.api.contact.ContactIndexDto)1 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)1 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)1 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1