use of de.symeda.sormas.api.event.SimilarEventParticipantDto in project SORMAS-Project by hzi-braunschweig.
the class CaseController method convertSamePersonContactsAndEventparticipants.
private void convertSamePersonContactsAndEventparticipants(CaseDataDto caze, Date relevantDate) {
ContactSimilarityCriteria contactCriteria = new ContactSimilarityCriteria().withPerson(caze.getPerson()).withDisease(caze.getDisease()).withContactClassification(ContactClassification.CONFIRMED).withExcludePseudonymized(true).withNoResultingCase(true);
List<SimilarContactDto> matchingContacts = FacadeProvider.getContactFacade().getMatchingContacts(contactCriteria);
EventParticipantCriteria eventParticipantCriteria = new EventParticipantCriteria().withPerson(caze.getPerson()).withDisease(caze.getDisease()).withExcludePseudonymized(true).withNoResultingCase(true);
List<SimilarEventParticipantDto> matchingEventParticipants = FacadeProvider.getEventParticipantFacade().getMatchingEventParticipants(eventParticipantCriteria);
if (matchingContacts.size() > 0 || matchingEventParticipants.size() > 0) {
String infoText = matchingEventParticipants.isEmpty() ? String.format(I18nProperties.getString(Strings.infoConvertToCaseContacts), matchingContacts.size(), caze.getDisease()) : (matchingContacts.isEmpty() ? String.format(I18nProperties.getString(Strings.infoConvertToCaseEventParticipants), matchingEventParticipants.size(), caze.getDisease()) : String.format(I18nProperties.getString(Strings.infoConvertToCaseContactsAndEventParticipants), matchingContacts.size(), caze.getDisease(), matchingEventParticipants.size(), caze.getDisease()));
HorizontalLayout infoComponent = VaadinUiUtil.createInfoComponent(infoText);
infoComponent.setWidth(600, Sizeable.Unit.PIXELS);
CommitDiscardWrapperComponent<HorizontalLayout> convertToCaseConfirmComponent = new CommitDiscardWrapperComponent<>(infoComponent);
convertToCaseConfirmComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionYesForAll));
convertToCaseConfirmComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionNo));
convertToCaseConfirmComponent.addCommitListener(() -> {
CaseDataDto refreshedCaze = FacadeProvider.getCaseFacade().getCaseDataByUuid(caze.getUuid());
refreshedCaze.getEpiData().setContactWithSourceCaseKnown(YesNoUnknown.YES);
saveCase(refreshedCaze);
setResultingCase(refreshedCaze, matchingContacts, matchingEventParticipants);
SormasUI.refreshView();
});
Button convertSomeButton = ButtonHelper.createButton("convertSome", I18nProperties.getCaption(Captions.actionYesForSome), (Button.ClickListener) event -> {
convertToCaseConfirmComponent.discard();
showConvertToCaseSelection(caze, matchingContacts, matchingEventParticipants);
}, ValoTheme.BUTTON_PRIMARY);
HorizontalLayout buttonsPanel = convertToCaseConfirmComponent.getButtonsPanel();
buttonsPanel.addComponent(convertSomeButton, convertToCaseConfirmComponent.getComponentCount() - 1);
buttonsPanel.setComponentAlignment(convertSomeButton, Alignment.BOTTOM_RIGHT);
buttonsPanel.setExpandRatio(convertSomeButton, 0);
VaadinUiUtil.showModalPopupWindow(convertToCaseConfirmComponent, I18nProperties.getString(Strings.headingCaseConversion));
}
}
use of de.symeda.sormas.api.event.SimilarEventParticipantDto in project SORMAS-Project by hzi-braunschweig.
the class CaseController method setResultingCase.
private void setResultingCase(CaseDataDto caze, List<SimilarContactDto> matchingContacts, List<SimilarEventParticipantDto> matchingEventParticipants) {
if (matchingContacts != null && !matchingContacts.isEmpty()) {
List<String> contactUuids = matchingContacts.stream().map(SimilarContactDto::getUuid).collect(Collectors.toList());
List<ContactDto> contacts = FacadeProvider.getContactFacade().getByUuids(contactUuids);
for (ContactDto contact : contacts) {
contact.setContactStatus(ContactStatus.CONVERTED);
contact.setResultingCase(caze.toReference());
contact.setResultingCaseUser(UserProvider.getCurrent().getUserReference());
FacadeProvider.getContactFacade().save(contact);
}
}
if (matchingEventParticipants != null && !matchingEventParticipants.isEmpty()) {
List<String> eventParticipantUuids = matchingEventParticipants.stream().map(SimilarEventParticipantDto::getUuid).collect(Collectors.toList());
List<EventParticipantDto> eventParticipants = FacadeProvider.getEventParticipantFacade().getByUuids(eventParticipantUuids);
for (EventParticipantDto eventParticipant : eventParticipants) {
eventParticipant.setResultingCase(caze.toReference());
FacadeProvider.getEventParticipantFacade().save(eventParticipant);
}
}
}
use of de.symeda.sormas.api.event.SimilarEventParticipantDto in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantFacadeEjb method getMatchingEventParticipants.
@Override
public List<SimilarEventParticipantDto> getMatchingEventParticipants(EventParticipantCriteria criteria) {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<SimilarEventParticipantDto> cq = cb.createQuery(SimilarEventParticipantDto.class);
final Root<EventParticipant> eventParticipantRoot = cq.from(EventParticipant.class);
cq.distinct(true);
Join<Object, Object> personJoin = eventParticipantRoot.join(EventParticipant.PERSON, JoinType.LEFT);
Join<Object, Object> eventJoin = eventParticipantRoot.join(EventParticipant.EVENT, JoinType.LEFT);
EventParticipantQueryContext eventParticipantQueryContext = new EventParticipantQueryContext(cb, cq, eventParticipantRoot);
Expression<Object> jurisdictionSelector = JurisdictionHelper.booleanSelector(cb, service.inJurisdictionOrOwned(new EventParticipantQueryContext(cb, cq, eventParticipantRoot)));
cq.multiselect(eventParticipantRoot.get(EventParticipant.UUID), personJoin.get(Person.FIRST_NAME), personJoin.get(Person.LAST_NAME), eventParticipantRoot.get(EventParticipant.INVOLVEMENT_DESCRIPTION), eventJoin.get(Event.UUID), eventJoin.get(Event.EVENT_STATUS), eventJoin.get(Event.EVENT_TITLE), eventJoin.get(Event.START_DATE), jurisdictionSelector);
cq.groupBy(eventParticipantRoot.get(EventParticipant.UUID), personJoin.get(Person.FIRST_NAME), personJoin.get(Person.LAST_NAME), eventParticipantRoot.get(EventParticipant.INVOLVEMENT_DESCRIPTION), eventJoin.get(Event.UUID), eventJoin.get(Event.EVENT_STATUS), eventJoin.get(Event.EVENT_TITLE), eventJoin.get(Event.START_DATE), jurisdictionSelector);
final Predicate defaultFilter = service.createDefaultFilter(cb, eventParticipantRoot);
final Predicate userFilter = service.createUserFilter(eventParticipantQueryContext);
final PersonReferenceDto person = criteria.getPerson();
final Predicate samePersonFilter = person != null ? cb.equal(personJoin.get(Person.UUID), person.getUuid()) : null;
final Disease disease = criteria.getDisease();
final Predicate diseaseFilter = disease != null ? cb.equal(eventJoin.get(Event.DISEASE), disease) : null;
final Date relevantDate = criteria.getRelevantDate();
final Predicate relevantDateFilter = CriteriaBuilderHelper.or(cb, contactService.recentDateFilter(cb, relevantDate, eventJoin.get(Event.START_DATE), 30), contactService.recentDateFilter(cb, relevantDate, eventJoin.get(Event.END_DATE), 30), contactService.recentDateFilter(cb, relevantDate, eventJoin.get(Event.REPORT_DATE_TIME), 30));
final Predicate noResulingCaseFilter = Boolean.TRUE.equals(criteria.getNoResultingCase()) ? cb.isNull(eventParticipantRoot.get(EventParticipant.RESULTING_CASE)) : null;
cq.where(CriteriaBuilderHelper.and(cb, defaultFilter, userFilter, samePersonFilter, diseaseFilter, relevantDateFilter, noResulingCaseFilter));
List<SimilarEventParticipantDto> participants = em.createQuery(cq).getResultList();
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
pseudonymizer.pseudonymizeDtoCollection(SimilarEventParticipantDto.class, participants, p -> p.getInJurisdiction(), null);
if (Boolean.TRUE.equals(criteria.getExcludePseudonymized())) {
participants = participants.stream().filter(e -> !e.isPseudonymized()).collect(Collectors.toList());
}
return participants;
}
use of de.symeda.sormas.api.event.SimilarEventParticipantDto in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantSelectionGrid method buildGrid.
private void buildGrid() {
setSizeFull();
setSelectionMode(SelectionMode.SINGLE);
setHeightMode(HeightMode.ROW);
BeanItemContainer<SimilarEventParticipantDto> container = new BeanItemContainer(SimilarEventParticipantDto.class);
GeneratedPropertyContainer generatedContainer = new GeneratedPropertyContainer(container);
setContainerDataSource(generatedContainer);
setColumns();
}
use of de.symeda.sormas.api.event.SimilarEventParticipantDto in project SORMAS-Project by hzi-braunschweig.
the class AbstractLabMessageProcessingFlowTest method init.
@Override
@SuppressWarnings("unchecked")
public void init() {
super.init();
missingDiseaseHandler = Mockito.mock(Supplier.class);
when(missingDiseaseHandler.get()).thenReturn(CompletableFuture.completedFuture(true));
relatedForwardedMessagesHandler = Mockito.mock(Supplier.class);
when(relatedForwardedMessagesHandler.get()).thenReturn(CompletableFuture.completedFuture(true));
relatedLabMessageHandler = Mockito.mock(AbstractRelatedLabMessageHandler.class);
when(relatedLabMessageHandler.handle(any())).thenReturn(CompletableFuture.completedFuture(new HandlerResult(HandlerResultStatus.NOT_HANDLED, null)));
handlePickOrCreatePerson = Mockito.mock(BiFunction.class);
doAnswer(answerPickOrCreatePerson(null)).when(handlePickOrCreatePerson).apply(any(), any());
handlePickOrCreateEntry = Mockito.mock(PickOrCreateEntryHandler.class);
PickOrCreateEntryResult pickOrCreateEntryResult = new PickOrCreateEntryResult();
pickOrCreateEntryResult.setNewCase(true);
doAnswer(answerPickOrCreateEntry(pickOrCreateEntryResult)).when(handlePickOrCreateEntry).handle(any(), any(), any(), any());
handleCreateCase = Mockito.mock(EntityCreationHandler.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(invocation.getArgument(0));
return null;
}).when(handleCreateCase).handle(any(), any(), any());
handleCreateSampleAndPathogenTests = Mockito.mock(CreateSampleAndPathogenTestHandler.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(new SampleAndPathogenTests(invocation.getArgument(0), invocation.getArgument(1)));
return null;
}).when(handleCreateSampleAndPathogenTests).handle(any(), any(), any(), any());
handleCreateContact = Mockito.mock(EntityCreationHandler.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(invocation.getArgument(0));
return null;
}).when(handleCreateContact).handle(any(), any(), any());
handlePickOrCreateEvent = Mockito.mock(Consumer.class);
PickOrCreateEventResult pickOrCreateEventResult = new PickOrCreateEventResult();
pickOrCreateEventResult.setNewEvent(true);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(pickOrCreateEventResult);
return null;
}).when(handlePickOrCreateEvent).accept(any());
handleCreateEvent = Mockito.mock(BiConsumer.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(invocation.getArgument(0));
return null;
}).when(handleCreateEvent).accept(any(), any());
handleCreateEventParticipant = Mockito.mock(BiConsumer.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(invocation.getArgument(0));
return null;
}).when(handleCreateEventParticipant).accept(any(), any());
confirmPickExistingEventParticipant = Mockito.mock(Supplier.class);
when(confirmPickExistingEventParticipant.get()).thenReturn(CompletableFuture.completedFuture(true));
handlePickOrCreateSample = Mockito.mock(BiConsumer.class);
PickOrCreateSampleResult pickOrCreateSampleResult = new PickOrCreateSampleResult();
pickOrCreateSampleResult.setNewSample(true);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(pickOrCreateSampleResult);
return null;
}).when(handlePickOrCreateSample).accept(any(), any());
handleEditSample = Mockito.mock(EditSampleHandler.class);
doAnswer((invocation) -> {
getCallbackParam(invocation).done(new SampleAndPathogenTests(invocation.getArgument(0), invocation.getArgument(1)));
return null;
}).when(handleEditSample).handle(any(), any(), any());
rdcf = creator.createRDCF();
user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
country = new CountryReferenceDto(DataHelper.createUuid(), "de-DE");
flow = new AbstractLabMessageProcessingFlow(user, country) {
@Override
protected CompletionStage<Boolean> handleMissingDisease() {
return missingDiseaseHandler.get();
}
@Override
protected CompletionStage<Boolean> handleRelatedForwardedMessages() {
return relatedForwardedMessagesHandler.get();
}
@Override
protected void handlePickOrCreatePerson(PersonDto person, HandlerCallback<PersonDto> callback) {
handlePickOrCreatePerson.apply(person, callback);
}
@Override
protected void handlePickOrCreateEntry(List<CaseSelectionDto> similarCases, List<SimilarContactDto> similarContacts, List<SimilarEventParticipantDto> similarEventParticipants, LabMessageDto labMessageDto, HandlerCallback<PickOrCreateEntryResult> callback) {
handlePickOrCreateEntry.handle(similarCases, similarContacts, similarEventParticipants, callback);
}
@Override
protected void handleCreateCase(CaseDataDto caze, PersonDto person, LabMessageDto labMessage, HandlerCallback<CaseDataDto> callback) {
handleCreateCase.handle(caze, person, callback);
}
@Override
protected void handleCreateSampleAndPathogenTests(SampleDto sample, List<PathogenTestDto> pathogenTests, Disease disease, LabMessageDto labMessage, boolean entityCreated, HandlerCallback<SampleAndPathogenTests> callback) {
handleCreateSampleAndPathogenTests.handle(sample, pathogenTests, entityCreated, callback);
}
@Override
protected void handleCreateContact(ContactDto contact, PersonDto person, LabMessageDto labMessage, HandlerCallback<ContactDto> callback) {
handleCreateContact.handle(contact, person, callback);
}
@Override
protected void handlePickOrCreateEvent(LabMessageDto labMessage, HandlerCallback<PickOrCreateEventResult> callback) {
handlePickOrCreateEvent.accept(callback);
}
@Override
protected void handleCreateEvent(EventDto event, HandlerCallback<EventDto> callback) {
handleCreateEvent.accept(event, callback);
}
@Override
protected void handleCreateEventParticipant(EventParticipantDto eventParticipant, EventDto event, LabMessageDto labMessage, HandlerCallback<EventParticipantDto> callback) {
handleCreateEventParticipant.accept(eventParticipant, callback);
}
@Override
protected CompletionStage<Boolean> confirmPickExistingEventParticipant() {
return confirmPickExistingEventParticipant.get();
}
@Override
protected void handlePickOrCreateSample(List<SampleDto> samples, LabMessageDto labMessageDto, HandlerCallback<PickOrCreateSampleResult> callback) {
handlePickOrCreateSample.accept(samples, callback);
}
@Override
protected void handleEditSample(SampleDto sample, List<PathogenTestDto> newPathogenTests, LabMessageDto labMessage, HandlerCallback<SampleAndPathogenTests> callback) {
handleEditSample.handle(sample, newPathogenTests, callback);
}
};
}
Aggregations