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;
}
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()));
}
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());
}
Aggregations