Search in sources :

Example 16 with PersonDto

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

the class CaseClassificationFacadeEjb method getClassification.

@Override
public CaseClassification getClassification(CaseDataDto caze) {
    if (criteriaMap.isEmpty()) {
        buildCriteria();
    }
    PersonDto person = personFacade.getPersonByUuid(caze.getPerson().getUuid());
    List<PathogenTestDto> pathogenTests = pathogenTestService.getAllByCase(caze.getUuid()).stream().map(PathogenTestFacadeEjb.PathogenTestFacadeEjbLocal::toDto).collect(Collectors.toList());
    List<EventDto> caseEvents = eventService.getAllByCase(caze.getUuid()).stream().map(eventFacade::toDto).collect(Collectors.toList());
    Date lastVaccinationDate = null;
    if (caze.getDisease() == Disease.YELLOW_FEVER && caze.getVaccinationStatus() == VaccinationStatus.VACCINATED) {
        lastVaccinationDate = immunizationService.getLastVaccinationDateBefore(person.getUuid(), caze.getDisease(), CaseLogic.getStartDate(caze));
    }
    DiseaseClassificationCriteriaDto criteria = criteriaMap.get(caze.getDisease());
    if (criteria != null) {
        if (criteria.getConfirmedCriteria() != null && criteria.getConfirmedCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
            return CaseClassification.CONFIRMED;
        } else if (criteria.getNotACaseCriteria() != null && criteria.getNotACaseCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
            return CaseClassification.NO_CASE;
        } else if (criteria.getProbableCriteria() != null && criteria.getProbableCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
            return CaseClassification.PROBABLE;
        } else if (criteria.getSuspectCriteria() != null && criteria.getSuspectCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
            return CaseClassification.SUSPECT;
        } else if (configFacade.isConfiguredCountry(CountryHelper.COUNTRY_CODE_GERMANY)) {
            if (criteria.getConfirmedNoSymptomsCriteria() != null && criteria.getConfirmedNoSymptomsCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
                return CaseClassification.CONFIRMED_NO_SYMPTOMS;
            } else if (criteria.getConfirmedUnknownSymptomsCriteria() != null && criteria.getConfirmedUnknownSymptomsCriteria().eval(caze, person, pathogenTests, caseEvents, lastVaccinationDate)) {
                return CaseClassification.CONFIRMED_UNKNOWN_SYMPTOMS;
            }
        }
    }
    return CaseClassification.NOT_CLASSIFIED;
}
Also used : PathogenTestFacadeEjb(de.symeda.sormas.backend.sample.PathogenTestFacadeEjb) PersonDto(de.symeda.sormas.api.person.PersonDto) EventDto(de.symeda.sormas.api.event.EventDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) Date(java.util.Date) DiseaseClassificationCriteriaDto(de.symeda.sormas.api.caze.classification.DiseaseClassificationCriteriaDto)

Example 17 with PersonDto

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

the class CaseFacadeEjbTest method testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest.

@Test
public void testGetAllActiveCasesIncludeExtendedChangeDateFiltersPathogenTest() 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 caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    SampleDto sample = creator.createSample(caze.toReference(), user.toReference(), rdcf.facility);
    PathogenTestDto pathogenTestDto = creator.createPathogenTest(sample.toReference(), caze);
    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);
    pathogenTestDto.setTestResultText("test result changed");
    getPathogenTestFacade().savePathogenTest(pathogenTestDto);
    assertEquals(0, getCaseFacade().getAllActiveCasesAfter(date).size());
    assertEquals(1, getCaseFacade().getAllActiveCasesAfter(date, true).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) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 18 with PersonDto

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

the class CaseFacadeEjbTest method testGetDuplicateCasesOfSameSexAndDifferentBirthDateIsEmpty.

@Test
public void testGetDuplicateCasesOfSameSexAndDifferentBirthDateIsEmpty() {
    final Date today = new Date();
    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);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, today, rdcf);
    PersonDto cazePerson2 = creator.createPerson("Case", "Person", Sex.MALE, 1980, 1, 2);
    creator.createCase(user.toReference(), cazePerson2.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, DateUtils.addMinutes(today, -3), rdcf);
    Assert.assertEquals(0, getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(today).creationDateTo(today), true).size());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) 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) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 19 with PersonDto

use of de.symeda.sormas.api.person.PersonDto 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 20 with PersonDto

use of de.symeda.sormas.api.person.PersonDto 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)

Aggregations

PersonDto (de.symeda.sormas.api.person.PersonDto)332 Test (org.junit.Test)241 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)178 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)171 Date (java.util.Date)165 UserDto (de.symeda.sormas.api.user.UserDto)152 ContactDto (de.symeda.sormas.api.contact.ContactDto)93 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 LocalDate (java.time.LocalDate)59 SampleDto (de.symeda.sormas.api.sample.SampleDto)54 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)51 EventDto (de.symeda.sormas.api.event.EventDto)45 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)43 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)39 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)38 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)37 Disease (de.symeda.sormas.api.Disease)36 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)36 ArrayList (java.util.ArrayList)35 List (java.util.List)32