Search in sources :

Example 96 with EventDto

use of de.symeda.sormas.api.event.EventDto in project SORMAS-Project by hzi-braunschweig.

the class CaseController method createFromEventParticipant.

public void createFromEventParticipant(EventParticipantDto eventParticipant) {
    EventDto event = FacadeProvider.getEventFacade().getEventByUuid(eventParticipant.getEvent().getUuid(), false);
    if (event.getDisease() == null) {
        new Notification(I18nProperties.getString(Strings.headingCreateNewCaseIssue), I18nProperties.getString(Strings.messageEventParticipantToCaseWithoutEventDisease), Notification.Type.ERROR_MESSAGE, false).show(Page.getCurrent());
        return;
    }
    CommitDiscardWrapperComponent<CaseCreateForm> caseCreateComponent = getCaseCreateComponent(null, eventParticipant, null, null, false);
    caseCreateComponent.addCommitListener(() -> {
        EventParticipantDto updatedEventparticipant = FacadeProvider.getEventParticipantFacade().getByUuid(eventParticipant.getUuid());
        if (updatedEventparticipant.getResultingCase() != null) {
            String caseUuid = updatedEventparticipant.getResultingCase().getUuid();
            CaseDataDto caze = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseUuid);
            Date relevantDate = event.getStartDate() != null ? event.getStartDate() : (event.getEndDate() != null ? event.getEndDate() : event.getReportDateTime());
            convertSamePersonContactsAndEventparticipants(caze, relevantDate);
        }
    });
    VaadinUiUtil.showModalPopupWindow(caseCreateComponent, I18nProperties.getString(Strings.headingCreateNewCase));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) SimilarEventParticipantDto(de.symeda.sormas.api.event.SimilarEventParticipantDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) Notification(com.vaadin.ui.Notification) Date(java.util.Date)

Example 97 with EventDto

use of de.symeda.sormas.api.event.EventDto in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method createEvent.

private void createEvent(LabMessageDto labMessageDto, PersonDto person) {
    EventDataForm eventCreateForm = new EventDataForm(true, false);
    eventCreateForm.setValue(ControllerProvider.getEventController().createNewEvent(labMessageDto.getTestedDisease()));
    eventCreateForm.getField(EventDto.DISEASE).setReadOnly(true);
    final CommitDiscardWrapperComponent<EventDataForm> editView = new CommitDiscardWrapperComponent<>(eventCreateForm, UserProvider.getCurrent().hasUserRight(UserRight.EVENT_CREATE), eventCreateForm.getFieldGroup());
    Window window = VaadinUiUtil.createPopupWindow();
    editView.addCommitListener(() -> {
        if (!eventCreateForm.getFieldGroup().isModified()) {
            EventDto dto = eventCreateForm.getValue();
            FacadeProvider.getEventFacade().save(dto);
            Notification.show(I18nProperties.getString(Strings.messageEventCreated), Notification.Type.WARNING_MESSAGE);
            createEventParticipant(dto, labMessageDto, person);
            window.close();
        }
    });
    editView.addDiscardListener(window::close);
    window.setContent(editView);
    window.setCaption(I18nProperties.getString(Strings.headingCreateNewEvent));
    UI.getCurrent().addWindow(window);
}
Also used : Window(com.vaadin.ui.Window) EventDto(de.symeda.sormas.api.event.EventDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventDataForm(de.symeda.sormas.ui.events.EventDataForm)

Example 98 with EventDto

use of de.symeda.sormas.api.event.EventDto in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method pickOrCreateSample.

private void pickOrCreateSample(PseudonymizableDto dto, LabMessageDto labMessageDto, List<SampleDto> samples) {
    SampleSelectionField selectField = new SampleSelectionField(samples, I18nProperties.getString(Strings.infoPickOrCreateSample));
    Window window = VaadinUiUtil.createPopupWindow();
    final CommitDiscardWrapperComponent<SampleSelectionField> selectionField = new CommitDiscardWrapperComponent<>(selectField);
    selectionField.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
    selectionField.setWidth(1280, Sizeable.Unit.PIXELS);
    selectionField.addCommitListener(() -> {
        SampleDto sampleDto = selectField.getValue();
        if (sampleDto != null) {
            editSample(sampleDto, labMessageDto);
        } else {
            UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
            if (CaseDataDto.class.equals(dto.getClass())) {
                createSample(SampleDto.build(userReference, ((CaseDataDto) dto).toReference()), labMessageDto, ((CaseDataDto) dto).getDisease(), false);
            } else if (ContactDto.class.equals(dto.getClass())) {
                createSample(SampleDto.build(userReference, ((ContactDto) dto).toReference()), labMessageDto, ((ContactDto) dto).getDisease(), false);
            } else if (EventParticipantDto.class.equals(dto.getClass())) {
                EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(((EventParticipantDto) dto).getEvent().getUuid(), false);
                createSample(SampleDto.build(userReference, ((EventParticipantDto) dto).toReference()), labMessageDto, eventDto.getDisease(), false);
            }
        }
        window.close();
    });
    selectField.setSelectionChangeCallback((commitAllowed) -> selectionField.getCommitButton().setEnabled(commitAllowed));
    selectionField.getCommitButton().setEnabled(false);
    selectionField.addDiscardListener(window::close);
    showFormWithLabMessage(labMessageDto, selectionField, window, I18nProperties.getString(Strings.headingPickOrCreateSample), false);
}
Also used : Window(com.vaadin.ui.Window) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SampleSelectionField(de.symeda.sormas.ui.samples.SampleSelectionField) ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SimilarEventParticipantDto(de.symeda.sormas.api.event.SimilarEventParticipantDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Example 99 with EventDto

use of de.symeda.sormas.api.event.EventDto in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method pickOrCreateEntry.

private void pickOrCreateEntry(LabMessageDto labMessageDto, List<CaseSelectionDto> cases, List<SimilarContactDto> contacts, List<SimilarEventParticipantDto> eventParticipants, PersonDto person) {
    EntrySelectionField selectField = new EntrySelectionField(labMessageDto, cases, contacts, eventParticipants);
    final CommitDiscardWrapperComponent<EntrySelectionField> selectionField = new CommitDiscardWrapperComponent<>(selectField);
    selectionField.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
    selectionField.setWidth(1280, Sizeable.Unit.PIXELS);
    selectionField.addCommitListener(() -> {
        if (FacadeProvider.getLabMessageFacade().isProcessed(labMessageDto.getUuid())) {
            showAlreadyProcessedPopup(null, false);
            return;
        }
        SimilarEntriesDto similarEntriesDto = selectField.getValue();
        if (similarEntriesDto.isNewCase()) {
            createCase(labMessageDto, person);
        } else if (similarEntriesDto.isNewContact()) {
            createContact(labMessageDto, person);
        } else if (similarEntriesDto.isNewEventParticipant()) {
            pickOrCreateEvent(labMessageDto, person);
        } else {
            UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
            if (similarEntriesDto.getCaze() != null) {
                CaseDataDto caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(similarEntriesDto.getCaze().getUuid());
                CaseReferenceDto cazeRef = caseDto.toReference();
                List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).caze(cazeRef));
                if (samples.isEmpty()) {
                    createSample(SampleDto.build(userReference, cazeRef), labMessageDto, caseDto.getDisease(), false);
                } else {
                    pickOrCreateSample(caseDto, labMessageDto, samples);
                }
            } else if (similarEntriesDto.getContact() != null) {
                ContactDto contactDto = FacadeProvider.getContactFacade().getByUuid(similarEntriesDto.getContact().getUuid());
                ContactReferenceDto contactRef = contactDto.toReference();
                List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).contact(contactRef));
                if (samples.isEmpty()) {
                    createSample(SampleDto.build(userReference, contactRef), labMessageDto, contactDto.getDisease(), false);
                } else {
                    pickOrCreateSample(contactDto, labMessageDto, samples);
                }
            } else if (similarEntriesDto.getEventParticipant() != null) {
                EventParticipantDto eventParticipantDto = FacadeProvider.getEventParticipantFacade().getByUuid(similarEntriesDto.getEventParticipant().getUuid());
                EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(eventParticipantDto.getEvent().getUuid(), false);
                EventParticipantReferenceDto eventParticipantRef = eventParticipantDto.toReference();
                List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).eventParticipant(eventParticipantRef));
                if (samples.isEmpty()) {
                    createSample(SampleDto.build(userReference, eventParticipantRef), labMessageDto, eventDto.getDisease(), false);
                } else {
                    pickOrCreateSample(eventParticipantDto, labMessageDto, samples);
                }
            } else {
                throw new UnsupportedOperationException();
            }
        }
    });
    selectField.setSelectionChangeCallback((commitAllowed) -> selectionField.getCommitButton().setEnabled(commitAllowed));
    selectionField.getCommitButton().setEnabled(false);
    VaadinUiUtil.showModalPopupWindow(selectionField, I18nProperties.getString(Strings.headingPickOrCreateEntry));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) SimilarEventParticipantDto(de.symeda.sormas.api.event.SimilarEventParticipantDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SimilarEntriesDto(de.symeda.sormas.api.labmessage.SimilarEntriesDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) List(java.util.List) ArrayList(java.util.ArrayList) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 100 with EventDto

use of de.symeda.sormas.api.event.EventDto in project SORMAS-Project by hzi-braunschweig.

the class DevModeView method generateEvents.

private void generateEvents() {
    initializeRandomGenerator();
    EventGenerationConfig config = eventGeneratorConfigBinder.getBean();
    int generatedParticipants = 0;
    int generatedCases = 0;
    int generatedContacts = 0;
    Disease disease = config.getDisease();
    float baseOffset = random().nextFloat();
    int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
    // this should be adjusted to be much more complex
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    facilityCriteria.region(config.getRegion());
    facilityCriteria.district(config.getDistrict());
    List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, (int) (config.getMaxParticipantsPerEvent() * config.getPercentageOfCases() / 100), null);
    // Filter list, so that only health facilities meant for accomodation are selected
    healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
    long dt = System.nanoTime();
    for (int i = 0; i < config.getEventCount(); i++) {
        LocalDateTime referenceDateTime;
        EventDto event = EventDto.build();
        // disease
        if (disease != null) {
            // reset
            event.setDisease(disease);
            if (event.getDisease() == Disease.OTHER) {
                event.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
            }
            referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, disease, config.getStartDate(), daysBetween);
            fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        } else {
            referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, Disease.OTHER, config.getStartDate(), daysBetween);
            fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(Disease.OTHER).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
        }
        // title
        event.setEventTitle(random(eventTitles));
        // description
        event.setEventDesc("Event generated using DevMode on " + LocalDate.now());
        // report
        UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
        event.setReportingUser(userReference);
        event.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
        // region & district
        event.getEventLocation().setRegion(config.getRegion());
        event.getEventLocation().setDistrict(config.getDistrict());
        // status
        event.setEventStatus(EventStatus.EVENT);
        FacadeProvider.getEventFacade().save(event);
        // EventParticipants
        int numParticipants = randomInt(config.getMinParticipantsPerEvent(), config.getMaxParticipantsPerEvent());
        for (int j = 0; j < numParticipants; j++) {
            EventParticipantDto eventParticipant = EventParticipantDto.build(event.toReference(), UserProvider.getCurrent().getUserReference());
            // person
            // instead of creating new persons everytime, it would be nice if some persons came of the original database
            PersonDto person = PersonDto.build();
            fillEntity(person, referenceDateTime);
            person.setSymptomJournalStatus(null);
            setPersonName(person);
            FacadeProvider.getPersonFacade().savePerson(person);
            eventParticipant.setPerson(person);
            eventParticipant.setInvolvementDescription("Participant");
            if (disease != null) {
                // generate cases for some participants
                if (randomPercent(config.getPercentageOfCases()) && !healthFacilities.isEmpty()) {
                    CaseDataDto caze = CaseDataDto.buildFromEventParticipant(eventParticipant, person, event.getDisease());
                    fillEntity(caze, referenceDateTime);
                    caze.setDisease(event.getDisease());
                    caze.setReportingUser(UserProvider.getCurrent().getUserReference());
                    caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                    caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
                    caze.setResponsibleRegion(config.getRegion());
                    caze.setResponsibleDistrict(config.getDistrict());
                    FacilityIndexDto facility = random(healthFacilities);
                    caze.setHealthFacility(facility.toReference());
                    caze.setFacilityType(facility.getType());
                    caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
                    FacadeProvider.getCaseFacade().save(caze);
                    eventParticipant.setResultingCase(caze.toReference());
                    generatedCases++;
                }
                // generate contacts for some participants
                List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(event.getDisease()), numParticipants * 2, random());
                int numContacts = randomInt(config.getMinContactsPerParticipant(), config.getMaxContactsPerParticipant());
                for (int k = 0; (k < numContacts && (cases != null)); k++) {
                    ContactDto contact = ContactDto.build(eventParticipant);
                    contact.setDisease(event.getDisease());
                    contact.setCaze(random(cases));
                    contact.setReportingUser(UserProvider.getCurrent().getUserReference());
                    contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                    contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
                    FacadeProvider.getContactFacade().save(contact);
                    generatedContacts++;
                }
            }
            FacadeProvider.getEventParticipantFacade().saveEventParticipant(eventParticipant);
            generatedParticipants++;
        }
    }
    dt = System.nanoTime() - dt;
    long perCase = dt / config.getEventCount();
    String msg = String.format("Generating %d events with a total of %d participants (%d contacts, %d cases) took %.2f  s (%.1f ms per event)", config.getEventCount(), generatedParticipants, generatedContacts, generatedCases, (double) dt / 1_000_000_000, (double) perCase / 1_000_000);
    logger.info(msg);
    Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Also used : LocalDateTime(java.time.LocalDateTime) Disease(de.symeda.sormas.api.Disease) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityIndexDto(de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Aggregations

EventDto (de.symeda.sormas.api.event.EventDto)125 Test (org.junit.Test)71 UserDto (de.symeda.sormas.api.user.UserDto)49 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)46 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)39 PersonDto (de.symeda.sormas.api.person.PersonDto)38 Date (java.util.Date)38 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)23 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)22 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)22 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)19 ContactDto (de.symeda.sormas.api.contact.ContactDto)17 SormasToSormasEventDto (de.symeda.sormas.api.sormastosormas.event.SormasToSormasEventDto)16 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)16 SampleDto (de.symeda.sormas.api.sample.SampleDto)14 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)14 List (java.util.List)13 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)11 LocalDate (java.time.LocalDate)11 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)10