Search in sources :

Example 1 with ContactDto

use of de.symeda.sormas.api.contact.ContactDto in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method save.

public ContactDto save(ContactDto dto, boolean handleChanges, boolean handleCaseChanges, boolean checkChangeDate, boolean internal) {
    final Contact existingContact = dto.getUuid() != null ? service.getByUuid(dto.getUuid()) : null;
    if (internal && existingContact != null && !service.isContactEditAllowed(existingContact)) {
        throw new AccessDeniedException(I18nProperties.getString(Strings.errorContactNotEditable));
    }
    final ContactDto existingContactDto = toDto(existingContact);
    restorePseudonymizedDto(dto, existingContactDto, existingContact, Pseudonymizer.getDefault(userService::hasRight));
    validate(dto);
    externalJournalService.handleExternalJournalPersonUpdateAsync(dto.getPerson());
    // taking this out because it may lead to server problems
    // case disease can change over time and there is currently no mechanism that would delete all related contacts
    // in this case the best solution is to only keep this hidden from the UI and still allow it in the backend
    // if (!DiseaseHelper.hasContactFollowUp(entity.getCaze().getDisease(), entity.getCaze().getPlagueType())) {
    // throw new UnsupportedOperationException("Contact creation is not allowed for diseases that don't have contact follow-up.");
    // }
    Contact entity = fillOrBuildEntity(dto, existingContact, checkChangeDate);
    doSave(entity, true);
    if (existingContact == null && featureConfigurationFacade.isTaskGenerationFeatureEnabled(TaskType.CONTACT_INVESTIGATION)) {
        createInvestigationTask(entity);
    }
    if (handleChanges) {
        updateContactVisitAssociations(existingContactDto, entity);
        final boolean convertedToCase = (existingContactDto == null || existingContactDto.getResultingCase() == null) && entity.getResultingCase() != null;
        final boolean dropped = entity.getContactStatus() == ContactStatus.DROPPED && (existingContactDto == null || existingContactDto.getContactStatus() != ContactStatus.DROPPED);
        if (dropped || convertedToCase) {
            service.cancelFollowUp(entity, I18nProperties.getString(convertedToCase ? Strings.messageSystemFollowUpCanceled : Strings.messageSystemFollowUpCanceledByDropping));
        } else {
            service.updateFollowUpDetails(entity, existingContactDto != null && entity.getFollowUpStatus() != existingContactDto.getFollowUpStatus());
        }
        service.udpateContactStatus(entity);
        if (handleCaseChanges && entity.getCaze() != null) {
            caseFacade.onCaseChanged(caseFacade.toDto(entity.getCaze()), entity.getCaze(), internal);
        }
        onContactChanged(existingContactDto, entity, internal);
    }
    return toDto(entity);
}
Also used : AccessDeniedException(de.symeda.sormas.api.utils.AccessDeniedException) DashboardContactDto(de.symeda.sormas.api.dashboard.DashboardContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto)

Example 2 with ContactDto

use of de.symeda.sormas.api.contact.ContactDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testGetAllActiveUuids.

@Test
public void testGetAllActiveUuids() throws ExternalSurveillanceToolException {
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto person = creator.createPerson();
    PersonDto person2 = creator.createPerson();
    PersonDto person3 = creator.createPerson();
    PersonDto person4 = creator.createPerson();
    PersonDto person5 = creator.createPerson();
    // contacts
    creator.createContact(user.toReference(), person.toReference());
    creator.createContact(user.toReference(), person5.toReference());
    ContactDto deletedContact = creator.createContact(user.toReference(), person2.toReference());
    getContactFacade().deleteContact(deletedContact.getUuid());
    // cases
    creator.createCase(user.toReference(), person.toReference(), rdcf);
    creator.createCase(user.toReference(), person3.toReference(), rdcf);
    CaseDataDto deletedCase = creator.createCase(user.toReference(), person4.toReference(), rdcf);
    getCaseFacade().deleteCase(deletedCase.getUuid());
    // Attached to case and contact
    creator.createVisit(person.toReference());
    // Attached to contact only
    creator.createVisit(person5.toReference());
    // Attached to case only
    creator.createVisit(person3.toReference());
    VisitDto visitOfDeletedContact = creator.createVisit(person2.toReference());
    VisitDto visitOfDeletedCase = creator.createVisit(person4.toReference());
    List<String> visitUuids = getVisitFacade().getAllActiveUuids();
    assertThat(visitUuids, hasSize(3));
    assertThat(visitUuids, not(contains(visitOfDeletedContact.getUuid())));
    assertThat(visitUuids, not(contains(visitOfDeletedCase.getUuid())));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with ContactDto

use of de.symeda.sormas.api.contact.ContactDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testGetAllActiveVisitsAfter.

@Test
public void testGetAllActiveVisitsAfter() throws InterruptedException, ExternalSurveillanceToolException {
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    Date date = new Date();
    PersonDto person = creator.createPerson();
    PersonDto person2 = creator.createPerson();
    PersonDto person3 = creator.createPerson();
    PersonDto person4 = creator.createPerson();
    PersonDto person5 = creator.createPerson();
    creator.createContact(user.toReference(), person.toReference());
    creator.createContact(user.toReference(), person3.toReference());
    ContactDto deletedContact = creator.createContact(user.toReference(), person2.toReference());
    getContactFacade().deleteContact(deletedContact.getUuid());
    creator.createCase(user.toReference(), person3.toReference(), rdcf);
    creator.createCase(user.toReference(), person4.toReference(), rdcf);
    CaseDataDto deletedCaseDto = creator.createCase(user.toReference(), person5.toReference(), rdcf);
    getCaseFacade().deleteCase(deletedCaseDto.getUuid());
    creator.createVisit(person.toReference());
    creator.createVisit(person3.toReference());
    VisitDto visitOfPureCase = creator.createVisit(person4.toReference());
    VisitDto visitWithChanges = creator.createVisit(person.toReference());
    VisitDto visitOfDeletedContact = creator.createVisit(person2.toReference());
    VisitDto visitOfDeletedCase = creator.createVisit(person5.toReference());
    List<VisitDto> visits = getVisitFacade().getAllActiveVisitsAfter(date);
    assertThat(visits, hasSize(3));
    // TODO change once visits are synchronized to app
    assertThat(visits, not(contains(visitOfPureCase)));
    assertThat(visits, not(contains(visitOfDeletedContact)));
    assertThat(visits, not(contains(visitOfDeletedCase)));
    List<VisitDto> visitsBatched = getVisitFacade().getAllActiveVisitsAfter(date, 2, null);
    assertThat(visitsBatched, hasSize(2));
    assertTrue(visitsBatched.get(0).getChangeDate().getTime() <= visitsBatched.get(1).getChangeDate().getTime());
    date = new Date();
    TimeUnit.MILLISECONDS.sleep(1);
    visitWithChanges.getSymptoms().setAbdominalPain(SymptomState.YES);
    visitWithChanges = getVisitFacade().saveVisit(visitWithChanges);
    visits = getVisitFacade().getAllActiveVisitsAfter(date);
    assertThat(visits, hasSize(1));
    assertThat(visits, contains(visitWithChanges));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with ContactDto

use of de.symeda.sormas.api.contact.ContactDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    UserDto user = creator.createUser(creator.createRDCF(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto person = creator.createPerson();
    PersonDto person2 = creator.createPerson();
    PersonDto person3 = creator.createPerson();
    PersonDto person4 = creator.createPerson();
    PersonDto person5 = creator.createPerson();
    ContactDto contact = creator.createContact(user.toReference(), person.toReference());
    creator.createContact(user.toReference(), person2.toReference());
    ContactDto contact2 = creator.createContact(user.toReference(), person3.toReference());
    CaseDataDto caze = creator.createCase(user.toReference(), person5.toReference(), creator.createRDCF());
    creator.createCase(user.toReference(), person4.toReference(), creator.createRDCF());
    CaseDataDto caze2 = creator.createCase(user.toReference(), person3.toReference(), creator.createRDCF());
    creator.createVisit(person.toReference());
    creator.createVisit(person.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person3.toReference());
    creator.createVisit(person5.toReference());
    VisitDto otherVisit = creator.createVisit(person2.toReference());
    VisitDto otherVisit2 = creator.createVisit(person4.toReference());
    List<VisitIndexDto> indexVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(contact.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(2));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    indexVisits = getVisitFacade().getIndexList(new VisitCriteria().caze(caze.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(1));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    indexVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(contact2.toReference()), null, null, null);
    assertThat(indexVisits, hasSize(3));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit.getUuid())));
    assertThat(indexVisits.stream().map(v -> v.getUuid()).collect(Collectors.toList()), not(contains(otherVisit2.getUuid())));
    List<VisitIndexDto> indexVisits2 = getVisitFacade().getIndexList(new VisitCriteria().caze(caze2.toReference()), null, null, null);
    assertEquals(indexVisits.size(), indexVisits2.size());
    for (int i = 0; i < indexVisits.size(); ++i) {
        assertEquals(indexVisits.get(i).getUuid(), indexVisits2.get(i).getUuid());
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with ContactDto

use of de.symeda.sormas.api.contact.ContactDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testCreateExternalVisit.

@Test
public void testCreateExternalVisit() {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Ext", "Vis", UserRole.REST_EXTERNAL_VISITS_USER);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    final ExternalVisitDto externalVisitDto = new ExternalVisitDto();
    externalVisitDto.setPersonUuid(contactPerson.getUuid());
    externalVisitDto.setDisease(contact.getDisease());
    externalVisitDto.setVisitDateTime(new Date());
    externalVisitDto.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks = "Everything good";
    externalVisitDto.setVisitRemarks(visitRemarks);
    final ExternalVisitDto externalVisitDto2 = new ExternalVisitDto();
    externalVisitDto2.setPersonUuid(cazePerson.getUuid());
    externalVisitDto2.setDisease(caze.getDisease());
    externalVisitDto2.setVisitDateTime(new Date());
    externalVisitDto2.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks2 = "Everything good 2";
    externalVisitDto2.setVisitRemarks(visitRemarks2);
    final VisitFacade visitFacade = getVisitFacade();
    visitFacade.saveExternalVisit(externalVisitDto);
    visitFacade.saveExternalVisit(externalVisitDto2);
    final VisitCriteria visitCriteria = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList = visitFacade.getIndexList(visitCriteria.contact(new ContactReferenceDto(contact.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList);
    assertEquals(1, visitIndexList.size());
    VisitIndexDto visitIndexDto = visitIndexList.get(0);
    assertNotNull(visitIndexDto.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto.getVisitStatus());
    assertEquals(visitRemarks, visitIndexDto.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
    final VisitCriteria visitCriteria2 = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList2 = visitFacade.getIndexList(visitCriteria2.caze(new CaseReferenceDto(caze.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList2);
    assertEquals(1, visitIndexList2.size());
    VisitIndexDto visitIndexDto2 = visitIndexList2.get(0);
    assertNotNull(visitIndexDto2.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto2.getVisitStatus());
    assertEquals(visitRemarks2, visitIndexDto2.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
}
Also used : ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) VisitFacade(de.symeda.sormas.api.visit.VisitFacade) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

ContactDto (de.symeda.sormas.api.contact.ContactDto)159 Test (org.junit.Test)101 Date (java.util.Date)88 PersonDto (de.symeda.sormas.api.person.PersonDto)87 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)86 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)78 UserDto (de.symeda.sormas.api.user.UserDto)59 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)57 SampleDto (de.symeda.sormas.api.sample.SampleDto)33 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)31 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)25 VisitDto (de.symeda.sormas.api.visit.VisitDto)25 LocalDate (java.time.LocalDate)24 Disease (de.symeda.sormas.api.Disease)22 EventDto (de.symeda.sormas.api.event.EventDto)21 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)21 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)20 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)19 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)19 SormasToSormasContactDto (de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)19