Search in sources :

Example 1 with SampleIndexDto

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

the class SampleFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    SampleDto sample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
    SampleDto referredSample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
    sample.setReferredTo(referredSample.toReference());
    creator.createAdditionalTest(sample.toReference());
    creator.createAdditionalTest(sample.toReference());
    creator.createPathogenTest(sample.toReference(), caze);
    PathogenTestDto test = creator.createPathogenTest(sample.toReference(), PathogenTestType.CQ_VALUE_DETECTION, caze.getDisease(), new Date(), rdcf.facility, caze.getReportingUser(), PathogenTestResultType.PENDING, "", false);
    test.setCqValue(1.5F);
    getPathogenTestFacade().savePathogenTest(test);
    List<SampleIndexDto> sampleIndexDtos = getSampleFacade().getIndexList(new SampleCriteria(), 0, 100, null);
    assertEquals(2, sampleIndexDtos.size());
    // First sample should have an additional test
    assertEquals(AdditionalTestingStatus.PERFORMED, sampleIndexDtos.get(1).getAdditionalTestingStatus());
    assertEquals(PathogenTestType.CQ_VALUE_DETECTION, sampleIndexDtos.get(1).getTypeOfLastTest());
    assertTrue(sampleIndexDtos.get(1).getLastTestCqValue().equals(1.5F));
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) UserDto(de.symeda.sormas.api.user.UserDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with SampleIndexDto

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

the class SampleFacadeEjbTest method testGetIndexListForCaseConvertedFromContact.

@Test
public void testGetIndexListForCaseConvertedFromContact() {
    RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person1");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person2");
    ContactDto contact = creator.createContact(user.toReference(), contactPerson.toReference(), caze);
    SampleDto cazeSample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
    cazeSample.setSampleDateTime(DateHelper.subtractDays(new Date(), 5));
    getSampleFacade().saveSample(cazeSample);
    SampleDto sample = creator.createSample(contact.toReference(), DateHelper.subtractDays(new Date(), 4), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
    SampleDto referredSample = creator.createSample(contact.toReference(), DateHelper.subtractDays(new Date(), 3), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
    sample.setReferredTo(referredSample.toReference());
    creator.createAdditionalTest(sample.toReference());
    CaseDataDto caseDataDto = CaseDataDto.buildFromContact(contact);
    caseDataDto.setResponsibleRegion(new RegionReferenceDto(rdcf.region.getUuid(), null, null));
    caseDataDto.setResponsibleDistrict(new DistrictReferenceDto(rdcf.district.getUuid(), null, null));
    caseDataDto.setFacilityType(rdcf.facility.getType());
    caseDataDto.setHealthFacility(new FacilityReferenceDto(rdcf.facility.getUuid(), null, null));
    caseDataDto.setReportingUser(user.toReference());
    CaseDataDto caseConvertedFromContact = getCaseFacade().save(caseDataDto);
    getCaseFacade().setSampleAssociations(contact.toReference(), caseConvertedFromContact.toReference());
    final SampleCriteria samplesConnectedToConvertedCaseCriteria = new SampleCriteria().caze(caseConvertedFromContact.toReference());
    assertEquals(2, getSampleFacade().count(samplesConnectedToConvertedCaseCriteria));
    final ArrayList<SortProperty> sortProperties = new ArrayList<>();
    sortProperties.add(new SortProperty(SampleIndexDto.SAMPLE_DATE_TIME));
    sortProperties.add(new SortProperty(SampleIndexDto.ASSOCIATED_CONTACT));
    final List<SampleIndexDto> samplesOfConvertedCase = getSampleFacade().getIndexList(samplesConnectedToConvertedCaseCriteria, 0, 100, sortProperties);
    assertEquals(2, samplesOfConvertedCase.size());
    final SampleIndexDto sample11 = samplesOfConvertedCase.get(0);
    Assert.assertEquals(sample.getUuid(), sample11.getUuid());
    Assert.assertEquals(caseConvertedFromContact.getUuid(), sample11.getAssociatedCase().getUuid());
    Assert.assertEquals(contact.getUuid(), sample11.getAssociatedContact().getUuid());
    final SampleIndexDto sample12 = samplesOfConvertedCase.get(1);
    Assert.assertEquals(referredSample.getUuid(), sample12.getUuid());
    Assert.assertEquals(contact.getUuid(), sample12.getAssociatedContact().getUuid());
    Assert.assertEquals(caseConvertedFromContact.getUuid(), sample11.getAssociatedCase().getUuid());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) UserDto(de.symeda.sormas.api.user.UserDto) ArrayList(java.util.ArrayList) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) SortProperty(de.symeda.sormas.api.utils.SortProperty) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with SampleIndexDto

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

the class SampleService method getIndexList.

public List<SampleIndexDto> getIndexList(SampleCriteria sampleCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<SampleIndexDto> cq = cb.createQuery(SampleIndexDto.class);
    final Root<Sample> sample = cq.from(Sample.class);
    SampleQueryContext sampleQueryContext = new SampleQueryContext(cb, cq, sample);
    SampleJoins joins = sampleQueryContext.getJoins();
    final Join<Sample, Case> caze = joins.getCaze();
    final Join<Case, District> caseDistrict = joins.getCaseDistrict();
    final Join<Sample, Contact> contact = joins.getContact();
    final Join<Contact, District> contactDistrict = joins.getContactDistrict();
    final Join<Case, District> contactCaseDistrict = joins.getContactCaseDistrict();
    final Join<EventParticipant, Event> event = joins.getEvent();
    final Join<Location, District> eventDistrict = joins.getEventDistrict();
    Expression<Object> diseaseSelect = cb.selectCase().when(cb.isNotNull(caze), caze.get(Case.DISEASE)).otherwise(cb.selectCase().when(cb.isNotNull(contact), contact.get(Contact.DISEASE)).otherwise(event.get(Event.DISEASE)));
    Expression<Object> diseaseDetailsSelect = cb.selectCase().when(cb.isNotNull(caze), caze.get(Case.DISEASE_DETAILS)).otherwise(cb.selectCase().when(cb.isNotNull(contact), contact.get(Contact.DISEASE_DETAILS)).otherwise(event.get(Event.DISEASE_DETAILS)));
    Expression<Object> districtSelect = cb.selectCase().when(cb.isNotNull(caseDistrict), caseDistrict.get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(contactDistrict), contactDistrict.get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(contactCaseDistrict), contactCaseDistrict.get(District.NAME)).otherwise(eventDistrict.get(District.NAME))));
    cq.distinct(true);
    List<Selection<?>> selections = new ArrayList<>(Arrays.asList(sample.get(Sample.UUID), caze.get(Case.EPID_NUMBER), sample.get(Sample.LAB_SAMPLE_ID), sample.get(Sample.SAMPLE_DATE_TIME), sample.get(Sample.SHIPPED), sample.get(Sample.SHIPMENT_DATE), sample.get(Sample.RECEIVED), sample.get(Sample.RECEIVED_DATE), sample.get(Sample.SAMPLE_MATERIAL), sample.get(Sample.SAMPLE_PURPOSE), sample.get(Sample.SPECIMEN_CONDITION), joins.getLab().get(Facility.NAME), joins.getReferredSample().get(Sample.UUID), sample.get(Sample.SAMPLING_REASON), sample.get(Sample.SAMPLING_REASON_DETAILS), caze.get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), joins.getContact().get(Contact.UUID), joins.getContactPerson().get(Person.FIRST_NAME), joins.getContactPerson().get(Person.LAST_NAME), joins.getEventParticipant().get(EventParticipant.UUID), joins.getEventParticipantPerson().get(Person.FIRST_NAME), joins.getEventParticipantPerson().get(Person.LAST_NAME), diseaseSelect, diseaseDetailsSelect, sample.get(Sample.PATHOGEN_TEST_RESULT), sample.get(Sample.ADDITIONAL_TESTING_REQUESTED), cb.isNotEmpty(sample.get(Sample.ADDITIONAL_TESTS)), districtSelect, joins.getLab().get(Facility.UUID)));
    // Tests count subquery
    Subquery<Long> testCountSq = cq.subquery(Long.class);
    Root<PathogenTest> testCountRoot = testCountSq.from(PathogenTest.class);
    testCountSq.where(cb.equal(testCountRoot.get(PathogenTest.SAMPLE), sample), cb.isFalse(testCountRoot.get(PathogenTest.DELETED)));
    testCountSq.select(cb.countDistinct(testCountRoot.get(PathogenTest.ID)));
    selections.add(testCountSq.getSelection());
    selections.addAll(getJurisdictionSelections(sampleQueryContext));
    cq.multiselect(selections);
    Predicate filter = createUserFilter(sampleQueryContext, sampleCriteria);
    if (sampleCriteria != null) {
        Predicate criteriaFilter = buildCriteriaFilter(sampleCriteria, sampleQueryContext);
        filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
    }
    if (filter != null) {
        cq.where(filter);
    }
    if (sortProperties != null && sortProperties.size() > 0) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case SampleIndexDto.UUID:
                case SampleIndexDto.LAB_SAMPLE_ID:
                case SampleIndexDto.SHIPPED:
                case SampleIndexDto.RECEIVED:
                case SampleIndexDto.REFERRED:
                case SampleIndexDto.SAMPLE_DATE_TIME:
                case SampleIndexDto.SHIPMENT_DATE:
                case SampleIndexDto.RECEIVED_DATE:
                case SampleIndexDto.SAMPLE_MATERIAL:
                case SampleIndexDto.SAMPLE_PURPOSE:
                case SampleIndexDto.PATHOGEN_TEST_RESULT:
                case SampleIndexDto.ADDITIONAL_TESTING_STATUS:
                    expression = sample.get(sortProperty.propertyName);
                    break;
                case SampleIndexDto.DISEASE:
                    expression = diseaseSelect;
                    break;
                case SampleIndexDto.EPID_NUMBER:
                    expression = caze.get(Case.EPID_NUMBER);
                    break;
                case SampleIndexDto.ASSOCIATED_CASE:
                    expression = joins.getCasePerson().get(Person.LAST_NAME);
                    order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
                    expression = joins.getCasePerson().get(Person.FIRST_NAME);
                    break;
                case SampleIndexDto.ASSOCIATED_CONTACT:
                    expression = joins.getContactPerson().get(Person.LAST_NAME);
                    order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
                    expression = joins.getContactPerson().get(Person.FIRST_NAME);
                    break;
                case SampleIndexDto.ASSOCIATED_EVENT_PARTICIPANT:
                    expression = joins.getEventParticipantPerson().get(Person.LAST_NAME);
                    order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
                    expression = joins.getEventParticipantPerson().get(Person.FIRST_NAME);
                    break;
                case SampleIndexDto.DISTRICT:
                    expression = districtSelect;
                    break;
                case SampleIndexDto.LAB:
                    expression = joins.getLab().get(Facility.NAME);
                    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(sample.get(Sample.SAMPLE_DATE_TIME)));
    }
    List<SampleIndexDto> samples = QueryHelper.getResultList(em, cq, first, max);
    if (!samples.isEmpty()) {
        CriteriaQuery<Object[]> testCq = cb.createQuery(Object[].class);
        Root<PathogenTest> testRoot = testCq.from(PathogenTest.class);
        Expression<String> sampleIdExpr = testRoot.get(PathogenTest.SAMPLE).get(Sample.UUID);
        Path<Long> testType = testRoot.get(PathogenTest.TEST_TYPE);
        Path<Date> cqValue = testRoot.get(PathogenTest.CQ_VALUE);
        testCq.select(cb.array(testType, cqValue, sampleIdExpr));
        testCq.where(cb.isFalse(testRoot.get(PathogenTest.DELETED)), sampleIdExpr.in(samples.stream().map(SampleIndexDto::getUuid).collect(Collectors.toList())));
        testCq.orderBy(cb.desc(testRoot.get(PathogenTest.CHANGE_DATE)));
        List<Object[]> testList = em.createQuery(testCq).getResultList();
        Map<String, Object[]> tests = testList.stream().filter(distinctByKey(pathogenTest -> pathogenTest[2])).collect(Collectors.toMap(pathogenTest -> pathogenTest[2].toString(), Function.identity()));
        for (SampleIndexDto indexDto : samples) {
            Optional.ofNullable(tests.get(indexDto.getUuid())).ifPresent(test -> {
                indexDto.setTypeOfLastTest((PathogenTestType) test[0]);
                indexDto.setLastTestCqValue((Float) test[1]);
            });
        }
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    Pseudonymizer emptyValuePseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
    pseudonymizer.pseudonymizeDtoCollection(SampleIndexDto.class, samples, s -> s.getSampleJurisdictionFlagsDto().getInJurisdiction(), (s, ignored) -> {
        final SampleJurisdictionFlagsDto sampleJurisdictionFlagsDto = s.getSampleJurisdictionFlagsDto();
        if (s.getAssociatedCase() != null) {
            emptyValuePseudonymizer.pseudonymizeDto(CaseReferenceDto.class, s.getAssociatedCase(), sampleJurisdictionFlagsDto.getCaseInJurisdiction(), null);
        }
        ContactReferenceDto associatedContact = s.getAssociatedContact();
        if (associatedContact != null) {
            emptyValuePseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, associatedContact.getContactName(), sampleJurisdictionFlagsDto.getContactInJurisdiction(), null);
            if (associatedContact.getCaseName() != null) {
                pseudonymizer.pseudonymizeDto(ContactReferenceDto.PersonName.class, associatedContact.getCaseName(), sampleJurisdictionFlagsDto.getContactCaseInJurisdiction(), null);
            }
        }
        if (s.getAssociatedEventParticipant() != null) {
            emptyValuePseudonymizer.pseudonymizeDto(EventParticipantReferenceDto.class, s.getAssociatedEventParticipant(), sampleJurisdictionFlagsDto.getEvenParticipantInJurisdiction(), null);
        }
    }, true);
    return samples;
}
Also used : Arrays(java.util.Arrays) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) TransactionAttributeType(javax.ejb.TransactionAttributeType) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) From(javax.persistence.criteria.From) Path(javax.persistence.criteria.Path) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) LabMessageService(de.symeda.sormas.backend.labmessage.LabMessageService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Instant(java.time.Instant) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) EventParticipantQueryContext(de.symeda.sormas.backend.event.EventParticipantQueryContext) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) SormasToSormasShareInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoFacadeEjb.SormasToSormasShareInfoFacadeEjbLocal) Order(javax.persistence.criteria.Order) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) Optional(java.util.Optional) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) SampleAssociationType(de.symeda.sormas.api.sample.SampleAssociationType) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) DateHelper(de.symeda.sormas.api.utils.DateHelper) SampleListEntryDtoResultTransformer(de.symeda.sormas.backend.sample.transformers.SampleListEntryDtoResultTransformer) Selection(javax.persistence.criteria.Selection) HashMap(java.util.HashMap) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) Function(java.util.function.Function) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) Case(de.symeda.sormas.backend.caze.Case) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) SampleReferenceDto(de.symeda.sormas.api.sample.SampleReferenceDto) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) TransactionAttribute(javax.ejb.TransactionAttribute) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) SampleListEntryDto(de.symeda.sormas.api.sample.SampleListEntryDto) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) AbstractDeletableAdoService(de.symeda.sormas.backend.common.AbstractDeletableAdoService) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) DataHelper(de.symeda.sormas.api.utils.DataHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) Event(de.symeda.sormas.backend.event.Event) ContactService(de.symeda.sormas.backend.contact.ContactService) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) Subquery(javax.persistence.criteria.Subquery) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Selection(javax.persistence.criteria.Selection) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) Date(java.util.Date) Contact(de.symeda.sormas.backend.contact.Contact) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Event(de.symeda.sormas.backend.event.Event) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) District(de.symeda.sormas.backend.infrastructure.district.District) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Location(de.symeda.sormas.backend.location.Location)

Example 4 with SampleIndexDto

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

the class SampleGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<SampleIndexDto, SampleCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getSampleFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getSampleFacade().count(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto)

Example 5 with SampleIndexDto

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

the class SampleFacadeEjbPseudonymizationTest method testPseudonymizeIndexList.

@Test
public void testPseudonymizeIndexList() {
    CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
    SampleDto sample1 = createCaseSample(caze1, user2);
    CaseDataDto caze2 = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
    ContactDto contact1 = creator.createContact(user2.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
    SampleDto sample2 = createCaseSample(caze2, user1);
    SampleDto sample3 = createContactSample(contact1);
    ContactDto contact2 = creator.createContact(user1.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf1);
    SampleDto sample4 = createContactSample(contact2);
    List<SampleIndexDto> indexList = getSampleFacade().getIndexList(new SampleCriteria(), null, null, Collections.emptyList());
    SampleIndexDto index1 = indexList.stream().filter(t -> t.getUuid().equals(sample1.getUuid())).findFirst().get();
    assertThat(index1.getAssociatedCase().getFirstName(), is("John"));
    assertThat(index1.getAssociatedCase().getLastName(), is("Smith"));
    SampleIndexDto index2 = indexList.stream().filter(t -> t.getUuid().equals(sample2.getUuid())).findFirst().get();
    assertThat(index2.getAssociatedCase().getFirstName(), isEmptyString());
    assertThat(index2.getAssociatedCase().getLastName(), isEmptyString());
    SampleIndexDto index3 = indexList.stream().filter(t -> t.getUuid().equals(sample3.getUuid())).findFirst().get();
    assertThat(index3.getAssociatedContact().getCaption(), containsString("John SMITH"));
    SampleIndexDto index4 = indexList.stream().filter(t -> t.getUuid().equals(sample4.getUuid())).findFirst().get();
    assertThat(index4.getAssociatedContact().getCaption(), is(DataHelper.getShortUuid(index4.getAssociatedContact().getUuid())));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)6 SampleIndexDto (de.symeda.sormas.api.sample.SampleIndexDto)6 Date (java.util.Date)5 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)4 SampleDto (de.symeda.sormas.api.sample.SampleDto)4 SortProperty (de.symeda.sormas.api.utils.SortProperty)4 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)4 Test (org.junit.Test)4 ContactDto (de.symeda.sormas.api.contact.ContactDto)3 PersonDto (de.symeda.sormas.api.person.PersonDto)3 UserDto (de.symeda.sormas.api.user.UserDto)3 ArrayList (java.util.ArrayList)3 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)2 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 DeletionDetails (de.symeda.sormas.api.common.DeletionDetails)1 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)1 EventDto (de.symeda.sormas.api.event.EventDto)1 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)1 EventParticipantReferenceDto (de.symeda.sormas.api.event.EventParticipantReferenceDto)1