Search in sources :

Example 1 with SampleExportDto

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

the class SampleFacadeEjb method getExportList.

private List<SampleExportDto> getExportList(SampleCriteria sampleCriteria, CaseCriteria caseCriteria, Collection<String> selectedRows, int first, int max) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<SampleExportDto> cq = cb.createQuery(SampleExportDto.class);
    Root<Sample> sampleRoot = cq.from(Sample.class);
    SampleQueryContext sampleQueryContext = new SampleQueryContext(cb, cq, sampleRoot);
    SampleJoins joins = sampleQueryContext.getJoins();
    cq.distinct(true);
    List<Selection<?>> selections = new ArrayList<>();
    Selection<?>[] tmp = new Selection<?>[] { sampleRoot.get(AbstractDomainObject.ID), sampleRoot.get(AbstractDomainObject.UUID), sampleRoot.get(Sample.LAB_SAMPLE_ID), sampleRoot.get(Sample.REPORT_DATE_TIME), joins.getCaze().get(Case.EPID_NUMBER), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), joins.getContactPerson().get(Person.FIRST_NAME), joins.getContactPerson().get(Person.LAST_NAME), joins.getEventParticipantPerson().get(Person.FIRST_NAME), joins.getEventParticipantPerson().get(Person.LAST_NAME), joins.getCaze().get(Case.DISEASE), joins.getCaze().get(Case.DISEASE_DETAILS), joins.getContact().get(Contact.DISEASE), joins.getContact().get(Contact.DISEASE_DETAILS), joins.getEvent().get(Event.DISEASE), joins.getEvent().get(Event.DISEASE_DETAILS), sampleRoot.get(Sample.SAMPLE_DATE_TIME), sampleRoot.get(Sample.SAMPLE_MATERIAL), sampleRoot.get(Sample.SAMPLE_MATERIAL_TEXT), sampleRoot.get(Sample.SAMPLE_PURPOSE), sampleRoot.get(Sample.SAMPLING_REASON), sampleRoot.get(Sample.SAMPLING_REASON_DETAILS), sampleRoot.get(Sample.SAMPLE_SOURCE), joins.getLab().get(Facility.NAME), sampleRoot.get(Sample.LAB_DETAILS), sampleRoot.get(Sample.PATHOGEN_TEST_RESULT), sampleRoot.get(Sample.PATHOGEN_TESTING_REQUESTED), sampleRoot.get(Sample.REQUESTED_PATHOGEN_TESTS_STRING), sampleRoot.get(Sample.REQUESTED_OTHER_PATHOGEN_TESTS), sampleRoot.get(Sample.ADDITIONAL_TESTING_REQUESTED), sampleRoot.get(Sample.REQUESTED_ADDITIONAL_TESTS_STRING), sampleRoot.get(Sample.REQUESTED_OTHER_ADDITIONAL_TESTS), sampleRoot.get(Sample.SHIPPED), sampleRoot.get(Sample.SHIPMENT_DATE), sampleRoot.get(Sample.SHIPMENT_DETAILS), sampleRoot.get(Sample.RECEIVED), sampleRoot.get(Sample.RECEIVED_DATE), sampleRoot.get(Sample.SPECIMEN_CONDITION), sampleRoot.get(Sample.NO_TEST_POSSIBLE_REASON), sampleRoot.get(Sample.COMMENT), joins.getReferredSample().get(AbstractDomainObject.UUID), joins.getCaze().get(AbstractDomainObject.UUID), joins.getContact().get(AbstractDomainObject.UUID), joins.getEventParticipant().get(AbstractDomainObject.UUID), joins.getCasePerson().get(Person.APPROXIMATE_AGE), joins.getCasePerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getCasePerson().get(Person.SEX), joins.getContactPerson().get(Person.APPROXIMATE_AGE), joins.getContactPerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getContactPerson().get(Person.SEX), joins.getEventParticipantPerson().get(Person.APPROXIMATE_AGE), joins.getEventParticipantPerson().get(Person.APPROXIMATE_AGE_TYPE), joins.getEventParticipantPerson().get(Person.SEX), joins.getCasePersonAddressRegion().get(Region.NAME), joins.getCasePersonAddressDistrict().get(District.NAME), joins.getCasePersonAddressCommunity().get(Community.NAME), joins.getCasePersonAddress().get(Location.CITY), joins.getCasePersonAddress().get(Location.STREET), joins.getCasePersonAddress().get(Location.HOUSE_NUMBER), joins.getCasePersonAddress().get(Location.ADDITIONAL_INFORMATION), joins.getContactPersonAddressRegion().get(Region.NAME), joins.getContactPersonAddressDistrict().get(District.NAME), joins.getContactPersonAddressCommunity().get(Community.NAME), joins.getContactPersonAddress().get(Location.CITY), joins.getContactPersonAddress().get(Location.STREET), joins.getContactPersonAddress().get(Location.HOUSE_NUMBER), joins.getContactPersonAddress().get(Location.ADDITIONAL_INFORMATION), joins.getEventRegion().get(Region.NAME), joins.getEventDistrict().get(District.NAME), joins.getEventCommunity().get(Community.NAME), joins.getEventLocation().get(Location.CITY), joins.getEventLocation().get(Location.STREET), joins.getEventLocation().get(Location.HOUSE_NUMBER), joins.getEventLocation().get(Location.ADDITIONAL_INFORMATION), joins.getCaze().get(Case.REPORT_DATE), joins.getCaze().get(Case.CASE_CLASSIFICATION), joins.getCaze().get(Case.OUTCOME), joins.getCaseRegion().get(Region.NAME), joins.getCaseDistrict().get(District.NAME), joins.getCaseCommunity().get(Community.NAME), joins.getCaseFacility().get(Facility.NAME), joins.getCaze().get(Case.HEALTH_FACILITY_DETAILS), joins.getContactRegion().get(Region.NAME), joins.getContactDistrict().get(District.NAME), joins.getContactCommunity().get(Community.NAME), joins.getContact().get(Contact.REPORT_DATE_TIME), joins.getContact().get(Contact.LAST_CONTACT_DATE), joins.getContact().get(Contact.CONTACT_CLASSIFICATION), joins.getContact().get(Contact.CONTACT_STATUS), joins.getLab().get(AbstractDomainObject.UUID), joins.getCaseFacility().get(AbstractDomainObject.UUID) };
    Collections.addAll(selections, tmp);
    selections.addAll(sampleService.getJurisdictionSelections(sampleQueryContext));
    cq.multiselect(selections);
    Predicate filter = sampleService.createUserFilter(sampleQueryContext, sampleCriteria);
    if (sampleCriteria != null) {
        Predicate criteriaFilter = sampleService.buildCriteriaFilter(sampleCriteria, sampleQueryContext);
        filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
        filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, sampleRoot.get(AbstractDomainObject.UUID));
    } else if (caseCriteria != null) {
        Predicate criteriaFilter = caseService.createCriteriaFilter(caseCriteria, new CaseQueryContext(cb, cq, joins.getCaseJoins()));
        filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
        filter = CriteriaBuilderHelper.and(cb, filter, cb.isFalse(sampleRoot.get(CoreAdo.DELETED)));
        filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, joins.getCaze().get(AbstractDomainObject.UUID));
    }
    if (filter != null) {
        cq.where(filter);
    }
    cq.orderBy(cb.desc(sampleRoot.get(Sample.REPORT_DATE_TIME)), cb.desc(sampleRoot.get(AbstractDomainObject.ID)));
    List<SampleExportDto> resultList = QueryHelper.getResultList(em, cq, first, max);
    for (SampleExportDto exportDto : resultList) {
        Sample sampleFromExportDto = sampleService.getById(exportDto.getId());
        List<PathogenTest> pathogenTests = sampleFromExportDto.getPathogenTests();
        int count = 0;
        for (PathogenTest pathogenTest : pathogenTests) {
            String lab = pathogenTest.getLab() != null ? FacilityHelper.buildFacilityString(pathogenTest.getLab().getUuid(), pathogenTest.getLab().getName(), pathogenTest.getLabDetails()) : null;
            SampleExportDto.SampleExportPathogenTest sampleExportPathogenTest = new SampleExportDto.SampleExportPathogenTest(pathogenTest.getTestType(), pathogenTest.getTestTypeText(), DiseaseHelper.toString(pathogenTest.getTestedDisease(), pathogenTest.getTestedDiseaseDetails()), pathogenTest.getTestDateTime(), lab, pathogenTest.getTestResult(), pathogenTest.getTestResultVerified());
            switch(++count) {
                case 1:
                    exportDto.setPathogenTest1(sampleExportPathogenTest);
                    break;
                case 2:
                    exportDto.setPathogenTest2(sampleExportPathogenTest);
                    break;
                case 3:
                    exportDto.setPathogenTest3(sampleExportPathogenTest);
                    break;
                default:
                    exportDto.addOtherPathogenTest(sampleExportPathogenTest);
                    break;
            }
        }
        if (exportDto.getAdditionalTestingRequested()) {
            List<AdditionalTest> additionalTests = additionalTestService.getAllBySample(sampleFromExportDto);
            if (!additionalTests.isEmpty()) {
                exportDto.setAdditionalTest(AdditionalTestFacadeEjb.toDto(additionalTests.get(0)));
            }
            if (additionalTests.size() > 1) {
                exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.yes));
            } else {
                exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.no));
            }
        } else {
            exportDto.setOtherAdditionalTestsDetails(I18nProperties.getString(Strings.no));
        }
        Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
        boolean isInJurisdiction = exportDto.getSampleJurisdictionFlagsDto().getInJurisdiction();
        pseudonymizer.pseudonymizeDto(SampleExportDto.class, exportDto, isInJurisdiction, s -> pseudonymizer.pseudonymizeDtoCollection(SampleExportDto.SampleExportPathogenTest.class, exportDto.getOtherPathogenTests(), t -> isInJurisdiction, null));
    }
    return resultList;
}
Also used : DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) 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) 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) 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) 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) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto) 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) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) 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) Selection(javax.persistence.criteria.Selection) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SampleExportDto(de.symeda.sormas.api.sample.SampleExportDto)

Example 2 with SampleExportDto

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

the class SampleFacadeEjbPseudonymizationTest method testPseudonymizeExportList.

@Test
public void testPseudonymizeExportList() {
    CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
    SampleDto sample1 = createCaseSample(caze1, user2);
    createPathogenTest(sample1, 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);
    createPathogenTest(sample2, user1);
    createPathogenTest(sample2, user1);
    createPathogenTest(sample2, user1);
    createPathogenTest(sample2, 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<SampleExportDto> exportList = getSampleFacade().getExportList(new SampleCriteria(), Collections.emptySet(), 0, 100);
    SampleExportDto export1 = exportList.stream().filter(t -> t.getUuid().equals(sample1.getUuid())).findFirst().get();
    assertThat(export1.getSampleAssociatedCase().getFirstName(), is("John"));
    assertThat(export1.getSampleAssociatedCase().getLastName(), is("Smith"));
    assertThat(export1.getLab(), is("Lab - Test lab details"));
    assertThat(export1.getPathogenTestLab1(), is("Lab - Test lab details"));
    assertThat(export1.getPathogenTestType1(), is("Test type text"));
    SampleExportDto export2 = exportList.stream().filter(t -> t.getUuid().equals(sample2.getUuid())).findFirst().get();
    assertThat(export2.getSampleAssociatedCase().getFirstName(), is("Confidential"));
    assertThat(export2.getSampleAssociatedCase().getLastName(), is("Confidential"));
    assertThat(export2.getLab(), is("Lab - Test lab details"));
    assertThat(export2.getPathogenTestLab1(), is("Lab - Test lab details"));
    assertThat(export2.getPathogenTestType1(), is("Confidential"));
    assertThat(export2.getPathogenTestLab2(), is("Lab - Test lab details"));
    assertThat(export2.getPathogenTestType2(), is("Confidential"));
    assertThat(export2.getPathogenTestLab3(), is("Lab - Test lab details"));
    assertThat(export2.getPathogenTestType3(), is("Confidential"));
    assertThat(export2.getOtherPathogenTestsDetails(), is("2020-06-10 (Confidential, COVID-19, Pending)"));
    SampleExportDto export3 = exportList.stream().filter(t -> t.getUuid().equals(sample3.getUuid())).findFirst().get();
    assertThat(export3.getAssociatedContact().getContactName().getFirstName(), is("John"));
    assertThat(export3.getAssociatedContact().getContactName().getLastName(), is("Smith"));
    assertThat(export3.getLab(), is("Lab"));
    SampleExportDto export4 = exportList.stream().filter(t -> t.getUuid().equals(sample4.getUuid())).findFirst().get();
    assertThat(export4.getAssociatedContact().getContactName().getFirstName(), is("Confidential"));
    assertThat(export4.getAssociatedContact().getContactName().getLastName(), is("Confidential"));
    assertThat(export4.getLab(), is("Lab"));
}
Also used : SampleExportDto(de.symeda.sormas.api.sample.SampleExportDto) 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) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)2 SampleDto (de.symeda.sormas.api.sample.SampleDto)2 SampleExportDto (de.symeda.sormas.api.sample.SampleExportDto)2 Date (java.util.Date)2 DiseaseHelper (de.symeda.sormas.api.DiseaseHelper)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 DeletionDetails (de.symeda.sormas.api.common.DeletionDetails)1 Page (de.symeda.sormas.api.common.Page)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)1 EventParticipantReferenceDto (de.symeda.sormas.api.event.EventParticipantReferenceDto)1 Captions (de.symeda.sormas.api.i18n.Captions)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 Strings (de.symeda.sormas.api.i18n.Strings)1 Validations (de.symeda.sormas.api.i18n.Validations)1 FacilityDto (de.symeda.sormas.api.infrastructure.facility.FacilityDto)1 FacilityHelper (de.symeda.sormas.api.infrastructure.facility.FacilityHelper)1 AdditionalTestDto (de.symeda.sormas.api.sample.AdditionalTestDto)1