Skip to content

Commit

Permalink
#10987 Fixed filter 'only cases changed since last shared with report…
Browse files Browse the repository at this point in the history
…ing tool' (#10996)

* #10987 [SurvNet] Filter 'only cases changed since last shared with reporting tool' does not work

* #10987 [SurvNet] Filter 'only cases changed since last shared with reporting tool' does not work - use constant in tests

* #10987 [SurvNet] Filter 'only cases changed since last shared with reporting tool' does not work - uncomment code

Co-authored-by: Levente Gal <[email protected]>
  • Loading branch information
leventegal-she and Levente Gal authored Nov 24, 2022
1 parent b532a87 commit 9d65bf4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.vladmihalcea.hibernate.type.json.JsonStringType;

import de.symeda.sormas.backend.vaccination.VaccinationService;

public class ExtendedPostgreSQL94Dialect extends PostgreSQL94Dialect {

public final static String SIMILARITY_OPERATOR = "similarity_operator";
Expand All @@ -24,7 +26,7 @@ public class ExtendedPostgreSQL94Dialect extends PostgreSQL94Dialect {
public final static String WINDOW_FIRST_VALUE_DESC = "window_first_value_desc";
public final static String WINDOW_COUNT = "window_count";
public final static String GREATEST = "greatest";
public final static String TIMESTAMP_SUBTRACT_DAYS = "timestamp_subtract_days";
public final static String TIMESTAMP_SUBTRACT_14_DAYS = "timestamp_subtract_14_days";
public final static String AT_END_OF_DAY = "at_end_of_day";

public ExtendedPostgreSQL94Dialect() {
Expand All @@ -51,7 +53,9 @@ public ExtendedPostgreSQL94Dialect() {
registerFunction(GREATEST, new StandardSQLFunction(GREATEST));
registerFunction(ARRAY_CONTAINS_TEXT, new SQLFunctionTemplate(StandardBasicTypes.BOOLEAN, "?1 @> array[?2]::text[]"));
registerFunction(JSON_EXTRACT_PATH_TEXT, new SQLFunctionTemplate(StandardBasicTypes.STRING, "json_extract_path_text(?1, ?2)"));
registerFunction(TIMESTAMP_SUBTRACT_DAYS, new SQLFunctionTemplate(StandardBasicTypes.DATE, "?1 - interval '?2 days'"));
registerFunction(
TIMESTAMP_SUBTRACT_14_DAYS,
new SQLFunctionTemplate(StandardBasicTypes.DATE, "?1 - interval '" + VaccinationService.REPORT_DATE_RELEVANT_DAYS + " days'"));
registerFunction(AT_END_OF_DAY, new SQLFunctionTemplate(StandardBasicTypes.DATE, "?1::date + interval '1 day' - interval '1 microsecond'"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public <T extends AbstractDomainObject> Predicate createCriteriaFilter(CaseCrite
cb,
from,
ExternalShareInfo.CAZE,
(latestShareDate) -> createChangeDateFilter(cq, cb, from, latestShareDate, true, true)));
(latestShareDate) -> createChangeDateFilter(cq, cb, from, joins, latestShareDate, true, true)));

return filter;
}
Expand Down Expand Up @@ -1224,19 +1224,15 @@ private Predicate createChangeDateFilter(
CriteriaQuery<?> cq,
CriteriaBuilder cb,
From<?, Case> casePath,
CaseJoins joins,
Expression<? extends Date> dateExpression,
boolean includeExtendedChangeDateFilters,
boolean includeRelevantVaccinations) {

ChangeDateFilterBuilder builder = addChangeDates(new ChangeDateFilterBuilder(cb, dateExpression), casePath, includeExtendedChangeDateFilters);

if (includeRelevantVaccinations) {
Subquery<Symptoms> symptomsSq = cq.subquery(Symptoms.class);
Root<Symptoms> symptomsSqRoot = symptomsSq.from(Symptoms.class);
symptomsSq.select(symptomsSqRoot.get(Symptoms.ONSET_DATE));
symptomsSq.where(cb.equal(symptomsSqRoot, casePath.get(Case.SYMPTOMS)));

Join<Person, Immunization> immunizationJoin = casePath.join(Case.PERSON, JoinType.LEFT).join(Person.IMMUNIZATIONS, JoinType.LEFT);
Join<Person, Immunization> immunizationJoin = joins.getPersonJoins().getImmunization();
Join<Immunization, Vaccination> vaccinationsJoin = immunizationJoin.join(Immunization.VACCINATIONS, JoinType.LEFT);

builder.add(vaccinationsJoin.on(vaccinationService.getRelevantVaccinationPredicate(casePath, cq, cb, vaccinationsJoin)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public Predicate buildLatestSurvToolShareDateFilter(
String associatedObjectName,
Function<Expression<Date>, Predicate> shareDatePredicateBuilder) {

Subquery<Timestamp> survToolShareSubQuery = cq.subquery(Timestamp.class);
Subquery<Object> survToolShareSubQuery = cq.subquery(Object.class);
Root<ExternalShareInfo> survToolShareRoot = survToolShareSubQuery.from(ExternalShareInfo.class);
Join<ExternalShareInfo, ?> associatedObject = survToolShareRoot.join(associatedObjectName, JoinType.LEFT);
@SuppressWarnings({
Expand All @@ -271,7 +271,7 @@ public Predicate buildLatestSurvToolShareDateFilter(
// double conversion because hibernate doesn't know the `max` function for timestamps
(Expression<Date>) ((Expression) cb.max(survToolShareRoot.get(ExternalShareInfo.CREATION_DATE)));

Path<Timestamp> associatedObjectId = associatedObject.get(AbstractDomainObject.ID);
Path<Object> associatedObjectId = associatedObject.get(AbstractDomainObject.ID);

survToolShareSubQuery.select(associatedObjectId);
survToolShareSubQuery.where(cb.equal(associatedObject, from.get(AbstractDomainObject.ID)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package de.symeda.sormas.backend.vaccination;

import static de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect.AT_END_OF_DAY;
import static de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect.TIMESTAMP_SUBTRACT_DAYS;
import static de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect.TIMESTAMP_SUBTRACT_14_DAYS;

import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -291,7 +291,7 @@ public Predicate getRelevantVaccinationPredicate(
Expression<Date> vaccinationDateExpr = cb.<Date> selectCase()
.when(
cb.isNull(vaccinationDate),
cb.function(TIMESTAMP_SUBTRACT_DAYS, Date.class, vaccinationPath.get(Vaccination.REPORT_DATE), cb.literal(REPORT_DATE_RELEVANT_DAYS)))
cb.function(TIMESTAMP_SUBTRACT_14_DAYS, Date.class, vaccinationPath.get(Vaccination.REPORT_DATE)))
.otherwise(vaccinationDate);

return getRelevantVaccinationPredicate(cb, vaccinationDateExpr, primaryDatePath, fallbackDatePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;

import de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal;
import org.junit.Before;

import de.symeda.sormas.api.ConfigFacade;
Expand Down Expand Up @@ -204,6 +203,7 @@
import de.symeda.sormas.backend.sormastosormas.entities.immunization.SormasToSormasImmunizationDtoValidator;
import de.symeda.sormas.backend.sormastosormas.entities.sample.ReceivedSampleProcessor;
import de.symeda.sormas.backend.sormastosormas.entities.sample.SormasToSormasSampleDtoValidator;
import de.symeda.sormas.backend.sormastosormas.origin.SormasToSormasOriginInfoFacadeEjb.SormasToSormasOriginInfoFacadeEjbLocal;
import de.symeda.sormas.backend.sormastosormas.share.ShareDataBuilderHelper;
import de.symeda.sormas.backend.sormastosormas.share.incoming.SormasToSormasShareRequestFacadeEJB.SormasToSormasShareRequestFacadeEJBLocal;
import de.symeda.sormas.backend.sormastosormas.share.incoming.SormasToSormasShareRequestService;
Expand Down Expand Up @@ -287,7 +287,7 @@ protected void initH2Functions() {
nativeQuery = em.createNativeQuery("CREATE ALIAS date FOR \"de.symeda.sormas.backend.H2Function.date\"");
nativeQuery.executeUpdate();
nativeQuery =
em.createNativeQuery("CREATE ALIAS timestamp_subtract_days FOR \"de.symeda.sormas.backend.H2Function.timestamp_subtract_days\"");
em.createNativeQuery("CREATE ALIAS timestamp_subtract_14_days FOR \"de.symeda.sormas.backend.H2Function.timestamp_subtract_14_days\"");
nativeQuery.executeUpdate();
nativeQuery = em.createNativeQuery("CREATE ALIAS at_end_of_day FOR \"de.symeda.sormas.backend.H2Function.at_end_of_day\"");
nativeQuery.executeUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import de.symeda.sormas.api.utils.DateHelper;
import de.symeda.sormas.api.utils.UtilDate;
import de.symeda.sormas.backend.vaccination.VaccinationService;

/**
* When extending this class make sure to also extend {@link AbstractBeanTest#initH2Functions()} and {@link ExtendedH2Dialect}.
Expand Down Expand Up @@ -45,8 +46,8 @@ public static Date date(Date timestamp) {
return DateHelper.getStartOfDay(timestamp);
}

public static Date timestamp_subtract_days(Date timestamp, int days) {
return DateHelper.subtractDays(timestamp, days);
public static Date timestamp_subtract_14_days(Date timestamp) {
return DateHelper.subtractDays(timestamp, VaccinationService.REPORT_DATE_RELEVANT_DAYS);
}

public static Date at_end_of_day(Date timestamp) {
Expand Down

0 comments on commit 9d65bf4

Please sign in to comment.