Search in sources :

Example 16 with CaseDataDto

use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetCaseMeasurePerDistrict.

@Test
public void testGetCaseMeasurePerDistrict() {
    List<DataHelper.Pair<DistrictDto, BigDecimal>> caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertTrue(caseMeasurePerDistrict.isEmpty());
    RDCF rdcf1 = creator.createRDCF("Region", "District1", "Community", "Facility");
    RDCF rdcf2 = creator.createRDCF("Region", "District2", "Community", "Facility");
    UserDto user = creator.createUser(rdcf1, UserRole.NATIONAL_USER);
    CaseDataDto caze = creator.createCase(user.toReference(), creator.createPerson("Person", "One").toReference(), rdcf1);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(1, caseMeasurePerDistrict.size());
    DataHelper.Pair<DistrictDto, BigDecimal> districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(1, districtCaseCount.getElement1().intValue());
    creator.createCase(user.toReference(), creator.createPerson("Person", "Two").toReference(), rdcf1);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(1, caseMeasurePerDistrict.size());
    districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(2, districtCaseCount.getElement1().intValue());
    caze.setDistrict(rdcf2.district);
    getCaseFacade().save(caze);
    creator.createCase(user.toReference(), creator.createPerson("Person", "Three").toReference(), rdcf2);
    caseMeasurePerDistrict = getCaseFacade().getCaseMeasurePerDistrict(null, null, Disease.EVD, CaseMeasure.CASE_COUNT);
    assertEquals(2, caseMeasurePerDistrict.size());
    districtCaseCount = caseMeasurePerDistrict.get(0);
    assertEquals(rdcf1.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(1, districtCaseCount.getElement1().intValue());
    districtCaseCount = caseMeasurePerDistrict.get(1);
    assertEquals(rdcf2.district.getUuid(), districtCaseCount.getElement0().getUuid());
    assertEquals(2, districtCaseCount.getElement1().intValue());
}
Also used : DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) UserDto(de.symeda.sormas.api.user.UserDto) DataHelper(de.symeda.sormas.api.utils.DataHelper) BigDecimal(java.math.BigDecimal) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 17 with CaseDataDto

use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testDoesEpidNumberExist.

@Test
public void testDoesEpidNumberExist() {
    RDCFEntities rdcf = creator.createRDCFEntities();
    UserReferenceDto user = creator.createUser(rdcf).toReference();
    PersonReferenceDto cazePerson = creator.createPerson("Horst", "Meyer").toReference();
    CaseDataDto caze = creator.createCase(user, cazePerson, Disease.CHOLERA, CaseClassification.NOT_CLASSIFIED, InvestigationStatus.PENDING, new Date(), rdcf);
    // 1. Same case
    assertFalse(getCaseFacade().doesEpidNumberExist(caze.getEpidNumber(), caze.getUuid(), caze.getDisease()));
    // 2. Same disease and epid number
    assertTrue(getCaseFacade().doesEpidNumberExist(caze.getEpidNumber(), "abc", caze.getDisease()));
    // 3. Same disease, different epid number
    assertFalse(getCaseFacade().doesEpidNumberExist("123", "abc", caze.getDisease()));
    // 4. Different disease and same epid number
    assertFalse(getCaseFacade().doesEpidNumberExist(caze.getEpidNumber(), "abc", Disease.ANTHRAX));
    // 5. Different disease and different epid number
    assertFalse(getCaseFacade().doesEpidNumberExist("def", "abc", Disease.ANTHRAX));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 18 with CaseDataDto

use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGenerateEpidNumber.

@Test
public void testGenerateEpidNumber() throws ExternalSurveillanceToolException {
    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, UserRole.ADMIN);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), rdcf);
    Calendar calendar = Calendar.getInstance();
    String year = String.valueOf(calendar.get(Calendar.YEAR)).substring(2);
    assertEquals("COU-REG-DIS-" + year + "-001", caze.getEpidNumber());
    CaseDataDto secondCaze = creator.createCase(user.toReference(), cazePerson.toReference(), rdcf);
    assertEquals("COU-REG-DIS-" + year + "-002", secondCaze.getEpidNumber());
    secondCaze.setEpidNumber("COU-REG-DIS-" + year + "-0004");
    getCaseFacade().save(secondCaze);
    CaseDataDto thirdCaze = creator.createCase(user.toReference(), cazePerson.toReference(), rdcf);
    assertEquals("COU-REG-DIS-" + year + "-005", thirdCaze.getEpidNumber());
    thirdCaze.setEpidNumber("COU-REG-DIS-" + year + "-3");
    getCaseFacade().save(thirdCaze);
    CaseDataDto fourthCaze = creator.createCase(user.toReference(), cazePerson.toReference(), rdcf);
    assertEquals("COU-REG-DIS-" + year + "-005", fourthCaze.getEpidNumber());
    fourthCaze.setEpidNumber("COU-REG-DIS-" + year + "-AAA");
    getCaseFacade().save(fourthCaze);
    fourthCaze = getCaseFacade().getCaseDataByUuid(fourthCaze.getUuid());
    assertEquals("COU-REG-DIS-" + year + "-005", fourthCaze.getEpidNumber());
    // Make sure that deleted cases are ignored when searching for the highest existing epid nummber
    getCaseFacade().deleteCase(fourthCaze.getUuid());
    CaseDataDto fifthCaze = creator.createCase(user.toReference(), cazePerson.toReference(), rdcf);
    assertEquals("COU-REG-DIS-" + year + "-005", fifthCaze.getEpidNumber());
}
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) Calendar(java.util.Calendar) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 19 with CaseDataDto

use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testCaseCompletenessWhenCaseFound.

@Test
public void testCaseCompletenessWhenCaseFound() {
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.NATIONAL_USER);
    int casesWithNoCompletenessFound = getCaseFacade().updateCompleteness();
    MatcherAssert.assertThat(casesWithNoCompletenessFound, is(0));
    PersonDto cazePerson = creator.createPerson("Case", "Person", Sex.MALE, 1980, 1, 1);
    CaseDataDto caseNoCompleteness = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto cazePerson2 = creator.createPerson("Case2", "Person2", Sex.MALE, 1981, 1, 1);
    CaseDataDto caseWithCompleteness = creator.createCase(user.toReference(), cazePerson2.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateUtils.addMinutes(new Date(), -3), rdcf);
    SessionImpl em = (SessionImpl) getEntityManager();
    QueryImplementor query2 = em.createQuery("select c from cases c where c.uuid=:uuid");
    query2.setParameter("uuid", caseWithCompleteness.getUuid());
    Case caseWithCompletenessSingleResult = (Case) query2.getSingleResult();
    caseWithCompletenessSingleResult.setCompleteness(0.7f);
    em.save(caseWithCompletenessSingleResult);
    int changedCases = getCaseFacade().updateCompleteness();
    Case completenessUpdateResult = getCaseService().getByUuid(caseNoCompleteness.getUuid());
    Case completenessUpdateResult2 = getCaseService().getByUuid(caseWithCompleteness.getUuid());
    MatcherAssert.assertThat(completenessUpdateResult.getCompleteness(), notNullValue());
    MatcherAssert.assertThat(completenessUpdateResult.getChangeDate(), equalTo(caseNoCompleteness.getChangeDate()));
    MatcherAssert.assertThat(completenessUpdateResult2.getCompleteness(), is(0.7f));
    MatcherAssert.assertThat(changedCases, is(1));
    int changedCasesAfterUpdateCompleteness = getCaseFacade().updateCompleteness();
    MatcherAssert.assertThat(changedCasesAfterUpdateCompleteness, is(0));
}
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) SessionImpl(org.hibernate.internal.SessionImpl) QueryImplementor(org.hibernate.query.spi.QueryImplementor) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 20 with CaseDataDto

use of de.symeda.sormas.api.caze.CaseDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testCreateInvestigationTask.

@Test
public void testCreateInvestigationTask() {
    RDCF rdcf = creator.createRDCF();
    UserReferenceDto user = creator.createUser(rdcf, "First", "User", UserRole.SURVEILLANCE_SUPERVISOR).toReference();
    UserReferenceDto surveillanceOfficer = creator.createUser(rdcf, "Second", "User", UserRole.SURVEILLANCE_OFFICER).toReference();
    PersonReferenceDto person = creator.createPerson("Case", "Person").toReference();
    CaseDataDto caze = creator.createCase(user, person, rdcf);
    List<TaskDto> caseTasks = getTaskFacade().getAllPendingByCase(caze.toReference());
    assertEquals(surveillanceOfficer, caseTasks.get(0).getAssigneeUser());
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) TaskDto(de.symeda.sormas.api.task.TaskDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)395 Test (org.junit.Test)287 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)239 PersonDto (de.symeda.sormas.api.person.PersonDto)174 Date (java.util.Date)159 UserDto (de.symeda.sormas.api.user.UserDto)140 ContactDto (de.symeda.sormas.api.contact.ContactDto)102 SampleDto (de.symeda.sormas.api.sample.SampleDto)74 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)62 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)58 LocalDate (java.time.LocalDate)57 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)43 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)43 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)43 List (java.util.List)42 Disease (de.symeda.sormas.api.Disease)40 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)36 PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)36 ArrayList (java.util.ArrayList)35 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)34