Search in sources :

Example 1 with CaseQueryContext

use of de.symeda.sormas.backend.caze.CaseQueryContext 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)

Example 2 with CaseQueryContext

use of de.symeda.sormas.backend.caze.CaseQueryContext in project SORMAS-Project by hzi-braunschweig.

the class SampleService method getJurisdictionSelections.

public List<Selection<?>> getJurisdictionSelections(SampleQueryContext qc) {
    CriteriaBuilder cb = qc.getCriteriaBuilder();
    SampleJoins joins = (SampleJoins) qc.getJoins();
    CriteriaQuery cq = qc.getQuery();
    ContactJoins<Sample> contactJoins = new ContactJoins(joins.getContact());
    return Arrays.asList(JurisdictionHelper.booleanSelector(cb, inJurisdictionOrOwned(qc)), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, cq, joins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), contactService.inJurisdictionOrOwned(new ContactQueryContext(cb, cq, joins.getContact())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), cb.isNotNull(contactJoins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, cq, contactJoins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getEventParticipant()), eventParticipantService.inJurisdictionOrOwned(new EventParticipantQueryContext(cb, cq, joins.getEventParticipant())))));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ContactJoins(de.symeda.sormas.backend.contact.ContactJoins) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) EventParticipantQueryContext(de.symeda.sormas.backend.event.EventParticipantQueryContext)

Example 3 with CaseQueryContext

use of de.symeda.sormas.backend.caze.CaseQueryContext in project SORMAS-Project by hzi-braunschweig.

the class ClinicalVisitFacadeEjb method getIndexList.

@Override
public List<ClinicalVisitIndexDto> getIndexList(ClinicalVisitCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ClinicalVisitIndexDto> cq = cb.createQuery(ClinicalVisitIndexDto.class);
    Root<ClinicalVisit> visit = cq.from(ClinicalVisit.class);
    ClinicalVisitJoins joins = new ClinicalVisitJoins(visit);
    cq.multiselect(visit.get(ClinicalVisit.UUID), visit.get(ClinicalVisit.VISIT_DATE_TIME), visit.get(ClinicalVisit.VISITING_PERSON), visit.get(ClinicalVisit.VISIT_REMARKS), joins.getSymptoms().get(Symptoms.TEMPERATURE), joins.getSymptoms().get(Symptoms.TEMPERATURE_SOURCE), joins.getSymptoms().get(Symptoms.BLOOD_PRESSURE_SYSTOLIC), joins.getSymptoms().get(Symptoms.BLOOD_PRESSURE_DIASTOLIC), joins.getSymptoms().get(Symptoms.HEART_RATE), joins.getSymptoms().get(Symptoms.ID), JurisdictionHelper.booleanSelector(cb, caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, cq, joins.getCaze()))));
    if (criteria != null) {
        cq.where(service.buildCriteriaFilter(criteria, cb, visit));
    }
    if (CollectionUtils.isNotEmpty(sortProperties)) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case ClinicalVisitDto.UUID:
                case ClinicalVisitDto.DISEASE:
                case ClinicalVisitDto.VISIT_DATE_TIME:
                case ClinicalVisitDto.CLINICAL_COURSE:
                    expression = visit.get(sortProperty.propertyName);
                    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(visit.get(ClinicalVisit.VISIT_DATE_TIME)));
    }
    List<ClinicalVisitIndexDto> results = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(ClinicalVisitIndexDto.class, results, v -> v.getInJurisdiction(), null);
    return results;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ArrayList(java.util.ArrayList) SortProperty(de.symeda.sormas.api.utils.SortProperty) ClinicalVisitIndexDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitIndexDto) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext)

Example 4 with CaseQueryContext

use of de.symeda.sormas.backend.caze.CaseQueryContext in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjb method getUsersHavingCaseInJurisdiction.

@Override
public List<UserReferenceDto> getUsersHavingCaseInJurisdiction(CaseReferenceDto caseReferenceDto) {
    return getUsersHavingEntityInJurisdiction((cb, cq, userRoot) -> {
        final Subquery<Case> caseJurisdictionSubquery = cq.subquery(Case.class);
        final Root<Case> caseRoot = caseJurisdictionSubquery.from(Case.class);
        final CaseJurisdictionPredicateValidator caseJurisdictionPredicateValidator = CaseJurisdictionPredicateValidator.of(new CaseQueryContext(cb, cq, caseRoot), userRoot);
        caseJurisdictionSubquery.select(caseRoot).where(cb.and(cb.equal(caseRoot.get(AbstractDomainObject.UUID), caseReferenceDto.getUuid()), cb.isTrue(caseJurisdictionPredicateValidator.inJurisdictionOrOwned())));
        return caseJurisdictionSubquery;
    });
}
Also used : CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Case(de.symeda.sormas.backend.caze.Case) CaseJurisdictionPredicateValidator(de.symeda.sormas.backend.caze.CaseJurisdictionPredicateValidator)

Example 5 with CaseQueryContext

use of de.symeda.sormas.backend.caze.CaseQueryContext in project SORMAS-Project by hzi-braunschweig.

the class PrescriptionFacadeEjb method getExportList.

@Override
public List<PrescriptionExportDto> getExportList(CaseCriteria criteria, Collection<String> selectedRows, int first, int max) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<PrescriptionExportDto> cq = cb.createQuery(PrescriptionExportDto.class);
    Root<Prescription> prescription = cq.from(Prescription.class);
    PrescriptionJoins joins = new PrescriptionJoins(prescription);
    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), prescription.get(Prescription.PRESCRIPTION_DATE), prescription.get(Prescription.PRESCRIPTION_START), prescription.get(Prescription.PRESCRIPTION_END), prescription.get(Prescription.PRESCRIBING_CLINICIAN), prescription.get(Prescription.PRESCRIPTION_TYPE), prescription.get(Prescription.PRESCRIPTION_DETAILS), prescription.get(Prescription.TYPE_OF_DRUG), prescription.get(Prescription.FREQUENCY), prescription.get(Prescription.DOSE), prescription.get(Prescription.ROUTE), prescription.get(Prescription.ROUTE_DETAILS), prescription.get(Prescription.ADDITIONAL_NOTES), JurisdictionHelper.booleanSelector(cb, caseService.inJurisdictionOrOwned(caseQueryContext)));
    Predicate filter = service.createUserFilter(cb, cq, prescription);
    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(prescription.get(Prescription.PRESCRIPTION_DATE)));
    List<PrescriptionExportDto> exportList = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(PrescriptionExportDto.class, exportList, p -> p.getInJurisdiction(), null);
    return exportList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) PrescriptionExportDto(de.symeda.sormas.api.therapy.PrescriptionExportDto) Predicate(javax.persistence.criteria.Predicate)

Aggregations

CaseQueryContext (de.symeda.sormas.backend.caze.CaseQueryContext)22 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)21 Predicate (javax.persistence.criteria.Predicate)13 Case (de.symeda.sormas.backend.caze.Case)10 ArrayList (java.util.ArrayList)9 CaseUserFilterCriteria (de.symeda.sormas.backend.caze.CaseUserFilterCriteria)8 Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)8 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)6 District (de.symeda.sormas.backend.infrastructure.district.District)6 Person (de.symeda.sormas.backend.person.Person)6 CaseJoins (de.symeda.sormas.utils.CaseJoins)6 Order (javax.persistence.criteria.Order)6 EventQueryContext (de.symeda.sormas.backend.event.EventQueryContext)5 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)5 Disease (de.symeda.sormas.api.Disease)4 DateHelper (de.symeda.sormas.api.utils.DateHelper)4 CaseService (de.symeda.sormas.backend.caze.CaseService)4 CriteriaBuilderHelper (de.symeda.sormas.backend.common.CriteriaBuilderHelper)4 ContactQueryContext (de.symeda.sormas.backend.contact.ContactQueryContext)4 Event (de.symeda.sormas.backend.event.Event)4