CaseFacadeEjb implements CaseFacade { @Override public void mergeCase(String leadUuid, String otherUuid) { mergeCase(getCaseDataWithoutPseudonyimization(leadUuid), getCaseDataWithoutPseudonyimization(otherUuid), false); }  @Override List<CaseDataDto> getAllActiveCasesAfter(Date date); @Override List<CaseDataDto> getAllActiveCasesAfter(Date date, boolean includeExtendedChangeDateFilters); @Override List<CaseDataDto> getByUuids(List<String> uuids); @Override String getUuidByUuidEpidNumberOrExternalId(String searchTerm); @Override long count(CaseCriteria caseCriteria); @Override List<CaseIndexDto> getIndexList(CaseCriteria caseCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override List<CaseIndexDetailedDto> getIndexDetailedList(CaseCriteria caseCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) List<CaseExportDto> getExportList(
		CaseCriteria caseCriteria,
		CaseExportType exportType,
		int first,
		int max,
		ExportConfigurationDto exportConfiguration,
		Language userLanguage); @Override List<String> getAllActiveUuids(); @Override List<DashboardCaseDto> getCasesForDashboard(CaseCriteria caseCriteria); List<DashboardQuarantineDataDto> getQuarantineDataForDashBoard(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date from,
		Date to); long countCasesConvertedFromContacts(CaseCriteria caseCriteria); @Override List<MapCaseDto> getCasesForMap(RegionReferenceDto regionRef, DistrictReferenceDto districtRef, Disease disease, Date from, Date to); @Override List<CaseDataDto> getAllCasesOfPerson(String personUuid); @Override Map<CaseClassification, Long> getCaseCountPerClassification(
		CaseCriteria caseCriteria,
		boolean excludeSharedCases,
		boolean excludeCasesFromContacts); @Override Map<PresentCondition, Long> getCaseCountPerPersonCondition(
		CaseCriteria caseCriteria,
		boolean excludeSharedCases,
		boolean excludeCasesFromContacts); @Override Map<Disease, Long> getCaseCountByDisease(CaseCriteria caseCriteria, boolean excludeSharedCases, boolean excludeCasesFromContacts); @Override List<CaseReferenceDto> getRandomCaseReferences(CaseCriteria criteria, int count); Map<Disease, District> getLastReportedDistrictByDisease(
		CaseCriteria caseCriteria,
		boolean excludeSharedCases,
		boolean excludeCasesFromContacts); @Override List<CaseIndexDto> getSimilarCases(CaseSimilarityCriteria criteria); @Override List<CaseIndexDto[]> getCasesForDuplicateMerging(CaseCriteria criteria, boolean ignoreRegion); void updateCompleteness(String caseUuid); @Override String getLastReportedDistrictName(CaseCriteria caseCriteria, boolean excludeSharedCases, boolean excludeCasesFromContacts); @Override CaseDataDto getCaseDataByUuid(String uuid); @Override CaseReferenceDto getReferenceByUuid(String uuid); @Override CaseDataDto saveCase(CaseDataDto dto); CaseDataDto saveCase(CaseDataDto dto, boolean handleChanges); @Override void setSampleAssociations(ContactReferenceDto sourceContact, CaseReferenceDto cazeRef); @Override void setSampleAssociations(EventParticipantReferenceDto sourceEventParticipant, CaseReferenceDto cazeRef); @Override void setSampleAssociationsUnrelatedDisease(EventParticipantReferenceDto sourceEventParticipant, CaseReferenceDto cazeRef); @Override void validate(CaseDataDto caze); @Override void archiveOrDearchiveCase(String caseUuid, boolean archive); void onCaseChanged(CaseDataDto existingCase, Case newCase); void setResponsibleSurveillanceOfficer(Case caze); void reassignTasks(Case caze); @Override String generateEpidNumber(CaseReferenceDto caze); String generateEpidNumber(Case caze); @Override void deleteCase(String caseUuid); @Override void deleteCaseAsDuplicate(String caseUuid, String duplicateOfCaseUuid); @Override List<String> getArchivedUuidsSince(Date since); @Override List<String> getDeletedUuidsSince(Date since); Case fillOrBuildEntity(@NotNull CaseDataDto source, Case target); CaseDataDto convertToDto(Case source, Pseudonymizer pseudonymizer); CaseReferenceDto convertToReferenceDto(Case source); static CaseReferenceDto toReferenceDto(Case entity); static CaseDataDto toDto(Case source); void updateInvestigationByStatus(CaseDataDto existingCase, Case caze); void updateInvestigationByTask(Case caze); @Override boolean doesEpidNumberExist(String epidNumber, String caseUuid, Disease caseDisease); @Override List<Pair<DistrictDto, BigDecimal>> getCaseMeasurePerDistrict(Date fromDate, Date toDate, Disease disease, CaseMeasure caseMeasure); @Override Date getOldestCaseOnsetDate(); @Override Date getOldestCaseReportDate(); @Override boolean isArchived(String caseUuid); @Override boolean isDeleted(String caseUuid); @Override void mergeCase(String leadUuid, String otherUuid); @Override CaseDataDto cloneCase(CaseDataDto existingCaseDto); @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void archiveAllArchivableCases(int daysAfterCaseGetsArchived); @Override void updateArchived(List<String> caseUuids, boolean archived); @Override boolean exists(String uuid); @Override boolean hasPositiveLabResult(String caseUuid); @Override List<CaseFollowUpDto> getCaseFollowUpList(
		CaseCriteria caseCriteria,
		Date referenceDate,
		int interval,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); Boolean isCaseEditAllowed(String caseUuid);  }
@Test public void testMergeCase() { useNationalUserLogin(); UserDto leadUser = creator.createUser("", "", "", "", ""); 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); leadCase.setClinicianEmail("mail"); getCaseFacade().saveCase(leadCase); VisitDto leadVisit = creator.createVisit(leadCase.getDisease(), leadCase.getPerson(), leadCase.getReportDate()); leadVisit.getSymptoms().setAnorexiaAppetiteLoss(SymptomState.YES); getVisitFacade().saveVisit(leadVisit); UserDto otherUser = creator.createUser("", "", "", "", ""); 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(); CaseDataDto otherCase = creator.createCase( otherUserReference, otherPersonReference, Disease.CHOLERA, CaseClassification.SUSPECT, InvestigationStatus.PENDING, new Date(), otherRdcf); 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); getCaseFacade().saveCase(otherCase); VisitDto otherVisit = creator.createVisit(otherCase.getDisease(), otherCase.getPerson(), otherCase.getReportDate()); otherVisit.getSymptoms().setAbdominalPain(SymptomState.YES); getVisitFacade().saveVisit(otherVisit); getCaseFacade().mergeCase(leadCase.getUuid(), otherCase.getUuid()); CaseDataDto mergedCase = getCaseFacade().getCaseDataByUuid(leadCase.getUuid()); assertNull(mergedCase.getClassificationComment()); assertEquals(leadCase.getDisease(), mergedCase.getDisease()); assertEquals(leadCase.getClinicianEmail(), mergedCase.getClinicianEmail()); assertEquals(otherCase.getClinicianName(), mergedCase.getClinicianName()); PersonDto mergedPerson = getPersonFacade().getPersonByUuid(mergedCase.getPerson().getUuid()); assertNull(mergedPerson.getBirthdateDD()); assertEquals(leadCase.getPerson().getFirstName(), mergedPerson.getFirstName()); assertEquals(leadCase.getPerson().getLastName(), mergedPerson.getLastName()); assertEquals(otherPerson.getBirthWeight(), mergedPerson.getBirthWeight()); List<String> contactUuids = new ArrayList<String>(); contactUuids.add(contact.getUuid()); assertEquals(leadCase.getUuid(), getContactFacade().getByUuids(contactUuids).get(0).getCaze().getUuid()); List<String> sampleUuids = new ArrayList<String>(); sampleUuids.add(sample.getUuid()); assertEquals(leadCase.getUuid(), getSampleFacade().getByUuids(sampleUuids).get(0).getAssociatedCase().getUuid()); List<String> taskUuids = new ArrayList<String>(); taskUuids.add(task.getUuid()); assertEquals(leadCase.getUuid(), getTaskFacade().getByUuids(taskUuids).get(0).getCaze().getUuid()); List<String> treatmentUuids = new ArrayList<String>(); treatmentUuids.add(treatment.getUuid()); assertEquals(leadCase.getTherapy().getUuid(), getTreatmentFacade().getByUuids(treatmentUuids).get(0).getTherapy().getUuid()); List<String> prescriptionUuids = new ArrayList<String>(); prescriptionUuids.add(prescription.getUuid()); assertEquals(leadCase.getTherapy().getUuid(), getPrescriptionFacade().getByUuids(prescriptionUuids).get(0).getTherapy().getUuid()); List<String> visitUuids = new ArrayList<String>(); visitUuids.add(visit.getUuid()); assertEquals(leadCase.getClinicalCourse().getUuid(), getClinicalVisitFacade().getByUuids(visitUuids).get(0).getClinicalCourse().getUuid()); 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())); assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAbdominalPain()); assertEquals(SymptomState.YES, mergedCase.getSymptoms().getAnorexiaAppetiteLoss()); assertTrue(mergedCase.getSymptoms().getSymptomatic()); }