Search in sources :

Example 1 with ContactClassification

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

the class CaseContactsView method createFilterBar.

public HorizontalLayout createFilterBar() {
    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setSpacing(true);
    topLayout.setSizeUndefined();
    classificationFilter = ComboBoxHelper.createComboBoxV7();
    classificationFilter.setWidth(240, Unit.PIXELS);
    classificationFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.CONTACT_CLASSIFICATION));
    classificationFilter.addValueChangeListener(e -> criteria.setContactClassification((ContactClassification) e.getProperty().getValue()));
    topLayout.addComponent(classificationFilter);
    UserDto user = UserProvider.getCurrent().getUser();
    regionFilter = ComboBoxHelper.createComboBoxV7();
    if (user.getRegion() == null) {
        regionFilter.setWidth(240, Unit.PIXELS);
        regionFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.REGION_UUID));
        regionFilter.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
        regionFilter.addValueChangeListener(e -> {
            RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
            if (region != null) {
                officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(region, UserRole.CONTACT_OFFICER));
            } else {
                officerFilter.removeAllItems();
            }
            criteria.region(region);
        });
        topLayout.addComponent(regionFilter);
    }
    districtFilter = ComboBoxHelper.createComboBoxV7();
    districtFilter.setWidth(240, Unit.PIXELS);
    districtFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.DISTRICT_UUID));
    districtFilter.addValueChangeListener(e -> criteria.district((DistrictReferenceDto) e.getProperty().getValue()));
    if (user.getRegion() != null && user.getDistrict() == null) {
        districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(user.getRegion().getUuid()));
        districtFilter.setEnabled(true);
    } else {
        regionFilter.addValueChangeListener(e -> {
            RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
            districtFilter.removeAllItems();
            if (region != null) {
                districtFilter.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
                districtFilter.setEnabled(true);
            } else {
                districtFilter.setEnabled(false);
            }
        });
        districtFilter.setEnabled(false);
    }
    topLayout.addComponent(districtFilter);
    Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
    infoLabel.setSizeUndefined();
    infoLabel.setDescription(I18nProperties.getString(Strings.infoContactsViewRegionDistrictFilter), ContentMode.HTML);
    CssStyles.style(infoLabel, CssStyles.LABEL_XLARGE, CssStyles.LABEL_SECONDARY);
    topLayout.addComponent(infoLabel);
    officerFilter = ComboBoxHelper.createComboBoxV7();
    officerFilter.setWidth(240, Unit.PIXELS);
    officerFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.CONTACT_OFFICER_UUID));
    officerFilter.addValueChangeListener(e -> criteria.setContactOfficer((UserReferenceDto) e.getProperty().getValue()));
    if (user.getRegion() != null) {
        officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(user.getRegion(), UserRole.CONTACT_OFFICER));
    }
    topLayout.addComponent(officerFilter);
    searchField = new TextField();
    searchField.setWidth(150, Unit.PIXELS);
    searchField.setNullRepresentation("");
    searchField.setInputPrompt(I18nProperties.getString(Strings.promptContactsSearchField));
    searchField.addTextChangeListener(e -> criteria.setContactOrCaseLike(e.getText()));
    topLayout.addComponent(searchField);
    personLikeField = new TextField();
    personLikeField.setWidth(150, Unit.PIXELS);
    personLikeField.setNullRepresentation("");
    personLikeField.setInputPrompt(I18nProperties.getString(Strings.promptRelatedPersonLikeField));
    personLikeField.addTextChangeListener(e -> criteria.setPersonLike(e.getText()));
    topLayout.addComponent(personLikeField);
    resetButton = ButtonHelper.createButton(Captions.actionResetFilters, event -> {
        ViewModelProviders.of(CaseContactsView.class).remove(ContactCriteria.class);
        navigateTo(null);
    });
    resetButton.setVisible(false);
    topLayout.addComponent(resetButton);
    applyButton = ButtonHelper.createButton(Captions.actionApplyFilters, event -> navigateTo(criteria));
    applyButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    applyButton.setVisible(false);
    topLayout.addComponent(applyButton);
    classificationFilter.addValueChangeListener(e -> updateApplyResetButtons());
    regionFilter.addValueChangeListener(e -> updateApplyResetButtons());
    officerFilter.addValueChangeListener(e -> updateApplyResetButtons());
    districtFilter.addValueChangeListener(e -> updateApplyResetButtons());
    searchField.addValueChangeListener(e -> updateApplyResetButtons());
    personLikeField.addValueChangeListener(e -> updateApplyResetButtons());
    return topLayout;
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) Window(com.vaadin.ui.Window) DetailSubComponentWrapper(de.symeda.sormas.ui.utils.DetailSubComponentWrapper) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) ExportEntityName(de.symeda.sormas.ui.utils.ExportEntityName) ContactDownloadUtil(de.symeda.sormas.ui.utils.ContactDownloadUtil) ViewModelProviders(de.symeda.sormas.ui.ViewModelProviders) CssStyles(de.symeda.sormas.ui.utils.CssStyles) ExpandableButton(de.symeda.sormas.ui.utils.components.expandablebutton.ExpandableButton) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto) MenuBarHelper(de.symeda.sormas.ui.utils.MenuBarHelper) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) ShortcutAction(com.vaadin.event.ShortcutAction) UserRole(de.symeda.sormas.api.user.UserRole) UserProvider(de.symeda.sormas.ui.UserProvider) ValoTheme(com.vaadin.ui.themes.ValoTheme) MenuBar(com.vaadin.ui.MenuBar) ComboBox(com.vaadin.v7.ui.ComboBox) Set(java.util.Set) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Collectors(java.util.stream.Collectors) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) ContactGrid(de.symeda.sormas.ui.contact.ContactGrid) ContactDto(de.symeda.sormas.api.contact.ContactDto) TextField(com.vaadin.v7.ui.TextField) Descriptions(de.symeda.sormas.api.i18n.Descriptions) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) StreamResource(com.vaadin.server.StreamResource) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) VerticalLayout(com.vaadin.ui.VerticalLayout) GridExportStreamResource(de.symeda.sormas.ui.utils.GridExportStreamResource) HashMap(java.util.HashMap) PopupButton(org.vaadin.hene.popupbutton.PopupButton) ViewConfiguration(de.symeda.sormas.ui.utils.ViewConfiguration) Label(com.vaadin.ui.Label) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ContentMode(com.vaadin.shared.ui.ContentMode) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserDto(de.symeda.sormas.api.user.UserDto) Captions(de.symeda.sormas.api.i18n.Captions) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) Button(com.vaadin.ui.Button) LayoutUtil(de.symeda.sormas.ui.utils.LayoutUtil) HorizontalLayout(com.vaadin.ui.HorizontalLayout) CaseContactsImportLayout(de.symeda.sormas.ui.contact.importer.CaseContactsImportLayout) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserDto(de.symeda.sormas.api.user.UserDto) Label(com.vaadin.ui.Label) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) TextField(com.vaadin.v7.ui.TextField) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 2 with ContactClassification

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

the class ContactClassificationCurveBuilder method buildEpiCurve.

@Override
public void buildEpiCurve(List<Date> datesGroupedBy, DashboardDataProvider dashboardDataProvider) {
    int[] unconfirmedNumbers = new int[datesGroupedBy.size()];
    int[] confirmedNumbers = new int[datesGroupedBy.size()];
    for (int i = 0; i < datesGroupedBy.size(); i++) {
        Date date = datesGroupedBy.get(i);
        ContactCriteria contactCriteria = new ContactCriteria().disease(dashboardDataProvider.getDisease()).region(dashboardDataProvider.getRegion()).district(dashboardDataProvider.getDistrict());
        if (epiCurveGrouping == DAY) {
            contactCriteria.reportDateBetween(DateHelper.getStartOfDay(date), DateHelper.getEndOfDay(date));
        } else if (epiCurveGrouping == EpiCurveGrouping.WEEK) {
            contactCriteria.reportDateBetween(DateHelper.getStartOfWeek(date), DateHelper.getEndOfWeek(date));
        } else {
            contactCriteria.reportDateBetween(DateHelper.getStartOfMonth(date), DateHelper.getEndOfMonth(date));
        }
        Map<ContactClassification, Long> contactCounts = FacadeProvider.getContactFacade().getNewContactCountPerClassification(contactCriteria);
        Long unconfirmedCount = contactCounts.get(ContactClassification.UNCONFIRMED);
        Long confirmedCount = contactCounts.get(ContactClassification.CONFIRMED);
        unconfirmedNumbers[i] = unconfirmedCount != null ? unconfirmedCount.intValue() : 0;
        confirmedNumbers[i] = confirmedCount != null ? confirmedCount.intValue() : 0;
    }
    hcjs.append("series: [");
    hcjs.append("{ name: '" + I18nProperties.getCaption(Captions.dashboardUnconfirmedContact) + "', color: '#808080', dataLabels: { allowOverlap: false }, data: [");
    for (int i = 0; i < unconfirmedNumbers.length; i++) {
        if (i == unconfirmedNumbers.length - 1) {
            hcjs.append(unconfirmedNumbers[i] + "]},");
        } else {
            hcjs.append(unconfirmedNumbers[i] + ", ");
        }
    }
    hcjs.append("{ name: '" + I18nProperties.getCaption(Captions.dashboardConfirmedContact) + "', color: '#005A9C', dataLabels: { allowOverlap: false },  data: [");
    for (int i = 0; i < confirmedNumbers.length; i++) {
        if (i == confirmedNumbers.length - 1) {
            hcjs.append(confirmedNumbers[i] + "]}],");
        } else {
            hcjs.append(confirmedNumbers[i] + ", ");
        }
    }
}
Also used : ContactClassification(de.symeda.sormas.api.contact.ContactClassification) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Date(java.util.Date)

Example 3 with ContactClassification

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

the class ContactService method getNewContactCountPerClassification.

public Map<ContactClassification, Long> getNewContactCountPerClassification(ContactCriteria contactCriteria, User user) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Contact> contact = cq.from(getElementClass());
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
    Predicate filter = createUserFilter(cb, cq, contact);
    Predicate criteriaFilter = buildCriteriaFilter(contactCriteria, contactQueryContext);
    Predicate notDeleted = cb.isFalse(contact.get(Contact.DELETED));
    if (filter != null) {
        filter = cb.and(filter, criteriaFilter, notDeleted);
    } else {
        filter = cb.and(criteriaFilter, notDeleted);
    }
    if (filter != null) {
        cq.where(filter);
    }
    cq.groupBy(contact.get(Contact.CONTACT_CLASSIFICATION));
    cq.multiselect(contact.get(Contact.CONTACT_CLASSIFICATION), cb.count(contact));
    List<Object[]> results = em.createQuery(cq).getResultList();
    return results.stream().collect(Collectors.toMap(e -> (ContactClassification) e[0], e -> (Long) e[1]));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) FeatureConfigurationFacadeEjb(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb) Visit(de.symeda.sormas.backend.visit.Visit) EpiData(de.symeda.sormas.backend.epidata.EpiData) From(javax.persistence.criteria.From) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) EnumMap(java.util.EnumMap) Transactional(javax.transaction.Transactional) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) DashboardContactDto(de.symeda.sormas.api.dashboard.DashboardContactDto) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) SampleService(de.symeda.sormas.backend.sample.SampleService) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) Selection(javax.persistence.criteria.Selection) Case(de.symeda.sormas.backend.caze.Case) LocalBean(javax.ejb.LocalBean) ContactListEntryDtoResultTransformer(de.symeda.sormas.backend.contact.transformers.ContactListEntryDtoResultTransformer) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) Disease(de.symeda.sormas.api.Disease) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) HealthConditions(de.symeda.sormas.backend.clinicalcourse.HealthConditions) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) ContactProximity(de.symeda.sormas.api.contact.ContactProximity) ExposureService(de.symeda.sormas.backend.exposure.ExposureService) UserRole(de.symeda.sormas.api.user.UserRole) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) Stateless(javax.ejb.Stateless) CaseService(de.symeda.sormas.backend.caze.CaseService) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) Person(de.symeda.sormas.backend.person.Person) Timestamp(java.sql.Timestamp) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) List(java.util.List) CoreAdo(de.symeda.sormas.backend.common.CoreAdo) ContactDto(de.symeda.sormas.api.contact.ContactDto) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) HashSet(java.util.HashSet) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) CollectionUtils(org.apache.commons.collections.CollectionUtils) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) ContactListEntryDto(de.symeda.sormas.api.contact.ContactListEntryDto) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) Event(de.symeda.sormas.backend.event.Event) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Predicate(javax.persistence.criteria.Predicate)

Example 4 with ContactClassification

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

the class ContactFacadeEjb method getMatchingContacts.

@Override
public List<SimilarContactDto> getMatchingContacts(ContactSimilarityCriteria criteria) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<SimilarContactDto> cq = cb.createQuery(SimilarContactDto.class);
    final Root<Contact> contactRoot = cq.from(Contact.class);
    cq.distinct(true);
    ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contactRoot);
    ContactJoins<Contact> joins = (ContactJoins<Contact>) contactQueryContext.getJoins();
    List<Selection<?>> selections = new ArrayList<>(Arrays.asList(joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), contactRoot.get(Contact.UUID), joins.getCaze().get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), contactRoot.get(Contact.CASE_ID_EXTERNAL_SYSTEM), contactRoot.get(Contact.LAST_CONTACT_DATE), contactRoot.get(Contact.CONTACT_PROXIMITY), contactRoot.get(Contact.CONTACT_CLASSIFICATION), contactRoot.get(Contact.CONTACT_STATUS), contactRoot.get(Contact.FOLLOW_UP_STATUS)));
    selections.addAll(service.getJurisdictionSelections(contactQueryContext));
    cq.multiselect(selections);
    final Predicate defaultFilter = service.createDefaultFilter(cb, contactRoot);
    final Predicate userFilter = service.createUserFilter(cb, cq, contactRoot);
    final PersonReferenceDto person = criteria.getPerson();
    final Predicate samePersonFilter = person != null ? cb.equal(joins.getPerson().get(Person.UUID), person.getUuid()) : null;
    final Disease disease = criteria.getDisease();
    final Predicate diseaseFilter = disease != null ? cb.equal(contactRoot.get(Contact.DISEASE), disease) : null;
    final CaseReferenceDto caze = criteria.getCaze();
    final Predicate cazeFilter = caze != null ? cb.equal(joins.getCaze().get(Case.UUID), caze.getUuid()) : null;
    final ContactClassification contactClassification = criteria.getContactClassification();
    final Predicate contactClassificationFilter = contactClassification != null ? cb.equal(contactRoot.get(Contact.CONTACT_CLASSIFICATION), contactClassification) : null;
    final Predicate noResulingCaseFilter = Boolean.TRUE.equals(criteria.getNoResultingCase()) ? cb.isNull(contactRoot.get(Contact.RESULTING_CASE)) : null;
    final Date reportDate = criteria.getReportDate();
    final Date lastContactDate = criteria.getLastContactDate();
    final Predicate recentContactsFilter = CriteriaBuilderHelper.and(cb, service.recentDateFilter(cb, reportDate, contactRoot.get(Contact.REPORT_DATE_TIME), 30), service.recentDateFilter(cb, lastContactDate, contactRoot.get(Contact.LAST_CONTACT_DATE), 30));
    final Date relevantDate = criteria.getRelevantDate();
    final Predicate relevantDateFilter = CriteriaBuilderHelper.or(cb, service.recentDateFilter(cb, relevantDate, contactRoot.get(Contact.REPORT_DATE_TIME), 30), service.recentDateFilter(cb, relevantDate, contactRoot.get(Contact.LAST_CONTACT_DATE), 30));
    cq.where(CriteriaBuilderHelper.and(cb, defaultFilter, userFilter, samePersonFilter, diseaseFilter, cazeFilter, contactClassificationFilter, noResulingCaseFilter, recentContactsFilter, relevantDateFilter));
    List<SimilarContactDto> contacts = em.createQuery(cq).getResultList();
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    pseudonymizer.pseudonymizeDtoCollection(SimilarContactDto.class, contacts, c -> c.getInJurisdiction(), (c, isInJurisdiction) -> {
        CaseReferenceDto contactCase = c.getCaze();
        if (contactCase != null) {
            pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, contactCase, c.getCaseInJurisdiction(), null);
        }
    });
    if (Boolean.TRUE.equals(criteria.getExcludePseudonymized())) {
        contacts = contacts.stream().filter(c -> !c.isPseudonymized()).collect(Collectors.toList());
    }
    return contacts;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Disease(de.symeda.sormas.api.Disease) Selection(javax.persistence.criteria.Selection) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ArrayList(java.util.ArrayList) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) Date(java.util.Date) LocalDate(java.time.LocalDate) Predicate(javax.persistence.criteria.Predicate) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 5 with ContactClassification

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

the class ContactService method udpateContactStatus.

/**
 * Calculates resultingCase and contact status based on: - existing disease
 * cases (and classification) of the person - the incubation period - the
 * contact classification - the follow-up status
 */
public void udpateContactStatus(Contact contact) {
    ContactClassification contactClassification = contact.getContactClassification();
    if (contactClassification == null) {
        // Fall-back
        contactClassification = ContactClassification.UNCONFIRMED;
    }
    switch(contactClassification) {
        case UNCONFIRMED:
            contact.setContactStatus(ContactStatus.ACTIVE);
            break;
        case NO_CONTACT:
            contact.setContactStatus(ContactStatus.DROPPED);
            cancelFollowUp(contact, I18nProperties.getString(Strings.messageSystemFollowUpCanceledByDropping));
            break;
        case CONFIRMED:
            if (contact.getResultingCase() != null) {
                contact.setContactStatus(ContactStatus.CONVERTED);
            } else {
                if (contact.getFollowUpStatus() != null) {
                    switch(contact.getFollowUpStatus()) {
                        case CANCELED:
                        case COMPLETED:
                        case LOST:
                        case NO_FOLLOW_UP:
                            contact.setContactStatus(ContactStatus.DROPPED);
                            break;
                        case FOLLOW_UP:
                            contact.setContactStatus(ContactStatus.ACTIVE);
                            break;
                        default:
                            throw new NoSuchElementException(contact.getFollowUpStatus().toString());
                    }
                } else {
                    contact.setContactStatus(ContactStatus.ACTIVE);
                }
            }
            break;
        default:
            throw new NoSuchElementException(DataHelper.toStringNullable(contactClassification));
    }
    externalJournalService.handleExternalJournalPersonUpdateAsync(contact.getPerson().toReference());
    ensurePersisted(contact);
}
Also used : ContactClassification(de.symeda.sormas.api.contact.ContactClassification) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ContactClassification (de.symeda.sormas.api.contact.ContactClassification)5 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)3 Date (java.util.Date)3 Disease (de.symeda.sormas.api.Disease)2 ContactDto (de.symeda.sormas.api.contact.ContactDto)2 ContactStatus (de.symeda.sormas.api.contact.ContactStatus)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 Strings (de.symeda.sormas.api.i18n.Strings)2 UserRole (de.symeda.sormas.api.user.UserRole)2 Collections (java.util.Collections)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 Selection (javax.persistence.criteria.Selection)2 ShortcutAction (com.vaadin.event.ShortcutAction)1 VaadinIcons (com.vaadin.icons.VaadinIcons)1 StreamResource (com.vaadin.server.StreamResource)1 ContentMode (com.vaadin.shared.ui.ContentMode)1 Alignment (com.vaadin.ui.Alignment)1