Search in sources :

Example 1 with Pseudonymizer

use of de.symeda.sormas.backend.util.Pseudonymizer in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method convertToReferenceDto.

private ContactReferenceDto convertToReferenceDto(Contact source) {
    ContactReferenceDto dto = toReferenceDto(source);
    if (source != null && dto != null) {
        final ContactJurisdictionFlagsDto contactJurisdictionFlagsDto = service.inJurisdictionOrOwned(source);
        boolean isInJurisdiction = contactJurisdictionFlagsDto.getInJurisdiction();
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
        pseudonymizer.pseudonymizeDto(ContactReferenceDto.class, dto, isInJurisdiction, (c) -> {
            if (source.getCaze() != null) {
                pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, c.getCaseName(), contactJurisdictionFlagsDto.getCaseInJurisdiction(), null);
            }
            pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, c.getContactName(), isInJurisdiction, null);
        });
    }
    return dto;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto)

Example 2 with Pseudonymizer

use of de.symeda.sormas.backend.util.Pseudonymizer in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method getIndexDetailedList.

@Override
public List<ContactIndexDetailedDto> getIndexDetailedList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaQuery<ContactIndexDetailedDto> query = listCriteriaBuilder.buildIndexDetailedCriteria(contactCriteria, sortProperties);
    List<ContactIndexDetailedDto> dtos = QueryHelper.getResultList(em, query, first, max);
    // Load event count and latest events info per contact
    Map<String, List<ContactEventSummaryDetails>> eventSummaries = eventService.getEventSummaryDetailsByContacts(dtos.stream().map(ContactIndexDetailedDto::getUuid).collect(Collectors.toList())).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
    for (ContactIndexDetailedDto contact : dtos) {
        List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(contact.getUuid(), Collections.emptyList());
        contact.setEventCount((long) contactEvents.size());
        contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
            contact.setLatestEventId(eventSummary.getEventUuid());
            contact.setLatestEventTitle(eventSummary.getEventTitle());
        });
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    User currentUser = userService.getCurrentUser();
    pseudonymizer.pseudonymizeDtoCollection(ContactIndexDetailedDto.class, dtos, c -> c.getInJurisdiction(), (c, isInJurisdiction) -> {
        pseudonymizer.pseudonymizeUser(userService.getByUuid(c.getReportingUser().getUuid()), currentUser, c::setReportingUser);
        if (c.getCaze() != null) {
            pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, c.getCaze(), c.getCaseInJurisdiction(), null);
        }
    });
    return dtos;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) User(de.symeda.sormas.backend.user.User) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto)

Example 3 with Pseudonymizer

use of de.symeda.sormas.backend.util.Pseudonymizer in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method getIndexList.

@Override
public List<ContactIndexDto> getIndexList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaQuery<ContactIndexDto> query = listCriteriaBuilder.buildIndexCriteria(contactCriteria, sortProperties);
    List<ContactIndexDto> dtos = QueryHelper.getResultList(em, query, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(ContactIndexDto.class, dtos, ContactIndexDto::getInJurisdiction, (c, isInJurisdiction) -> {
        if (c.getCaze() != null) {
            pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, c.getCaze(), c.getCaseInJurisdiction(), null);
        }
    });
    return dtos;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) MergeContactIndexDto(de.symeda.sormas.api.contact.MergeContactIndexDto) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto)

Example 4 with Pseudonymizer

use of de.symeda.sormas.backend.util.Pseudonymizer in project SORMAS-Project by hzi-braunschweig.

the class ClinicalVisitFacadeEjb method restorePseudonymizedDto.

private void restorePseudonymizedDto(ClinicalVisitDto clinicalVisit, ClinicalVisit existingClinicalVisit) {
    if (existingClinicalVisit != null) {
        Boolean inJurisdiction = caseService.inJurisdictionOrOwned(existingClinicalVisit.getClinicalCourse().getCaze());
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
        ClinicalVisitDto existingDto = toDto(existingClinicalVisit);
        pseudonymizer.restorePseudonymizedValues(ClinicalVisitDto.class, clinicalVisit, existingDto, inJurisdiction);
        pseudonymizer.restorePseudonymizedValues(SymptomsDto.class, clinicalVisit.getSymptoms(), existingDto.getSymptoms(), inJurisdiction);
    }
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto)

Example 5 with Pseudonymizer

use of de.symeda.sormas.backend.util.Pseudonymizer in project SORMAS-Project by hzi-braunschweig.

the class ClinicalVisitFacadeEjb method getExportList.

@Override
public List<ClinicalVisitExportDto> getExportList(CaseCriteria criteria, Collection<String> selectedRows, int first, int max) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ClinicalVisitExportDto> cq = cb.createQuery(ClinicalVisitExportDto.class);
    Root<ClinicalVisit> clinicalVisit = cq.from(ClinicalVisit.class);
    ClinicalVisitJoins joins = new ClinicalVisitJoins(clinicalVisit);
    CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, joins.getCaze());
    cq.multiselect(joins.getCaze().get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), clinicalVisit.get(ClinicalVisit.DISEASE), clinicalVisit.get(ClinicalVisit.VISIT_DATE_TIME), clinicalVisit.get(ClinicalVisit.VISIT_REMARKS), clinicalVisit.get(ClinicalVisit.VISITING_PERSON), joins.getSymptoms().get(Symptoms.ID), JurisdictionHelper.booleanSelector(cb, caseService.inJurisdictionOrOwned(caseQueryContext)));
    Predicate filter = service.createUserFilter(cb, cq, clinicalVisit);
    Predicate criteriaFilter = caseService.createCriteriaFilter(criteria, caseQueryContext);
    filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, joins.getCaze().get(Case.UUID));
    cq.where(filter);
    cq.orderBy(cb.desc(joins.getCaze().get(Case.UUID)), cb.desc(clinicalVisit.get(ClinicalVisit.VISIT_DATE_TIME)));
    List<ClinicalVisitExportDto> resultList = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    for (ClinicalVisitExportDto exportDto : resultList) {
        exportDto.setSymptoms(SymptomsFacadeEjb.toDto(symptomsService.getById(exportDto.getSymptomsId())));
        Boolean inJurisdiction = exportDto.getInJurisdiction();
        pseudonymizer.pseudonymizeDto(ClinicalVisitExportDto.class, exportDto, inJurisdiction, (v) -> {
            pseudonymizer.pseudonymizeDto(SymptomsDto.class, v.getSymptoms(), inJurisdiction, null);
        });
    }
    return resultList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ClinicalVisitExportDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitExportDto) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Predicate(javax.persistence.criteria.Predicate)

Aggregations

Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)78 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)42 Predicate (javax.persistence.criteria.Predicate)38 User (de.symeda.sormas.backend.user.User)31 ArrayList (java.util.ArrayList)29 SortProperty (de.symeda.sormas.api.utils.SortProperty)28 Date (java.util.Date)27 List (java.util.List)27 UserService (de.symeda.sormas.backend.user.UserService)26 Collectors (java.util.stream.Collectors)26 EJB (javax.ejb.EJB)26 LocalBean (javax.ejb.LocalBean)26 Stateless (javax.ejb.Stateless)26 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)25 DtoHelper (de.symeda.sormas.backend.util.DtoHelper)25 ModelConstants (de.symeda.sormas.backend.util.ModelConstants)25 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)25 Root (javax.persistence.criteria.Root)25 Captions (de.symeda.sormas.api.i18n.Captions)24 Case (de.symeda.sormas.backend.caze.Case)24