|
27 | 27 | import static org.junit.Assert.assertThat; |
28 | 28 | import static org.junit.Assert.assertTrue; |
29 | 29 |
|
| 30 | +import java.sql.Timestamp; |
30 | 31 | import java.time.LocalDate; |
31 | 32 | import java.util.ArrayList; |
32 | 33 | import java.util.Arrays; |
|
36 | 37 | import java.util.List; |
37 | 38 | import java.util.stream.Collectors; |
38 | 39 |
|
39 | | -import de.symeda.sormas.api.VisitOrigin; |
40 | | -import de.symeda.sormas.api.messaging.MessageType; |
| 40 | +import org.apache.commons.lang3.time.DateUtils; |
| 41 | +import org.hibernate.internal.SessionImpl; |
| 42 | +import org.hibernate.query.spi.QueryImplementor; |
41 | 43 | import org.junit.Assert; |
42 | 44 | import org.junit.Rule; |
43 | 45 | import org.junit.Test; |
44 | 46 | import org.junit.rules.ExpectedException; |
45 | 47 |
|
46 | 48 | import de.symeda.sormas.api.Disease; |
47 | 49 | import de.symeda.sormas.api.Language; |
| 50 | +import de.symeda.sormas.api.VisitOrigin; |
48 | 51 | import de.symeda.sormas.api.caze.CaseClassification; |
49 | 52 | import de.symeda.sormas.api.caze.CaseCriteria; |
50 | 53 | import de.symeda.sormas.api.caze.CaseDataDto; |
|
72 | 75 | import de.symeda.sormas.api.exposure.ExposureType; |
73 | 76 | import de.symeda.sormas.api.facility.FacilityReferenceDto; |
74 | 77 | import de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto; |
| 78 | +import de.symeda.sormas.api.messaging.MessageType; |
75 | 79 | import de.symeda.sormas.api.person.PersonDto; |
76 | 80 | import de.symeda.sormas.api.person.PersonReferenceDto; |
77 | 81 | import de.symeda.sormas.api.person.PresentCondition; |
@@ -116,6 +120,52 @@ public class CaseFacadeEjbTest extends AbstractBeanTest { |
116 | 120 | @Rule |
117 | 121 | public final ExpectedException exception = ExpectedException.none(); |
118 | 122 |
|
| 123 | + @Test |
| 124 | + public void testGetCasesForDuplicateMerging() { |
| 125 | + |
| 126 | + final Date today = new Date(); |
| 127 | + final Date threeDaysAgo = DateUtils.addDays(today, -3); |
| 128 | + |
| 129 | + RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility"); |
| 130 | + UserDto user = creator |
| 131 | + .createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); |
| 132 | + PersonDto cazePerson = creator.createPerson("Case", "Person"); |
| 133 | + CaseDataDto caze = creator.createCase( |
| 134 | + user.toReference(), |
| 135 | + cazePerson.toReference(), |
| 136 | + Disease.EVD, |
| 137 | + CaseClassification.PROBABLE, |
| 138 | + InvestigationStatus.PENDING, |
| 139 | + today, |
| 140 | + rdcf); |
| 141 | + |
| 142 | + SessionImpl em = (SessionImpl) getEntityManager(); |
| 143 | + QueryImplementor query = em.createQuery("select c from cases c where c.uuid=:uuid"); |
| 144 | + query.setParameter("uuid", caze.getUuid()); |
| 145 | + Case singleResult = (Case) query.getSingleResult(); |
| 146 | + |
| 147 | + singleResult.setCreationDate(new Timestamp(threeDaysAgo.getTime())); |
| 148 | + singleResult.setReportDate(threeDaysAgo); |
| 149 | + em.save(singleResult); |
| 150 | + |
| 151 | + PersonDto cazePerson2 = creator.createPerson("Case", "Person"); |
| 152 | + CaseDataDto case2 = creator.createCase( |
| 153 | + user.toReference(), |
| 154 | + cazePerson2.toReference(), |
| 155 | + Disease.EVD, |
| 156 | + CaseClassification.PROBABLE, |
| 157 | + InvestigationStatus.PENDING, |
| 158 | + DateUtils.addMinutes(today, -3), |
| 159 | + rdcf); |
| 160 | + |
| 161 | + final List<CaseIndexDto[]> casesForDuplicateMergingToday = |
| 162 | + getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(today).creationDateTo(today), true); |
| 163 | + final List<CaseIndexDto[]> casesForDuplicateMergingThreeDaysAgo = |
| 164 | + getCaseFacade().getCasesForDuplicateMerging(new CaseCriteria().creationDateFrom(threeDaysAgo).creationDateTo(threeDaysAgo), true); |
| 165 | + Assert.assertEquals(1, casesForDuplicateMergingToday.size()); |
| 166 | + Assert.assertEquals(1, casesForDuplicateMergingThreeDaysAgo.size()); |
| 167 | + } |
| 168 | + |
119 | 169 | @Test |
120 | 170 | public void testDiseaseChangeUpdatesContacts() { |
121 | 171 |
|
|
0 commit comments