Search in sources :

Example 31 with TaskDto

use of de.symeda.sormas.api.task.TaskDto in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testContactDeletion.

@Test
public void testContactDeletion() {
    Date since = new Date();
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    UserDto admin = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Another", "Admin", UserRole.ADMIN);
    String adminUuid = admin.getUuid();
    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);
    VisitDto visit = creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateUtils.addDays(new Date(), 21), VisitStatus.UNAVAILABLE, VisitOrigin.USER);
    TaskDto task = creator.createTask(TaskContext.CONTACT, TaskType.CONTACT_INVESTIGATION, TaskStatus.PENDING, null, contact.toReference(), null, new Date(), user.toReference());
    SampleDto sample = creator.createSample(contact.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
    SampleDto sample2 = creator.createSample(contact.toReference(), new Date(), new Date(), user.toReference(), SampleMaterial.BLOOD, rdcf.facility);
    sample2.setAssociatedCase(new CaseReferenceDto(caze.getUuid()));
    getSampleFacade().saveSample(sample2);
    // Database should contain the created contact, visit and task
    assertNotNull(getContactFacade().getByUuid(contact.getUuid()));
    assertNotNull(getTaskFacade().getByUuid(task.getUuid()));
    assertNotNull(getVisitFacade().getVisitByUuid(visit.getUuid()));
    assertNotNull(getSampleFacade().getSampleByUuid(sample.getUuid()));
    getContactFacade().delete(contact.getUuid(), new DeletionDetails(DeletionReason.OTHER_REASON, "test reason"));
    // Deleted flag should be set for contact; Task should be deleted
    assertTrue(getContactFacade().getDeletedUuidsSince(since).contains(contact.getUuid()));
    // Can't delete visit because it might be associated with other contacts as well
    // assertNull(getVisitFacade().getVisitByUuid(visit.getUuid()));
    assertNull(getTaskFacade().getByUuid(task.getUuid()));
    assertTrue(getSampleFacade().getDeletedUuidsSince(since).contains(sample.getUuid()));
    assertFalse(getSampleFacade().getDeletedUuidsSince(since).contains(sample2.getUuid()));
    assertEquals(DeletionReason.OTHER_REASON, getContactFacade().getByUuid(contact.getUuid()).getDeletionReason());
    assertEquals("test reason", getContactFacade().getByUuid(contact.getUuid()).getOtherDeletionReason());
}
Also used : DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) TaskDto(de.symeda.sormas.api.task.TaskDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date) LocalDate(java.time.LocalDate) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 32 with TaskDto

use of de.symeda.sormas.api.task.TaskDto in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testGenerateContactFollowUpTasks.

@Test
public void testGenerateContactFollowUpTasks() {
    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);
    UserDto contactOfficer = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Cont", "Off", UserRole.CONTACT_OFFICER);
    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(), contactOfficer.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    getContactFacade().generateContactFollowUpTasks();
    // task should have been generated
    List<TaskDto> tasks = getTaskFacade().getAllByContact(contact.toReference()).stream().filter(t -> t.getTaskType() == TaskType.CONTACT_FOLLOW_UP).collect(Collectors.toList());
    assertEquals(1, tasks.size());
    TaskDto task = tasks.get(0);
    assertEquals(TaskType.CONTACT_FOLLOW_UP, task.getTaskType());
    assertEquals(TaskStatus.PENDING, task.getTaskStatus());
    assertEquals(LocalDate.now(), DateHelper8.toLocalDate(task.getDueDate()));
    assertEquals(contactOfficer.toReference(), task.getAssigneeUser());
    // task should not be generated multiple times
    getContactFacade().generateContactFollowUpTasks();
    tasks = getTaskFacade().getAllByContact(contact.toReference()).stream().filter(t -> t.getTaskType() == TaskType.CONTACT_FOLLOW_UP).collect(Collectors.toList());
    assertEquals(1, tasks.size());
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) VisitStatus(de.symeda.sormas.api.visit.VisitStatus) Matchers.not(org.hamcrest.Matchers.not) Vaccine(de.symeda.sormas.api.caze.Vaccine) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) VaccineManufacturer(de.symeda.sormas.api.caze.VaccineManufacturer) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) Visit(de.symeda.sormas.backend.visit.Visit) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) ContactExportDto(de.symeda.sormas.api.contact.ContactExportDto) StandardCharsets(java.nio.charset.StandardCharsets) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) Assert.assertFalse(org.junit.Assert.assertFalse) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) Matchers.is(org.hamcrest.Matchers.is) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ContactFacade(de.symeda.sormas.api.contact.ContactFacade) HealthConditionsDto(de.symeda.sormas.api.clinicalcourse.HealthConditionsDto) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) EventStatus(de.symeda.sormas.api.event.EventStatus) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) VaccinationInfoSource(de.symeda.sormas.api.caze.VaccinationInfoSource) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ContactSimilarityCriteria(de.symeda.sormas.api.contact.ContactSimilarityCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) DocumentDto(de.symeda.sormas.api.document.DocumentDto) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) SortProperty(de.symeda.sormas.api.utils.SortProperty) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) DateUtils(org.apache.commons.lang3.time.DateUtils) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Assert.assertNull(org.junit.Assert.assertNull) Disease(de.symeda.sormas.api.Disease) VisitDto(de.symeda.sormas.api.visit.VisitDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) DeletionReason(de.symeda.sormas.api.common.DeletionReason) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) DateHelper8(de.symeda.sormas.backend.util.DateHelper8) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) ExposureType(de.symeda.sormas.api.exposure.ExposureType) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) Assert.assertThat(org.junit.Assert.assertThat) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ContactIndexDto(de.symeda.sormas.api.contact.ContactIndexDto) EventInvestigationStatus(de.symeda.sormas.api.event.EventInvestigationStatus) UserRole(de.symeda.sormas.api.user.UserRole) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) TaskDto(de.symeda.sormas.api.task.TaskDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) Region(de.symeda.sormas.backend.infrastructure.region.Region) EventDto(de.symeda.sormas.api.event.EventDto) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) Language(de.symeda.sormas.api.Language) ContactClassification(de.symeda.sormas.api.contact.ContactClassification) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) TaskType(de.symeda.sormas.api.task.TaskType) List(java.util.List) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) LocalDate(java.time.LocalDate) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) EpiDataHelper(de.symeda.sormas.api.epidata.EpiDataHelper) VisitSummaryExportDto(de.symeda.sormas.api.visit.VisitSummaryExportDto) MockProducer(de.symeda.sormas.backend.MockProducer) ContactFacadeEjbLocal(de.symeda.sormas.backend.contact.ContactFacadeEjb.ContactFacadeEjbLocal) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) VisitOrigin(de.symeda.sormas.api.VisitOrigin) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) SymptomState(de.symeda.sormas.api.symptoms.SymptomState) TaskStatus(de.symeda.sormas.api.task.TaskStatus) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) TaskContext(de.symeda.sormas.api.task.TaskContext) Matchers.empty(org.hamcrest.Matchers.empty) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserDto(de.symeda.sormas.api.user.UserDto) Mockito.when(org.mockito.Mockito.when) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) VisitSummaryExportDetailsDto(de.symeda.sormas.api.visit.VisitSummaryExportDetailsDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TaskDto(de.symeda.sormas.api.task.TaskDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 33 with TaskDto

use of de.symeda.sormas.api.task.TaskDto in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testMergeContact.

@Test
public void testMergeContact() throws IOException {
    useNationalUserLogin();
    // 1. Create
    // Create leadContact
    UserDto leadUser = creator.createUser("", "", "", "First", "User");
    UserReferenceDto leadUserReference = new UserReferenceDto(leadUser.getUuid());
    PersonDto leadPerson = creator.createPerson("Alex", "Miller");
    PersonContactDetailDto leadContactDetail = creator.createPersonContactDetail(leadPerson.toReference(), true, PersonContactDetailType.PHONE, "123");
    leadPerson.setPersonContactDetails(Collections.singletonList(leadContactDetail));
    getPersonFacade().savePerson(leadPerson);
    PersonReferenceDto leadPersonReference = new PersonReferenceDto(leadPerson.getUuid());
    RDCF leadRdcf = creator.createRDCF();
    CaseDataDto sourceCase = creator.createCase(leadUserReference, leadPersonReference, Disease.CORONAVIRUS, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), leadRdcf);
    ContactDto leadContact = creator.createContact(leadUserReference, leadUserReference, leadPersonReference, sourceCase, new Date(), new Date(), Disease.CORONAVIRUS, leadRdcf, (c) -> {
        c.setAdditionalDetails("Test additional details");
        c.setFollowUpComment("Test followup comment");
    });
    getContactFacade().save(leadContact);
    VisitDto leadVisit = creator.createVisit(leadContact.getDisease(), leadContact.getPerson(), leadContact.getReportDateTime());
    getVisitFacade().saveVisit(leadVisit);
    // Create otherContact
    UserDto otherUser = creator.createUser("", "", "", "Some", "User");
    UserReferenceDto otherUserReference = new UserReferenceDto(otherUser.getUuid());
    PersonDto otherPerson = creator.createPerson("Max", "Smith");
    PersonContactDetailDto otherContactDetail = creator.createPersonContactDetail(otherPerson.toReference(), true, PersonContactDetailType.PHONE, "456");
    otherPerson.setPersonContactDetails(Collections.singletonList(otherContactDetail));
    otherPerson.setBirthWeight(2);
    getPersonFacade().savePerson(otherPerson);
    PersonReferenceDto otherPersonReference = new PersonReferenceDto(otherPerson.getUuid());
    RDCF otherRdcf = creator.createRDCF();
    ContactDto otherContact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, sourceCase, new Date(), new Date(), Disease.CORONAVIRUS, otherRdcf, (c) -> {
        c.setAdditionalDetails("Test other additional details");
        c.setFollowUpComment("Test other followup comment");
    });
    ContactReferenceDto otherContactReference = getContactFacade().getReferenceByUuid(otherContact.getUuid());
    ContactDto contact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, sourceCase, new Date(), new Date(), null);
    Region region = creator.createRegion("");
    District district = creator.createDistrict("", region);
    Facility facility = creator.createFacility("", region, district, creator.createCommunity("", district));
    SampleDto sample = creator.createSample(otherContactReference, otherUserReference, getFacilityFacade().getReferenceByUuid(facility.getUuid()), null);
    TaskDto task = creator.createTask(TaskContext.CONTACT, TaskType.CONTACT_INVESTIGATION, TaskStatus.PENDING, null, otherContactReference, new EventReferenceDto(), new Date(), otherUserReference);
    getContactFacade().save(otherContact);
    VisitDto otherVisit = creator.createVisit(otherContact.getDisease(), otherContact.getPerson(), otherContact.getReportDateTime());
    otherVisit.getSymptoms().setAbdominalPain(SymptomState.YES);
    getVisitFacade().saveVisit(otherVisit);
    DocumentDto document = creator.createDocument(leadUserReference, "document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CONTACT, leadContact.getUuid(), "content".getBytes(StandardCharsets.UTF_8));
    DocumentDto otherDocument = creator.createDocument(leadUserReference, "other_document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CONTACT, otherContact.getUuid(), "other content".getBytes(StandardCharsets.UTF_8));
    // 2. Merge
    getContactFacade().mergeContact(leadContact.getUuid(), otherContact.getUuid());
    // 3. Test
    ContactDto mergedContact = getContactFacade().getByUuid(leadContact.getUuid());
    PersonDto mergedPerson = getPersonFacade().getPersonByUuid(mergedContact.getPerson().getUuid());
    // Check no values
    assertNull(mergedPerson.getBirthdateDD());
    // Check 'lead and other have different values'
    assertEquals(leadContact.getPerson().getFirstName(), mergedPerson.getFirstName());
    // Check 'lead has value, other has not'
    assertEquals(leadContact.getPerson().getLastName(), mergedPerson.getLastName());
    // Check 'lead has no value, other has'
    assertEquals(otherPerson.getBirthWeight(), mergedPerson.getBirthWeight());
    // Check merge comments
    assertEquals("Test additional details Test other additional details", mergedContact.getAdditionalDetails());
    assertEquals("Test followup comment Test other followup comment", mergedContact.getFollowUpComment());
    // 4. Test Reference Changes
    // 4.1 Samples
    List<String> sampleUuids = new ArrayList<String>();
    sampleUuids.add(sample.getUuid());
    assertEquals(leadContact.getUuid(), getSampleFacade().getByUuids(sampleUuids).get(0).getAssociatedContact().getUuid());
    // 4.2 Tasks
    List<String> taskUuids = new ArrayList<String>();
    taskUuids.add(task.getUuid());
    assertEquals(leadContact.getUuid(), getTaskFacade().getByUuids(taskUuids).get(0).getContact().getUuid());
    // 4.3 Visits;
    List<String> mergedVisits = getVisitFacade().getIndexList(new VisitCriteria().contact(mergedContact.toReference()), null, null, null).stream().map(VisitIndexDto::getUuid).collect(Collectors.toList());
    assertEquals(2, mergedVisits.size());
    assertTrue(mergedVisits.contains(leadVisit.getUuid()));
    assertTrue(mergedVisits.contains(otherVisit.getUuid()));
    // 5 Documents
    List<DocumentDto> mergedDocuments = getDocumentFacade().getDocumentsRelatedToEntity(DocumentRelatedEntityType.CONTACT, leadContact.getUuid());
    assertEquals(mergedDocuments.size(), 2);
    List<String> documentUuids = mergedDocuments.stream().map(DocumentDto::getUuid).collect(Collectors.toList());
    assertTrue(documentUuids.contains(document.getUuid()));
    assertTrue(documentUuids.contains(otherDocument.getUuid()));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ArrayList(java.util.ArrayList) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) TaskDto(de.symeda.sormas.api.task.TaskDto) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) DocumentDto(de.symeda.sormas.api.document.DocumentDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) VisitDto(de.symeda.sormas.api.visit.VisitDto) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) District(de.symeda.sormas.backend.infrastructure.district.District) SampleDto(de.symeda.sormas.api.sample.SampleDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 34 with TaskDto

use of de.symeda.sormas.api.task.TaskDto in project SORMAS-Project by hzi-braunschweig.

the class TestDataCreator method createTask.

public TaskDto createTask(TaskContext context, ReferenceDto entityRef, Consumer<TaskDto> customConfig) {
    TaskDto task = TaskDto.build(context, entityRef);
    if (customConfig != null) {
        customConfig.accept(task);
    }
    task = beanTest.getTaskFacade().saveTask(task);
    return task;
}
Also used : TaskDto(de.symeda.sormas.api.task.TaskDto)

Example 35 with TaskDto

use of de.symeda.sormas.api.task.TaskDto in project SORMAS-Project by hzi-braunschweig.

the class CoreEntityDeletionServiceTest method testContactPermanentDeletion.

@Test
public void testContactPermanentDeletion() throws IOException {
    createDeletionConfigurations();
    DeletionConfiguration coreEntityTypeConfig = getDeletionConfigurationService().getCoreEntityTypeConfig(CoreEntityType.CONTACT);
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf, UserRole.ADMIN, UserRole.NATIONAL_USER);
    PersonDto person = creator.createPerson();
    ContactDto contactDto = creator.createContact(user.toReference(), person.toReference(), Disease.CORONAVIRUS);
    TaskDto taskDto = creator.createTask(TaskContext.CONTACT, TaskType.CONTACT_FOLLOW_UP, TaskStatus.PENDING, null, contactDto.toReference(), null, new Date(), null);
    SampleDto sample = creator.createSample(contactDto.toReference(), user.toReference(), rdcf.facility, sampleDto -> sampleDto.setAssociatedContact(contactDto.toReference()));
    VisitDto visitDto = creator.createVisit(contactDto.getDisease(), contactDto.getPerson(), contactDto.getReportDateTime());
    assertEquals(1, getContactService().count());
    assertEquals(1, getTaskFacade().getAllByContact(contactDto.toReference()).size());
    assertEquals(1, getSampleService().count());
    assertEquals(1, getVisitService().count());
    final Date tenYearsPlusAgo = DateUtils.addDays(new Date(), (-1) * coreEntityTypeConfig.deletionPeriod - 1);
    SessionImpl em = (SessionImpl) getEntityManager();
    QueryImplementor query = em.createQuery("select i from contact i where i.uuid=:uuid");
    query.setParameter("uuid", contactDto.getUuid());
    Contact singleResult = (Contact) query.getSingleResult();
    singleResult.setCreationDate(new Timestamp(tenYearsPlusAgo.getTime()));
    singleResult.setChangeDate(new Timestamp(tenYearsPlusAgo.getTime()));
    em.save(singleResult);
    useSystemUser();
    getCoreEntityDeletionService().executeAutomaticDeletion();
    loginWith(user);
    assertEquals(0, getContactService().count());
    assertEquals(0, getTaskFacade().getAllByContact(contactDto.toReference()).size());
    assertEquals(0, getSampleService().count());
    assertEquals(0, getVisitService().count());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) TaskDto(de.symeda.sormas.api.task.TaskDto) Timestamp(java.sql.Timestamp) Date(java.util.Date) Contact(de.symeda.sormas.backend.contact.Contact) ContactDto(de.symeda.sormas.api.contact.ContactDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) VisitDto(de.symeda.sormas.api.visit.VisitDto) SessionImpl(org.hibernate.internal.SessionImpl) SampleDto(de.symeda.sormas.api.sample.SampleDto) QueryImplementor(org.hibernate.query.spi.QueryImplementor) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

TaskDto (de.symeda.sormas.api.task.TaskDto)38 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)24 Test (org.junit.Test)24 Date (java.util.Date)23 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)21 ContactDto (de.symeda.sormas.api.contact.ContactDto)15 UserDto (de.symeda.sormas.api.user.UserDto)14 PersonDto (de.symeda.sormas.api.person.PersonDto)10 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)10 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)9 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)7 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)7 SampleDto (de.symeda.sormas.api.sample.SampleDto)7 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)6 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)6 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)6 VisitDto (de.symeda.sormas.api.visit.VisitDto)5 LocalDate (java.time.LocalDate)5 DeletionDetails (de.symeda.sormas.api.common.DeletionDetails)4 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)4