Search in sources :

Example 1 with TaskCriteria

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

the class CaseFacadeEjb method mergeCase.

private void mergeCase(CaseDataDto leadCaseData, CaseDataDto otherCaseData, boolean cloning) {
    // 1 Merge Dtos
    // 1.1 Case
    copyDtoValues(leadCaseData, otherCaseData, cloning);
    save(leadCaseData, !cloning, true, true, false);
    // 1.2 Person - Only merge when the persons have different UUIDs
    if (!cloning && !DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid())) {
        PersonDto leadPerson = personFacade.getPersonByUuid(leadCaseData.getPerson().getUuid());
        PersonDto otherPerson = personFacade.getPersonByUuid(otherCaseData.getPerson().getUuid());
        personFacade.mergePerson(leadPerson, otherPerson);
    } else {
        assert (DataHelper.equal(leadCaseData.getPerson().getUuid(), otherCaseData.getPerson().getUuid()));
    }
    // 2 Change CaseReference
    Case leadCase = service.getByUuid(leadCaseData.getUuid());
    Case otherCase = service.getByUuid(otherCaseData.getUuid());
    // 2.1 Contacts
    List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(otherCase.toReference()), null);
    for (Contact contact : contacts) {
        if (cloning) {
            ContactDto newContact = ContactDto.build(leadCase.toReference(), leadCase.getDisease(), leadCase.getDiseaseDetails(), leadCase.getDiseaseVariant());
            newContact.setPerson(new PersonReferenceDto(contact.getPerson().getUuid()));
            DtoHelper.copyDtoValues(newContact, contactFacade.toDto(contact), cloning);
            contactFacade.save(newContact, false, false);
        } else {
            // simply move existing entities to the merge target
            contact.setCaze(leadCase);
            contactService.ensurePersisted(contact);
        }
    }
    // 2.2 Samples
    List<Sample> samples = sampleService.findBy(new SampleCriteria().caze(otherCase.toReference()), null);
    for (Sample sample : samples) {
        if (cloning) {
            SampleDto newSample = SampleDto.build(sample.getReportingUser().toReference(), leadCase.toReference());
            DtoHelper.copyDtoValues(newSample, SampleFacadeEjb.toDto(sample), cloning);
            sampleFacade.saveSample(newSample, false, true, true);
            // 2.2.1 Pathogen Tests
            for (PathogenTest pathogenTest : sample.getPathogenTests()) {
                PathogenTestDto newPathogenTest = PathogenTestDto.build(newSample.toReference(), pathogenTest.getLabUser().toReference());
                DtoHelper.copyDtoValues(newPathogenTest, PathogenTestFacadeEjbLocal.toDto(pathogenTest), cloning);
                sampleTestFacade.savePathogenTest(newPathogenTest);
            }
            for (AdditionalTest additionalTest : sample.getAdditionalTests()) {
                AdditionalTestDto newAdditionalTest = AdditionalTestDto.build(newSample.toReference());
                DtoHelper.copyDtoValues(newAdditionalTest, AdditionalTestFacadeEjbLocal.toDto(additionalTest), cloning);
                additionalTestFacade.saveAdditionalTest(newAdditionalTest);
            }
        } else {
            // simply move existing entities to the merge target
            sample.setAssociatedCase(leadCase);
            sampleService.ensurePersisted(sample);
        }
    }
    // 2.3 Tasks
    if (!cloning) {
        // simply move existing entities to the merge target
        List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(otherCase.getUuid())), true);
        for (Task task : tasks) {
            task.setCaze(leadCase);
            taskService.ensurePersisted(task);
        }
    }
    // 3 Change Therapy Reference
    // 3.1 Treatments
    List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    TherapyReferenceDto leadCaseTherapyReference = new TherapyReferenceDto(leadCase.getTherapy().getUuid());
    for (Treatment treatment : treatments) {
        if (cloning) {
            TreatmentDto newTreatment = TreatmentDto.build(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newTreatment, TreatmentFacadeEjb.toDto(treatment), cloning);
            treatmentFacade.saveTreatment(newTreatment);
        } else {
            // simply move existing entities to the merge target
            treatment.setTherapy(leadCase.getTherapy());
            treatmentService.ensurePersisted(treatment);
        }
    }
    // 3.2 Prescriptions
    List<Prescription> prescriptions = prescriptionService.findBy(new PrescriptionCriteria().therapy(new TherapyReferenceDto(otherCase.getTherapy().getUuid())));
    for (Prescription prescription : prescriptions) {
        if (cloning) {
            PrescriptionDto newPrescription = PrescriptionDto.buildPrescription(leadCaseTherapyReference);
            DtoHelper.copyDtoValues(newPrescription, PrescriptionFacadeEjb.toDto(prescription), cloning);
            prescriptionFacade.savePrescription(newPrescription);
        } else {
            // simply move existing entities to the merge target
            prescription.setTherapy(leadCase.getTherapy());
            prescriptionService.ensurePersisted(prescription);
        }
    }
    // 4 Change Clinical Course Reference
    // 4.1 Clinical Visits
    List<ClinicalVisit> clinicalVisits = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(new ClinicalCourseReferenceDto(otherCase.getClinicalCourse().getUuid())));
    for (ClinicalVisit clinicalVisit : clinicalVisits) {
        if (cloning) {
            ClinicalVisitDto newClinicalVisit = ClinicalVisitDto.build(leadCaseData.getClinicalCourse().toReference(), leadCase.getDisease());
            DtoHelper.copyDtoValues(newClinicalVisit, ClinicalVisitFacadeEjb.toDto(clinicalVisit), cloning);
            clinicalVisitFacade.saveClinicalVisit(newClinicalVisit, leadCase.getUuid(), false);
        } else {
            // simply move existing entities to the merge target
            clinicalVisit.setClinicalCourse(leadCase.getClinicalCourse());
            clinicalVisitService.ensurePersisted(clinicalVisit);
        }
    }
    // (set the person and the disease of the visit, saveVisit does the rest)
    for (VisitDto otherVisit : otherCase.getVisits().stream().map(VisitFacadeEjb::toDto).collect(Collectors.toList())) {
        otherVisit.setPerson(leadCaseData.getPerson());
        otherVisit.setDisease(leadCaseData.getDisease());
        visitFacade.saveVisit(otherVisit);
    }
    // 6 Documents
    List<Document> documents = documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, otherCase.getUuid());
    for (Document document : documents) {
        document.setRelatedEntityUuid(leadCaseData.getUuid());
        documentService.ensurePersisted(document);
    }
    // 7 Persist Event links through eventparticipants
    Set<EventParticipant> eventParticipants = otherCase.getEventParticipants();
    for (EventParticipant eventParticipant : eventParticipants) {
        eventParticipant.setResultingCase(leadCase);
        eventParticipantService.ensurePersisted(eventParticipant);
    }
    otherCase.getEventParticipants().clear();
    // 8 Exposures - Make sure there are no two probable infection environments
    // if there are more than 2 exposures marked as probable infection environment, find the one that originates from the otherCase and set it to false
    // the one originating from the otherCase should always be found at the higher index
    List<Exposure> probableExposuresList = leadCase.getEpiData().getExposures().stream().filter(Exposure::isProbableInfectionEnvironment).collect(Collectors.toList());
    while (probableExposuresList.size() >= 2) {
        // should never be > 2, but still make sure to set all but one exposures to false
        probableExposuresList.get(probableExposuresList.size() - 1).setProbableInfectionEnvironment(false);
        exposureService.ensurePersisted(probableExposuresList.get(probableExposuresList.size() - 1));
        probableExposuresList.remove(probableExposuresList.size() - 1);
    }
    // 9 Reports
    List<SurveillanceReport> surveillanceReports = surveillanceReportService.getByCaseUuids(Collections.singletonList(otherCase.getUuid()));
    surveillanceReports.forEach(surveillanceReport -> {
        SurveillanceReportDto surveillanceReportDto = SurveillanceReportFacadeEjb.toDto(surveillanceReport);
        surveillanceReportDto.setCaze(leadCase.toReference());
        surveillanceReportFacade.saveSurveillanceReport(surveillanceReportDto);
    });
    // 10 Activity as case
    final EpiData otherEpiData = otherCase.getEpiData();
    if (otherEpiData != null && YesNoUnknown.YES == otherEpiData.getActivityAsCaseDetailsKnown() && CollectionUtils.isNotEmpty(otherEpiData.getActivitiesAsCase())) {
        final EpiData leadEpiData = leadCase.getEpiData();
        leadEpiData.setActivityAsCaseDetailsKnown(YesNoUnknown.YES);
        epiDataService.ensurePersisted(leadEpiData);
    }
    // Travel entries reference
    List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(otherCase);
    travelEntries.forEach(t -> {
        t.setResultingCase(leadCase);
        travelEntryService.ensurePersisted(t);
    });
}
Also used : AdditionalTest(de.symeda.sormas.backend.sample.AdditionalTest) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) Task(de.symeda.sormas.backend.task.Task) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) Document(de.symeda.sormas.backend.document.Document) TreatmentDto(de.symeda.sormas.api.therapy.TreatmentDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) EpiData(de.symeda.sormas.backend.epidata.EpiData) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) Sample(de.symeda.sormas.backend.sample.Sample) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) Exposure(de.symeda.sormas.backend.exposure.Exposure) PathogenTest(de.symeda.sormas.backend.sample.PathogenTest) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) Contact(de.symeda.sormas.backend.contact.Contact) Treatment(de.symeda.sormas.backend.therapy.Treatment) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) ClinicalVisitDto(de.symeda.sormas.api.clinicalcourse.ClinicalVisitDto) SurveillanceReportDto(de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) AdditionalTestDto(de.symeda.sormas.api.sample.AdditionalTestDto)

Example 2 with TaskCriteria

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

the class CaseFacadeEjb method updateInvestigationByStatus.

public void updateInvestigationByStatus(CaseDataDto existingCase, Case caze) {
    CaseReferenceDto caseRef = caze.toReference();
    InvestigationStatus investigationStatus = caze.getInvestigationStatus();
    if (investigationStatus != InvestigationStatus.PENDING) {
        // Set the investigation date
        if (caze.getInvestigatedDate() == null) {
            caze.setInvestigatedDate(new Date());
        }
        // the case status has been updated manually
        if (existingCase != null) {
            List<Task> pendingTasks = taskService.findBy(new TaskCriteria().taskType(TaskType.CASE_INVESTIGATION).caze(caseRef).taskStatus(TaskStatus.PENDING), true);
            final boolean caseStatusSetToDone = caze.getInvestigationStatus() == InvestigationStatus.DONE && existingCase.getInvestigationStatus() != InvestigationStatus.DONE;
            for (Task task : pendingTasks) {
                task.setTaskStatus(caseStatusSetToDone ? TaskStatus.DONE : TaskStatus.REMOVED);
                task.setStatusChangeDate(new Date());
            }
            if (caseStatusSetToDone) {
                sendInvestigationDoneNotifications(caze);
            }
        }
    } else {
        // Remove the investigation date
        caze.setInvestigatedDate(null);
        // Create a new investigation task if none is present
        long pendingCount = existingCase != null ? taskService.getCount(new TaskCriteria().taskType(TaskType.CASE_INVESTIGATION).caze(caseRef).taskStatus(TaskStatus.PENDING)) : 0;
        if (pendingCount == 0 && featureConfigurationFacade.isTaskGenerationFeatureEnabled(TaskType.CASE_INVESTIGATION)) {
            createInvestigationTask(caze);
        }
    }
}
Also used : Task(de.symeda.sormas.backend.task.Task) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Date(java.util.Date) LocalDate(java.time.LocalDate) ExternalShareInfoCountAndLatestDate(de.symeda.sormas.backend.share.ExternalShareInfoCountAndLatestDate)

Example 3 with TaskCriteria

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

Example 4 with TaskCriteria

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

the class TravelEntryService method delete.

@Override
public void delete(TravelEntry travelEntry) {
    // Delete all tasks associated with this travel entry
    List<Task> tasks = taskService.findBy(new TaskCriteria().travelEntry(new TravelEntryReferenceDto(travelEntry.getUuid(), travelEntry.getExternalId(), travelEntry.getPerson().getFirstName(), travelEntry.getPerson().getLastName())), true);
    for (Task task : tasks) {
        taskService.delete(task);
    }
    // Mark the travel entry as deleted
    super.delete(travelEntry);
}
Also used : Task(de.symeda.sormas.backend.task.Task) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) TravelEntryReferenceDto(de.symeda.sormas.api.travelentry.TravelEntryReferenceDto)

Example 5 with TaskCriteria

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

the class EventService method delete.

@Override
public void delete(Event event) {
    // Delete all event participants associated with this event
    List<EventParticipant> eventParticipants = eventParticipantService.getAllByEventAfter(null, event);
    for (EventParticipant eventParticipant : eventParticipants) {
        eventParticipantService.delete(eventParticipant);
    }
    // Delete all tasks associated with this event
    List<Task> tasks = taskService.findBy(new TaskCriteria().event(new EventReferenceDto(event.getUuid())), true);
    for (Task task : tasks) {
        taskService.delete(task);
    }
    // Delete all event actions associated with this event
    List<Action> actions = actionService.getAllByEvent(event);
    for (Action action : actions) {
        actionService.delete(action);
    }
    // Mark the event as deleted
    super.delete(event);
}
Also used : Task(de.symeda.sormas.backend.task.Task) Action(de.symeda.sormas.backend.action.Action) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria)

Aggregations

TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)16 Task (de.symeda.sormas.backend.task.Task)10 Date (java.util.Date)9 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)5 ContactDto (de.symeda.sormas.api.contact.ContactDto)5 TransactionAttribute (javax.ejb.TransactionAttribute)5 Sample (de.symeda.sormas.backend.sample.Sample)4 User (de.symeda.sormas.backend.user.User)4 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 TaskIndexDto (de.symeda.sormas.api.task.TaskIndexDto)3 Map (java.util.Map)3 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)2 TaskDto (de.symeda.sormas.api.task.TaskDto)2 DataHelper (de.symeda.sormas.api.utils.DataHelper)2 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 CaseFacadeEjbLocal (de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal)2 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)2 CriteriaBuilderHelper (de.symeda.sormas.backend.common.CriteriaBuilderHelper)2 NotificationDeliveryFailedException (de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException)2