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());
}
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());
}
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()));
}
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;
}
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());
}
Aggregations