Search in sources :

Example 1 with VisitOrigin

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

the class ContactFacadeEjb method getContactFollowUpList.

@Override
public List<ContactFollowUpDto> getContactFollowUpList(ContactCriteria contactCriteria, Date referenceDate, int interval, Integer first, Integer max, List<SortProperty> sortProperties) {
    Date end = DateHelper.getEndOfDay(referenceDate);
    Date start = DateHelper.getStartOfDay(DateHelper.subtractDays(end, interval));
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ContactFollowUpDto> cq = cb.createQuery(ContactFollowUpDto.class);
    Root<Contact> contact = cq.from(Contact.class);
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
    final ContactJoins<Contact> joins = (ContactJoins<Contact>) contactQueryContext.getJoins();
    cq.multiselect(contact.get(Contact.UUID), contact.get(Contact.CHANGE_DATE), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getContactOfficer().get(User.UUID), joins.getContactOfficer().get(User.FIRST_NAME), joins.getContactOfficer().get(User.LAST_NAME), contact.get(Contact.LAST_CONTACT_DATE), contact.get(Contact.REPORT_DATE_TIME), contact.get(Contact.FOLLOW_UP_UNTIL), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), contact.get(Contact.DISEASE), jurisdictionSelector(contactQueryContext));
    // Only use user filter if no restricting case is specified
    Predicate filter = listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext);
    if (filter != null) {
        cq.where(filter);
    }
    cq.distinct(true);
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<Order>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case FollowUpDto.UUID:
                case ContactFollowUpDto.LAST_CONTACT_DATE:
                case FollowUpDto.FOLLOW_UP_UNTIL:
                    expression = contact.get(sortProperty.propertyName);
                    break;
                case FollowUpDto.REPORT_DATE:
                    expression = contact.get(Contact.REPORT_DATE_TIME);
                    break;
                case FollowUpDto.SYMPTOM_JOURNAL_STATUS:
                    expression = joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS);
                    break;
                case FollowUpDto.FIRST_NAME:
                    expression = joins.getPerson().get(Person.FIRST_NAME);
                    break;
                case FollowUpDto.LAST_NAME:
                    expression = joins.getPerson().get(Person.LAST_NAME);
                    break;
                case ContactFollowUpDto.CONTACT_OFFICER:
                    expression = joins.getContactOfficer().get(User.FIRST_NAME);
                    order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
                    expression = joins.getContactOfficer().get(User.LAST_NAME);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.desc(contact.get(Contact.CHANGE_DATE)));
    }
    List<ContactFollowUpDto> resultList = QueryHelper.getResultList(em, cq, first, max);
    if (!resultList.isEmpty()) {
        List<String> contactUuids = resultList.stream().map(d -> d.getUuid()).collect(Collectors.toList());
        CriteriaQuery<Object[]> visitsCq = cb.createQuery(Object[].class);
        Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
        Join<Contact, Visit> visitsJoin = visitsCqRoot.join(Contact.VISITS, JoinType.LEFT);
        Join<Visit, Symptoms> visitSymptomsJoin = visitsJoin.join(Visit.SYMPTOMS, JoinType.LEFT);
        visitsCq.where(CriteriaBuilderHelper.and(cb, contact.get(AbstractDomainObject.UUID).in(contactUuids), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS)), cb.between(visitsJoin.get(Visit.VISIT_DATE_TIME), start, end)));
        visitsCq.multiselect(visitsCqRoot.get(Contact.UUID), visitsJoin.get(Visit.VISIT_DATE_TIME), visitsJoin.get(Visit.VISIT_STATUS), visitsJoin.get(Visit.ORIGIN), visitSymptomsJoin.get(Symptoms.SYMPTOMATIC));
        visitsCq.orderBy(cb.asc(visitsJoin.get(Visit.VISIT_DATE_TIME)), cb.asc(visitsJoin.get(Visit.CREATION_DATE)));
        List<Object[]> visits = em.createQuery(visitsCq).getResultList();
        Map<String, ContactFollowUpDto> resultMap = resultList.stream().collect(Collectors.toMap(ContactFollowUpDto::getUuid, Function.identity()));
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        for (ContactFollowUpDto contactFollowUpDto : resultMap.values()) {
            contactFollowUpDto.initVisitSize(interval + 1);
            boolean isInJurisdiction = contactFollowUpDto.getInJurisdiction();
            pseudonymizer.pseudonymizeDto(ContactFollowUpDto.class, contactFollowUpDto, isInJurisdiction, null);
        }
        for (Object[] v : visits) {
            int day = DateHelper.getDaysBetween(start, (Date) v[1]);
            VisitResultDto result = getVisitResult((VisitStatus) v[2], (VisitOrigin) v[3], (Boolean) v[4]);
            resultMap.get(v[0]).getVisitResults()[day - 1] = result;
        }
    }
    return resultList;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) VisitService(de.symeda.sormas.backend.visit.VisitService) Arrays(java.util.Arrays) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) PersonDto(de.symeda.sormas.api.person.PersonDto) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) Valid(javax.validation.Valid) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Page(de.symeda.sormas.api.common.Page) FollowUpDto(de.symeda.sormas.api.followup.FollowUpDto) 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) BigInteger(java.math.BigInteger) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) Visit(de.symeda.sormas.backend.visit.Visit) EpiData(de.symeda.sormas.backend.epidata.EpiData) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ContactExportDto(de.symeda.sormas.api.contact.ContactExportDto) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Resource(javax.annotation.Resource) Set(java.util.Set) SampleFacadeEjbLocal(de.symeda.sormas.backend.sample.SampleFacadeEjb.SampleFacadeEjbLocal) TaskPriority(de.symeda.sormas.api.task.TaskPriority) 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) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) ContactFacade(de.symeda.sormas.api.contact.ContactFacade) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Community(de.symeda.sormas.backend.infrastructure.community.Community) FollowUpPeriodDto(de.symeda.sormas.api.followup.FollowUpPeriodDto) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) LocalDateTime(java.time.LocalDateTime) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Selection(javax.persistence.criteria.Selection) VisitFacadeEjbLocal(de.symeda.sormas.backend.visit.VisitFacadeEjb.VisitFacadeEjbLocal) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) MergeContactIndexDto(de.symeda.sormas.api.contact.MergeContactIndexDto) Case(de.symeda.sormas.backend.caze.Case) EpiDataFacadeEjb(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb) LocalBean(javax.ejb.LocalBean) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) ExportHelper(de.symeda.sormas.backend.importexport.ExportHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ContactSimilarityCriteria(de.symeda.sormas.api.contact.ContactSimilarityCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) 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) TaskCreationException(de.symeda.sormas.backend.common.TaskCreationException) Exposure(de.symeda.sormas.backend.exposure.Exposure) DAYS(java.time.temporal.ChronoUnit.DAYS) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) DateHelper8(de.symeda.sormas.backend.util.DateHelper8) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) SymptomsFacadeEjb(de.symeda.sormas.backend.symptoms.SymptomsFacadeEjb) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) EventService(de.symeda.sormas.backend.event.EventService) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) ExposureType(de.symeda.sormas.api.exposure.ExposureType) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) HealthConditionsMapper(de.symeda.sormas.backend.clinicalcourse.HealthConditionsMapper) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) SormasToSormasContactFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb.SormasToSormasContactFacadeEjbLocal) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) UserRole(de.symeda.sormas.api.user.UserRole) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) ContactFollowUpDto(de.symeda.sormas.api.contact.ContactFollowUpDto) Stateless(javax.ejb.Stateless) DocumentService(de.symeda.sormas.backend.document.DocumentService) CaseService(de.symeda.sormas.backend.caze.CaseService) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) Person(de.symeda.sormas.backend.person.Person) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) SormasToSormasFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb.SormasToSormasFacadeEjbLocal) TaskType(de.symeda.sormas.api.task.TaskType) Objects(java.util.Objects) ExportConfigurationDto(de.symeda.sormas.api.importexport.ExportConfigurationDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) Query(javax.persistence.Query) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) ContactDto(de.symeda.sormas.api.contact.ContactDto) LocalDate(java.time.LocalDate) Order(javax.persistence.criteria.Order) Optional(java.util.Optional) EpiDataHelper(de.symeda.sormas.api.epidata.EpiDataHelper) Location(de.symeda.sormas.backend.location.Location) VisitSummaryExportDto(de.symeda.sormas.api.visit.VisitSummaryExportDto) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) ClinicalCourseFacadeEjb(de.symeda.sormas.backend.clinicalcourse.ClinicalCourseFacadeEjb) VaccinationFacadeEjb(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) CoreEntityType(de.symeda.sormas.backend.deletionconfiguration.CoreEntityType) Function(java.util.function.Function) VisitOrigin(de.symeda.sormas.api.VisitOrigin) Inject(javax.inject.Inject) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) LocationDto(de.symeda.sormas.api.location.LocationDto) TaskContext(de.symeda.sormas.api.task.TaskContext) ContactListEntryDto(de.symeda.sormas.api.contact.ContactListEntryDto) EpiDataFacadeEjbLocal(de.symeda.sormas.backend.epidata.EpiDataFacadeEjb.EpiDataFacadeEjbLocal) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) Document(de.symeda.sormas.backend.document.Document) VisitLogic.getVisitResult(de.symeda.sormas.backend.visit.VisitLogic.getVisitResult) UserReference(de.symeda.sormas.backend.user.UserReference) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) TimeUnit(java.util.concurrent.TimeUnit) UserRight(de.symeda.sormas.api.user.UserRight) VisitSummaryExportDetailsDto(de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) Country(de.symeda.sormas.backend.infrastructure.country.Country) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Visit(de.symeda.sormas.backend.visit.Visit) ArrayList(java.util.ArrayList) VisitResultDto(de.symeda.sormas.api.visit.VisitResultDto) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) ContactFollowUpDto(de.symeda.sormas.api.contact.ContactFollowUpDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms)

Aggregations

Disease (de.symeda.sormas.api.Disease)1 Language (de.symeda.sormas.api.Language)1 VisitOrigin (de.symeda.sormas.api.VisitOrigin)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 Page (de.symeda.sormas.api.common.Page)1 ContactClassification (de.symeda.sormas.api.contact.ContactClassification)1 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 ContactExportDto (de.symeda.sormas.api.contact.ContactExportDto)1 ContactFacade (de.symeda.sormas.api.contact.ContactFacade)1 ContactFollowUpDto (de.symeda.sormas.api.contact.ContactFollowUpDto)1 ContactIndexDetailedDto (de.symeda.sormas.api.contact.ContactIndexDetailedDto)1 ContactIndexDto (de.symeda.sormas.api.contact.ContactIndexDto)1 ContactListEntryDto (de.symeda.sormas.api.contact.ContactListEntryDto)1 ContactLogic (de.symeda.sormas.api.contact.ContactLogic)1 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)1 ContactSimilarityCriteria (de.symeda.sormas.api.contact.ContactSimilarityCriteria)1 ContactStatus (de.symeda.sormas.api.contact.ContactStatus)1 FollowUpStatus (de.symeda.sormas.api.contact.FollowUpStatus)1 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)1