Skip to content

Commit

Permalink
#13086 - Add filters and search functionality to the Self Reporting (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carina29 authored May 14, 2024
1 parent 2b842ed commit 5c4bd57
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,11 @@ public interface Strings {
String promptSamplesSearchField = "promptSamplesSearchField";
String promptSearch = "promptSearch";
String promptSelectPeriod = "promptSelectPeriod";
String promptSelfReportDateFrom = "promptSelfReportDateFrom";
String promptSelfReportDateTo = "promptSelfReportDateTo";
String promptSelfReportEpiWeekFrom = "promptSelfReportEpiWeekFrom";
String promptSelfReportEpiWeekTo = "promptSelfReportEpiWeekTo";
String promptSelfReportFreeTextSearch = "promptSelfReportFreeTextSearch";
String promptTaskDateFrom = "promptTaskDateFrom";
String promptTaskDateTo = "promptTaskDateTo";
String promptTaskDateType = "promptTaskDateType";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,72 @@

package de.symeda.sormas.api.selfreport;

import java.io.Serializable;
import java.util.Date;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.disease.DiseaseVariant;
import de.symeda.sormas.api.utils.DateFilterOption;
import de.symeda.sormas.api.utils.IgnoreForUrl;
import de.symeda.sormas.api.utils.criteria.BaseCriteria;

public class SelfReportCriteria extends BaseCriteria {
public class SelfReportCriteria extends BaseCriteria implements Serializable {

public static final String FREE_TEXT = "freeText";
public static final String TYPE = "type";
public static final String DISEASE = "disease";
public static final String DISEASE_VARIANT = "diseaseVariant";
public static final String REPORT_DATE = "reportDate";
private static final long serialVersionUID = 7245463026500908524L;

private String freeText;
private SelfReportType type;
private Disease disease;
private DiseaseVariant diseaseVariant;
private SelfReportInvestigationStatus investigationStatus;
private EntityRelevanceStatus relevanceStatus;
private DateFilterOption dateFilterOption = DateFilterOption.DATE;
private Date reportDateFrom;
private Date reportDateTo;

@IgnoreForUrl
public String getFreeText() {
return freeText;
}

public SelfReportCriteria freeText(String freeText) {
this.freeText = freeText;
return this;
}

public void setFreeText(String freeText) {
this.freeText = freeText;
}

public SelfReportType getType() {
return type;
}

public void setType(SelfReportType type) {
this.type = type;
}

public Disease getDisease() {
return disease;
}

public void setDisease(Disease disease) {
this.disease = disease;
}

public DiseaseVariant getDiseaseVariant() {
return diseaseVariant;
}

public void setDiseaseVariant(DiseaseVariant diseaseVariant) {
this.diseaseVariant = diseaseVariant;
}

public SelfReportInvestigationStatus getInvestigationStatus() {
return investigationStatus;
Expand All @@ -33,6 +90,7 @@ public void setInvestigationStatus(SelfReportInvestigationStatus investigationSt
this.investigationStatus = investigationStatus;
}

@IgnoreForUrl
public EntityRelevanceStatus getRelevanceStatus() {
return relevanceStatus;
}
Expand All @@ -45,4 +103,34 @@ public SelfReportCriteria relevanceStatus(EntityRelevanceStatus relevanceStatus)
setRelevanceStatus(relevanceStatus);
return this;
}

public DateFilterOption getDateFilterOption() {
return dateFilterOption;
}

public void setDateFilterOption(DateFilterOption dateFilterOption) {
this.dateFilterOption = dateFilterOption;
}

public Date getReportDateFrom() {
return reportDateFrom;
}

public void setReportDateFrom(Date reportDateFrom) {
this.reportDateFrom = reportDateFrom;
}

public Date getReportDateTo() {
return reportDateTo;
}

public void setReportDateTo(Date reportDateTo) {
this.reportDateTo = reportDateTo;
}

public void reportDateBetween(Date reportDateFrom, Date reportDateTo, DateFilterOption dateFilterOption) {
this.reportDateFrom = reportDateFrom;
this.reportDateTo = reportDateTo;
this.dateFilterOption = dateFilterOption;
}
}
8 changes: 7 additions & 1 deletion sormas-api/src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,12 @@ promptTypeToAdd = Type here to add...
promptUserSearch = Search user
promptFilterByPeriod = Filter by period
promptSelectPeriod = Select period
promptSelfReportDateFrom = Report date from...
promptSelfReportDateTo = ... to
promptSelfReportEpiWeekFrom = Report date from epi week...
promptSelfReportEpiWeekTo = Report date to epi week...
promptSelfReportFreeTextSearch = Case reference/ name/ contact information/ NationalHealthID

promptCampaign = Campaign
promptArea = Area
promptAllAreas=All areas
Expand Down Expand Up @@ -1794,4 +1800,4 @@ confirmationBulkGrantSpecialAccess = The selected user already has special acces
headingBulkSpecialCaseAccessSomeNotProcessed= Granted special access to some of the selected cases
headingBulkSpecialCaseAccessNoneProcessed = Not granted special access to any of the selected cases
messageBulkSpecialCaseAccessAllProcessed = Granted special access to all selected cases
messageCountAccessesNotGrantedDueToError=%s cases have not been processed: %s
messageCountAccessesNotGrantedDueToError=%s cases have not been processed: %s
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;

import org.apache.commons.lang3.StringUtils;

import de.symeda.sormas.api.EntityRelevanceStatus;
import de.symeda.sormas.api.common.DeletableEntityType;
import de.symeda.sormas.api.selfreport.SelfReportCriteria;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.backend.common.AbstractCoreAdoService;
import de.symeda.sormas.backend.common.CriteriaBuilderHelper;
import de.symeda.sormas.backend.location.Location;

@Stateless
@LocalBean
Expand Down Expand Up @@ -62,9 +67,53 @@ public Predicate buildCriteriaFilter(SelfReportCriteria criteria, SelfReportQuer

CriteriaBuilder cb = selfReportQueryContext.getCriteriaBuilder();
From<?, SelfReport> from = selfReportQueryContext.getRoot();
final SelfReportJoins joins = selfReportQueryContext.getJoins();
Join<SelfReport, Location> location = joins.getAddress();

Predicate filter = null;

if (StringUtils.isNotEmpty(criteria.getFreeText())) {
String[] textFilters = criteria.getFreeText().split("\\s+");
for (String textFilter : textFilters) {
if (DataHelper.isNullOrEmpty(textFilter)) {
continue;
}

Predicate likeFilters = cb.or(
CriteriaBuilderHelper.ilike(cb, from.get(SelfReport.CASE_REFERENCE), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, from.get(SelfReport.FIRST_NAME), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, from.get(SelfReport.LAST_NAME), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, from.get(SelfReport.EMAIL), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, location.get(Location.STREET), textFilter),
CriteriaBuilderHelper.unaccentedIlike(cb, location.get(Location.CITY), textFilter),
CriteriaBuilderHelper.ilike(cb, location.get(Location.POSTAL_CODE), textFilter),
CriteriaBuilderHelper.ilike(cb, from.get(SelfReport.PHONE_NUMBER), textFilter),
CriteriaBuilderHelper.ilike(cb, from.get(SelfReport.NATIONAL_HEALTH_ID), textFilter));
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
}

if (criteria.getType() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(SelfReport.TYPE), criteria.getType()));
}

if (criteria.getDisease() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(SelfReport.DISEASE), criteria.getDisease()));
}

if (criteria.getDiseaseVariant() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(from.get(SelfReport.DISEASE_VARIANT), criteria.getDiseaseVariant()));
}

if (criteria.getReportDateFrom() != null && criteria.getReportDateTo() != null) {
filter = CriteriaBuilderHelper
.and(cb, filter, cb.between(from.get(SelfReport.REPORT_DATE), criteria.getReportDateFrom(), criteria.getReportDateTo()));
} else if (criteria.getReportDateFrom() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(from.get(SelfReport.REPORT_DATE), criteria.getReportDateFrom()));
} else if (criteria.getReportDateTo() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(from.get(SelfReport.REPORT_DATE), criteria.getReportDateTo()));
}

if (criteria.getRelevanceStatus() != null) {
if (criteria.getRelevanceStatus() == EntityRelevanceStatus.ACTIVE) {
filter = CriteriaBuilderHelper
Expand Down
Loading

0 comments on commit 5c4bd57

Please sign in to comment.