Search in sources :

Example 1 with CaseReferenceDto

use of de.symeda.sormas.api.caze.CaseReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class VisitFacadeEjbTest method testCreateExternalVisit.

@Test
public void testCreateExternalVisit() {
    TestDataCreator.RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Ext", "Vis", UserRole.REST_EXTERNAL_VISITS_USER);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    final ExternalVisitDto externalVisitDto = new ExternalVisitDto();
    externalVisitDto.setPersonUuid(contactPerson.getUuid());
    externalVisitDto.setDisease(contact.getDisease());
    externalVisitDto.setVisitDateTime(new Date());
    externalVisitDto.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks = "Everything good";
    externalVisitDto.setVisitRemarks(visitRemarks);
    final ExternalVisitDto externalVisitDto2 = new ExternalVisitDto();
    externalVisitDto2.setPersonUuid(cazePerson.getUuid());
    externalVisitDto2.setDisease(caze.getDisease());
    externalVisitDto2.setVisitDateTime(new Date());
    externalVisitDto2.setVisitStatus(VisitStatus.COOPERATIVE);
    final String visitRemarks2 = "Everything good 2";
    externalVisitDto2.setVisitRemarks(visitRemarks2);
    final VisitFacade visitFacade = getVisitFacade();
    visitFacade.saveExternalVisit(externalVisitDto);
    visitFacade.saveExternalVisit(externalVisitDto2);
    final VisitCriteria visitCriteria = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList = visitFacade.getIndexList(visitCriteria.contact(new ContactReferenceDto(contact.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList);
    assertEquals(1, visitIndexList.size());
    VisitIndexDto visitIndexDto = visitIndexList.get(0);
    assertNotNull(visitIndexDto.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto.getVisitStatus());
    assertEquals(visitRemarks, visitIndexDto.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
    final VisitCriteria visitCriteria2 = new VisitCriteria();
    final List<VisitIndexDto> visitIndexList2 = visitFacade.getIndexList(visitCriteria2.caze(new CaseReferenceDto(caze.getUuid())), 0, 100, null);
    assertNotNull(visitIndexList2);
    assertEquals(1, visitIndexList2.size());
    VisitIndexDto visitIndexDto2 = visitIndexList2.get(0);
    assertNotNull(visitIndexDto2.getVisitDateTime());
    assertEquals(VisitStatus.COOPERATIVE, visitIndexDto2.getVisitStatus());
    assertEquals(visitRemarks2, visitIndexDto2.getVisitRemarks());
    assertEquals(VisitOrigin.EXTERNAL_JOURNAL, visitIndexDto.getOrigin());
}
Also used : ExternalVisitDto(de.symeda.sormas.api.visit.ExternalVisitDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) VisitIndexDto(de.symeda.sormas.api.visit.VisitIndexDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) VisitCriteria(de.symeda.sormas.api.visit.VisitCriteria) VisitFacade(de.symeda.sormas.api.visit.VisitFacade) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with CaseReferenceDto

use of de.symeda.sormas.api.caze.CaseReferenceDto 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 3 with CaseReferenceDto

use of de.symeda.sormas.api.caze.CaseReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjb method convertToReferenceDto.

public CaseReferenceDto convertToReferenceDto(Case source) {
    CaseReferenceDto dto = toReferenceDto(source);
    if (dto != null) {
        boolean inJurisdiction = service.inJurisdictionOrOwned(source);
        Pseudonymizer.getDefault(userService::hasRight).pseudonymizeDto(CaseReferenceDto.class, dto, inJurisdiction, null);
    }
    return dto;
}
Also used : CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Example 4 with CaseReferenceDto

use of de.symeda.sormas.api.caze.CaseReferenceDto 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 5 with CaseReferenceDto

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

Aggregations

CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)47 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)21 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)19 Date (java.util.Date)19 ContactDto (de.symeda.sormas.api.contact.ContactDto)17 EventParticipantReferenceDto (de.symeda.sormas.api.event.EventParticipantReferenceDto)15 SampleDto (de.symeda.sormas.api.sample.SampleDto)15 PersonDto (de.symeda.sormas.api.person.PersonDto)14 Disease (de.symeda.sormas.api.Disease)13 ArrayList (java.util.ArrayList)13 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)12 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)11 List (java.util.List)11 Strings (de.symeda.sormas.api.i18n.Strings)10 DataHelper (de.symeda.sormas.api.utils.DataHelper)10 LocalDate (java.time.LocalDate)10 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)9 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)9 Collectors (java.util.stream.Collectors)9 Captions (de.symeda.sormas.api.i18n.Captions)8