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);
}
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);
}
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();
}
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);
}
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();
}
Aggregations