Search in sources :

Example 21 with Immunization

use of de.symeda.sormas.backend.immunization.entity.Immunization in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFacadeEjb method delete.

@Override
@RolesAllowed(UserRight._IMMUNIZATION_DELETE)
public void delete(String uuid, DeletionDetails deletionDetails) {
    Immunization immunization = service.getByUuid(uuid);
    service.delete(immunization, deletionDetails);
}
Also used : Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 22 with Immunization

use of de.symeda.sormas.backend.immunization.entity.Immunization in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFacadeEjb method save.

@RolesAllowed({ UserRight._IMMUNIZATION_CREATE, UserRight._IMMUNIZATION_EDIT })
public ImmunizationDto save(@Valid @NotNull ImmunizationDto dto, boolean checkChangeDate, boolean internal) {
    Immunization existingImmunization = service.getByUuid(dto.getUuid());
    if (internal && existingImmunization != null && !service.isImmunizationEditAllowed(existingImmunization).equals(EditPermissionType.ALLOWED)) {
        throw new AccessDeniedException(I18nProperties.getString(Strings.errorImmunizationNotEditable));
    }
    ImmunizationDto existingDto = toDto(existingImmunization);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    restorePseudonymizedDto(dto, existingDto, existingImmunization, pseudonymizer);
    validate(dto);
    Immunization immunization = fillOrBuildEntity(dto, existingImmunization, checkChangeDate);
    service.updateImmunizationStatusBasedOnVaccinations(immunization);
    immunization.getVaccinations().forEach(vaccination -> {
        VaccinationDto existingVaccination = null;
        if (existingDto != null) {
            existingVaccination = existingDto.getVaccinations().stream().filter(vaccinationDto -> vaccination.getUuid().equals(vaccinationDto.getUuid())).findAny().orElse(null);
        }
        Date oldVaccinationDate = existingVaccination != null ? existingVaccination.getVaccinationDate() : null;
        vaccinationFacade.updateVaccinationStatuses(vaccination.getVaccinationDate(), oldVaccinationDate, immunization.getPerson().getId(), immunization.getDisease());
    });
    service.ensurePersisted(immunization);
    if (existingImmunization != null && internal && sormasToSormasFacade.isFeatureConfigured()) {
        syncSharesAsync(existingImmunization);
    }
    return convertToDto(immunization, pseudonymizer);
}
Also used : ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PathogenTestFacadeEjb(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb) LoggerFactory(org.slf4j.LoggerFactory) ImmunizationFacade(de.symeda.sormas.api.immunization.ImmunizationFacade) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) PersonDto(de.symeda.sormas.api.person.PersonDto) CountryService(de.symeda.sormas.backend.infrastructure.country.CountryService) Valid(javax.validation.Valid) EntityDto(de.symeda.sormas.api.EntityDto) AbstractCoreFacadeEjb(de.symeda.sormas.backend.common.AbstractCoreFacadeEjb) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) ImmunizationReferenceDto(de.symeda.sormas.api.immunization.ImmunizationReferenceDto) SormasToSormasCaseFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.caze.SormasToSormasCaseFacadeEjb) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ImmunizationListEntryDto(de.symeda.sormas.api.immunization.ImmunizationListEntryDto) Vaccination(de.symeda.sormas.backend.vaccination.Vaccination) ImmunizationListCriteria(de.symeda.sormas.api.immunization.ImmunizationListCriteria) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) CaseService(de.symeda.sormas.backend.caze.CaseService) CountryFacadeEjb(de.symeda.sormas.backend.infrastructure.country.CountryFacadeEjb) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ShareRequestDataType(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestDataType) Resource(javax.annotation.Resource) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) NotNull(javax.validation.constraints.NotNull) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) ImmunizationCriteria(de.symeda.sormas.api.immunization.ImmunizationCriteria) UserService(de.symeda.sormas.backend.user.UserService) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) EditPermissionType(de.symeda.sormas.api.EditPermissionType) LocalDate(java.time.LocalDate) CoreEntityType(de.symeda.sormas.api.common.CoreEntityType) SormasToSormasContactFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.contact.SormasToSormasContactFacadeEjb) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Inject(javax.inject.Inject) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) TransactionAttribute(javax.ejb.TransactionAttribute) LocalBean(javax.ejb.LocalBean) SampleFacadeEjb(de.symeda.sormas.backend.sample.SampleFacadeEjb) VaccinationFacadeEjbLocal(de.symeda.sormas.backend.vaccination.VaccinationFacadeEjb.VaccinationFacadeEjbLocal) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) DataHelper(de.symeda.sormas.api.utils.DataHelper) PersonFacadeEjb(de.symeda.sormas.backend.person.PersonFacadeEjb) SormasToSormasFacadeEjb(de.symeda.sormas.backend.sormastosormas.SormasToSormasFacadeEjb) ImmunizationIndexDto(de.symeda.sormas.api.immunization.ImmunizationIndexDto) PersonService(de.symeda.sormas.backend.person.PersonService) SortProperty(de.symeda.sormas.api.utils.SortProperty) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) Captions(de.symeda.sormas.api.i18n.Captions) TimeUnit(java.util.concurrent.TimeUnit) UserRight(de.symeda.sormas.api.user.UserRight) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ImmunizationSimilarityCriteria(de.symeda.sormas.api.immunization.ImmunizationSimilarityCriteria) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) SormasToSormasEventFacadeEjb(de.symeda.sormas.backend.sormastosormas.entities.event.SormasToSormasEventFacadeEjb) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) Date(java.util.Date) LocalDate(java.time.LocalDate) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 23 with Immunization

use of de.symeda.sormas.backend.immunization.entity.Immunization in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationService method getEntriesList.

public List<ImmunizationListEntryDto> getEntriesList(Long personId, Disease disease, Integer first, Integer max) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    final Root<Immunization> immunization = cq.from(Immunization.class);
    ImmunizationQueryContext immunizationQueryContext = new ImmunizationQueryContext(cb, cq, immunization);
    cq.multiselect(immunization.get(Immunization.UUID), immunization.get(Immunization.DISEASE), immunization.get(Immunization.MEANS_OF_IMMUNIZATION), immunization.get(Immunization.IMMUNIZATION_STATUS), immunization.get(Immunization.IMMUNIZATION_MANAGEMENT_STATUS), immunization.get(Immunization.START_DATE), immunization.get(Immunization.END_DATE), immunization.get(Immunization.CHANGE_DATE), JurisdictionHelper.booleanSelector(cb, isInJurisdictionOrOwned(immunizationQueryContext)));
    final Predicate criteriaFilter = buildCriteriaFilter(personId, disease, immunizationQueryContext);
    if (criteriaFilter != null) {
        cq.where(criteriaFilter);
    }
    cq.orderBy(cb.desc(immunization.get(Immunization.CHANGE_DATE)));
    cq.distinct(true);
    return createQuery(cq, first, max).unwrap(org.hibernate.query.Query.class).setResultTransformer(new ImmunizationListEntryDtoResultTransformer()).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DirectoryImmunization(de.symeda.sormas.backend.immunization.entity.DirectoryImmunization) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) ImmunizationListEntryDtoResultTransformer(de.symeda.sormas.backend.immunization.transformers.ImmunizationListEntryDtoResultTransformer) Predicate(javax.persistence.criteria.Predicate)

Example 24 with Immunization

use of de.symeda.sormas.backend.immunization.entity.Immunization in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationService method getAllAfter.

public List<Immunization> getAllAfter(Date date, Integer batchSize, String lastSynchronizedUuid) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Immunization> cq = cb.createQuery(getElementClass());
    Root<Immunization> from = cq.from(getElementClass());
    ImmunizationQueryContext immunizationQueryContext = new ImmunizationQueryContext(cb, cq, from);
    Predicate filter = createDefaultFilter(cb, from);
    if (getCurrentUser() != null) {
        Predicate userFilter = createUserFilter(immunizationQueryContext);
        if (userFilter != null) {
            filter = cb.and(filter, userFilter);
        }
    }
    if (date != null) {
        Predicate dateFilter = createChangeDateFilter(cb, from, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
        if (dateFilter != null) {
            filter = cb.and(filter, dateFilter);
        }
    }
    cq.where(filter);
    cq.distinct(true);
    return getBatchedQueryResults(cb, cq, from, batchSize);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DirectoryImmunization(de.symeda.sormas.backend.immunization.entity.DirectoryImmunization) Predicate(javax.persistence.criteria.Predicate)

Example 25 with Immunization

use of de.symeda.sormas.backend.immunization.entity.Immunization in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationService method getArchivedUuidsSince.

public List<String> getArchivedUuidsSince(Date since) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<String> cq = cb.createQuery(String.class);
    Root<Immunization> from = cq.from(getElementClass());
    ImmunizationQueryContext immunizationQueryContext = new ImmunizationQueryContext(cb, cq, from);
    Predicate filter = createUserFilter(immunizationQueryContext);
    if (since != null) {
        Predicate dateFilter = cb.greaterThanOrEqualTo(from.get(Immunization.CHANGE_DATE), since);
        if (filter != null) {
            filter = cb.and(filter, dateFilter);
        } else {
            filter = dateFilter;
        }
    }
    Predicate archivedFilter = cb.equal(from.get(Immunization.ARCHIVED), true);
    if (filter != null) {
        filter = cb.and(filter, archivedFilter);
    } else {
        filter = archivedFilter;
    }
    cq.where(filter);
    cq.select(from.get(Immunization.UUID));
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) DirectoryImmunization(de.symeda.sormas.backend.immunization.entity.DirectoryImmunization) Predicate(javax.persistence.criteria.Predicate)

Aggregations

Immunization (de.symeda.sormas.backend.immunization.entity.Immunization)37 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)28 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)25 Predicate (javax.persistence.criteria.Predicate)16 DirectoryImmunization (de.symeda.sormas.backend.immunization.entity.DirectoryImmunization)13 Date (java.util.Date)12 Timestamp (java.sql.Timestamp)11 ArrayList (java.util.ArrayList)11 RolesAllowed (javax.annotation.security.RolesAllowed)11 ImmunizationDto (de.symeda.sormas.api.immunization.ImmunizationDto)10 User (de.symeda.sormas.backend.user.User)10 UserService (de.symeda.sormas.backend.user.UserService)10 List (java.util.List)10 EJB (javax.ejb.EJB)10 LocalBean (javax.ejb.LocalBean)10 Stateless (javax.ejb.Stateless)10 Validations (de.symeda.sormas.api.i18n.Validations)9 PersonDto (de.symeda.sormas.api.person.PersonDto)9 Captions (de.symeda.sormas.api.i18n.Captions)8 DataHelper (de.symeda.sormas.api.utils.DataHelper)8