Search in sources :

Example 1 with SampleCriteria

use of de.symeda.sormas.api.sample.SampleCriteria in project SORMAS-Project by hzi-braunschweig.

the class SampleFacadeEjb method getSimilarSamples.

@Override
public List<SampleDto> getSimilarSamples(SampleSimilarityCriteria criteria) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Sample> cq = cb.createQuery(Sample.class);
    final Root<Sample> root = cq.from(Sample.class);
    cq.distinct(true);
    SampleJoins<Sample> joins = new SampleJoins<>(root);
    SampleCriteria sampleCriteria = new SampleCriteria();
    sampleCriteria.caze(criteria.getCaze()).contact(criteria.getContact()).eventParticipant(criteria.getEventParticipant());
    Predicate filter = sampleService.createUserFilter(cq, cb, joins, sampleCriteria);
    filter = CriteriaBuilderHelper.and(cb, filter, sampleService.buildCriteriaFilter(sampleCriteria, cb, joins));
    Predicate similarityFilter = null;
    if (criteria.getLabSampleId() != null) {
        similarityFilter = cb.equal(root.get(Sample.LAB_SAMPLE_ID), criteria.getLabSampleId());
    }
    Date sampleDateTime = criteria.getSampleDateTime();
    SampleMaterial sampleMaterial = criteria.getSampleMaterial();
    if (sampleDateTime != null && sampleMaterial != null) {
        Predicate dateAndMaterialFilter = cb.and(cb.between(root.get(Sample.SAMPLE_DATE_TIME), DateHelper.getStartOfDay(DateHelper.subtractDays(sampleDateTime, SIMILARITY_DATE_TIME_THRESHOLD)), DateHelper.getEndOfDay(DateHelper.addDays(sampleDateTime, SIMILARITY_DATE_TIME_THRESHOLD))), cb.equal(root.get(Sample.SAMPLE_MATERIAL), sampleMaterial));
        similarityFilter = CriteriaBuilderHelper.or(cb, similarityFilter, dateAndMaterialFilter);
    }
    filter = CriteriaBuilderHelper.and(cb, filter, similarityFilter);
    if (filter != null) {
        cq.where(filter);
    }
    List<Sample> samples = em.createQuery(cq).getResultList();
    if (samples.size() == 0 && (sampleDateTime == null || sampleMaterial == null)) {
        return getByCriteria(sampleCriteria);
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    return samples.stream().map(s -> convertToDto(s, pseudonymizer)).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) FacilityHelper(de.symeda.sormas.api.infrastructure.facility.FacilityHelper) NotNull(javax.validation.constraints.NotNull) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) UserRoleConfigFacadeEjbLocal(de.symeda.sormas.backend.user.UserRoleConfigFacadeEjb.UserRoleConfigFacadeEjbLocal) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Selection(javax.persistence.criteria.Selection) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) SampleFacade(de.symeda.sormas.api.sample.SampleFacade) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) SampleListEntryDto(de.symeda.sormas.api.sample.SampleListEntryDto) LocalBean(javax.ejb.LocalBean) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) DataHelper(de.symeda.sormas.api.utils.DataHelper) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) EventParticipantFacadeEjb(de.symeda.sormas.backend.event.EventParticipantFacadeEjb) ContactService(de.symeda.sormas.backend.contact.ContactService) SampleDto(de.symeda.sormas.api.sample.SampleDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) NotificationService(de.symeda.sormas.backend.common.NotificationService) UserRole(de.symeda.sormas.api.user.UserRole) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) CoreAdo(de.symeda.sormas.backend.common.CoreAdo) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) DateHelper(de.symeda.sormas.api.utils.DateHelper) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) Function(java.util.function.Function) PathogenTestFacadeEjbLocal(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) AdditionalTestFacadeEjbLocal(de.symeda.sormas.backend.sample.AdditionalTestFacadeEjb.AdditionalTestFacadeEjbLocal) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) Event(de.symeda.sormas.backend.event.Event) UserRight(de.symeda.sormas.api.user.UserRight) SampleExportDto(de.symeda.sormas.api.sample.SampleExportDto) NotificationType(de.symeda.sormas.api.user.NotificationType) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) SampleSimilarityCriteria(de.symeda.sormas.api.sample.SampleSimilarityCriteria) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial)

Example 2 with SampleCriteria

use of de.symeda.sormas.api.sample.SampleCriteria in project SORMAS-Project by hzi-braunschweig.

the class SampleFacadeEjb method getByCriteria.

private List<SampleDto> getByCriteria(SampleCriteria criteria) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Sample> cq = cb.createQuery(Sample.class);
    final Root<Sample> root = cq.from(Sample.class);
    SampleJoins<Sample> joins = new SampleJoins<>(root);
    Predicate filter = sampleService.createUserFilter(cq, cb, joins, criteria);
    filter = CriteriaBuilderHelper.and(cb, filter, sampleService.buildCriteriaFilter(criteria, cb, joins));
    if (filter != null) {
        cq.where(filter);
    }
    List<Sample> samples = em.createQuery(cq).getResultList();
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    return samples.stream().map(s -> convertToDto(s, pseudonymizer)).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) StringUtils(org.apache.commons.lang3.StringUtils) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SormasToSormasOriginInfoFacadeEjb(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) DiseaseHelper(de.symeda.sormas.api.DiseaseHelper) FacilityHelper(de.symeda.sormas.api.infrastructure.facility.FacilityHelper) NotNull(javax.validation.constraints.NotNull) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) UserRoleConfigFacadeEjbLocal(de.symeda.sormas.backend.user.UserRoleConfigFacadeEjb.UserRoleConfigFacadeEjbLocal) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Selection(javax.persistence.criteria.Selection) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) SampleFacade(de.symeda.sormas.api.sample.SampleFacade) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) SampleListEntryDto(de.symeda.sormas.api.sample.SampleListEntryDto) LocalBean(javax.ejb.LocalBean) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) DataHelper(de.symeda.sormas.api.utils.DataHelper) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) EventParticipantFacadeEjb(de.symeda.sormas.backend.event.EventParticipantFacadeEjb) ContactService(de.symeda.sormas.backend.contact.ContactService) SampleDto(de.symeda.sormas.api.sample.SampleDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) NotificationService(de.symeda.sormas.backend.common.NotificationService) UserRole(de.symeda.sormas.api.user.UserRole) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) CoreAdo(de.symeda.sormas.backend.common.CoreAdo) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) DateHelper(de.symeda.sormas.api.utils.DateHelper) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) Function(java.util.function.Function) PathogenTestFacadeEjbLocal(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) AdditionalTestFacadeEjbLocal(de.symeda.sormas.backend.sample.AdditionalTestFacadeEjb.AdditionalTestFacadeEjbLocal) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SormasToSormasOriginInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) Event(de.symeda.sormas.backend.event.Event) UserRight(de.symeda.sormas.api.user.UserRight) SampleExportDto(de.symeda.sormas.api.sample.SampleExportDto) NotificationType(de.symeda.sormas.api.user.NotificationType) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) SampleSimilarityCriteria(de.symeda.sormas.api.sample.SampleSimilarityCriteria) ShareInfoHelper(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareInfoHelper) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Predicate(javax.persistence.criteria.Predicate)

Example 3 with SampleCriteria

use of de.symeda.sormas.api.sample.SampleCriteria 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);
        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) 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 4 with SampleCriteria

use of de.symeda.sormas.api.sample.SampleCriteria in project SORMAS-Project by hzi-braunschweig.

the class SampleController method caseSampleCountOf.

public int caseSampleCountOf(SampleDto sample) {
    CaseReferenceDto cazeRef = sample.getAssociatedCase();
    if (cazeRef == null) {
        return 0;
    } else {
        SampleCriteria sampleCriteria = new SampleCriteria();
        sampleCriteria.caze(cazeRef);
        return (int) FacadeProvider.getSampleFacade().count(sampleCriteria);
    }
}
Also used : SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 5 with SampleCriteria

use of de.symeda.sormas.api.sample.SampleCriteria in project SORMAS-Project by hzi-braunschweig.

the class SampleGridFilterForm method onApplyClick.

private void onApplyClick(EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter) {
    SampleCriteria criteria = getValue();
    DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
    Date fromDate, toDate;
    if (dateFilterOption == DateFilterOption.DATE) {
        Date dateFrom = weekAndDateFilter.getDateFromFilter().getValue();
        fromDate = dateFrom != null ? DateHelper.getStartOfDay(dateFrom) : null;
        Date dateTo = weekAndDateFilter.getDateToFilter().getValue();
        toDate = dateFrom != null ? DateHelper.getEndOfDay(dateTo) : null;
    } else {
        fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
        toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
    }
    if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
        criteria.reportDateBetween(fromDate, toDate, dateFilterOption);
    } else {
        weekAndDateFilter.setNotificationsForMissingFilters();
    }
}
Also used : DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Aggregations

SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)22 Date (java.util.Date)11 SampleDto (de.symeda.sormas.api.sample.SampleDto)10 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)9 SampleIndexDto (de.symeda.sormas.api.sample.SampleIndexDto)9 ContactDto (de.symeda.sormas.api.contact.ContactDto)8 ArrayList (java.util.ArrayList)8 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)7 SortProperty (de.symeda.sormas.api.utils.SortProperty)7 Contact (de.symeda.sormas.backend.contact.Contact)7 Captions (de.symeda.sormas.api.i18n.Captions)6 PersonDto (de.symeda.sormas.api.person.PersonDto)6 ContactService (de.symeda.sormas.backend.contact.ContactService)6 User (de.symeda.sormas.backend.user.User)6 Collections (java.util.Collections)6 List (java.util.List)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 EJB (javax.ejb.EJB)6 LocalBean (javax.ejb.LocalBean)6