|
72 | 72 | import javax.validation.constraints.NotNull; |
73 | 73 |
|
74 | 74 | import org.apache.commons.lang3.StringUtils; |
| 75 | +import org.joda.time.DateTime; |
75 | 76 | import org.slf4j.Logger; |
76 | 77 | import org.slf4j.LoggerFactory; |
77 | 78 |
|
@@ -3508,13 +3509,32 @@ public List<CasePersonDto> getDuplicates(CasePersonDto casePerson, int reportDat |
3508 | 3509 | and(cb, personPredicate, or(cb, cb.isNull(person.get(Person.SEX)), cb.equal(person.get(Person.SEX), searchPerson.getSex()))); |
3509 | 3510 | } |
3510 | 3511 |
|
| 3512 | + Predicate reportDatePredicate; |
| 3513 | + |
| 3514 | + if (reportDateThreshold == 0){ |
| 3515 | + // threshold is zero: we want to get exact matches |
| 3516 | + reportDatePredicate = cb.equal( |
| 3517 | + cb.function("date", Date.class, caseRoot.get(Case.REPORT_DATE)), |
| 3518 | + cb.function("date", Date.class, cb.literal(searchCaze.getReportDate())) |
| 3519 | + ); |
| 3520 | + } else{ |
| 3521 | + // threshold is nonzero: apply time range of threshold to the reportDate |
| 3522 | + Date reportDate = casePerson.getCaze().getReportDate(); |
| 3523 | + Date dateBefore = new DateTime(reportDate).minusDays(reportDateThreshold).toDate(); |
| 3524 | + Date dateAfter= new DateTime(reportDate).plusDays(reportDateThreshold).toDate();; |
| 3525 | + |
| 3526 | + reportDatePredicate = cb.between( |
| 3527 | + cb.function("date", Date.class, caseRoot.get(Case.REPORT_DATE)), |
| 3528 | + cb.function("date", Date.class, cb.literal(dateBefore)), |
| 3529 | + cb.function("date", Date.class, cb.literal(dateAfter)) |
| 3530 | + ); |
| 3531 | + } |
| 3532 | + |
3511 | 3533 | combinedPredicate = and( |
3512 | 3534 | cb, |
3513 | 3535 | personPredicate, |
3514 | 3536 | cb.equal(caseRoot.get(Case.DISEASE), searchCaze.getDisease()), |
3515 | | - cb.equal( |
3516 | | - cb.function("date", Date.class, caseRoot.get(Case.REPORT_DATE)), |
3517 | | - cb.function("date", Date.class, cb.literal(searchCaze.getReportDate()))), |
| 3537 | + reportDatePredicate, |
3518 | 3538 | cb.equal(caseCaseJoins.getDistrict().get(District.UUID), searchCaze.getDistrict().getUuid())); |
3519 | 3539 | } |
3520 | 3540 |
|
|
0 commit comments