Search in sources :

Example 21 with Language

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

the class ContactFacadeEjb method getExportList.

@Override
public List<ContactExportDto> getExportList(ContactCriteria contactCriteria, Collection<String> selectedRows, int first, int max, ExportConfigurationDto exportConfiguration, Language userLanguage) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<ContactExportDto> cq = cb.createQuery(ContactExportDto.class);
    final Root<Contact> contact = cq.from(Contact.class);
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contact);
    final ContactJoins<Contact> joins = (ContactJoins) contactQueryContext.getJoins();
    cq.multiselect(contact.get(Contact.ID), joins.getPerson().get(Person.ID), contact.get(Contact.UUID), joins.getCaze().get(Case.UUID), joins.getCaze().get(Case.CASE_CLASSIFICATION), contact.get(Contact.DISEASE), contact.get(Contact.DISEASE_DETAILS), contact.get(Contact.CONTACT_CLASSIFICATION), contact.get(Contact.MULTI_DAY_CONTACT), contact.get(Contact.FIRST_CONTACT_DATE), contact.get(Contact.LAST_CONTACT_DATE), contact.get(Contact.CREATION_DATE), joins.getPerson().get(Person.UUID), joins.getPerson().get(Person.FIRST_NAME), joins.getPerson().get(Person.LAST_NAME), joins.getPerson().get(Person.SALUTATION), joins.getPerson().get(Person.OTHER_SALUTATION), joins.getPerson().get(Person.SEX), joins.getPerson().get(Person.BIRTHDATE_DD), joins.getPerson().get(Person.BIRTHDATE_MM), joins.getPerson().get(Person.BIRTHDATE_YYYY), joins.getPerson().get(Person.APPROXIMATE_AGE), joins.getPerson().get(Person.APPROXIMATE_AGE_TYPE), contact.get(Contact.REPORT_DATE_TIME), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE), contact.get(Contact.CONTACT_IDENTIFICATION_SOURCE_DETAILS), contact.get(Contact.TRACING_APP), contact.get(Contact.TRACING_APP_DETAILS), contact.get(Contact.CONTACT_PROXIMITY), contact.get(Contact.CONTACT_STATUS), contact.get(Contact.COMPLETENESS), contact.get(Contact.FOLLOW_UP_STATUS), contact.get(Contact.FOLLOW_UP_UNTIL), contact.get(Contact.QUARANTINE), contact.get(Contact.QUARANTINE_TYPE_DETAILS), contact.get(Contact.QUARANTINE_FROM), contact.get(Contact.QUARANTINE_TO), contact.get(Contact.QUARANTINE_HELP_NEEDED), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT), contact.get(Contact.QUARANTINE_ORDERED_VERBALLY_DATE), contact.get(Contact.QUARANTINE_ORDERED_OFFICIAL_DOCUMENT_DATE), contact.get(Contact.QUARANTINE_EXTENDED), contact.get(Contact.QUARANTINE_REDUCED), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT), contact.get(Contact.QUARANTINE_OFFICIAL_ORDER_SENT_DATE), contact.get(Contact.PROHIBITION_TO_WORK), contact.get(Contact.PROHIBITION_TO_WORK_FROM), contact.get(Contact.PROHIBITION_TO_WORK_UNTIL), joins.getPerson().get(Person.PRESENT_CONDITION), joins.getPerson().get(Person.DEATH_DATE), joins.getAddressRegion().get(Region.NAME), joins.getAddressDistrict().get(District.NAME), joins.getAddressCommunity().get(Community.NAME), joins.getAddress().get(Location.CITY), joins.getAddress().get(Location.STREET), joins.getAddress().get(Location.HOUSE_NUMBER), joins.getAddress().get(Location.ADDITIONAL_INFORMATION), joins.getAddress().get(Location.POSTAL_CODE), joins.getAddressFacility().get(Facility.NAME), joins.getAddressFacility().get(Facility.UUID), joins.getAddress().get(Location.FACILITY_DETAILS), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_PHONE_OWNER_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_EMAIL_SUBQUERY)), ((Expression<String>) contactQueryContext.getSubqueryExpression(ContactQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY)), joins.getPerson().get(Person.OCCUPATION_TYPE), joins.getPerson().get(Person.OCCUPATION_DETAILS), joins.getPerson().get(Person.ARMED_FORCES_RELATION_TYPE), joins.getRegion().get(Region.NAME), joins.getDistrict().get(District.NAME), joins.getCommunity().get(Community.NAME), joins.getEpiData().get(EpiData.ID), joins.getEpiData().get(EpiData.CONTACT_WITH_SOURCE_CASE_KNOWN), contact.get(Contact.RETURNING_TRAVELER), contact.get(Contact.VACCINATION_STATUS), contact.get(Contact.EXTERNAL_ID), contact.get(Contact.EXTERNAL_TOKEN), contact.get(Contact.INTERNAL_TOKEN), joins.getPerson().get(Person.BIRTH_NAME), joins.getPersonBirthCountry().get(Country.ISO_CODE), joins.getPersonBirthCountry().get(Country.DEFAULT_NAME), joins.getPersonCitizenship().get(Country.ISO_CODE), joins.getPersonCitizenship().get(Country.DEFAULT_NAME), joins.getReportingDistrict().get(District.NAME), joins.getPerson().get(Person.SYMPTOM_JOURNAL_STATUS), joins.getReportingUser().get(User.ID), joins.getFollowUpStatusChangeUser().get(User.ID), contact.get(Contact.PREVIOUS_QUARANTINE_TO), contact.get(Contact.QUARANTINE_CHANGE_COMMENT), jurisdictionSelector(contactQueryContext));
    cq.distinct(true);
    Predicate filter = listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext);
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, contact.get(Contact.UUID));
    if (filter != null) {
        cq.where(filter);
    }
    cq.orderBy(cb.desc(contact.get(Contact.REPORT_DATE_TIME)), cb.desc(contact.get(Contact.ID)));
    List<ContactExportDto> exportContacts = QueryHelper.getResultList(em, cq, first, max);
    List<String> resultContactsUuids = exportContacts.stream().map(ContactExportDto::getUuid).collect(Collectors.toList());
    if (!exportContacts.isEmpty()) {
        List<Long> exportContactIds = exportContacts.stream().map(e -> e.getId()).collect(Collectors.toList());
        List<VisitSummaryExportDetails> visitSummaries = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.NUMBER_OF_VISITS, ContactExportDto.LAST_COOPERATIVE_VISIT_DATE, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMATIC, ContactExportDto.LAST_COOPERATIVE_VISIT_SYMPTOMS)) {
            CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
            Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
            ContactJoins<Contact> visitContactJoins = new ContactJoins(visitsCqRoot);
            visitsCq.where(CriteriaBuilderHelper.and(cb, contact.get(AbstractDomainObject.ID).in(exportContactIds), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS))));
            visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), visitContactJoins.getVisits().get(Visit.VISIT_DATE_TIME), visitContactJoins.getVisits().get(Visit.VISIT_STATUS), visitContactJoins.getVisitSymptoms(), jurisdictionSelector(new ContactQueryContext(cb, cq, visitsCqRoot)));
            visitSummaries = em.createQuery(visitsCq).getResultList();
        }
        Map<Long, List<Exposure>> exposures = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.TRAVELED, ContactExportDto.TRAVEL_HISTORY, ContactExportDto.BURIAL_ATTENDED)) {
            CriteriaQuery<Exposure> exposuresCq = cb.createQuery(Exposure.class);
            Root<Exposure> exposuresRoot = exposuresCq.from(Exposure.class);
            Join<Exposure, EpiData> exposuresEpiDataJoin = exposuresRoot.join(Exposure.EPI_DATA, JoinType.LEFT);
            Expression<String> epiDataIdsExpr = exposuresEpiDataJoin.get(EpiData.ID);
            Predicate exposuresPredicate = cb.and(epiDataIdsExpr.in(exportContacts.stream().map(ContactExportDto::getEpiDataId).collect(Collectors.toList())), cb.or(cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.TRAVEL), cb.equal(exposuresRoot.get(Exposure.EXPOSURE_TYPE), ExposureType.BURIAL)));
            exposuresCq.where(exposuresPredicate);
            exposuresCq.orderBy(cb.asc(exposuresEpiDataJoin.get(EpiData.ID)));
            List<Exposure> exposureList = em.createQuery(exposuresCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            exposures = exposureList.stream().collect(Collectors.groupingBy(e -> e.getEpiData().getId()));
        }
        Map<Long, List<Immunization>> immunizations = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ExportHelper.getVaccinationExportProperties())) {
            List<Immunization> immunizationList;
            CriteriaQuery<Immunization> immunizationsCq = cb.createQuery(Immunization.class);
            Root<Immunization> immunizationsCqRoot = immunizationsCq.from(Immunization.class);
            Join<Immunization, Person> personJoin = immunizationsCqRoot.join(Immunization.PERSON, JoinType.LEFT);
            Expression<String> personIdsExpr = personJoin.get(Person.ID);
            immunizationsCq.where(CriteriaBuilderHelper.and(cb, cb.or(cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION), cb.equal(immunizationsCqRoot.get(Immunization.MEANS_OF_IMMUNIZATION), MeansOfImmunization.VACCINATION_RECOVERY)), personIdsExpr.in(exportContacts.stream().map(ContactExportDto::getPersonId).collect(Collectors.toList()))));
            immunizationList = em.createQuery(immunizationsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            immunizations = immunizationList.stream().collect(Collectors.groupingBy(i -> i.getPerson().getId()));
        }
        Map<String, List<ContactEventSummaryDetails>> eventSummaries = null;
        if (ExportHelper.shouldExportFields(exportConfiguration, ContactExportDto.EVENT_COUNT, ContactExportDto.LATEST_EVENT_ID, ContactExportDto.LATEST_EVENT_TITLE)) {
            // Load event count and latest events info per contact
            eventSummaries = eventService.getEventSummaryDetailsByContacts(resultContactsUuids).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
        }
        Map<Long, UserReference> contactUsers = getContactUsersForExport(exportContacts, exportConfiguration);
        // Adding a second query here is not perfect, but selecting the last cooperative visit with a criteria query
        // doesn't seem to be possible and using a native query is not an option because of user filters
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        for (ContactExportDto exportContact : exportContacts) {
            boolean inJurisdiction = exportContact.getInJurisdiction();
            if (visitSummaries != null) {
                List<VisitSummaryExportDetails> visits = visitSummaries.stream().filter(v -> v.getContactId() == exportContact.getId()).collect(Collectors.toList());
                VisitSummaryExportDetails lastCooperativeVisit = visits.stream().filter(v -> v.getVisitStatus() == VisitStatus.COOPERATIVE).max(Comparator.comparing(VisitSummaryExportDetails::getVisitDateTime)).orElse(null);
                exportContact.setNumberOfVisits(visits.size());
                if (lastCooperativeVisit != null) {
                    SymptomsDto symptoms = SymptomsFacadeEjb.toDto(lastCooperativeVisit.getSymptoms());
                    pseudonymizer.pseudonymizeDto(SymptomsDto.class, symptoms, inJurisdiction, null);
                    exportContact.setLastCooperativeVisitDate(lastCooperativeVisit.getVisitDateTime());
                    exportContact.setLastCooperativeVisitSymptoms(SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage));
                    exportContact.setLastCooperativeVisitSymptomatic(symptoms.getSymptomatic() == null ? YesNoUnknown.UNKNOWN : (symptoms.getSymptomatic() ? YesNoUnknown.YES : YesNoUnknown.NO));
                }
            }
            if (exposures != null) {
                Optional.ofNullable(exposures.get(exportContact.getEpiDataId())).ifPresent(contactExposures -> {
                    StringBuilder travelHistoryBuilder = new StringBuilder();
                    if (contactExposures.stream().anyMatch(e -> ExposureType.BURIAL.equals(e.getExposureType()))) {
                        exportContact.setBurialAttended(true);
                    }
                    contactExposures.stream().filter(e -> ExposureType.TRAVEL.equals(e.getExposureType())).forEach(exposure -> {
                        travelHistoryBuilder.append(EpiDataHelper.buildDetailedTravelString(exposure.getLocation().toString(), exposure.getDescription(), exposure.getStartDate(), exposure.getEndDate(), userLanguage)).append(", ");
                    });
                    if (travelHistoryBuilder.length() > 0) {
                        exportContact.setTraveled(true);
                        travelHistoryBuilder.delete(travelHistoryBuilder.lastIndexOf(", "), travelHistoryBuilder.length());
                    }
                    exportContact.setTravelHistory(travelHistoryBuilder.toString());
                });
            }
            if (immunizations != null) {
                Optional.ofNullable(immunizations.get(exportContact.getPersonId())).ifPresent(contactImmunizations -> {
                    List<Immunization> filteredImmunizations = contactImmunizations.stream().filter(i -> i.getDisease() == exportContact.getDisease()).collect(Collectors.toList());
                    if (filteredImmunizations.size() > 0) {
                        filteredImmunizations.sort(Comparator.comparing(i -> ImmunizationEntityHelper.getDateForComparison(i, false)));
                        Immunization mostRecentImmunization = filteredImmunizations.get(filteredImmunizations.size() - 1);
                        Integer numberOfDoses = mostRecentImmunization.getNumberOfDoses();
                        exportContact.setNumberOfDoses(numberOfDoses != null ? String.valueOf(numberOfDoses) : "");
                        if (CollectionUtils.isNotEmpty(mostRecentImmunization.getVaccinations())) {
                            List<Vaccination> sortedVaccinations = mostRecentImmunization.getVaccinations().stream().sorted(Comparator.comparing(ImmunizationEntityHelper::getVaccinationDateForComparison)).collect(Collectors.toList());
                            Vaccination firstVaccination = sortedVaccinations.get(0);
                            Vaccination lastVaccination = sortedVaccinations.get(sortedVaccinations.size() - 1);
                            exportContact.setFirstVaccinationDate(firstVaccination.getVaccinationDate());
                            exportContact.setLastVaccinationDate(lastVaccination.getVaccinationDate());
                            exportContact.setVaccineName(lastVaccination.getVaccineName());
                            exportContact.setOtherVaccineName(lastVaccination.getOtherVaccineName());
                            exportContact.setVaccineManufacturer(lastVaccination.getVaccineManufacturer());
                            exportContact.setOtherVaccineManufacturer(lastVaccination.getOtherVaccineManufacturer());
                            exportContact.setVaccinationInfoSource(lastVaccination.getVaccinationInfoSource());
                            exportContact.setVaccineAtcCode(lastVaccination.getVaccineAtcCode());
                            exportContact.setVaccineBatchNumber(lastVaccination.getVaccineBatchNumber());
                            exportContact.setVaccineUniiCode(lastVaccination.getVaccineUniiCode());
                            exportContact.setVaccineInn(lastVaccination.getVaccineInn());
                        }
                    }
                });
            }
            if (eventSummaries != null) {
                List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(exportContact.getUuid(), Collections.emptyList());
                exportContact.setEventCount((long) contactEvents.size());
                contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
                    exportContact.setLatestEventId(eventSummary.getEventUuid());
                    exportContact.setLatestEventTitle(eventSummary.getEventTitle());
                });
            }
            if (!contactUsers.isEmpty()) {
                if (exportContact.getReportingUserId() != null) {
                    UserReference user = contactUsers.get(exportContact.getReportingUserId());
                    exportContact.setReportingUserName(user.getName());
                    exportContact.setReportingUserRoles(user.getUserRoles());
                }
                if (exportContact.getFollowUpStatusChangeUserId() != null) {
                    UserReference user = contactUsers.get(exportContact.getFollowUpStatusChangeUserId());
                    exportContact.setFollowUpStatusChangeUserName(user.getName());
                    exportContact.setFollowUpStatusChangeUserRoles(user.getUserRoles());
                }
            }
            pseudonymizer.pseudonymizeDto(ContactExportDto.class, exportContact, inJurisdiction, null);
        }
    }
    return exportContacts;
}
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) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ImmunizationEntityHelper(de.symeda.sormas.backend.immunization.ImmunizationEntityHelper) Predicate(javax.persistence.criteria.Predicate) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Exposure(de.symeda.sormas.backend.exposure.Exposure) UserReference(de.symeda.sormas.backend.user.UserReference) Person(de.symeda.sormas.backend.person.Person) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) ContactExportDto(de.symeda.sormas.api.contact.ContactExportDto) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) EpiData(de.symeda.sormas.backend.epidata.EpiData) BigInteger(java.math.BigInteger) Expression(javax.persistence.criteria.Expression)

Example 22 with Language

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

the class ContactFacadeEjb method getVisitSummaryExportList.

@Override
public List<VisitSummaryExportDto> getVisitSummaryExportList(ContactCriteria contactCriteria, Collection<String> selectedRows, int first, int max, Language userLanguage) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<VisitSummaryExportDto> cq = cb.createQuery(VisitSummaryExportDto.class);
    final Root<Contact> contactRoot = cq.from(Contact.class);
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, contactRoot);
    final ContactJoins contactJoins = (ContactJoins) contactQueryContext.getJoins();
    final Join<Contact, Person> contactPerson = contactJoins.getPerson();
    cq.multiselect(contactRoot.get(Contact.UUID), contactRoot.get(Contact.ID), contactPerson.get(Person.FIRST_NAME), contactPerson.get(Person.LAST_NAME), cb.<Date>selectCase().when(cb.isNotNull(contactRoot.get(Contact.LAST_CONTACT_DATE)), contactRoot.get(Contact.LAST_CONTACT_DATE)).otherwise(contactRoot.get(Contact.REPORT_DATE_TIME)), contactRoot.get(Contact.FOLLOW_UP_UNTIL));
    Predicate filter = CriteriaBuilderHelper.and(cb, listCriteriaBuilder.buildContactFilter(contactCriteria, contactQueryContext), cb.isNotEmpty(contactRoot.get(Contact.VISITS)));
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, contactRoot.get(Contact.UUID));
    cq.where(filter);
    cq.orderBy(cb.asc(contactRoot.get(Contact.REPORT_DATE_TIME)));
    List<VisitSummaryExportDto> visitSummaries = QueryHelper.getResultList(em, cq, first, max);
    if (!visitSummaries.isEmpty()) {
        List<String> visitSummaryUuids = visitSummaries.stream().map(e -> e.getUuid()).collect(Collectors.toList());
        CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class);
        Root<Contact> visitsCqRoot = visitsCq.from(Contact.class);
        ContactJoins<Contact> joins = new ContactJoins(visitsCqRoot);
        visitsCq.where(CriteriaBuilderHelper.and(cb, contactRoot.get(AbstractDomainObject.UUID).in(visitSummaryUuids), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS))));
        visitsCq.multiselect(visitsCqRoot.get(AbstractDomainObject.ID), joins.getVisits().get(Visit.VISIT_DATE_TIME), joins.getVisits().get(Visit.VISIT_STATUS), joins.getVisitSymptoms(), jurisdictionSelector(new ContactQueryContext(cb, cq, visitsCqRoot)));
        visitsCq.orderBy(cb.asc(joins.getVisits().get(Visit.VISIT_DATE_TIME)));
        List<VisitSummaryExportDetails> visitSummaryDetails = em.createQuery(visitsCq).getResultList();
        Map<Long, VisitSummaryExportDto> visitSummaryMap = visitSummaries.stream().collect(Collectors.toMap(VisitSummaryExportDto::getContactId, Function.identity()));
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        visitSummaryDetails.forEach(v -> {
            SymptomsDto symptoms = SymptomsFacadeEjb.toDto(v.getSymptoms());
            pseudonymizer.pseudonymizeDto(SymptomsDto.class, symptoms, v.getInJurisdiction(), null);
            visitSummaryMap.get(v.getContactId()).getVisitDetails().add(new VisitSummaryExportDetailsDto(v.getVisitDateTime(), v.getVisitStatus(), SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage)));
        });
    }
    return visitSummaries;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) 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) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) VisitSummaryExportDetailsDto(de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto) Predicate(javax.persistence.criteria.Predicate) VisitSummaryExportDto(de.symeda.sormas.api.visit.VisitSummaryExportDto) Person(de.symeda.sormas.backend.person.Person)

Example 23 with Language

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

the class CustomizableEnumFacadeEjb method getEnumValue.

/**
 * Using LockType.READ to provide concurrent locks to multiple clients.
 */
@Lock(LockType.READ)
@Override
@SuppressWarnings("unchecked")
public <T extends CustomizableEnum> T getEnumValue(CustomizableEnumType type, String value) {
    if (!enumValues.get(type).contains(value)) {
        throw new IllegalArgumentException("Invalid enum value " + value + " for customizable enum type " + type.toString());
    }
    Language language = I18nProperties.getUserLanguage();
    Class<T> enumClass = (Class<T>) type.getEnumClass();
    if (!enumValuesByLanguage.get(enumClass).containsKey(language)) {
        fillLanguageCache(type, enumClass, language);
    }
    return buildCustomizableEnum(type, value, language, enumClass);
}
Also used : Language(de.symeda.sormas.api.Language) Lock(javax.ejb.Lock)

Example 24 with Language

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

the class CustomizableEnumFacadeEjb method getEnumValues.

/**
 * @return Entries are currently not returned in any specific order
 */
@Lock(LockType.READ)
@Override
@SuppressWarnings("unchecked")
public <T extends CustomizableEnum> List<T> getEnumValues(CustomizableEnumType type, Disease disease) {
    Language language = I18nProperties.getUserLanguage();
    Class<T> enumClass = (Class<T>) type.getEnumClass();
    Optional<Disease> innerDisease = Optional.ofNullable(disease);
    if (!enumValuesByLanguage.get(enumClass).containsKey(language)) {
        fillLanguageCache(type, enumClass, language);
    }
    if (!enumValuesByDisease.get(enumClass).containsKey(innerDisease)) {
        fillDiseaseCache(type, enumClass, innerDisease);
    }
    Stream<String> diseaseValuesStream;
    if (innerDisease.isPresent()) {
        // combine specific and unspecific values
        diseaseValuesStream = Stream.concat(enumValuesByDisease.get(enumClass).get(innerDisease).stream(), enumValuesByDisease.get(enumClass).get(Optional.empty()).stream());
    } else {
        diseaseValuesStream = enumValuesByDisease.get(enumClass).get(Optional.empty()).stream();
    }
    return diseaseValuesStream.map(value -> buildCustomizableEnum(type, value, language, enumClass)).collect(Collectors.toList());
}
Also used : CustomEnumNotFoundException(de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Lock(javax.ejb.Lock) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) CustomizableEnumFacade(de.symeda.sormas.api.customizableenum.CustomizableEnumFacade) Map(java.util.Map) CustomizableEnumTranslation(de.symeda.sormas.api.customizableenum.CustomizableEnumTranslation) CustomizableEnumValueDto(de.symeda.sormas.api.customizableenum.CustomizableEnumValueDto) EJB(javax.ejb.EJB) ConfigFacadeEjb(de.symeda.sormas.backend.common.ConfigFacadeEjb) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) LockType(javax.ejb.LockType) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Stream(java.util.stream.Stream) Disease(de.symeda.sormas.api.Disease) Singleton(javax.ejb.Singleton) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CustomizableEnum(de.symeda.sormas.api.customizableenum.CustomizableEnum) InvalidCustomizationException(de.symeda.sormas.api.utils.InvalidCustomizationException) Language(de.symeda.sormas.api.Language) Disease(de.symeda.sormas.api.Disease) Lock(javax.ejb.Lock)

Example 25 with Language

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

the class TravelEntryImportFacadeEjb method insertColumnEntryIntoData.

private void insertColumnEntryIntoData(TravelEntryDto travelEntry, PersonDto person, String entry, String[] entryHeaderPath) throws InvalidColumnException, ImportErrorException {
    String propertyCaption = String.join("", entryHeaderPath);
    // Build the SORMAS property based on the DEA caption
    String personProperty = getPersonProperty(propertyCaption);
    Object currentElement = personProperty != null ? person : travelEntry;
    if (personProperty != null) {
        // Map the entry to an expected SORMAS value if necessary
        entry = getPersonValue(personProperty, entry);
    }
    Language language = I18nProperties.getUserLanguage();
    try {
        // Some person-related fields need to be handled in a specific way for the DEA import
        if (PersonDto.BIRTH_DATE.equals(personProperty)) {
            Date birthDate = DateHelper.parseDate(entry, new SimpleDateFormat("dd.MM.yyyy"));
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(birthDate);
            person.setBirthdateDD(calendar.get(Calendar.DAY_OF_MONTH));
            // In calendar API months are indexed from 0 @see https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH
            int birthdateMonth = calendar.get(Calendar.MONTH) + 1;
            person.setBirthdateMM(birthdateMonth);
            person.setBirthdateYYYY(calendar.get(Calendar.YEAR));
            return;
        } else if (PHONE_PRIVATE.equals(personProperty)) {
            person.setPhone(entry);
            return;
        } else if (PHONE_ADDITIONAL.equals(personProperty)) {
            person.setAdditionalPhone(entry);
            return;
        } else if (EMAIL.equals(personProperty)) {
            person.setEmailAddress(entry);
            return;
        }
        String relevantProperty = personProperty != null ? personProperty : propertyCaption;
        PropertyDescriptor pd = new PropertyDescriptor(relevantProperty, currentElement.getClass());
        Class<?> propertyType = pd.getPropertyType();
        // according to the types of the case or person fields
        if (importFacade.executeDefaultInvoke(pd, currentElement, entry, entryHeaderPath, false)) {
        // No action needed
        } else if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
            List<DistrictReferenceDto> district = districtFacade.getByName(entry, ImportHelper.getRegionBasedOnDistrict(pd.getName(), null, null, travelEntry, person, currentElement), false);
            if (district.isEmpty()) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, entry, buildEntityProperty(entryHeaderPath)));
            } else if (district.size() > 1) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, entry, buildEntityProperty(entryHeaderPath)));
            } else {
                pd.getWriteMethod().invoke(currentElement, district.get(0));
            }
        } else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
            List<CommunityReferenceDto> community = communityFacade.getByName(entry, travelEntry.getResponsibleDistrict(), false);
            if (community.isEmpty()) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
            } else if (community.size() > 1) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCommunityNotUnique, entry, buildEntityProperty(entryHeaderPath)));
            } else {
                pd.getWriteMethod().invoke(currentElement, community.get(0));
            }
        } else if (propertyType.isAssignableFrom(PointOfEntryReferenceDto.class)) {
            PointOfEntryReferenceDto pointOfEntryReference;
            DistrictReferenceDto pointOfEntryDistrict = travelEntry.getPointOfEntryDistrict() != null ? travelEntry.getPointOfEntryDistrict() : travelEntry.getResponsibleDistrict();
            List<PointOfEntryReferenceDto> customPointsOfEntry = pointOfEntryFacade.getByName(entry, pointOfEntryDistrict, false);
            if (customPointsOfEntry.isEmpty()) {
                final String poeName = entry;
                List<PointOfEntryDto> defaultPointOfEntries = pointOfEntryFacade.getByUuids(PointOfEntryDto.CONSTANT_POE_UUIDS);
                Optional<PointOfEntryDto> defaultPointOfEntry = defaultPointOfEntries.stream().filter(defaultPoe -> InfrastructureHelper.buildPointOfEntryString(defaultPoe.getUuid(), defaultPoe.getName()).equals(poeName)).findFirst();
                if (!defaultPointOfEntry.isPresent()) {
                    throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
                }
                pointOfEntryReference = defaultPointOfEntry.get().toReference();
            } else if (customPointsOfEntry.size() > 1) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importPointOfEntryNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
            } else {
                pointOfEntryReference = customPointsOfEntry.get(0);
            }
            pd.getWriteMethod().invoke(currentElement, pointOfEntryReference);
        } else {
            throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
        }
    } catch (IntrospectionException e) {
        // Add the property to the deaContent field of the travel entry
        if (travelEntry.getDeaContent() == null) {
            travelEntry.setDeaContent(new ArrayList<>());
        }
        travelEntry.getDeaContent().add(new DeaContentEntry(propertyCaption, entry));
    } catch (InvocationTargetException | IllegalAccessException e) {
        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entryHeaderPath)));
    } catch (IllegalArgumentException | EnumService.InvalidEnumCaptionException e) {
        throw new ImportErrorException(entry, buildEntityProperty(entryHeaderPath));
    } catch (ParseException e) {
        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importInvalidDate, buildEntityProperty(entryHeaderPath), DateHelper.getAllowedDateFormats(language.getDateFormat())));
    } catch (ImportErrorException | UnsupportedOperationException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Unexpected error when trying to import a travel entry: " + e.getMessage(), e);
        throw new ImportErrorException(I18nProperties.getValidationError(Validations.importUnexpectedError));
    }
}
Also used : IntrospectionException(java.beans.IntrospectionException) ArrayList(java.util.ArrayList) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) Language(de.symeda.sormas.api.Language) List(java.util.List) ArrayList(java.util.ArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) Optional(java.util.Optional) DeaContentEntry(de.symeda.sormas.api.travelentry.DeaContentEntry) Calendar(java.util.Calendar) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) ParseException(java.text.ParseException) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Language (de.symeda.sormas.api.Language)31 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)14 List (java.util.List)14 Date (java.util.Date)12 Optional (java.util.Optional)11 ArrayList (java.util.ArrayList)10 Collectors (java.util.stream.Collectors)9 Map (java.util.Map)8 StringUtils (org.apache.commons.lang3.StringUtils)8 DateRenderer (com.vaadin.ui.renderers.DateRenderer)7 Disease (de.symeda.sormas.api.Disease)7 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)7 DateHelper (de.symeda.sormas.api.utils.DateHelper)7 Collection (java.util.Collection)7 HashMap (java.util.HashMap)7 EJB (javax.ejb.EJB)7 Captions (de.symeda.sormas.api.i18n.Captions)6 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)6 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)5 LocationDto (de.symeda.sormas.api.location.LocationDto)5