Search in sources :

Example 1 with TravelEntry

use of de.symeda.sormas.backend.travelentry.TravelEntry in project SORMAS-Project by hzi-braunschweig.

the class TravelEntryService method getAllByResultingCase.

public List<TravelEntry> getAllByResultingCase(Case caze) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<TravelEntry> cq = cb.createQuery(getElementClass());
    Root<TravelEntry> from = cq.from(getElementClass());
    cq.where(cb.and(createDefaultFilter(cb, from), cb.equal(from.get(TravelEntry.RESULTING_CASE), caze)));
    cq.orderBy(cb.desc(from.get(TravelEntry.REPORT_DATE)));
    return em.createQuery(cq).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry)

Example 2 with TravelEntry

use of de.symeda.sormas.backend.travelentry.TravelEntry in project SORMAS-Project by hzi-braunschweig.

the class PersonService method getAllAfter.

@Override
public // todo refactor this to use the create user filter form persons
List<Person> getAllAfter(Date date, Integer batchSize, String lastSynchronizedUuid) {
    User user = getCurrentUser();
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Person> personsQuery = cb.createQuery(Person.class);
    final Root<Person> personsRoot = personsQuery.from(Person.class);
    final PersonQueryContext personQueryContext = new PersonQueryContext(cb, personsQuery, personsRoot);
    final PersonJoins joins = personQueryContext.getJoins();
    // persons by district
    Join<Person, Location> address = joins.getAddress();
    Predicate districtFilter = cb.equal(address.get(Location.DISTRICT), user.getDistrict());
    // date range
    if (date != null) {
        Predicate dateFilter = createChangeDateFilter(personQueryContext, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
        districtFilter = cb.and(districtFilter, dateFilter);
    }
    personsQuery.where(districtFilter);
    List<Person> districtResultList = getBatchedQueryResults(cb, personsQuery, personsRoot, batchSize);
    // persons by case
    CriteriaQuery<Person> casePersonsQuery = cb.createQuery(Person.class);
    Root<Case> casePersonsRoot = casePersonsQuery.from(Case.class);
    Join<Person, Person> casePersonsSelect = casePersonsRoot.join(Case.PERSON);
    casePersonsSelect.fetch(Person.ADDRESS);
    casePersonsQuery.select(casePersonsSelect);
    Predicate casePersonsFilter = caseService.createUserFilter(new CaseQueryContext(cb, casePersonsQuery, new CaseJoins(casePersonsRoot)));
    // date range
    if (date != null) {
        Predicate dateFilter = createChangeDateFilter(cb, casePersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
        if (batchSize == null) {
            // include case change dates: When a case is relocated it may become available to another user and this will have to include the person as-well
            Predicate caseDateFilter = caseService.createChangeDateFilter(cb, casePersonsRoot, DateHelper.toTimestampUpper(date));
            dateFilter = cb.or(dateFilter, caseDateFilter);
        }
        if (casePersonsFilter != null) {
            casePersonsFilter = cb.and(casePersonsFilter, dateFilter);
        } else {
            casePersonsFilter = dateFilter;
        }
    }
    if (casePersonsFilter != null) {
        casePersonsQuery.where(casePersonsFilter);
    }
    casePersonsQuery.distinct(true);
    List<Person> casePersonsResultList = getBatchedQueryResults(cb, casePersonsQuery, casePersonsSelect, batchSize);
    // persons by contact
    CriteriaQuery<Person> contactPersonsQuery = cb.createQuery(Person.class);
    Root<Contact> contactPersonsRoot = contactPersonsQuery.from(Contact.class);
    Join<Person, Person> contactPersonsSelect = contactPersonsRoot.join(Contact.PERSON);
    contactPersonsSelect.fetch(Person.ADDRESS);
    contactPersonsQuery.select(contactPersonsSelect);
    Predicate contactPersonsFilter = contactService.createUserFilter(new ContactQueryContext(cb, contactPersonsQuery, new ContactJoins(contactPersonsRoot)));
    // date range
    if (date != null) {
        Predicate dateFilter = createChangeDateFilter(cb, contactPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
        if (batchSize == null) {
            Predicate contactDateFilter = contactService.createChangeDateFilter(cb, contactPersonsRoot, date);
            dateFilter = cb.or(dateFilter, contactDateFilter);
        }
        contactPersonsFilter = and(cb, contactPersonsFilter, dateFilter);
    }
    if (contactPersonsFilter != null) {
        contactPersonsQuery.where(contactPersonsFilter);
    }
    contactPersonsQuery.distinct(true);
    List<Person> contactPersonsResultList = getBatchedQueryResults(cb, contactPersonsQuery, contactPersonsSelect, batchSize);
    // persons by event participant
    CriteriaQuery<Person> eventPersonsQuery = cb.createQuery(Person.class);
    Root<EventParticipant> eventPersonsRoot = eventPersonsQuery.from(EventParticipant.class);
    Join<Person, Person> eventPersonsSelect = eventPersonsRoot.join(EventParticipant.PERSON);
    eventPersonsSelect.fetch(Person.ADDRESS);
    eventPersonsQuery.select(eventPersonsSelect);
    Predicate eventPersonsFilter = eventParticipantService.createUserFilter(new EventParticipantQueryContext(cb, eventPersonsQuery, new EventParticipantJoins(eventPersonsRoot)));
    // date range
    if (date != null) {
        Predicate dateFilter = createChangeDateFilter(cb, eventPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
        if (batchSize == null) {
            Predicate eventParticipantDateFilter = eventParticipantService.createChangeDateFilter(cb, eventPersonsRoot, DateHelper.toTimestampUpper(date));
            dateFilter = cb.or(dateFilter, eventParticipantDateFilter);
        }
        eventPersonsFilter = and(cb, eventPersonsFilter, dateFilter);
    }
    if (eventPersonsFilter != null) {
        eventPersonsQuery.where(eventPersonsFilter);
    }
    eventPersonsQuery.distinct(true);
    List<Person> eventPersonsResultList = getBatchedQueryResults(cb, eventPersonsQuery, eventPersonsSelect, batchSize);
    // persons by immunization
    List<Person> immunizationPersonsResultList = new ArrayList<>();
    if (!featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
        CriteriaQuery<Person> immunizationPersonsQuery = cb.createQuery(Person.class);
        Root<Immunization> immunizationPersonsRoot = immunizationPersonsQuery.from(Immunization.class);
        Join<Immunization, Person> immunizationPersonsSelect = immunizationPersonsRoot.join(Immunization.PERSON);
        immunizationPersonsSelect.fetch(Person.ADDRESS);
        immunizationPersonsQuery.select(immunizationPersonsSelect);
        Predicate immunizationPersonsFilter = immunizationService.createUserFilter(new ImmunizationQueryContext(cb, immunizationPersonsQuery, new ImmunizationJoins(immunizationPersonsRoot)));
        // date range
        if (date != null) {
            Predicate dateFilter = createChangeDateFilter(cb, immunizationPersonsSelect, DateHelper.toTimestampUpper(date), lastSynchronizedUuid);
            if (batchSize == null) {
                Predicate immunizationDateFilter = immunizationService.createChangeDateFilter(cb, immunizationPersonsRoot, DateHelper.toTimestampUpper(date));
                dateFilter = cb.or(dateFilter, immunizationDateFilter);
            }
            immunizationPersonsFilter = and(cb, immunizationPersonsFilter, dateFilter);
        }
        if (immunizationPersonsFilter != null) {
            immunizationPersonsQuery.where(immunizationPersonsFilter);
        }
        immunizationPersonsQuery.distinct(true);
        immunizationPersonsResultList = getBatchedQueryResults(cb, immunizationPersonsQuery, immunizationPersonsSelect, batchSize);
    }
    List<Person> travelEntryPersonsResultList = new ArrayList<>();
    // if a batch size is given, this is a sync from the mobile app where travel entries are not relevant for now
    if (batchSize == null) {
        // persons by travel entries
        CriteriaQuery<Person> tepQuery = cb.createQuery(Person.class);
        Root<TravelEntry> tepRoot = tepQuery.from(TravelEntry.class);
        Join<TravelEntry, Person> tepSelect = tepRoot.join(TravelEntry.PERSON);
        tepSelect.fetch(Person.ADDRESS);
        tepQuery.select(tepSelect);
        Predicate tepFilter = travelEntryService.createUserFilter(new TravelEntryQueryContext(cb, tepQuery, new TravelEntryJoins(tepRoot)));
        // date range
        if (date != null) {
            Predicate dateFilter = createChangeDateFilter(cb, tepSelect, DateHelper.toTimestampUpper(date));
            Predicate travelEntryDateFilter = travelEntryService.createChangeDateFilter(cb, tepRoot, DateHelper.toTimestampUpper(date));
            tepFilter = and(cb, tepFilter, cb.or(dateFilter, travelEntryDateFilter));
        }
        if (tepFilter != null) {
            tepQuery.where(tepFilter);
        }
        tepQuery.distinct(true);
        travelEntryPersonsResultList = em.createQuery(tepQuery).getResultList();
    }
    return Stream.of(districtResultList, casePersonsResultList, contactPersonsResultList, eventPersonsResultList, immunizationPersonsResultList, travelEntryPersonsResultList).flatMap(List<Person>::stream).distinct().sorted(new ChangeDateUuidComparator<>()).limit(batchSize == null ? Long.MAX_VALUE : batchSize).collect(Collectors.toList());
}
Also used : TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) User(de.symeda.sormas.backend.user.User) TravelEntryJoins(de.symeda.sormas.backend.travelentry.TravelEntryJoins) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) Case(de.symeda.sormas.backend.caze.Case) EventParticipantJoins(de.symeda.sormas.backend.event.EventParticipantJoins) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ImmunizationQueryContext(de.symeda.sormas.backend.immunization.ImmunizationQueryContext) CaseJoins(de.symeda.sormas.backend.caze.CaseJoins) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) ContactJoins(de.symeda.sormas.backend.contact.ContactJoins) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) EventParticipantQueryContext(de.symeda.sormas.backend.event.EventParticipantQueryContext) Contact(de.symeda.sormas.backend.contact.Contact) ImmunizationJoins(de.symeda.sormas.backend.immunization.ImmunizationJoins) TravelEntryQueryContext(de.symeda.sormas.backend.travelentry.TravelEntryQueryContext) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Location(de.symeda.sormas.backend.location.Location)

Example 3 with TravelEntry

use of de.symeda.sormas.backend.travelentry.TravelEntry in project SORMAS-Project by hzi-braunschweig.

the class PersonService method getSimilarPersonDtos.

public List<SimilarPersonDto> getSimilarPersonDtos(PersonSimilarityCriteria criteria, Integer limit) {
    setSimilarityThresholdQuery();
    boolean activeEntriesOnly = configFacade.isDuplicateChecksExcludePersonsOfArchivedEntries();
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Person> personQuery = cb.createQuery(Person.class);
    final Root<Person> personRoot = personQuery.from(Person.class);
    final PersonQueryContext personQueryContext = new PersonQueryContext(cb, personQuery, personRoot);
    final PersonJoins joins = personQueryContext.getJoins();
    Join<Person, Case> personCaseJoin = joins.getCaze();
    Join<Person, Contact> personContactJoin = joins.getContact();
    Join<Person, EventParticipant> personEventParticipantJoin = joins.getEventParticipant();
    Join<Person, Immunization> personImmunizationJoin = joins.getImmunization();
    Join<Person, TravelEntry> personTravelEntryJoin = joins.getTravelEntry();
    // Persons of active cases
    Predicate personSimilarityFilter = buildSimilarityCriteriaFilter(criteria, cb, personRoot);
    Predicate activeCasesFilter = activeEntriesOnly ? caseService.createActiveCasesFilter(cb, personCaseJoin) : caseService.createDefaultFilter(cb, personCaseJoin);
    Predicate caseUserFilter = caseService.createUserFilter(new CaseQueryContext(cb, personQuery, personQueryContext.getJoins().getCaseJoins()));
    Predicate personCasePredicate = and(cb, personCaseJoin.get(Case.ID).isNotNull(), activeCasesFilter, caseUserFilter);
    // Persons of active contacts
    final ContactQueryContext contactQueryContext = new ContactQueryContext(cb, personQuery, joins.getContactJoins());
    Predicate activeContactsFilter = activeEntriesOnly ? contactService.createActiveContactsFilter(contactQueryContext) : contactService.createDefaultFilter(cb, personContactJoin);
    Predicate contactUserFilter = contactService.createUserFilter(contactQueryContext, null);
    Predicate personContactPredicate = and(cb, personContactJoin.get(Contact.ID).isNotNull(), contactUserFilter, activeContactsFilter);
    // Persons of event participants in active events
    final EventParticipantQueryContext eventParticipantQueryContext = new EventParticipantQueryContext(cb, personQuery, joins.getEventParticipantJoins());
    Predicate activeEventParticipantsFilter = activeEntriesOnly ? eventParticipantService.createActiveEventParticipantsInActiveEventsFilter(eventParticipantQueryContext) : eventParticipantService.createDefaultInUndeletedEventsFilter(eventParticipantQueryContext);
    Predicate eventParticipantUserFilter = eventParticipantService.createUserFilter(eventParticipantQueryContext);
    Predicate personEventParticipantPredicate = and(cb, personEventParticipantJoin.get(EventParticipant.ID).isNotNull(), activeEventParticipantsFilter, eventParticipantUserFilter);
    // Persons of active immunizations
    Predicate personImmunizationPredicate = null;
    if (!featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
        Predicate activeImmunizationsFilter = activeEntriesOnly ? immunizationService.createActiveImmunizationsFilter(cb, personImmunizationJoin) : immunizationService.createDefaultFilter(cb, personImmunizationJoin);
        Predicate immunizationUserFilter = immunizationService.createUserFilter(new ImmunizationQueryContext(cb, personQuery, joins.getImmunizationJoins()));
        personImmunizationPredicate = and(cb, personImmunizationJoin.get(Immunization.ID).isNotNull(), immunizationUserFilter, activeImmunizationsFilter);
    }
    // Persons of active travel entries
    Predicate activeTravelEntriesFilter = activeEntriesOnly ? travelEntryService.createActiveTravelEntriesFilter(cb, personTravelEntryJoin) : travelEntryService.createDefaultFilter(cb, personTravelEntryJoin);
    Predicate travelEntryUserFilter = travelEntryService.createUserFilter(new TravelEntryQueryContext(cb, personQuery, joins.getTravelEntryJoins()));
    Predicate personTravelEntryPredicate = and(cb, personTravelEntryJoin.get(TravelEntry.ID).isNotNull(), travelEntryUserFilter, activeTravelEntriesFilter);
    Predicate finalPredicate = CriteriaBuilderHelper.or(cb, personCasePredicate, personContactPredicate, personEventParticipantPredicate, personImmunizationPredicate, personTravelEntryPredicate);
    personQuery.where(and(cb, personSimilarityFilter, finalPredicate));
    personQuery.distinct(true);
    TypedQuery<Person> query = em.createQuery(personQuery);
    if (limit != null) {
        query.setMaxResults(limit);
    }
    List<Person> persons = query.getResultList();
    List<Long> personsInJurisdiction = getInJurisdictionIDs(persons);
    return persons.stream().filter(p -> personsInJurisdiction.contains(p.getId())).map(this::toSimilarPersonDto).collect(Collectors.toList());
}
Also used : TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) ImmunizationQueryContext(de.symeda.sormas.backend.immunization.ImmunizationQueryContext) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Immunization(de.symeda.sormas.backend.immunization.entity.Immunization) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) EventParticipantQueryContext(de.symeda.sormas.backend.event.EventParticipantQueryContext) Contact(de.symeda.sormas.backend.contact.Contact) TravelEntryQueryContext(de.symeda.sormas.backend.travelentry.TravelEntryQueryContext) EventParticipant(de.symeda.sormas.backend.event.EventParticipant)

Example 4 with TravelEntry

use of de.symeda.sormas.backend.travelentry.TravelEntry in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method mergeCase.

private void mergeCase(CaseDataDto leadCaseData, CaseDataDto otherCaseData, boolean cloning) {
    // 1 Merge Dtos
    // 1.1 Case
    copyDtoValues(leadCaseData, otherCaseData, cloning);
    save(leadCaseData, !cloning, true, true, false);
    // 1.2 Person - Only merge when the persons have different UUIDs
    if (!cloning && !DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid())) {
        PersonDto leadPerson = personFacade.getPersonByUuid(leadCaseData.getPerson().getUuid());
        PersonDto otherPerson = personFacade.getPersonByUuid(otherCaseData.getPerson().getUuid());
        personFacade.mergePerson(leadPerson, otherPerson);
    } else {
        assert (DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid()));
    }
    // 2 Change CaseReference
    Case leadCase = service.getByUuid(leadCaseData.getUuid());
    Case otherCase = service.getByUuid(otherCaseData.getUuid());
    // 2.1 Contacts
    List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(otherCase.toReference()), null);
    for (Contact contact : contacts) {
        if (cloning) {
            ContactDto newContact = ContactDto.build(leadCase.toReference(), leadCase.getDisease(), leadCase.getDiseaseDetails(), leadCase.getDiseaseVariant());
            newContact.setPerson(new PersonReferenceDto(contact.getPerson().getUuid()));
            DtoHelper.copyDtoValues(newContact, contactFacade.toDto(contact), cloning);
            contactFacade.save(newContact, false, false);
        } else {
            // simply move existing entities to the merge target
            contact.setCaze(leadCase);
            contactService.ensurePersisted(contact);
        }
    }
    // 2.2 Samples
    List<Sample> samples = sampleService.findBy(new SampleCriteria().caze(otherCase.toReference()), null);
    for (Sample sample : samples) {
        if (cloning) {
            SampleDto newSample = SampleDto.build(sample.getReportingUser().toReference(), leadCase.toReference());
            DtoHelper.copyDtoValues(newSample, SampleFacadeEjb.toDto(sample), cloning);
            sampleFacade.saveSample(newSample, false, true, true);
            // 2.2.1 Pathogen Tests
            for (PathogenTest pathogenTest : sample.getPathogenTests()) {
                PathogenTestDto newPathogenTest = PathogenTestDto.build(newSample.toReference(), pathogenTest.getLabUser().toReference());
                DtoHelper.copyDtoValues(newPathogenTest, PathogenTestFacadeEjbLocal.toDto(pathogenTest), cloning);
                sampleTestFacade.savePathogenTest(newPathogenTest);
            }
            for (AdditionalTest additionalTest : sample.getAdditionalTests()) {
                AdditionalTestDto newAdditionalTest = AdditionalTestDto.build(newSample.toReference());
                DtoHelper.copyDtoValues(newAdditionalTest, AdditionalTestFacadeEjbLocal.toDto(additionalTest), cloning);
                additionalTestFacade.saveAdditionalTest(newAdditionalTest);
            }
        } else {
            // simply move existing entities to the merge target
            sample.setAssociatedCase(leadCase);
            sampleService.ensurePersisted(sample);
        }
    }
    // 2.3 Tasks
    if (!cloning) {
        // simply move existing entities to the merge target
        List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(otherCase.getUuid())), true);
        for (Task task : tasks) {
            task.setCaze(leadCase);
            taskService.ensurePersisted(task);
        }
    }
    // 3 Change Therapy Reference
    // 3.1 Treatments
    List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    TherapyReferenceDto leadCaseTherapyReference = new TherapyReferenceDto(leadCase.getTherapy().getUuid());
    for (Treatment treatment : treatments) {
        if (cloning) {
            TreatmentDto newTreatment = TreatmentDto.build(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newTreatment, TreatmentFacadeEjb.toDto(treatment), cloning);
            treatmentFacade.saveTreatment(newTreatment);
        } else {
            // simply move existing entities to the merge target
            treatment.setTherapy(leadCase.getTherapy());
            treatmentService.ensurePersisted(treatment);
        }
    }
    // 3.2 Prescriptions
    List<Prescription> prescriptions = prescriptionService.findBy(new PrescriptionCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    for (Prescription prescription : prescriptions) {
        if (cloning) {
            PrescriptionDto newPrescription = PrescriptionDto.buildPrescription(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newPrescription, PrescriptionFacadeEjb.toDto(prescription), cloning);
            prescriptionFacade.savePrescription(newPrescription);
        } else {
            // simply move existing entities to the merge target
            prescription.setTherapy(leadCase.getTherapy());
            prescriptionService.ensurePersisted(prescription);
        }
    }
    // 4 Change Clinical Course Reference
    // 4.1 Clinical Visits
    List<ClinicalVisit> clinicalVisits = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(new ClinicalCourseReferenceDto(otherCase.getClinicalCourse().getUuid())));
    for (ClinicalVisit clinicalVisit : clinicalVisits) {
        if (cloning) {
            ClinicalVisitDto newClinicalVisit = ClinicalVisitDto.build(leadCaseData.getClinicalCourse().toReference(), leadCase.getDisease());
            DtoHelper.copyDtoValues(newClinicalVisit, ClinicalVisitFacadeEjb.toDto(clinicalVisit), cloning);
            clinicalVisitFacade.saveClinicalVisit(newClinicalVisit, leadCase.getUuid(), false);
        } else {
            // simply move existing entities to the merge target
            clinicalVisit.setClinicalCourse(leadCase.getClinicalCourse());
            clinicalVisitService.ensurePersisted(clinicalVisit);
        }
    }
    // (set the person and the disease of the visit, saveVisit does the rest)
    for (VisitDto otherVisit : otherCase.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
        otherVisit.setPerson(leadCaseData.getPerson());
        otherVisit.setDisease(leadCaseData.getDisease());
        visitFacade.saveVisit(otherVisit);
    }
    // 6 Documents
    List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, otherCase.getUuid());
    for (Document document : documents) {
        document.setRelatedEntityUuid(leadCaseData.getUuid());
        documentService.ensurePersisted(document);
    }
    // 7 Persist Event links through eventparticipants
    Set<EventParticipant> eventParticipants = otherCase.getEventParticipants();
    for (EventParticipant eventParticipant : eventParticipants) {
        eventParticipant.setResultingCase(leadCase);
        eventParticipantService.ensurePersisted(eventParticipant);
    }
    otherCase.getEventParticipants().clear();
    // 8 Exposures - Make sure there are no two probable infection environments
    // if there are more than 2 exposures marked as probable infection environment, find the one that originates from the otherCase and set it to false
    // the one originating from the otherCase should always be found at the higher index
    List<Exposure> probableExposuresList = leadCase.getEpiData().getExposures().stream().filter(Exposure::isProbableInfectionEnvironment).collect(Collectors.toList());
    while (probableExposuresList.size() >= 2) {
        // should never be > 2, but still make sure to set all but one exposures to false
        probableExposuresList.get(probableExposuresList.size() - 1).setProbableInfectionEnvironment(false);
        exposureService.ensurePersisted(probableExposuresList.get(probableExposuresList.size() - 1));
        probableExposuresList.remove(probableExposuresList.size() - 1);
    }
    // 9 Reports
    List<SurveillanceReport> surveillanceReports = surveillanceReportService.getByCaseUuids(Collections.singletonList(otherCase.getUuid()));
    surveillanceReports.forEach(surveillanceReport -> {
        SurveillanceReportDto surveillanceReportDto = SurveillanceReportFacadeEjb.toDto(surveillanceReport);
        surveillanceReportDto.setCaze(leadCase.toReference());
        surveillanceReportFacade.saveSurveillanceReport(surveillanceReportDto);
    });
    // 10 Activity as case
    final EpiData otherEpiData = otherCase.getEpiData();
    if (otherEpiData != null && YesNoUnknown.YES == otherEpiData.getActivityAsCaseDetailsKnown() && CollectionUtils.isNotEmpty(otherEpiData.getActivitiesAsCase())) {
        final EpiData leadEpiData = leadCase.getEpiData();
        leadEpiData.setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
        epiDataService.ensurePersisted(leadEpiData);
    }
    // Travel entries reference
    List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(otherCase);
    travelEntries.forEach(t -> {
        t.setResultingCase(leadCase);
        t.setPerson(leadCase.getPerson());
        travelEntryService.ensurePersisted(t);
    });
}
Also used : AdditionalTest(de.symeda.sormas.backend.sample.AdditionalTest) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) Task(de.symeda.sormas.backend.task.Task) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) Document(de.symeda.sormas.backend.document.Document) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) EpiData(de.symeda.sormas.backend.epidata.EpiData) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) CoreAndPersonDto(de.symeda.sormas.api.caze.CoreAndPersonDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) Sample(de.symeda.sormas.backend.sample.Sample) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) Exposure(de.symeda.sormas.backend.exposure.Exposure) PathogenTest(de.symeda.sormas.backend.sample.PathogenTest) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) Contact(de.symeda.sormas.backend.contact.Contact) Treatment(de.symeda.sormas.backend.therapy.Treatment) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto)

Example 5 with TravelEntry

use of de.symeda.sormas.backend.travelentry.TravelEntry in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjb method getUsersHavingTravelEntryInJurisdiction.

@Override
public List<UserReferenceDto> getUsersHavingTravelEntryInJurisdiction(TravelEntryReferenceDto travelEntryReferenceDto) {
    return getUsersHavingEntityInJurisdiction((cb, cq, userRoot) -> {
        final Subquery<TravelEntry> travelEntrySubquery = cq.subquery(TravelEntry.class);
        final Root<TravelEntry> travelEntryRoot = travelEntrySubquery.from(TravelEntry.class);
        final TravelEntryJurisdictionPredicateValidator travelEntryJurisdictionPredicateValidator = TravelEntryJurisdictionPredicateValidator.of(new TravelEntryQueryContext(cb, cq, new TravelEntryJoins(travelEntryRoot)), userRoot);
        travelEntrySubquery.select(travelEntryRoot).where(cb.and(cb.equal(travelEntryRoot.get(AbstractDomainObject.UUID), travelEntryReferenceDto.getUuid()), cb.isTrue(travelEntryJurisdictionPredicateValidator.inJurisdictionOrOwned()), cb.or(cb.isNull(userRoot.get(User.LIMITED_DISEASE)), cb.equal(userRoot.get(User.LIMITED_DISEASE), travelEntryRoot.get(TravelEntry.DISEASE)))));
        return travelEntrySubquery;
    });
}
Also used : TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) TravelEntryJoins(de.symeda.sormas.backend.travelentry.TravelEntryJoins) TravelEntryJurisdictionPredicateValidator(de.symeda.sormas.backend.travelentry.TravelEntryJurisdictionPredicateValidator) TravelEntryQueryContext(de.symeda.sormas.backend.travelentry.TravelEntryQueryContext)

Aggregations

TravelEntry (de.symeda.sormas.backend.travelentry.TravelEntry)19 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)16 Predicate (javax.persistence.criteria.Predicate)11 TravelEntryQueryContext (de.symeda.sormas.backend.travelentry.TravelEntryQueryContext)9 Contact (de.symeda.sormas.backend.contact.Contact)6 TravelEntryJoins (de.symeda.sormas.backend.travelentry.TravelEntryJoins)6 Case (de.symeda.sormas.backend.caze.Case)5 EventParticipant (de.symeda.sormas.backend.event.EventParticipant)5 ContactQueryContext (de.symeda.sormas.backend.contact.ContactQueryContext)4 Location (de.symeda.sormas.backend.location.Location)3 Person (de.symeda.sormas.backend.person.Person)3 ArrayList (java.util.ArrayList)3 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)2 ClinicalCourseReferenceDto (de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto)2 ClinicalVisitCriteria (de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria)2 CaseQueryContext (de.symeda.sormas.backend.caze.CaseQueryContext)2 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)2 EventParticipantQueryContext (de.symeda.sormas.backend.event.EventParticipantQueryContext)2 ImmunizationQueryContext (de.symeda.sormas.backend.immunization.ImmunizationQueryContext)2 Immunization (de.symeda.sormas.backend.immunization.entity.Immunization)2