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));
}
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);
}
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);
}
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));
}
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);
}
Aggregations