Search in sources :

Example 6 with PersonIndexDto

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

the class ImportExportTest method testImportExportedCase.

@Test
public void testImportExportedCase() throws IOException, CsvException, InvalidColumnException, InterruptedException {
    TestDataCreator.RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Health facility");
    UserDto user = creator.createUser(null, null, null, "james", "Smith", UserRole.NATIONAL_USER);
    PersonDto person = creator.createPerson("John", "Doe");
    Date dateNow = new Date();
    CaseDataDto caze = creator.createCase(user.toReference(), person.toReference(), Disease.CORONAVIRUS, CaseClassification.PROBABLE, InvestigationStatus.PENDING, dateNow, rdcf);
    caze.setExternalID("text-ext-id");
    caze.setExternalToken("text-ext-token");
    caze.setDiseaseDetails("Corona");
    caze.setHealthFacilityDetails("test HF details");
    caze.setQuarantine(QuarantineType.INSTITUTIONELL);
    caze.setQuarantineFrom(dateNow);
    caze.setQuarantineTo(dateNow);
    caze.getHospitalization().setAdmittedToHealthFacility(YesNoUnknown.YES);
    caze.getHospitalization().setAdmissionDate(dateNow);
    caze.getHospitalization().setDischargeDate(dateNow);
    caze.getHospitalization().setLeftAgainstAdvice(YesNoUnknown.YES);
    caze.getSymptoms().setAbdominalPain(SymptomState.YES);
    caze.getSymptoms().setAgitation(SymptomState.YES);
    caze.getSymptoms().setBedridden(SymptomState.YES);
    caze.getSymptoms().setEyesBleeding(SymptomState.YES);
    caze.getSymptoms().setKopliksSpots(SymptomState.YES);
    caze.getSymptoms().setPigmentaryRetinopathy(SymptomState.YES);
    caze.getSymptoms().setTremor(SymptomState.YES);
    caze.getSymptoms().setVomiting(SymptomState.YES);
    getCaseFacade().save(caze);
    person.setSex(Sex.MALE);
    person.setBirthdateDD(11);
    person.setBirthdateMM(12);
    person.setBirthdateYYYY(1962);
    person.setPresentCondition(PresentCondition.ALIVE);
    person.getAddress().setRegion(rdcf.region.toReference());
    person.getAddress().setDistrict(rdcf.district.toReference());
    person.getAddress().setCommunity(rdcf.community.toReference());
    person.getAddress().setCity("test city");
    person.getAddress().setStreet("test street");
    person.getAddress().setHouseNumber("test house number");
    person.getAddress().setAdditionalInformation("test additional information");
    person.getAddress().setPostalCode("test postal code");
    person.getAddress().setPostalCode("test postal code");
    getPersonFacade().savePerson(person);
    StreamResource exportStreamResource = CaseDownloadUtil.createCaseExportResource(new CaseCriteria(), Collections::emptySet, CaseExportType.CASE_SURVEILLANCE, null);
    List<String[]> rows = getCsvReader(exportStreamResource.getStreamSource().getStream()).readAll();
    assertThat(rows, hasSize(4));
    String[] columns = rows.get(1);
    String[] values = rows.get(3);
    String importUuid = DataHelper.createUuid();
    for (int i = 0, getLength = columns.length; i < getLength; i++) {
        String column = columns[i];
        if (CaseDataDto.UUID.equals(column)) {
            values[i] = importUuid;
        } else // update name avoid duplicate checking
        if (String.join(".", CaseDataDto.PERSON, PersonDto.FIRST_NAME).equals(column)) {
            values[i] = "Import John";
        } else if (String.join(".", CaseDataDto.PERSON, PersonDto.LAST_NAME).equals(column)) {
            values[i] = "Import Doe";
        } else if (String.join(".", CaseDataDto.PERSON, PersonDto.UUID).equals(column)) {
            // Workaround: Reset the change date to avoid OutdatedEntityExceptions
            // Applying a setChangeDate(new Date()) to the person before saving it will result in creating 2 cases and will fail the test
            // So let's just ignore this column for now...
            values[i] = "";
        }
    }
    File tempFile = File.createTempFile("export", "csv");
    tempFile.deleteOnExit();
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(new ByteArrayInputStream(rows.stream().map(r -> String.join(",", Arrays.asList(r))).collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8)), out);
    CaseImporterExtension caseImporter = new CaseImporterExtension(tempFile, true, user);
    caseImporter.runImport();
    InputStream errorStream = new ByteArrayInputStream(caseImporter.stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
    List<String[]> errorRows = getCsvReader(errorStream).readAll();
    if (errorRows.size() > 1) {
        assertThat("Error during import: " + StringUtils.join(errorRows.get(1), ", "), errorRows, hasSize(0));
    }
    PersonCriteria importPersonCriteria = new PersonCriteria();
    importPersonCriteria.setNameAddressPhoneEmailLike("Import John");
    List<PersonIndexDto> importedPersons = getPersonFacade().getIndexList(importPersonCriteria, null, null, null);
    assertThat(importedPersons.size(), is(1));
    List<CaseDataDto> importedCases = getCaseFacade().getByPersonUuids(Collections.singletonList(importedPersons.get(0).getUuid()));
    assertThat(importedCases.size(), is(1));
    CaseDataDto importedCase = importedCases.get(0);
    assertThat(importedCase.getExternalID(), is("text-ext-id"));
    assertThat(importedCase.getExternalToken(), is("text-ext-token"));
    assertThat(importedCase.getDisease(), is(Disease.CORONAVIRUS));
    assertThat(importedCase.getDiseaseDetails(), is("Corona"));
    assertNull(importedCase.getPregnant());
    assertNull(importedCase.getTrimester());
    assertNull(importedCase.getPostpartum());
    assertThat(importedCase.getResponsibleRegion(), is(rdcf.region));
    assertThat(importedCase.getResponsibleDistrict(), is(rdcf.district));
    assertThat(importedCase.getResponsibleCommunity(), is(rdcf.community));
    assertThat(importedCase.getHealthFacility(), is(rdcf.facility));
    assertThat(importedCase.getHealthFacilityDetails(), is("test HF details"));
    assertThat(importedCase.getQuarantine(), is(QuarantineType.INSTITUTIONELL));
    assertThat(importedCase.getQuarantineFrom().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedCase.getQuarantineTo().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedCase.getHospitalization().getAdmittedToHealthFacility(), is(YesNoUnknown.YES));
    assertThat(importedCase.getHospitalization().getAdmissionDate().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedCase.getHospitalization().getDischargeDate().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedCase.getHospitalization().getLeftAgainstAdvice(), is(YesNoUnknown.YES));
    assertThat(importedCase.getSymptoms().getAbdominalPain(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getBedridden(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getEyesBleeding(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getKopliksSpots(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getPigmentaryRetinopathy(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getTremor(), is(SymptomState.YES));
    assertThat(importedCase.getSymptoms().getVomiting(), is(SymptomState.YES));
    PersonDto importedPerson = getPersonFacade().getPersonByUuid(importedCase.getPerson().getUuid());
    assertThat(importedPerson.getFirstName(), is("Import John"));
    assertThat(importedPerson.getLastName(), is("Import Doe"));
    assertThat(importedPerson.getSex(), is(Sex.MALE));
    assertThat(importedPerson.getBirthdateDD(), is(11));
    assertThat(importedPerson.getBirthdateMM(), is(12));
    assertThat(importedPerson.getBirthdateYYYY(), is(1962));
    assertThat(importedPerson.getPresentCondition(), is(PresentCondition.ALIVE));
    assertThat(importedPerson.getAddress().getRegion(), is(rdcf.region));
    assertThat(importedPerson.getAddress().getDistrict(), is(rdcf.district));
    assertThat(importedPerson.getAddress().getCommunity(), is(rdcf.community));
    assertThat(importedPerson.getAddress().getCity(), is("test city"));
    assertThat(importedPerson.getAddress().getStreet(), is("test street"));
    assertThat(importedPerson.getAddress().getHouseNumber(), is("test house number"));
    assertThat(importedPerson.getAddress().getAdditionalInformation(), is("test additional information"));
}
Also used : CaseImporterExtension(de.symeda.sormas.ui.caze.importer.CaseImporterTest.CaseImporterExtension) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) StreamResource(com.vaadin.server.StreamResource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) Collections(java.util.Collections) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 7 with PersonIndexDto

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

the class DirectoryImmunizationService method buildCriteriaFilter.

private Predicate buildCriteriaFilter(ImmunizationCriteria criteria, DirectoryImmunizationQueryContext directoryImmunizationQueryContext) {
    final DirectoryImmunizationJoins joins = directoryImmunizationQueryContext.getJoins();
    final CriteriaBuilder cb = directoryImmunizationQueryContext.getCriteriaBuilder();
    final From<?, ?> from = directoryImmunizationQueryContext.getRoot();
    final Join<DirectoryImmunization, Person> person = joins.getPerson();
    final Join<DirectoryImmunization, LastVaccineType> lastVaccineType = joins.getLastVaccineType();
    final Join<Person, Location> location = joins.getPersonJoins().getAddress();
    Predicate filter = null;
    if (criteria.getDisease() != null) {
        filter = CriteriaBuilderHelper.and(cb, null, cb.equal(from.get(Immunization.DISEASE), criteria.getDisease()));
    }
    if (!DataHelper.isNullOrEmpty(criteria.getNameAddressPhoneEmailLike())) {
        final CriteriaQuery<PersonIndexDto> cq = cb.createQuery(PersonIndexDto.class);
        final PersonQueryContext personQueryContext = new PersonQueryContext(cb, cq, joins.getPersonJoins());
        String[] textFilters = criteria.getNameAddressPhoneEmailLike().split("\\s+");
        for (String textFilter : textFilters) {
            if (DataHelper.isNullOrEmpty(textFilter)) {
                continue;
            }
            Predicate likeFilters = cb.or(CriteriaBuilderHelper.unaccentedIlike(cb, person.get(Person.FIRST_NAME), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, person.get(Person.LAST_NAME), textFilter), CriteriaBuilderHelper.ilike(cb, person.get(Person.UUID), textFilter), CriteriaBuilderHelper.ilike(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_EMAIL_SUBQUERY), textFilter), phoneNumberPredicate(cb, personQueryContext.getSubqueryExpression(PersonQueryContext.PERSON_PHONE_SUBQUERY), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, location.get(Location.STREET), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, location.get(Location.CITY), textFilter), CriteriaBuilderHelper.ilike(cb, location.get(Location.POSTAL_CODE), textFilter), CriteriaBuilderHelper.ilike(cb, person.get(Person.INTERNAL_TOKEN), textFilter), CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_ID), textFilter), CriteriaBuilderHelper.ilike(cb, person.get(Person.EXTERNAL_TOKEN), textFilter), CriteriaBuilderHelper.unaccentedIlike(cb, lastVaccineType.get(LastVaccineType.VACCINE_TYPE), textFilter));
            filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
        }
    }
    filter = andEquals(cb, person, filter, criteria.getBirthdateYYYY(), Person.BIRTHDATE_YYYY);
    filter = andEquals(cb, person, filter, criteria.getBirthdateMM(), Person.BIRTHDATE_MM);
    filter = andEquals(cb, person, filter, criteria.getBirthdateDD(), Person.BIRTHDATE_DD);
    if (criteria.getMeansOfImmunization() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Immunization.MEANS_OF_IMMUNIZATION), criteria.getMeansOfImmunization()));
    }
    if (criteria.getImmunizationManagementStatus() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Immunization.IMMUNIZATION_MANAGEMENT_STATUS), criteria.getImmunizationManagementStatus()));
    }
    if (criteria.getImmunizationStatus() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Immunization.IMMUNIZATION_STATUS), criteria.getImmunizationStatus()));
    }
    filter = andEqualsReferenceDto(cb, joins.getResponsibleRegion(), filter, criteria.getRegion());
    filter = andEqualsReferenceDto(cb, joins.getResponsibleDistrict(), filter, criteria.getDistrict());
    filter = andEqualsReferenceDto(cb, joins.getResponsibleCommunity(), filter, criteria.getCommunity());
    if (criteria.getFacilityType() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Immunization.FACILITY_TYPE), criteria.getFacilityType()));
    }
    filter = andEqualsReferenceDto(cb, joins.getHealthFacility(), filter, criteria.getHealthFacility());
    if (Boolean.TRUE.equals(criteria.getOnlyPersonsWithOverdueImmunization())) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(Immunization.IMMUNIZATION_MANAGEMENT_STATUS), ImmunizationManagementStatus.ONGOING));
        filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThan(from.get(Immunization.END_DATE), DateHelper.getStartOfDay(new Date())));
    }
    if (criteria.getImmunizationDateType() != null) {
        Path<Object> path = buildPathForDateFilter(criteria.getImmunizationDateType(), directoryImmunizationQueryContext);
        if (path != null) {
            filter = CriteriaBuilderHelper.applyDateFilter(cb, filter, path, criteria.getFromDate(), criteria.getToDate());
        }
    }
    filter = CriteriaBuilderHelper.and(cb, filter, cb.isFalse(from.get(Immunization.DELETED)));
    return filter;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DirectoryImmunization(de.symeda.sormas.backend.immunization.entity.DirectoryImmunization) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) LastVaccineType(de.symeda.sormas.backend.vaccination.LastVaccineType) Date(java.util.Date) LastVaccinationDate(de.symeda.sormas.backend.vaccination.LastVaccinationDate) FirstVaccinationDate(de.symeda.sormas.backend.vaccination.FirstVaccinationDate) Predicate(javax.persistence.criteria.Predicate) PersonQueryContext(de.symeda.sormas.backend.person.PersonQueryContext) Person(de.symeda.sormas.backend.person.Person) Location(de.symeda.sormas.backend.location.Location)

Example 8 with PersonIndexDto

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

the class PersonFacadeEjbTest method testUserWithLimitedDiseaseSeeOnlyLimitedTravelEntry.

@Test
public void testUserWithLimitedDiseaseSeeOnlyLimitedTravelEntry() {
    PersonCriteria criteria = new PersonCriteria();
    criteria.setPersonAssociation(PersonAssociation.TRAVEL_ENTRY);
    // CORONAVIRUS Travel Entry
    PersonDto personWithCorona = creator.createPerson("Person Coronavirus", "Test");
    creator.createTravelEntry(personWithCorona.toReference(), nationalUser.toReference(), Disease.CORONAVIRUS, rdcf.region, rdcf.district, rdcf.pointOfEntry);
    // DENGUE Travel Entry
    PersonDto personWithDengue = creator.createPerson("Person Dengue", "Test");
    creator.createTravelEntry(personWithDengue.toReference(), nationalUser.toReference(), Disease.DENGUE, rdcf.region, rdcf.district, rdcf.pointOfEntry);
    // National User with no restrictions can see all the travel entries
    List<PersonIndexDto> personIndexDtos = getPersonFacade().getIndexList(criteria, 0, 100, null);
    assertEquals(2, personIndexDtos.size());
    List<String> firstNames = personIndexDtos.stream().map(p -> p.getFirstName()).collect(Collectors.toList());
    assertTrue(firstNames.contains(personWithCorona.getFirstName()));
    assertTrue(firstNames.contains(personWithDengue.getFirstName()));
    // login with a user wiht limieted disease restrictions
    final UserDto user = creator.createUser(rdcf, "Limieted Disease", "National User", Disease.DENGUE, UserRole.NATIONAL_USER);
    loginWith(user);
    personIndexDtos = getPersonFacade().getIndexList(criteria, 0, 100, null);
    assertEquals(1, personIndexDtos.size());
    assertEquals(personWithDengue.getFirstName(), personIndexDtos.get(0).getFirstName());
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) Arrays(java.util.Arrays) Date(java.util.Date) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Matchers.not(org.hamcrest.Matchers.not) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) PersonDto(de.symeda.sormas.api.person.PersonDto) EntityDto(de.symeda.sormas.api.EntityDto) PersonContext(de.symeda.sormas.api.person.PersonContext) UserRole(de.symeda.sormas.api.user.UserRole) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) EventDto(de.symeda.sormas.api.event.EventDto) Collectors(java.util.stream.Collectors) PhoneNumberType(de.symeda.sormas.api.person.PhoneNumberType) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) SymptomJournalStatus(de.symeda.sormas.api.person.SymptomJournalStatus) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Matchers.is(org.hamcrest.Matchers.is) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) HealthConditionsDto(de.symeda.sormas.api.clinicalcourse.HealthConditionsDto) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonFacade(de.symeda.sormas.api.person.PersonFacade) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationDto(de.symeda.sormas.api.location.LocationDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Matchers.empty(org.hamcrest.Matchers.empty) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserDto(de.symeda.sormas.api.user.UserDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SortProperty(de.symeda.sormas.api.utils.SortProperty) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Assert.assertNull(org.junit.Assert.assertNull) Disease(de.symeda.sormas.api.Disease) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) DeletionReason(de.symeda.sormas.api.common.DeletionReason) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) 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) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 9 with PersonIndexDto

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

the class PersonFacadeEjbUserFilterTest method testGetPersonIndexListWhenSeveralAssociations.

@Test
public void testGetPersonIndexListWhenSeveralAssociations() {
    loginWith(nationalUser);
    PersonDto person1 = creator.createPerson("John", "Doe");
    PersonDto person2 = creator.createPerson("John2", "Doe2");
    CaseDataDto case1 = creator.createCase(nationalUser.toReference(), person1.toReference(), Disease.CORONAVIRUS, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf1, null);
    ContactDto contactForPerson1AndCase1 = creator.createContact(nationalUser.toReference(), person1.toReference(), case1);
    CaseDataDto case2 = creator.createCase(nationalUser.toReference(), person2.toReference(), Disease.CORONAVIRUS, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf2, null);
    ContactDto contactForPerson1AndCase2 = creator.createContact(nationalUser.toReference(), person1.toReference(), case2);
    TravelEntryDto travelEntryForPerson1 = creator.createTravelEntry(person1.toReference(), nationalUser.toReference(), Disease.CORONAVIRUS, rdcf1.region, rdcf1.district, rdcf1.pointOfEntry);
    PersonCriteria criteria = new PersonCriteria();
    criteria.setPersonAssociation(PersonAssociation.TRAVEL_ENTRY);
    List<PersonIndexDto> travelEntryPersonsFornationalUser = getPersonFacade().getIndexList(criteria, null, null, null);
    assertEquals(1, travelEntryPersonsFornationalUser.size());
    assertEquals(person1.getUuid(), travelEntryPersonsFornationalUser.get(0).getUuid());
    loginWith(districtUser1);
    List<PersonIndexDto> indexListForDistrictUser1 = getPersonFacade().getIndexList(null, null, null, null);
    assertEquals(1, indexListForDistrictUser1.size());
    assertEquals(person1.getUuid(), indexListForDistrictUser1.get(0).getUuid());
    loginWith(districtUser2);
    List<PersonIndexDto> indexListForDistrictUser2 = getPersonFacade().getIndexList(null, null, null, null);
    assertEquals(2, indexListForDistrictUser2.size());
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Date(java.util.Date) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 10 with PersonIndexDto

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

the class ImportExportTest method testImportExportedContact.

@Test
public void testImportExportedContact() throws IOException, CsvException, InvalidColumnException, InterruptedException {
    TestDataCreator.RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Health facility");
    UserDto user = creator.createUser(null, null, null, "james", "Smith", UserRole.NATIONAL_USER);
    PersonDto person = creator.createPerson("John", "Doe");
    Date dateNow = new Date();
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), person.toReference(), creator.createCase(user.toReference(), person.toReference(), Disease.CORONAVIRUS, CaseClassification.PROBABLE, InvestigationStatus.PENDING, dateNow, rdcf), dateNow, dateNow);
    contact.setExternalID("text-ext-id");
    contact.setExternalToken("text-ext-token");
    contact.setDiseaseDetails("Corona");
    contact.setRegion(rdcf.region.toReference());
    contact.setDistrict(rdcf.district.toReference());
    contact.setCommunity(rdcf.community.toReference());
    contact.setQuarantine(QuarantineType.INSTITUTIONELL);
    contact.setQuarantineFrom(dateNow);
    contact.setQuarantineTo(dateNow);
    contact.setQuarantineExtended(true);
    contact.setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
    contact.setFollowUpUntil(dateNow);
    getContactFacade().save(contact);
    person.setSex(Sex.MALE);
    person.setBirthdateDD(11);
    person.setBirthdateMM(12);
    person.setBirthdateYYYY(1962);
    person.setPresentCondition(PresentCondition.ALIVE);
    person.getAddress().setRegion(rdcf.region.toReference());
    person.getAddress().setDistrict(rdcf.district.toReference());
    person.getAddress().setCommunity(rdcf.community.toReference());
    person.getAddress().setCity("test city");
    person.getAddress().setStreet("test street");
    person.getAddress().setHouseNumber("test house number");
    person.getAddress().setAdditionalInformation("test additional information");
    person.getAddress().setPostalCode("test postal code");
    person.getAddress().setPostalCode("test postal code");
    getPersonFacade().savePerson(person);
    StreamResource exportStreamResource = ContactDownloadUtil.createContactExportResource(new ContactCriteria(), Collections::emptySet, null);
    List<String[]> rows = getCsvReader(exportStreamResource.getStreamSource().getStream()).readAll();
    assertThat(rows, hasSize(4));
    String[] columns = rows.get(1);
    String[] values = rows.get(3);
    String importUuid = DataHelper.createUuid();
    for (int i = 0, getLength = columns.length; i < getLength; i++) {
        String column = columns[i];
        if (ContactDto.UUID.equals(column)) {
            values[i] = importUuid;
        } else // update name avoid duplicate checking
        if (String.join(".", ContactDto.PERSON, PersonDto.FIRST_NAME).equals(column)) {
            values[i] = "Import John";
        } else if (String.join(".", ContactDto.PERSON, PersonDto.LAST_NAME).equals(column)) {
            values[i] = "Import Doe";
        } else if (String.join(".", ContactDto.PERSON, PersonDto.UUID).equals(column)) {
            // Workaround: Reset the change date to avoid OutdatedEntityExceptions
            // Applying a setChangeDate(new Date()) to the person before saving it will result in creating 2 cases and will fail the test
            // So let's just ignore this column for now...
            values[i] = "";
        }
    }
    File tempFile = File.createTempFile("export", "csv");
    tempFile.deleteOnExit();
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(new ByteArrayInputStream(rows.stream().map(r -> String.join(",", Arrays.asList(r))).collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8)), out);
    ContactImporterExtension contactImporter = new ContactImporterExtension(tempFile, user);
    contactImporter.runImport();
    InputStream errorStream = new ByteArrayInputStream(contactImporter.stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
    List<String[]> errorRows = getCsvReader(errorStream).readAll();
    if (errorRows.size() > 1) {
        assertThat("Error during import: " + StringUtils.join(errorRows.get(1), ", "), errorRows, hasSize(0));
    }
    PersonCriteria importPersonCriteria = new PersonCriteria();
    importPersonCriteria.setNameAddressPhoneEmailLike("Import John");
    List<PersonIndexDto> importedPersons = getPersonFacade().getIndexList(importPersonCriteria, null, null, null);
    assertThat(importedPersons.size(), is(1));
    List<ContactDto> importedContacts = getContactFacade().getByPersonUuids(Collections.singletonList(importedPersons.get(0).getUuid()));
    assertThat(importedContacts.size(), is(1));
    ContactDto importedContact = importedContacts.get(0);
    assertThat(importedContact.getUuid(), not(importUuid));
    assertThat(importedContact.getExternalID(), is("text-ext-id"));
    assertThat(importedContact.getExternalToken(), is("text-ext-token"));
    assertThat(importedContact.getDisease(), is(Disease.CORONAVIRUS));
    assertThat(importedContact.getDiseaseDetails(), is("Corona"));
    assertThat(importedContact.getRegion(), is(rdcf.region));
    assertThat(importedContact.getDistrict(), is(rdcf.district));
    assertThat(importedContact.getCommunity(), is(rdcf.community));
    assertThat(importedContact.getQuarantine(), is(QuarantineType.INSTITUTIONELL));
    assertThat(importedContact.getQuarantineFrom().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedContact.getQuarantineTo().getTime(), is(DateHelper.getStartOfDay(dateNow).getTime()));
    assertThat(importedContact.isQuarantineExtended(), is(true));
    assertThat(importedContact.getFollowUpStatus(), is(FollowUpStatus.FOLLOW_UP));
    PersonDto importedPerson = getPersonFacade().getPersonByUuid(importedContact.getPerson().getUuid());
    assertThat(importedPerson.getFirstName(), is("Import John"));
    assertThat(importedPerson.getLastName(), is("Import Doe"));
    assertThat(importedPerson.getSex(), is(Sex.MALE));
    assertThat(importedPerson.getBirthdateDD(), is(11));
    assertThat(importedPerson.getBirthdateMM(), is(12));
    assertThat(importedPerson.getBirthdateYYYY(), is(1962));
    assertThat(importedPerson.getPresentCondition(), is(PresentCondition.ALIVE));
    assertThat(importedPerson.getAddress().getRegion(), is(rdcf.region));
    assertThat(importedPerson.getAddress().getDistrict(), is(rdcf.district));
    assertThat(importedPerson.getAddress().getCommunity(), is(rdcf.community));
    assertThat(importedPerson.getAddress().getCity(), is("test city"));
    assertThat(importedPerson.getAddress().getStreet(), is("test street"));
    assertThat(importedPerson.getAddress().getHouseNumber(), is("test house number"));
    assertThat(importedPerson.getAddress().getAdditionalInformation(), is("test additional information"));
}
Also used : PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UserDto(de.symeda.sormas.api.user.UserDto) ContactImporterExtension(de.symeda.sormas.ui.contact.importer.ContactImporterTest.ContactImporterExtension) Date(java.util.Date) StreamResource(com.vaadin.server.StreamResource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) TestDataCreator(de.symeda.sormas.ui.TestDataCreator) Collections(java.util.Collections) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonIndexDto (de.symeda.sormas.api.person.PersonIndexDto)11 PersonCriteria (de.symeda.sormas.api.person.PersonCriteria)7 Date (java.util.Date)7 PersonDto (de.symeda.sormas.api.person.PersonDto)5 Test (org.junit.Test)5 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)4 ContactDto (de.symeda.sormas.api.contact.ContactDto)4 UserDto (de.symeda.sormas.api.user.UserDto)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 Collections (java.util.Collections)3 StreamResource (com.vaadin.server.StreamResource)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 Location (de.symeda.sormas.backend.location.Location)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 TextRenderer (com.vaadin.ui.renderers.TextRenderer)1 Disease (de.symeda.sormas.api.Disease)1 EntityDto (de.symeda.sormas.api.EntityDto)1 AgeAndBirthDateDto (de.symeda.sormas.api.caze.AgeAndBirthDateDto)1 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)1