Search in sources :

Example 1 with TaskDto

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

Example 2 with TaskDto

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

the class CaseFacadeEjbTest method testMergeCase.

@Test
public void testMergeCase() throws IOException {
    useNationalUserLogin();
    // 1. Create
    // Create leadCase
    UserDto leadUser = creator.createUser("", "", "", "First", "User");
    UserReferenceDto leadUserReference = new UserReferenceDto(leadUser.getUuid());
    PersonDto leadPerson = creator.createPerson("Alex", "Miller");
    PersonReferenceDto leadPersonReference = new PersonReferenceDto(leadPerson.getUuid());
    RDCF leadRdcf = creator.createRDCF();
    CaseDataDto leadCase = creator.createCase(leadUserReference, leadPersonReference, Disease.DENGUE, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), leadRdcf, (c) -> {
        c.setAdditionalDetails("Test additional details");
        c.setFollowUpComment("Test followup comment");
    });
    leadCase.setClinicianEmail("mail");
    leadCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.NO);
    getCaseFacade().save(leadCase);
    VisitDto leadVisit = creator.createVisit(leadCase.getDisease(), leadCase.getPerson(), leadCase.getReportDate());
    leadVisit.getSymptoms().setAnorexiaAppetiteLoss(SymptomState.YES);
    getVisitFacade().saveVisit(leadVisit);
    // Create otherCase
    UserDto otherUser = creator.createUser("", "", "", "Second", "User");
    UserReferenceDto otherUserReference = new UserReferenceDto(otherUser.getUuid());
    PersonDto otherPerson = creator.createPerson("Max", "Smith");
    otherPerson.setBirthWeight(2);
    getPersonFacade().savePerson(otherPerson);
    PersonReferenceDto otherPersonReference = new PersonReferenceDto(otherPerson.getUuid());
    RDCF otherRdcf = creator.createRDCF("Reg2", "Dis2", "Comm2", "Fac2", "Poe2");
    CaseDataDto otherCase = creator.createCase(otherUserReference, otherPersonReference, Disease.CHOLERA, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), otherRdcf, (c) -> {
        c.setAdditionalDetails("Test other additional details");
        c.setFollowUpComment("Test other followup comment");
    });
    otherCase.setClinicianName("name");
    CaseReferenceDto otherCaseReference = getCaseFacade().getReferenceByUuid(otherCase.getUuid());
    ContactDto contact = creator.createContact(otherUserReference, otherUserReference, otherPersonReference, otherCase, new Date(), new Date(), null);
    Region region = creator.createRegion("");
    District district = creator.createDistrict("", region);
    SampleDto sample = creator.createSample(otherCaseReference, otherUserReference, creator.createFacility("", region, district, creator.createCommunity("", district)));
    TaskDto task = creator.createTask(TaskContext.CASE, TaskType.CASE_INVESTIGATION, TaskStatus.PENDING, otherCaseReference, new ContactReferenceDto(), new EventReferenceDto(), new Date(), otherUserReference);
    TreatmentDto treatment = creator.createTreatment(otherCase);
    PrescriptionDto prescription = creator.createPrescription(otherCase);
    ClinicalVisitDto visit = creator.createClinicalVisit(otherCase);
    otherCase.getEpiData().setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
    final ArrayList<ActivityAsCaseDto> otherActivitiesAsCase = new ArrayList<>();
    ActivityAsCaseDto activityAsCaseDto = new ActivityAsCaseDto();
    activityAsCaseDto.setActivityAsCaseType(ActivityAsCaseType.GATHERING);
    otherActivitiesAsCase.add(activityAsCaseDto);
    otherCase.getEpiData().setActivitiesAsCase(otherActivitiesAsCase);
    getCaseFacade().save(otherCase);
    VisitDto otherVisit = creator.createVisit(otherCase.getDisease(), otherCase.getPerson(), otherCase.getReportDate());
    otherVisit.getSymptoms().setAbdominalPain(SymptomState.YES);
    getVisitFacade().saveVisit(otherVisit);
    EventDto event = creator.createEvent(otherUserReference);
    event.setDisease(otherCase.getDisease());
    getEventFacade().save(event);
    EventParticipantDto otherCaseEventParticipant = creator.createEventParticipant(event.toReference(), otherPerson, otherUserReference);
    otherCaseEventParticipant.setResultingCase(otherCaseReference);
    getEventParticipantFacade().saveEventParticipant(otherCaseEventParticipant);
    creator.createSurveillanceReport(otherUserReference, otherCaseReference);
    TravelEntryDto travelEntry = creator.createTravelEntry(otherPersonReference, otherUserReference, otherCase.getDisease(), otherRdcf.region, otherRdcf.district, otherRdcf.pointOfEntry);
    travelEntry.setResultingCase(otherCaseReference);
    travelEntry = getTravelEntryFacade().save(travelEntry);
    DocumentDto document = creator.createDocument(leadUserReference, "document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CASE, leadCase.getUuid(), "content".getBytes(StandardCharsets.UTF_8));
    DocumentDto otherDocument = creator.createDocument(leadUserReference, "other_document.pdf", "application/pdf", 42L, DocumentRelatedEntityType.CASE, otherCase.getUuid(), "other content".getBytes(StandardCharsets.UTF_8));
    // 2. Merge
    getCaseFacade().mergeCase(leadCase.getUuid(), otherCase.getUuid());
    // 3. Test
    CaseDataDto mergedCase = getCaseFacade().getCaseDataByUuid(leadCase.getUuid());
    // Check no values
    assertNull(mergedCase.getClassificationComment());
    // Check 'lead and other have different values'
    assertEquals(leadCase.getDisease(), mergedCase.getDisease());
    // Check 'lead has value, other has not'
    assertEquals(leadCase.getClinicianEmail(), mergedCase.getClinicianEmail());
    // Check 'lead has no value, other has'
    assertEquals(otherCase.getClinicianName(), mergedCase.getClinicianName());
    PersonDto mergedPerson = getPersonFacade().getPersonByUuid(mergedCase.getPerson().getUuid());
    // Check no values
    assertNull(mergedPerson.getBirthdateDD());
    // Check 'lead and other have different values'
    assertEquals(leadCase.getPerson().getFirstName(), mergedPerson.getFirstName());
    // Check 'lead has value, other has not'
    assertEquals(leadCase.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", mergedCase.getAdditionalDetails());
    assertEquals("Test followup comment Test other followup comment", mergedCase.getFollowUpComment());
    // 4. Test Reference Changes
    // 4.1 Contacts
    List<String> contactUuids = new ArrayList<>();
    contactUuids.add(contact.getUuid());
    assertEquals(leadCase.getUuid(), getContactFacade().getByUuids(contactUuids).get(0).getCaze().getUuid());
    // 4.2 Samples
    List<String> sampleUuids = new ArrayList<>();
    sampleUuids.add(sample.getUuid());
    assertEquals(leadCase.getUuid(), getSampleFacade().getByUuids(sampleUuids).get(0).getAssociatedCase().getUuid());
    // 4.3 Tasks
    List<String> taskUuids = new ArrayList<>();
    taskUuids.add(task.getUuid());
    assertEquals(leadCase.getUuid(), getTaskFacade().getByUuids(taskUuids).get(0).getCaze().getUuid());
    // 4.4 Treatments
    List<String> treatmentUuids = new ArrayList<>();
    treatmentUuids.add(treatment.getUuid());
    assertEquals(leadCase.getTherapy().getUuid(), getTreatmentFacade().getByUuids(treatmentUuids).get(0).getTherapy().getUuid());
    // 4.5 Prescriptions
    List<String> prescriptionUuids = new ArrayList<>();
    prescriptionUuids.add(prescription.getUuid());
    assertEquals(leadCase.getTherapy().getUuid(), getPrescriptionFacade().getByUuids(prescriptionUuids).get(0).getTherapy().getUuid());
    // 4.6 Clinical Visits
    List<String> visitUuids = new ArrayList<>();
    visitUuids.add(visit.getUuid());
    assertEquals(leadCase.getClinicalCourse().getUuid(), getClinicalVisitFacade().getByUuids(visitUuids).get(0).getClinicalCourse().getUuid());
    // 4.7 Visits;
    List<String> mergedVisits = getVisitFacade().getIndexList(new VisitCriteria().caze(mergedCase.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()));
    // and symptoms
    assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAbdominalPain());
    assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAnorexiaAppetiteLoss());
    assertTrue(mergedCase.getSymptoms().getSymptomatic());
    // 4.8 Linked Events
    assertEquals(1, getEventFacade().count(new EventCriteria().caze(mergedCase.toReference())));
    // 4.8 Linked Surveillance Reports
    List<SurveillanceReportDto> surveillanceReportList = getSurveillanceReportFacade().getByCaseUuids(Collections.singletonList(mergedCase.getUuid()));
    MatcherAssert.assertThat(surveillanceReportList, hasSize(1));
    // 5 Documents
    List<DocumentDto> mergedDocuments = getDocumentFacade().getDocumentsRelatedToEntity(DocumentRelatedEntityType.CASE, leadCase.getUuid());
    assertEquals(2, mergedDocuments.size());
    List<String> documentUuids = mergedDocuments.stream().map(DocumentDto::getUuid).collect(Collectors.toList());
    assertTrue(documentUuids.contains(document.getUuid()));
    assertTrue(documentUuids.contains(otherDocument.getUuid()));
    // 10 Activities as case
    final EpiDataDto epiData = mergedCase.getEpiData();
    assertEquals(YesNoUnknown.YES, epiData.getActivityAsCaseDetailsKnown());
    final List<ActivityAsCaseDto> activitiesAsCase = epiData.getActivitiesAsCase();
    assertEquals(1, activitiesAsCase.size());
    assertEquals(ActivityAsCaseType.GATHERING, activitiesAsCase.get(0).getActivityAsCaseType());
    // Travel entry
    travelEntry = getTravelEntryFacade().getByUuid(travelEntry.getUuid());
    assertEquals(mergedCase.toReference(), travelEntry.getResultingCase());
}
Also used : UserDto(de.symeda.sormas.api.user.UserDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ArrayList(java.util.ArrayList) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) EventCriteria(de.symeda.sormas.api.event.EventCriteria) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) ActivityAsCaseDto(de.symeda.sormas.api.activityascase.ActivityAsCaseDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) 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) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) DocumentDto(de.symeda.sormas.api.document.DocumentDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) District(de.symeda.sormas.backend.infrastructure.district.District) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with TaskDto

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

the class TestEntityCreator method createCaseTask.

public static Task createCaseTask(Case caze, TaskStatus taskStatus, User user) {
    TaskDto taskDto = new TaskDto();
    Task task = new TaskDtoHelper().fillOrCreateFromDto(null, taskDto);
    task.setUuid(DataHelper.createUuid());
    task.setCreationDate(new Date());
    task.setChangeDate(new Date());
    task.setTaskContext(TaskContext.CASE);
    task.setTaskType(TaskType.CASE_INVESTIGATION);
    task.setTaskStatus(taskStatus);
    task.setCaze(caze);
    task.setAssigneeUser(user);
    try {
        DatabaseHelper.getTaskDao().saveAndSnapshot(task);
        DatabaseHelper.getTaskDao().accept(task);
    } catch (DaoException e) {
        throw new RuntimeException(e);
    }
    return DatabaseHelper.getTaskDao().queryForIdWithEmbedded(task.getId());
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) TaskDtoHelper(de.symeda.sormas.app.backend.task.TaskDtoHelper) DaoException(de.symeda.sormas.app.backend.common.DaoException) TaskDto(de.symeda.sormas.api.task.TaskDto) Date(java.util.Date)

Example 4 with TaskDto

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

the class TaskFacadeEjbPseudonymizationTest method testGetTaskWithCaseOutsideJurisdiction.

@Test
public void testGetTaskWithCaseOutsideJurisdiction() {
    CaseDataDto caze = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
    TaskDto task = createCaseTask(caze);
    assertPseudonymized(getTaskFacade().getByUuid(task.getUuid()));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) TaskDto(de.symeda.sormas.api.task.TaskDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with TaskDto

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

the class TaskFacadeEjbPseudonymizationTest method testPseudonymizeExportList.

@Test
public void testPseudonymizeExportList() {
    CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
    TaskDto task1 = createCaseTask(caze1);
    CaseDataDto caze2 = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
    ContactDto contact1 = creator.createContact(user2.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
    TaskDto task2 = createCaseTask(caze2);
    TaskDto task3 = createContactTask(contact1);
    ContactDto contact2 = creator.createContact(user1.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf1);
    TaskDto task4 = createContactTask(contact2);
    List<TaskExportDto> exportList = getTaskFacade().getExportList(new TaskCriteria(), null, 1, 100);
    TaskExportDto export1 = exportList.stream().filter(t -> t.getUuid().equals(task1.getUuid())).findFirst().get();
    assertThat(export1.getPersonFirstName(), is("John"));
    assertThat(export1.getPersonLastName(), is("Smith"));
    TaskExportDto export2 = exportList.stream().filter(t -> t.getUuid().equals(task2.getUuid())).findFirst().get();
    assertThat(export2.getPersonFirstName(), is("Confidential"));
    assertThat(export2.getPersonLastName(), is("Confidential"));
    TaskExportDto export3 = exportList.stream().filter(t -> t.getUuid().equals(task3.getUuid())).findFirst().get();
    assertThat(export3.getPersonFirstName(), is("John"));
    assertThat(export3.getPersonLastName(), is("Smith"));
    TaskExportDto export4 = exportList.stream().filter(t -> t.getUuid().equals(task4.getUuid())).findFirst().get();
    assertThat(export4.getPersonFirstName(), is("Confidential"));
    assertThat(export4.getPersonLastName(), is("Confidential"));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) TaskDto(de.symeda.sormas.api.task.TaskDto) TaskExportDto(de.symeda.sormas.api.task.TaskExportDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

TaskDto (de.symeda.sormas.api.task.TaskDto)34 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)21 Test (org.junit.Test)21 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)20 Date (java.util.Date)20 ContactDto (de.symeda.sormas.api.contact.ContactDto)13 UserDto (de.symeda.sormas.api.user.UserDto)11 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)9 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)9 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)7 PersonDto (de.symeda.sormas.api.person.PersonDto)7 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)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 SampleDto (de.symeda.sormas.api.sample.SampleDto)5 LocalDate (java.time.LocalDate)5 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)4 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)4 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)4