Search in sources :

Example 16 with VisitDto

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

the class VisitFacadeEjb method getVisitsByContactAndPeriod.

@Override
public List<VisitDto> getVisitsByContactAndPeriod(ContactReferenceDto contactRef, Date begin, Date end) {
    Contact contact = contactService.getByReferenceDto(contactRef);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    return contact.getVisits().stream().filter(visit -> visit.getVisitDateTime().after(begin) && visit.getVisitDateTime().before(end)).map(visit -> convertToDto(visit, pseudonymizer)).collect(Collectors.toList());
}
Also used : DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Join(javax.persistence.criteria.Join) SymptomsFacadeEjbLocal(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb.SymptomsFacadeEjbLocal) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) LoggerFactory(org.slf4j.LoggerFactory) VisitExportDto(de.symeda.sormas.api.visit.VisitExportDto) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) VisitReferenceDto(de.symeda.sormas.api.visit.VisitReferenceDto) NotificationService(de.symeda.sormas.backend.common.NotificationService) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) Collection(java.util.Collection) Set(java.util.Set) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) NotNull(javax.validation.constraints.NotNull) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) Optional(java.util.Optional) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) TransactionAttribute(javax.ejb.TransactionAttribute) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) Expression(javax.persistence.criteria.Expression) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) VisitExportType(de.symeda.sormas.api.visit.VisitExportType) Validations(de.symeda.sormas.api.i18n.Validations) DataHelper(de.symeda.sormas.api.utils.DataHelper) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitFacade(de.symeda.sormas.api.visit.VisitFacade) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) PersonService(de.symeda.sormas.backend.person.PersonService) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) VisitDto(de.symeda.sormas.api.visit.VisitDto) ContactService(de.symeda.sormas.backend.contact.ContactService) NotificationType(de.symeda.sormas.api.user.NotificationType) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) Comparator(java.util.Comparator) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Contact(de.symeda.sormas.backend.contact.Contact)

Example 17 with VisitDto

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

the class VisitFacadeEjb method onVisitChanged.

private void onVisitChanged(VisitDto existingVisit, Visit newVisit) {
    updateContactVisitAssociations(existingVisit, newVisit);
    updateCaseVisitAssociations(existingVisit, newVisit);
    // Send an email to all responsible supervisors when the contact has become
    // symptomatic
    boolean previousSymptomaticStatus = existingVisit != null && Boolean.TRUE.equals(existingVisit.getSymptoms().getSymptomatic());
    if (newVisit.getContacts() != null && previousSymptomaticStatus == false && Boolean.TRUE.equals(newVisit.getSymptoms().getSymptomatic())) {
        for (Contact contact : newVisit.getContacts()) {
            // Skip if there is already a symptomatic visit for this contact
            if (contact.getVisits().stream().filter(v -> !v.equals(newVisit)).filter(v -> Boolean.TRUE.equals(v.getSymptoms().getSymptomatic())).count() > 0) {
                continue;
            }
            Case contactCase = contact.getCaze();
            try {
                String messageContent;
                if (contactCase != null) {
                    messageContent = String.format(I18nProperties.getString(MessageContents.CONTENT_CONTACT_SYMPTOMATIC), DataHelper.getShortUuid(contact.getUuid()), DataHelper.getShortUuid(contactCase.getUuid()));
                } else {
                    messageContent = String.format(I18nProperties.getString(MessageContents.CONTENT_CONTACT_WITHOUT_CASE_SYMPTOMATIC), DataHelper.getShortUuid(contact.getUuid()));
                }
                notificationService.sendNotifications(NotificationType.CONTACT_SYMPTOMATIC, JurisdictionHelper.getContactRegions(contact), null, MessageSubject.CONTACT_SYMPTOMATIC, messageContent);
            } catch (NotificationDeliveryFailedException e) {
                logger.error("EmailDeliveryFailedException when trying to notify supervisors about a contact that has become symptomatic.");
            }
        }
    }
    if (newVisit.getContacts() != null) {
        for (Contact contact : newVisit.getContacts()) {
            contactService.updateFollowUpDetails(contact, false);
        }
    }
    if (newVisit.getCaze() != null) {
        // Update case symptoms
        CaseDataDto caze = caseFacade.toDto(newVisit.getCaze());
        SymptomsDto caseSymptoms = caze.getSymptoms();
        SymptomsHelper.updateSymptoms(toDto(newVisit).getSymptoms(), caseSymptoms);
        caseFacade.save(caze, true);
    }
}
Also used : DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Join(javax.persistence.criteria.Join) SymptomsFacadeEjbLocal(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb.SymptomsFacadeEjbLocal) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) LoggerFactory(org.slf4j.LoggerFactory) VisitExportDto(de.symeda.sormas.api.visit.VisitExportDto) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) VisitReferenceDto(de.symeda.sormas.api.visit.VisitReferenceDto) NotificationService(de.symeda.sormas.backend.common.NotificationService) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) Collection(java.util.Collection) Set(java.util.Set) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) NotNull(javax.validation.constraints.NotNull) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) Optional(java.util.Optional) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) TransactionAttribute(javax.ejb.TransactionAttribute) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) Expression(javax.persistence.criteria.Expression) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) VisitExportType(de.symeda.sormas.api.visit.VisitExportType) Validations(de.symeda.sormas.api.i18n.Validations) DataHelper(de.symeda.sormas.api.utils.DataHelper) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitFacade(de.symeda.sormas.api.visit.VisitFacade) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) PersonService(de.symeda.sormas.backend.person.PersonService) SymptomsHelper(de.symeda.sormas.api.symptoms.SymptomsHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) VisitDto(de.symeda.sormas.api.visit.VisitDto) ContactService(de.symeda.sormas.backend.contact.ContactService) NotificationType(de.symeda.sormas.api.user.NotificationType) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) Comparator(java.util.Comparator) Collections(java.util.Collections) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Contact(de.symeda.sormas.backend.contact.Contact) Case(de.symeda.sormas.backend.caze.Case)

Example 18 with VisitDto

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

the class VisitController method createVisit.

private void createVisit(VisitEditForm createForm, Consumer<VisitReferenceDto> doneConsumer) {
    final CommitDiscardWrapperComponent<VisitEditForm> editView = new CommitDiscardWrapperComponent<VisitEditForm>(createForm, UserProvider.getCurrent().hasUserRight(UserRight.VISIT_CREATE), createForm.getFieldGroup());
    editView.addCommitListener(() -> {
        if (!createForm.getFieldGroup().isModified()) {
            VisitDto dto = createForm.getValue();
            dto = FacadeProvider.getVisitFacade().saveVisit(dto);
            if (doneConsumer != null) {
                doneConsumer.accept(dto.toReference());
            }
        }
    });
    Window window = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getString(Strings.headingCreateNewVisit));
    // visit form is too big for typical screens
    window.setWidth(createForm.getWidth() + 64 + 24, Unit.PIXELS);
    window.setHeight(80, Unit.PERCENTAGE);
}
Also used : Window(com.vaadin.ui.Window) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Example 19 with VisitDto

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

the class VisitController method createNewVisit.

private VisitDto createNewVisit(PersonReferenceDto personRef, Disease disease) {
    VisitDto visit = VisitDto.build(personRef, disease, VisitOrigin.USER);
    UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
    visit.setVisitUser(userReference);
    return visit;
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Example 20 with VisitDto

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

the class VisitController method createVisit.

public void createVisit(CaseReferenceDto caseRef, Consumer<VisitReferenceDto> doneConsumer) {
    VisitDto visit = createNewVisit(caseRef);
    CaseDataDto caze = FacadeProvider.getCaseFacade().getCaseDataByUuid(caseRef.getUuid());
    PersonDto person = FacadeProvider.getPersonFacade().getPersonByUuid(caze.getPerson().getUuid());
    VisitEditForm createForm = new VisitEditForm(visit.getDisease(), caze, person, true, true);
    createForm.setValue(visit);
    createVisit(createForm, doneConsumer);
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) VisitDto(de.symeda.sormas.api.visit.VisitDto)

Aggregations

VisitDto (de.symeda.sormas.api.visit.VisitDto)44 PersonDto (de.symeda.sormas.api.person.PersonDto)27 Test (org.junit.Test)25 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)24 Date (java.util.Date)24 ContactDto (de.symeda.sormas.api.contact.ContactDto)22 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)20 UserDto (de.symeda.sormas.api.user.UserDto)19 ExternalVisitDto (de.symeda.sormas.api.visit.ExternalVisitDto)14 LocalDate (java.time.LocalDate)11 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)10 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)8 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)7 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)7 VisitCriteria (de.symeda.sormas.api.visit.VisitCriteria)7 ArrayList (java.util.ArrayList)7 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)6 ClinicalVisitDto (de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)5 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)5 SampleDto (de.symeda.sormas.api.sample.SampleDto)4