Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit fe22d5e

Browse files
author
Jonas Cirotzki
committed
[SORMAS-Foundation#4247] add threshold query
1 parent d26e93c commit fe22d5e

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import javax.validation.constraints.NotNull;
7373

7474
import org.apache.commons.lang3.StringUtils;
75+
import org.joda.time.DateTime;
7576
import org.slf4j.Logger;
7677
import org.slf4j.LoggerFactory;
7778

@@ -3508,13 +3509,32 @@ public List<CasePersonDto> getDuplicates(CasePersonDto casePerson, int reportDat
35083509
and(cb, personPredicate, or(cb, cb.isNull(person.get(Person.SEX)), cb.equal(person.get(Person.SEX), searchPerson.getSex())));
35093510
}
35103511

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+
35113533
combinedPredicate = and(
35123534
cb,
35133535
personPredicate,
35143536
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,
35183538
cb.equal(caseCaseJoins.getDistrict().get(District.UUID), searchCaze.getDistrict().getUuid()));
35193539
}
35203540

0 commit comments

Comments
 (0)