Search in sources :

Example 1 with PathogenTestDto

use of de.symeda.sormas.api.sample.PathogenTestDto in project SORMAS-Project by hzi-braunschweig.

the class PathogenTestFacadeEjb method toDto.

public static PathogenTestDto toDto(PathogenTest source) {
    if (source == null) {
        return null;
    }
    PathogenTestDto target = new PathogenTestDto();
    DtoHelper.fillDto(target, source);
    target.setSample(SampleFacadeEjb.toReferenceDto(source.getSample()));
    target.setTestedDisease(source.getTestedDisease());
    target.setTestedDiseaseVariant(source.getTestedDiseaseVariant());
    target.setTestedDiseaseDetails(source.getTestedDiseaseDetails());
    target.setTestedDiseaseVariantDetails(source.getTestedDiseaseVariantDetails());
    target.setTypingId(source.getTypingId());
    target.setTestType(source.getTestType());
    target.setPcrTestSpecification(source.getPcrTestSpecification());
    target.setTestTypeText(source.getTestTypeText());
    target.setTestDateTime(source.getTestDateTime());
    target.setLab(FacilityFacadeEjb.toReferenceDto(source.getLab()));
    target.setLabDetails(source.getLabDetails());
    target.setLabUser(UserFacadeEjb.toReferenceDto(source.getLabUser()));
    target.setTestResult(source.getTestResult());
    target.setTestResultText(source.getTestResultText());
    target.setTestResultVerified(source.getTestResultVerified());
    target.setFourFoldIncreaseAntibodyTiter(source.isFourFoldIncreaseAntibodyTiter());
    target.setSerotype(source.getSerotype());
    target.setCqValue(source.getCqValue());
    target.setReportDate(source.getReportDate());
    target.setViaLims(source.isViaLims());
    target.setExternalId(source.getExternalId());
    target.setExternalOrderId(source.getExternalOrderId());
    target.setPreliminary(source.getPreliminary());
    return target;
}
Also used : PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto)

Example 2 with PathogenTestDto

use of de.symeda.sormas.api.sample.PathogenTestDto in project SORMAS-Project by hzi-braunschweig.

the class PathogenTestFacadeEjb method convertToDto.

public PathogenTestDto convertToDto(PathogenTest source, Pseudonymizer pseudonymizer) {
    PathogenTestDto target = toDto(source);
    pseudonymizeDto(source, target, pseudonymizer);
    return target;
}
Also used : PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto)

Example 3 with PathogenTestDto

use of de.symeda.sormas.api.sample.PathogenTestDto 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 4 with PathogenTestDto

use of de.symeda.sormas.api.sample.PathogenTestDto in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method saveImportedEntities.

@Override
public ImportLineResultDto<CaseImportEntities> saveImportedEntities(@Valid CaseImportEntities entities, boolean skipPersonValidation) {
    CaseDataDto caze = entities.getCaze();
    PersonDto person = entities.getPerson();
    List<SampleDto> samples = entities.getSamples();
    List<PathogenTestDto> pathogenTests = entities.getPathogenTests();
    List<VaccinationDto> vaccinations = entities.getVaccinations();
    try {
        // Necessary to make sure that the follow-up information is retained
        if (featureConfigurationFacade.isFeatureEnabled(FeatureType.CASE_FOLLOWUP) && caze.getFollowUpStatus() == null) {
            caze.setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
        }
        if (caze.getEpidNumber() != null && caseFacade.doesEpidNumberExist(caze.getEpidNumber(), caze.getUuid(), caze.getDisease())) {
            return ImportLineResultDto.errorResult(I18nProperties.getString(Strings.messageEpidNumberWarning));
        }
        // PersonDto savedPerson = personFacade.savePerson(person);
        final PersonDto savedPerson = personFacade.savePerson(person, skipPersonValidation);
        caze.setPerson(savedPerson.toReference());
        // Workaround: Reset the change date to avoid OutdatedEntityExceptions
        // Should be changed when doing #2265
        caze.setChangeDate(new Date());
        caseFacade.save(caze);
        for (SampleDto sample : samples) {
            sampleFacade.saveSample(sample);
        }
        for (PathogenTestDto pathogenTest : pathogenTests) {
            pathogenTestFacade.savePathogenTest(pathogenTest);
        }
        for (VaccinationDto vaccination : vaccinations) {
            vaccinationFacade.createWithImmunization(vaccination, caze.getResponsibleRegion(), caze.getResponsibleDistrict(), caze.getPerson(), caze.getDisease());
        }
        return ImportLineResultDto.successResult();
    } catch (ValidationRuntimeException e) {
        return ImportLineResultDto.errorResult(e.getMessage());
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto) Date(java.util.Date)

Example 5 with PathogenTestDto

use of de.symeda.sormas.api.sample.PathogenTestDto in project SORMAS-Project by hzi-braunschweig.

the class CaseImportFacadeEjb method validateEntities.

private ImportLineResultDto<CaseImportEntities> validateEntities(CaseImportEntities entities) {
    ImportLineResultDto<CaseImportEntities> validationResult = importFacade.validateConstraints(entities);
    if (validationResult.isError()) {
        return validationResult;
    }
    try {
        personFacade.validate(entities.getPerson());
        caseFacade.validate(entities.getCaze());
        for (SampleDto sample : entities.getSamples()) {
            sampleFacade.validate(sample);
        }
        for (PathogenTestDto pathogenTest : entities.getPathogenTests()) {
            pathogenTestFacade.validate(pathogenTest);
        }
    } catch (ValidationRuntimeException e) {
        return ImportLineResultDto.errorResult(e.getMessage());
    }
    return ImportLineResultDto.successResult();
}
Also used : CaseImportEntities(de.symeda.sormas.api.caze.caseimport.CaseImportEntities) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Aggregations

PathogenTestDto (de.symeda.sormas.api.sample.PathogenTestDto)66 SampleDto (de.symeda.sormas.api.sample.SampleDto)48 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)34 Test (org.junit.Test)34 PersonDto (de.symeda.sormas.api.person.PersonDto)22 Date (java.util.Date)22 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)21 UserDto (de.symeda.sormas.api.user.UserDto)17 Facility (de.symeda.sormas.backend.infrastructure.facility.Facility)12 List (java.util.List)11 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)10 Disease (de.symeda.sormas.api.Disease)9 ContactDto (de.symeda.sormas.api.contact.ContactDto)9 LabMessageDto (de.symeda.sormas.api.labmessage.LabMessageDto)9 TestReportDto (de.symeda.sormas.api.labmessage.TestReportDto)9 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)8 PathogenTestResultType (de.symeda.sormas.api.sample.PathogenTestResultType)8 SampleReferenceDto (de.symeda.sormas.api.sample.SampleReferenceDto)8 AdditionalTestDto (de.symeda.sormas.api.sample.AdditionalTestDto)7 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)7