Search in sources :

Example 31 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetAllActiveCasesIncludeExtendedChangeDateFiltersLocationTest.

@Test
public void testGetAllActiveCasesIncludeExtendedChangeDateFiltersLocationTest() throws InterruptedException {
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = useSurveillanceOfficerLogin(rdcf);
    CaseDataDto caze = creator.createCase(user.toReference(), creator.createPerson("Case", "Person").toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    Date date = new Date();
    // the delay is needed in order to ensure the time difference between the date and the case dependent objects update
    Thread.sleep(10L);
    PersonDto cazePerson = getPersonFacade().getPersonByUuid(caze.getPerson().getUuid());
    cazePerson.getAddress().setStreet("new Street");
    cazePerson.getAddress().setHouseNumber("new Number");
    cazePerson.getAddress().setAdditionalInformation("new Information");
    getPersonFacade().savePerson(cazePerson);
    assertEquals(0, getCaseFacade().getAllActiveCasesAfter(date).size());
    assertEquals(1, getCaseFacade().getAllActiveCasesAfter(date, true).size());
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 32 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetCasesForDuplicateMerging.

@Test
public void testGetCasesForDuplicateMerging() {
    final Date today = new Date();
    final Date threeDaysAgo = DateUtils.addDays(today, -3);
    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", Sex.MALE, 1980, 1, 1);
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, today, rdcf);
    SessionImpl em = (SessionImpl) getEntityManager();
    QueryImplementor query = em.createQuery("select c from cases c where c.uuid=:uuid");
    query.setParameter("uuid", caze.getUuid());
    Case singleResult = (Case) query.getSingleResult();
    singleResult.setCreationDate(new Timestamp(threeDaysAgo.getTime()));
    singleResult.setReportDate(threeDaysAgo);
    em.save(singleResult);
    PersonDto cazePerson2 = creator.createPerson("Case", "Person", Sex.MALE, 1980, 1, 1);
    CaseDataDto case2 = creator.createCase(user.toReference(), cazePerson2.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateUtils.addMinutes(today, -3), rdcf);
    final List<CaseIndexDto[]> casesForDuplicateMergingToday = getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(today).creationDateTo(today), true);
    final List<CaseIndexDto[]> casesForDuplicateMergingThreeDaysAgo = getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(threeDaysAgo).creationDateTo(threeDaysAgo), true);
    Assert.assertEquals(1, casesForDuplicateMergingToday.size());
    Assert.assertEquals(1, casesForDuplicateMergingThreeDaysAgo.size());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) SessionImpl(org.hibernate.internal.SessionImpl) QueryImplementor(org.hibernate.query.spi.QueryImplementor) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 33 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testMapCaseListCreation.

@Test
public void testMapCaseListCreation() {
    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", p -> {
        p.getAddress().setLatitude(0.0);
        p.getAddress().setLongitude(0.0);
    });
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    Long count = getCaseFacade().countCasesForMap(caze.getRegion(), caze.getDistrict(), caze.getDisease(), DateHelper.subtractDays(new Date(), 1), DateHelper.addDays(new Date(), 1), null);
    List<MapCaseDto> mapCaseDtos = getCaseFacade().getCasesForMap(caze.getRegion(), caze.getDistrict(), caze.getDisease(), DateHelper.subtractDays(new Date(), 1), DateHelper.addDays(new Date(), 1), null);
    // List should have one entry
    assertEquals((long) count, mapCaseDtos.size());
    assertEquals(1, mapCaseDtos.size());
}
Also used : MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 34 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testOutcomePersonConditionUpdateForAppSync.

@Test
public void testOutcomePersonConditionUpdateForAppSync() throws InterruptedException {
    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 firstCase = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    // simulate short delay between transmissions
    Thread.sleep(DtoHelper.CHANGE_DATE_TOLERANCE_MS + 1);
    // set person to dead so that case will be updated automatically
    cazePerson.setPresentCondition(PresentCondition.DEAD);
    cazePerson.setDeathDate(new Date());
    cazePerson.setCauseOfDeath(CauseOfDeath.EPIDEMIC_DISEASE);
    cazePerson.setCauseOfDeathDisease(firstCase.getDisease());
    getPersonFacade().savePerson(cazePerson);
    // this should throw an exception
    exception.expect(OutdatedEntityException.class);
    getCaseFacade().save(firstCase);
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 35 with UserDto

use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testArchiveAndDearchiveCase.

@Test
public void testArchiveAndDearchiveCase() {
    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);
    Date testStartDate = new Date();
    // getAllActiveCases and getAllUuids should return length 1
    assertEquals(1, getCaseFacade().getAllActiveCasesAfter(null).size());
    assertEquals(1, getCaseFacade().getAllActiveUuids().size());
    getCaseFacade().archive(caze.getUuid(), null);
    // getAllActiveCases and getAllUuids should return length 0
    assertEquals(0, getCaseFacade().getAllActiveCasesAfter(null).size());
    assertEquals(0, getCaseFacade().getAllActiveUuids().size());
    // getArchivedUuidsSince should return length 1
    assertEquals(1, getCaseFacade().getArchivedUuidsSince(testStartDate).size());
    getCaseFacade().dearchive(Collections.singletonList(caze.getUuid()), null);
    // getAllActiveCases and getAllUuids should return length 1
    assertEquals(1, getCaseFacade().getAllActiveCasesAfter(null).size());
    assertEquals(1, getCaseFacade().getAllActiveUuids().size());
    // getArchivedUuidsSince should return length 0
    assertEquals(0, getCaseFacade().getArchivedUuidsSince(testStartDate).size());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

UserDto (de.symeda.sormas.api.user.UserDto)274 Test (org.junit.Test)210 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)160 PersonDto (de.symeda.sormas.api.person.PersonDto)142 Date (java.util.Date)138 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)121 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 ContactDto (de.symeda.sormas.api.contact.ContactDto)57 LocalDate (java.time.LocalDate)57 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)56 EventDto (de.symeda.sormas.api.event.EventDto)52 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)47 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)43 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)43 SampleDto (de.symeda.sormas.api.sample.SampleDto)41 File (java.io.File)41 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)31 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)30 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)27 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)27