Search in sources :

Example 1 with PersonExportDto

use of de.symeda.sormas.api.person.PersonExportDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method getExportList.

@Override
public List<PersonExportDto> getExportList(PersonCriteria criteria, int first, int max) {
    long startTime = DateHelper.startTime();
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<PersonExportDto> cq = cb.createQuery(PersonExportDto.class);
    final Root<Person> person = cq.from(Person.class);
    final PersonQueryContext personQueryContext = new PersonQueryContext(cb, cq, person);
    PersonJoins joins = (PersonJoins) personQueryContext.getJoins();
    joins.configure(criteria);
    cq.multiselect(person.get(Person.UUID), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.SALUTATION), person.get(Person.OTHER_SALUTATION), person.get(Person.SEX), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), person.get(Person.BIRTHDATE_DD), person.get(Person.BIRTHDATE_MM), person.get(Person.BIRTHDATE_YYYY), person.get(Person.NICKNAME), person.get(Person.MOTHERS_NAME), person.get(Person.MOTHERS_MAIDEN_NAME), person.get(Person.FATHERS_NAME), person.get(Person.NAMES_OF_GUARDIANS), person.get(Person.PRESENT_CONDITION), person.get(Person.DEATH_DATE), person.get(Person.CAUSE_OF_DEATH), person.get(Person.CAUSE_OF_DEATH_DETAILS), person.get(Person.CAUSE_OF_DEATH_DISEASE), joins.getAddressJoins().getRegion().get(Region.NAME), joins.getAddressJoins().getDistrict().get(District.NAME), joins.getAddressJoins().getCommunity().get(Community.NAME), joins.getAddress().get(Location.STREET), joins.getAddress().get(Location.HOUSE_NUMBER), joins.getAddress().get(Location.POSTAL_CODE), joins.getAddress().get(Location.CITY), joins.getAddress().get(Location.ADDITIONAL_INFORMATION), joins.getAddressJoins().getFacility().get(Facility.NAME), joins.getAddress().get(Location.FACILITY_DETAILS), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PHONE_SUBQUERY), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PHONE_OWNER_SUBQUERY), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_EMAIL_SUBQUERY), personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY), person.get(Person.EDUCATION_TYPE), person.get(Person.EDUCATION_DETAILS), person.get(Person.OCCUPATION_TYPE), person.get(Person.OCCUPATION_DETAILS), person.get(Person.ARMED_FORCES_RELATION_TYPE), person.get(Person.PASSPORT_NUMBER), person.get(Person.NATIONAL_HEALTH_ID), person.get(Person.HAS_COVID_APP), person.get(Person.COVID_CODE_DELIVERED), person.get(Person.SYMPTOM_JOURNAL_STATUS), person.get(Person.EXTERNAL_ID), person.get(Person.EXTERNAL_TOKEN), person.get(Person.INTERNAL_TOKEN), joins.getBirthCountry().get(Country.ISO_CODE), joins.getBirthCountry().get(Country.DEFAULT_NAME), joins.getCitizenship().get(Country.ISO_CODE), joins.getCitizenship().get(Country.DEFAULT_NAME), person.get(Person.ADDITIONAL_DETAILS), JurisdictionHelper.booleanSelector(cb, personService.inJurisdictionOrOwned(personQueryContext)));
    Predicate filter = createIndexListFilter(criteria, personQueryContext);
    if (filter != null) {
        cq.where(filter);
    }
    cq.distinct(true);
    List<PersonExportDto> persons = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(PersonExportDto.class, persons, PersonExportDto::getInJurisdiction, (p, isInJurisdiction) -> pseudonymizer.pseudonymizeDto(BirthDateDto.class, p.getBirthdate(), isInJurisdiction, null));
    logger.debug("getExportList() finished. association={}, count={}, {}ms", Optional.ofNullable(criteria).orElse(new PersonCriteria()).getPersonAssociation().name(), persons.size(), DateHelper.durationMillies(startTime));
    return persons;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Predicate(javax.persistence.criteria.Predicate) AgeAndBirthDateDto(de.symeda.sormas.api.caze.AgeAndBirthDateDto) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto)

Example 2 with PersonExportDto

use of de.symeda.sormas.api.person.PersonExportDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testGetExportList.

@Test
public void testGetExportList() {
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.REST_EXTERNAL_VISITS_USER);
    PersonDto casePerson = creator.createPerson("Test Fname", "Test Lname", p -> {
        p.setBirthdateYYYY(1999);
        p.setBirthdateMM(3);
        p.setBirthdateDD(28);
        p.setPresentCondition(PresentCondition.ALIVE);
        p.setSex(Sex.UNKNOWN);
        p.setNickname("TestNick");
        p.getAddress().setRegion(rdcf.region);
        p.getAddress().setDistrict(rdcf.district);
        p.getAddress().setFacility(rdcf.facility);
        p.getAddress().setCity("Test city");
        p.setPersonContactDetails(Arrays.asList(PersonContactDetailDto.build(p.toReference(), true, PersonContactDetailType.PHONE, PhoneNumberType.MOBILE, null, "12345678", "Test additional info", false, null, null), PersonContactDetailDto.build(p.toReference(), true, PersonContactDetailType.EMAIL, null, null, "test@email.com", "Test additional info", false, null, null)));
    });
    creator.createCase(user.toReference(), casePerson.toReference(), rdcf);
    PersonDto contactPerson = creator.createPerson();
    creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), null, new Date(), new Date(), Disease.EVD, rdcf);
    List<PersonExportDto> casePersonExport = getPersonFacade().getExportList(new PersonCriteria(), 0, 100);
    assertThat(casePersonExport, hasSize(2));
    PersonExportDto exportedCasePerson = casePersonExport.stream().filter(p -> p.getUuid().equals(casePerson.getUuid())).findFirst().get();
    assertThat(exportedCasePerson.getUuid(), is(casePerson.getUuid()));
    assertThat(exportedCasePerson.getFirstName(), is(casePerson.getFirstName()));
    assertThat(exportedCasePerson.getLastName(), is(casePerson.getLastName()));
    assertThat(exportedCasePerson.getBirthdate().getDateOfBirthYYYY(), is(casePerson.getBirthdateYYYY()));
    assertThat(exportedCasePerson.getBirthdate().getDateOfBirthMM(), is(casePerson.getBirthdateMM()));
    assertThat(exportedCasePerson.getBirthdate().getDateOfBirthDD(), is(casePerson.getBirthdateDD()));
    assertThat(exportedCasePerson.getPresentCondition(), is(casePerson.getPresentCondition()));
    assertThat(exportedCasePerson.getSex(), is(casePerson.getSex()));
    assertThat(exportedCasePerson.getNickname(), is(casePerson.getNickname()));
    assertThat(exportedCasePerson.getRegion(), is(casePerson.getAddress().getRegion().getCaption()));
    assertThat(exportedCasePerson.getDistrict(), is(casePerson.getAddress().getDistrict().getCaption()));
    assertThat(exportedCasePerson.getFacility(), is(casePerson.getAddress().getFacility().getCaption()));
    assertThat(exportedCasePerson.getCity(), is(casePerson.getAddress().getCity()));
    assertThat(exportedCasePerson.getPhone(), is(casePerson.getPhone()));
    assertThat(exportedCasePerson.getEmailAddress(), is(casePerson.getEmailAddress()));
    // only contact persons
    List<PersonExportDto> contactPersonExport = getPersonFacade().getExportList(new PersonCriteria().personAssociation(PersonAssociation.CONTACT), 0, 100);
    assertThat(contactPersonExport, hasSize(1));
    assertThat(contactPersonExport.get(0).getUuid(), is(contactPerson.getUuid()));
    // filter by name
    PersonCriteria nameCriteria = new PersonCriteria();
    nameCriteria.setNameAddressPhoneEmailLike("Test Fname");
    List<PersonExportDto> exportByName = getPersonFacade().getExportList(nameCriteria, 0, 100);
    assertThat(exportByName, hasSize(1));
    assertThat(exportByName.get(0).getUuid(), is(casePerson.getUuid()));
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with PersonExportDto

use of de.symeda.sormas.api.person.PersonExportDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbPseudonymizationTest method testPseudonymizeExportList.

@Test
public void testPseudonymizeExportList() {
    loginWith(districtUser2);
    person = createPerson();
    creator.createCase(districtUser1.toReference(), person.toReference(), rdcf2);
    PersonDto person2 = createPerson();
    // create readonly case with person2 --> person2 should be pseudonymized
    CaseDataDto caze = creator.createCase(districtUser1.toReference(), person2.toReference(), rdcf1);
    creator.createContact(districtUser2.toReference(), null, createPerson().toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
    List<PersonExportDto> exportList = getPersonFacade().getExportList(new PersonCriteria(), 0, 100);
    PersonExportDto exportedPerson = exportList.stream().filter(p -> p.getUuid().equals(person.getUuid())).findFirst().get();
    assertThat(exportedPerson.getFirstName(), is("James"));
    assertThat(exportedPerson.getLastName(), is("Smith"));
    assertThat(exportedPerson.getBirthdate().getDateOfBirthDD(), is(1));
    Assert.assertEquals(Optional.empty(), exportList.stream().filter(p -> p.getUuid().equals(person2.getUuid())).findFirst());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonCriteria (de.symeda.sormas.api.person.PersonCriteria)3 PersonExportDto (de.symeda.sormas.api.person.PersonExportDto)3 PersonDto (de.symeda.sormas.api.person.PersonDto)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 Date (java.util.Date)2 Test (org.junit.Test)2 AgeAndBirthDateDto (de.symeda.sormas.api.caze.AgeAndBirthDateDto)1 BirthDateDto (de.symeda.sormas.api.caze.BirthDateDto)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)1 Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1