Search in sources :

Example 1 with CaseIndexDto

use of de.symeda.sormas.api.caze.CaseIndexDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method getIndexList.

@Override
public List<CaseIndexDto> getIndexList(CaseCriteria caseCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaQuery<CaseIndexDto> cq = listQueryBuilder.buildIndexCriteria(caseCriteria, sortProperties);
    List<CaseIndexDto> cases = QueryHelper.getResultList(em, cq, first, max);
    List<Long> caseIds = cases.stream().map(CaseIndexDto::getId).collect(Collectors.toList());
    Map<String, ExternalShareInfoCountAndLatestDate> survToolShareCountAndDates = null;
    if (externalSurveillanceToolGatewayFacade.isFeatureEnabled()) {
        survToolShareCountAndDates = externalShareInfoService.getCaseShareCountAndLatestDate(caseIds).stream().collect(Collectors.toMap(ExternalShareInfoCountAndLatestDate::getAssociatedObjectUuid, Function.identity()));
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    for (CaseIndexDto caze : cases) {
        if (survToolShareCountAndDates != null) {
            ExternalShareInfoCountAndLatestDate survToolShareCountAndDate = survToolShareCountAndDates.get(caze.getUuid());
            if (survToolShareCountAndDate != null) {
                caze.setSurveillanceToolShareCount(survToolShareCountAndDate.getCount());
                caze.setSurveillanceToolLastShareDate(survToolShareCountAndDate.getLatestDate());
                caze.setSurveillanceToolStatus(survToolShareCountAndDate.getLatestStatus());
            }
        }
        Boolean isInJurisdiction = caze.getInJurisdiction();
        pseudonymizer.pseudonymizeDto(CaseIndexDto.class, caze, isInJurisdiction, c -> pseudonymizer.pseudonymizeDto(AgeAndBirthDateDto.class, caze.getAgeAndBirthDate(), isInJurisdiction, null));
    }
    return cases;
}
Also used : AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto)

Example 2 with CaseIndexDto

use of de.symeda.sormas.api.caze.CaseIndexDto in project SORMAS-Project by hzi-braunschweig.

the class CaseService method getCasesForDuplicateMerging.

public List<CaseIndexDto[]> getCasesForDuplicateMerging(CaseCriteria criteria, boolean ignoreRegion, double nameSimilarityThreshold) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Case> root = cq.from(Case.class);
    final CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, root);
    final CaseJoins<Case> joins = (CaseJoins<Case>) caseQueryContext.getJoins();
    Root<Case> root2 = cq.from(Case.class);
    Join<Case, Person> person = joins.getPerson();
    Join<Case, Person> person2 = root2.join(Case.PERSON, JoinType.LEFT);
    Join<Case, Region> responsibleRegion = joins.getResponsibleRegion();
    Join<Case, Region> responsibleRegion2 = root2.join(Case.RESPONSIBLE_REGION, JoinType.LEFT);
    Join<Case, Region> region = joins.getRegion();
    Join<Case, Region> region2 = root2.join(Case.REGION, JoinType.LEFT);
    Join<Case, Symptoms> symptoms = joins.getSymptoms();
    Join<Case, Symptoms> symptoms2 = root2.join(Case.SYMPTOMS, JoinType.LEFT);
    cq.distinct(true);
    // similarity:
    // * first & last name concatenated with whitespace. Similarity function with default threshold of 0.65D
    // uses postgres pg_trgm: https://www.postgresql.org/docs/9.6/pgtrgm.html
    // * same disease
    // * same region (optional)
    // * report date within 30 days of each other
    // * same sex or same birth date (when defined)
    // * same birth date (when fully defined)
    // * onset date within 30 days of each other (when defined)
    Predicate userFilter = createUserFilter(cb, cq, root);
    Predicate criteriaFilter = criteria != null ? createCriteriaFilter(criteria, caseQueryContext) : null;
    Expression<String> nameSimilarityExpr = cb.concat(person.get(Person.FIRST_NAME), " ");
    nameSimilarityExpr = cb.concat(nameSimilarityExpr, person.get(Person.LAST_NAME));
    Expression<String> nameSimilarityExpr2 = cb.concat(person2.get(Person.FIRST_NAME), " ");
    nameSimilarityExpr2 = cb.concat(nameSimilarityExpr2, person2.get(Person.LAST_NAME));
    Predicate nameSimilarityFilter = cb.gt(cb.function("similarity", double.class, nameSimilarityExpr, nameSimilarityExpr2), nameSimilarityThreshold);
    Predicate diseaseFilter = cb.equal(root.get(Case.DISEASE), root2.get(Case.DISEASE));
    Predicate regionFilter = cb.and(cb.equal(responsibleRegion.get(Region.ID), responsibleRegion2.get(Region.ID)), cb.or(cb.and(cb.isNull(region)), cb.equal(region.get(Region.ID), region2.get(Region.ID))));
    Predicate reportDateFilter = cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root.get(Case.REPORT_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), root2.get(Case.REPORT_DATE)))), SECONDS_30_DAYS);
    // // todo this should use PersonService.buildSimilarityCriteriaFilter
    // Sex filter: only when sex is filled in for both cases
    Predicate sexFilter = cb.or(cb.or(cb.isNull(person.get(Person.SEX)), cb.isNull(person2.get(Person.SEX))), cb.or(cb.equal(person.get(Person.SEX), Sex.UNKNOWN), cb.equal(person2.get(Person.SEX), Sex.UNKNOWN)), cb.equal(person.get(Person.SEX), person2.get(Person.SEX)));
    // Birth date filter: only when birth date is filled in for both cases
    Predicate birthDateFilter = cb.or(cb.or(cb.isNull(person.get(Person.BIRTHDATE_DD)), cb.isNull(person.get(Person.BIRTHDATE_MM)), cb.isNull(person.get(Person.BIRTHDATE_YYYY)), cb.isNull(person2.get(Person.BIRTHDATE_DD)), cb.isNull(person2.get(Person.BIRTHDATE_MM)), cb.isNull(person2.get(Person.BIRTHDATE_YYYY))), cb.and(cb.equal(person.get(Person.BIRTHDATE_DD), person2.get(Person.BIRTHDATE_DD)), cb.equal(person.get(Person.BIRTHDATE_MM), person2.get(Person.BIRTHDATE_MM)), cb.equal(person.get(Person.BIRTHDATE_YYYY), person2.get(Person.BIRTHDATE_YYYY))));
    // Onset date filter: only when onset date is filled in for both cases
    Predicate onsetDateFilter = cb.or(cb.or(cb.isNull(symptoms.get(Symptoms.ONSET_DATE)), cb.isNull(symptoms2.get(Symptoms.ONSET_DATE))), cb.lessThanOrEqualTo(cb.abs(cb.diff(cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms.get(Symptoms.ONSET_DATE)), cb.function("date_part", Long.class, cb.parameter(String.class, "date_type"), symptoms2.get(Symptoms.ONSET_DATE)))), SECONDS_30_DAYS));
    Predicate creationDateFilter = cb.or(cb.lessThan(root.get(Case.CREATION_DATE), root2.get(Case.CREATION_DATE)), cb.or(cb.lessThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getStartOfDay(criteria.getCreationDateFrom())), cb.greaterThanOrEqualTo(root2.get(Case.CREATION_DATE), DateHelper.getEndOfDay(criteria.getCreationDateTo()))));
    Predicate filter = cb.and(createDefaultFilter(cb, root), createDefaultFilter(cb, root2));
    if (userFilter != null) {
        filter = cb.and(filter, userFilter);
    }
    if (filter != null) {
        filter = cb.and(filter, criteriaFilter);
    } else {
        filter = criteriaFilter;
    }
    if (filter != null) {
        filter = cb.and(filter, nameSimilarityFilter);
    } else {
        filter = nameSimilarityFilter;
    }
    filter = cb.and(filter, diseaseFilter);
    if (!ignoreRegion) {
        filter = cb.and(filter, regionFilter);
    }
    filter = cb.and(filter, reportDateFilter);
    filter = cb.and(filter, cb.and(sexFilter, birthDateFilter));
    filter = cb.and(filter, onsetDateFilter);
    filter = cb.and(filter, creationDateFilter);
    filter = cb.and(filter, cb.notEqual(root.get(Case.ID), root2.get(Case.ID)));
    cq.where(filter);
    cq.multiselect(root.get(Case.ID), root2.get(Case.ID), root.get(Case.CREATION_DATE));
    cq.orderBy(cb.desc(root.get(Case.CREATION_DATE)));
    List<Object[]> foundIds = em.createQuery(cq).setParameter("date_type", "epoch").getResultList();
    List<CaseIndexDto[]> resultList = new ArrayList<>();
    if (!foundIds.isEmpty()) {
        CriteriaQuery<CaseIndexDto> indexCasesCq = cb.createQuery(CaseIndexDto.class);
        Root<Case> indexRoot = indexCasesCq.from(Case.class);
        selectIndexDtoFields(new CaseQueryContext(cb, indexCasesCq, indexRoot));
        indexCasesCq.where(indexRoot.get(Case.ID).in(foundIds.stream().map(a -> Arrays.copyOf(a, 2)).flatMap(Arrays::stream).collect(Collectors.toSet())));
        Map<Long, CaseIndexDto> indexCases = em.createQuery(indexCasesCq).getResultStream().collect(Collectors.toMap(c -> c.getId(), Function.identity()));
        for (Object[] idPair : foundIds) {
            try {
                // Cloning is necessary here to allow us to add the same CaseIndexDto to the grid multiple times
                CaseIndexDto parent = (CaseIndexDto) indexCases.get(idPair[0]).clone();
                CaseIndexDto child = (CaseIndexDto) indexCases.get(idPair[1]).clone();
                if (parent.getCompleteness() == null && child.getCompleteness() == null || parent.getCompleteness() != null && (child.getCompleteness() == null || (parent.getCompleteness() >= child.getCompleteness()))) {
                    resultList.add(new CaseIndexDto[] { parent, child });
                } else {
                    resultList.add(new CaseIndexDto[] { child, parent });
                }
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return resultList;
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) NoResultException(javax.persistence.NoResultException) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) Visit(de.symeda.sormas.backend.visit.Visit) From(javax.persistence.criteria.From) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) Transactional(javax.transaction.Transactional) NotNull(javax.validation.constraints.NotNull) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Treatment(de.symeda.sormas.backend.therapy.Treatment) Disease(de.symeda.sormas.api.Disease) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) CaseSelectionDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseSelectionDtoResultTransformer) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Join(javax.persistence.criteria.Join) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) Fetch(javax.persistence.criteria.Fetch) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) List(java.util.List) ExtendedPostgreSQL94Dialect(de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) ClinicalCourse(de.symeda.sormas.backend.clinicalcourse.ClinicalCourse) Location(de.symeda.sormas.backend.location.Location) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) Function(java.util.function.Function) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) CollectionUtils(org.apache.commons.collections.CollectionUtils) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) CaseJoins(de.symeda.sormas.utils.CaseJoins) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) Event(de.symeda.sormas.backend.event.Event) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) Comparator(java.util.Comparator) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) CaseListEntryDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseListEntryDtoResultTransformer) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) CaseJoins(de.symeda.sormas.utils.CaseJoins) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Person(de.symeda.sormas.backend.person.Person) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms)

Example 3 with CaseIndexDto

use of de.symeda.sormas.api.caze.CaseIndexDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    String districtName = "District";
    RDCF rdcf = creator.createRDCF("Region", districtName, "Community", "Facility");
    useSurveillanceOfficerLogin(rdcf);
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    String lastName = "Person";
    PersonDto cazePerson = creator.createPerson("Case", lastName);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf, c -> c.setHealthFacilityDetails("abc"));
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf, c -> c.setHealthFacilityDetails("xyz"));
    List<CaseIndexDto> results = getCaseFacade().getIndexList(null, 0, 100, Arrays.asList(new SortProperty(CaseIndexDto.DISEASE), new SortProperty(CaseIndexDto.PERSON_FIRST_NAME), new SortProperty(CaseIndexDto.RESPONSIBLE_DISTRICT_NAME), new SortProperty(CaseIndexDto.HEALTH_FACILITY_NAME, false), new SortProperty(CaseIndexDto.SURVEILLANCE_OFFICER_UUID)));
    // List should have one entry
    assertEquals(3, results.size());
    assertEquals(districtName, results.get(0).getResponsibleDistrictName());
    assertEquals(lastName, results.get(0).getPersonLastName());
    assertEquals("Facility - xyz", results.get(0).getHealthFacilityName());
    assertEquals("Facility - abc", results.get(1).getHealthFacilityName());
    assertEquals("Facility", results.get(2).getHealthFacilityName());
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Date(java.util.Date) LocalDate(java.time.LocalDate) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with CaseIndexDto

use of de.symeda.sormas.api.caze.CaseIndexDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testSearchCasesFreetext.

@Test
public void testSearchCasesFreetext() {
    RDCF rdcf = creator.createRDCF();
    final UserReferenceDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    CaseDataDto caze = creator.createCase(user, creator.createPerson().toReference(), rdcf);
    caze.setInternalToken("internalToken");
    caze.setExternalToken("externalToken");
    caze.setExternalID("externalID");
    getCaseFacade().save(caze);
    CaseDataDto secondCaze = creator.createCase(user, creator.createPerson().toReference(), rdcf);
    secondCaze.setInternalToken("internalToken2");
    getCaseFacade().save(secondCaze);
    List<CaseIndexDto> indexList = getCaseFacade().getIndexList(new CaseCriteria(), 0, 100, Collections.emptyList());
    // test several freetext variations
    assertEquals(2, indexList.size());
    CaseCriteria caseCriteria = new CaseCriteria();
    caseCriteria.setCaseLike("internal");
    List<CaseIndexDto> indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(2, indexListFiltered.size());
    caseCriteria.setCaseLike("Token");
    indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(2, indexListFiltered.size());
    caseCriteria.setCaseLike("externalToken");
    indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(1, indexListFiltered.size());
    assertThat(indexListFiltered.get(0).getUuid(), is(caze.getUuid()));
    caseCriteria.setCaseLike("externalID");
    indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(1, indexListFiltered.size());
    assertThat(indexListFiltered.get(0).getUuid(), is(caze.getUuid()));
    caseCriteria.setCaseLike("unmatchableString");
    indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(0, indexListFiltered.size());
    caseCriteria.setCaseLike(caze.getUuid());
    indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertEquals(1, indexListFiltered.size());
    assertThat(indexListFiltered.get(0).getUuid(), is(caze.getUuid()));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with CaseIndexDto

use of de.symeda.sormas.api.caze.CaseIndexDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testSearchCasesWithReducedQuarantine.

@Test
public void testSearchCasesWithReducedQuarantine() {
    RDCF rdcf = creator.createRDCF();
    CaseDataDto caze = creator.createCase(creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference(), creator.createPerson().toReference(), rdcf);
    caze.setQuarantineReduced(true);
    getCaseFacade().save(caze);
    List<CaseIndexDto> indexList = getCaseFacade().getIndexList(new CaseCriteria(), 0, 100, Collections.emptyList());
    assertThat(indexList.get(0).getUuid(), is(caze.getUuid()));
    CaseCriteria caseCriteria = new CaseCriteria();
    caseCriteria.setWithReducedQuarantine(true);
    List<CaseIndexDto> indexListFiltered = getCaseFacade().getIndexList(caseCriteria, 0, 100, Collections.emptyList());
    assertThat(indexListFiltered.get(0).getUuid(), is(caze.getUuid()));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseIndexDto (de.symeda.sormas.api.caze.CaseIndexDto)29 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)23 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)20 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)19 Test (org.junit.Test)19 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)8 Date (java.util.Date)6 Label (com.vaadin.ui.Label)5 Notification (com.vaadin.ui.Notification)5 FeatureType (de.symeda.sormas.api.feature.FeatureType)5 PersonDto (de.symeda.sormas.api.person.PersonDto)5 UserDto (de.symeda.sormas.api.user.UserDto)5 DateHelper (de.symeda.sormas.api.utils.DateHelper)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 CountryHelper (de.symeda.sormas.api.CountryHelper)4 Page (com.vaadin.server.Page)3 ContentMode (com.vaadin.shared.ui.ContentMode)3 Alignment (com.vaadin.ui.Alignment)3 Button (com.vaadin.ui.Button)3