Search in sources :

Example 1 with TherapyReferenceDto

use of de.symeda.sormas.api.therapy.TherapyReferenceDto 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);
        t.setPerson(leadCase.getPerson());
        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) CoreAndPersonDto(de.symeda.sormas.api.caze.CoreAndPersonDto) 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 TherapyReferenceDto

use of de.symeda.sormas.api.therapy.TherapyReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class CaseService method deletePermanent.

@Override
public void deletePermanent(Case caze) {
    // Delete all tasks associated with this case
    Optional.ofNullable(caze.getTasks()).ifPresent(tl -> tl.forEach(t -> taskService.deletePermanent(t)));
    // Delete all samples that are only associated with this case
    caze.getSamples().stream().filter(sample -> sample.getAssociatedContact() == null && sample.getAssociatedEventParticipant() == null).forEach(sample -> sampleService.deletePermanent(sample));
    caze.getVisits().stream().forEach(visit -> {
        if (visit.getContacts() == null || visit.getContacts().isEmpty()) {
            visitService.deletePermanent(visit);
        } else {
            visit.setCaze(null);
            visitService.ensurePersisted(visit);
        }
    });
    // Delete surveillance reports related to this case
    surveillanceReportService.getByCaseUuids(Collections.singletonList(caze.getUuid())).forEach(s -> surveillanceReportService.deletePermanent(s));
    // Delete documents related to this case
    documentService.getRelatedToEntity(DocumentRelatedEntityType.CASE, caze.getUuid()).forEach(d -> documentService.markAsDeleted(d));
    // Delete clinical management data
    if (caze.getTherapy() != null) {
        TherapyReferenceDto therapy = new TherapyReferenceDto(caze.getTherapy().getUuid());
        List<Treatment> treatments = treatmentService.findBy(new TreatmentCriteria().therapy(therapy));
        treatments.forEach(t -> treatmentService.deletePermanent(t));
        prescriptionService.findBy(new PrescriptionCriteria().therapy(therapy)).forEach(p -> prescriptionService.deletePermanent(p));
    }
    if (caze.getClinicalCourse() != null) {
        ClinicalCourseReferenceDto clinicalCourse = new ClinicalCourseReferenceDto(caze.getClinicalCourse().getUuid());
        List<ClinicalVisit> cvs = clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(clinicalCourse));
        cvs.forEach(c -> clinicalVisitService.deletePermanent(c));
    }
    // Remove the case from any S2S share info referencing it
    sormasToSormasShareInfoService.getByAssociatedEntity(SormasToSormasShareInfo.CAZE, caze.getUuid()).forEach(s -> {
        s.setCaze(null);
        if (sormasToSormasShareInfoFacade.hasAnyEntityReference(s)) {
            sormasToSormasShareInfoService.ensurePersisted(s);
        } else {
            sormasToSormasShareInfoService.deletePermanent(s);
        }
    });
    // Remove the case from any external share info referencing it
    externalShareInfoService.getShareInfoByCase(caze.getUuid()).forEach(e -> {
        externalShareInfoService.deletePermanent(e);
    });
    // Remove the case from all cases in which it has been set as a duplicate
    getCasesSetAsDuplicate(caze.getId()).forEach(c -> {
        c.setDuplicateOf(null);
        ensurePersisted(c);
    });
    caseFacade.deleteCaseInExternalSurveillanceTool(caze);
    deleteCaseLinks(caze);
    super.deletePermanent(caze);
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) VisitService(de.symeda.sormas.backend.visit.VisitService) Arrays(java.util.Arrays) NoResultException(javax.persistence.NoResultException) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) DocumentRelatedEntityType(de.symeda.sormas.api.document.DocumentRelatedEntityType) ContactJoins(de.symeda.sormas.backend.contact.ContactJoins) Visit(de.symeda.sormas.backend.visit.Visit) From(javax.persistence.criteria.From) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) Transactional(javax.transaction.Transactional) NotNull(javax.validation.constraints.NotNull) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) DataHelper(de.symeda.sormas.api.utils.DataHelper) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Treatment(de.symeda.sormas.backend.therapy.Treatment) Disease(de.symeda.sormas.api.Disease) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) CaseSelectionDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseSelectionDtoResultTransformer) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) SurveillanceReport(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) SurveillanceReportService(de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReportService) Join(javax.persistence.criteria.Join) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) DocumentService(de.symeda.sormas.backend.document.DocumentService) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Sex(de.symeda.sormas.api.person.Sex) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) List(java.util.List) EditPermissionType(de.symeda.sormas.api.EditPermissionType) ExtendedPostgreSQL94Dialect(de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect) SormasToSormasShareInfoFacadeEjbLocal(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoFacadeEjb.SormasToSormasShareInfoFacadeEjbLocal) Optional(java.util.Optional) RequestContextHolder(de.symeda.sormas.api.RequestContextHolder) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) ClinicalCourse(de.symeda.sormas.backend.clinicalcourse.ClinicalCourse) Location(de.symeda.sormas.backend.location.Location) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) Function(java.util.function.Function) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) Event(de.symeda.sormas.backend.event.Event) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) Comparator(java.util.Comparator) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) CaseListEntryDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseListEntryDtoResultTransformer) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) Treatment(de.symeda.sormas.backend.therapy.Treatment) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria)

Example 3 with TherapyReferenceDto

use of de.symeda.sormas.api.therapy.TherapyReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class CaseService method delete.

@Override
public void delete(Case caze) {
    // Mark all contacts associated with this case as deleted and remove this case
    // from any contacts where it is set as the resulting case
    List<Contact> contacts = contactService.findBy(new ContactCriteria().caze(caze.toReference()), null);
    for (Contact contact : contacts) {
        contactService.delete(contact);
    }
    contacts = contactService.getAllByResultingCase(caze);
    for (Contact contact : contacts) {
        contact.setResultingCase(null);
        externalJournalService.handleExternalJournalPersonUpdateAsync(contact.getPerson().toReference());
        contactService.ensurePersisted(contact);
    }
    caze.getSamples().stream().filter(sample -> sample.getAssociatedContact() == null && sample.getAssociatedEventParticipant() == null).forEach(sample -> sampleService.delete(sample));
    // Delete all tasks associated with this case
    List<Task> tasks = taskService.findBy(new TaskCriteria().caze(new CaseReferenceDto(caze.getUuid())), true);
    for (Task task : tasks) {
        taskService.delete(task);
    }
    // Delete all prescriptions/treatments/clinical visits
    if (caze.getTherapy() != null) {
        TherapyReferenceDto therapy = new TherapyReferenceDto(caze.getTherapy().getUuid());
        treatmentService.findBy(new TreatmentCriteria().therapy(therapy)).stream().forEach(t -> treatmentService.delete(t));
        prescriptionService.findBy(new PrescriptionCriteria().therapy(therapy)).stream().forEach(p -> prescriptionService.delete(p));
    }
    if (caze.getClinicalCourse() != null) {
        ClinicalCourseReferenceDto clinicalCourse = new ClinicalCourseReferenceDto(caze.getClinicalCourse().getUuid());
        clinicalVisitService.findBy(new ClinicalVisitCriteria().clinicalCourse(clinicalCourse)).stream().forEach(c -> clinicalVisitService.delete(c));
    }
    // Remove all events linked to case by removing the case_id from event participant
    caze.getEventParticipants().stream().forEach(eventParticipant -> eventParticipant.setResultingCase(null));
    // Unlink TravelEntries where this case is set as the resulting case
    List<TravelEntry> travelEntries = travelEntryService.getAllByResultingCase(caze);
    for (TravelEntry travelEntry : travelEntries) {
        travelEntry.setResultingCase(null);
        travelEntryService.ensurePersisted(travelEntry);
    }
    // Unlink Immunizations where this case is set as the related case
    immunizationService.unlinkRelatedCase(caze);
    // Mark the case as deleted
    super.delete(caze);
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) NoResultException(javax.persistence.NoResultException) CaseSimilarityCriteria(de.symeda.sormas.api.caze.CaseSimilarityCriteria) ExternalDataUpdateException(de.symeda.sormas.api.externaldata.ExternalDataUpdateException) StringUtils(org.apache.commons.lang3.StringUtils) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) Visit(de.symeda.sormas.backend.visit.Visit) From(javax.persistence.criteria.From) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) Transactional(javax.transaction.Transactional) NotNull(javax.validation.constraints.NotNull) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseLogic(de.symeda.sormas.api.caze.CaseLogic) ExternalDataDto(de.symeda.sormas.api.externaldata.ExternalDataDto) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) SampleService(de.symeda.sormas.backend.sample.SampleService) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Sample(de.symeda.sormas.backend.sample.Sample) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) Hospitalization(de.symeda.sormas.backend.hospitalization.Hospitalization) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseReferenceDefinition(de.symeda.sormas.api.caze.CaseReferenceDefinition) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) TypedQuery(javax.persistence.TypedQuery) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) CaseListEntryDto(de.symeda.sormas.api.caze.CaseListEntryDto) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) LocalBean(javax.ejb.LocalBean) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ChangeDateFilterBuilder(de.symeda.sormas.backend.common.ChangeDateFilterBuilder) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) Task(de.symeda.sormas.backend.task.Task) CriteriaDateType(de.symeda.sormas.api.utils.criteria.CriteriaDateType) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) Prescription(de.symeda.sormas.backend.therapy.Prescription) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Treatment(de.symeda.sormas.backend.therapy.Treatment) Disease(de.symeda.sormas.api.Disease) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) ContactService(de.symeda.sormas.backend.contact.ContactService) FollowUpLogic(de.symeda.sormas.api.followup.FollowUpLogic) CaseSelectionDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseSelectionDtoResultTransformer) Subquery(javax.persistence.criteria.Subquery) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) FeatureType(de.symeda.sormas.api.feature.FeatureType) VisitFacadeEjb(de.symeda.sormas.backend.visit.VisitFacadeEjb) CaseSelectionDto(de.symeda.sormas.api.caze.CaseSelectionDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) Join(javax.persistence.criteria.Join) ClinicalVisitService(de.symeda.sormas.backend.clinicalcourse.ClinicalVisitService) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) ChangeDateBuilder(de.symeda.sormas.backend.common.ChangeDateBuilder) Fetch(javax.persistence.criteria.Fetch) AbstractCoreAdoService(de.symeda.sormas.backend.common.AbstractCoreAdoService) PrescriptionService(de.symeda.sormas.backend.therapy.PrescriptionService) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) ExternalShareInfo(de.symeda.sormas.backend.share.ExternalShareInfo) UserRole(de.symeda.sormas.api.user.UserRole) ExternalShareDateType(de.symeda.sormas.api.utils.criteria.ExternalShareDateType) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) Person(de.symeda.sormas.backend.person.Person) CaseCriteria(de.symeda.sormas.api.caze.CaseCriteria) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) List(java.util.List) ExtendedPostgreSQL94Dialect(de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) ClinicalCourse(de.symeda.sormas.backend.clinicalcourse.ClinicalCourse) Location(de.symeda.sormas.backend.location.Location) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) TaskService(de.symeda.sormas.backend.task.TaskService) DateHelper(de.symeda.sormas.api.utils.DateHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) Function(java.util.function.Function) ExternalDataUtil(de.symeda.sormas.backend.util.ExternalDataUtil) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) CollectionUtils(org.apache.commons.collections.CollectionUtils) PreviousCaseDto(de.symeda.sormas.api.caze.PreviousCaseDto) TransactionAttribute(javax.ejb.TransactionAttribute) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) TreatmentService(de.symeda.sormas.backend.therapy.TreatmentService) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ExternalShareInfoService(de.symeda.sormas.backend.share.ExternalShareInfoService) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) EpiDataService(de.symeda.sormas.backend.epidata.EpiDataService) CaseJoins(de.symeda.sormas.utils.CaseJoins) ClinicalVisit(de.symeda.sormas.backend.clinicalcourse.ClinicalVisit) MapCaseDto(de.symeda.sormas.api.caze.MapCaseDto) ImmunizationService(de.symeda.sormas.backend.immunization.ImmunizationService) Event(de.symeda.sormas.backend.event.Event) SormasToSormasShareInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfo) ExternalJournalService(de.symeda.sormas.backend.externaljournal.ExternalJournalService) Comparator(java.util.Comparator) Collections(java.util.Collections) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) CaseListEntryDtoResultTransformer(de.symeda.sormas.backend.caze.transformers.CaseListEntryDtoResultTransformer) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) PrescriptionCriteria(de.symeda.sormas.api.therapy.PrescriptionCriteria) Task(de.symeda.sormas.backend.task.Task) ClinicalCourseReferenceDto(de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto) TherapyReferenceDto(de.symeda.sormas.api.therapy.TherapyReferenceDto) ClinicalVisitCriteria(de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria) Contact(de.symeda.sormas.backend.contact.Contact) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) TreatmentCriteria(de.symeda.sormas.api.therapy.TreatmentCriteria) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Aggregations

ClinicalCourseReferenceDto (de.symeda.sormas.api.clinicalcourse.ClinicalCourseReferenceDto)3 ClinicalVisitCriteria (de.symeda.sormas.api.clinicalcourse.ClinicalVisitCriteria)3 PrescriptionCriteria (de.symeda.sormas.api.therapy.PrescriptionCriteria)3 TherapyReferenceDto (de.symeda.sormas.api.therapy.TherapyReferenceDto)3 TreatmentCriteria (de.symeda.sormas.api.therapy.TreatmentCriteria)3 Disease (de.symeda.sormas.api.Disease)2 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)2 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)2 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)2 CaseIndexDto (de.symeda.sormas.api.caze.CaseIndexDto)2 CaseListEntryDto (de.symeda.sormas.api.caze.CaseListEntryDto)2 CaseLogic (de.symeda.sormas.api.caze.CaseLogic)2 CaseOrigin (de.symeda.sormas.api.caze.CaseOrigin)2 CaseOutcome (de.symeda.sormas.api.caze.CaseOutcome)2 CaseReferenceDefinition (de.symeda.sormas.api.caze.CaseReferenceDefinition)2 CaseSelectionDto (de.symeda.sormas.api.caze.CaseSelectionDto)2 CaseSimilarityCriteria (de.symeda.sormas.api.caze.CaseSimilarityCriteria)2 InvestigationStatus (de.symeda.sormas.api.caze.InvestigationStatus)2 MapCaseDto (de.symeda.sormas.api.caze.MapCaseDto)2 NewCaseDateType (de.symeda.sormas.api.caze.NewCaseDateType)2