Skip to content

Commit

Permalink
Merge pull request #11776 from hzi-braunschweig/feature-7647_external…
Browse files Browse the repository at this point in the history
…_message_content_filter

#7647 [DEMIS2SORMAS] Introduce a messages content search field
  • Loading branch information
leventegal-she authored Apr 13, 2023
2 parents 17ccd76 + 29fa515 commit 3e23ad8
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ExternalMessageCriteria extends BaseCriteria implements Serializabl
public static final String I18N_PREFIX = "ExternalMessageCriteria";

public static final String SEARCH_FIELD_LIKE = "searchFieldLike";
public static final String MESSAGE_CONTENT_LIKE = "messageContentLike";
public static final String MESSAGE_DATE_FROM = "messageDateFrom";
public static final String MESSAGE_DATE_TO = "messageDateTo";
public static final String BIRTH_DATE_FROM = "birthDateFrom";
Expand All @@ -32,6 +33,7 @@ public class ExternalMessageCriteria extends BaseCriteria implements Serializabl
private SampleReferenceDto sample;
private SurveillanceReportReferenceDto surveillanceReport;
private String searchFieldLike;
private String messageContentLike;
private Date messageDateFrom;
private Date messageDateTo;
private Date birthDateFrom;
Expand Down Expand Up @@ -89,6 +91,14 @@ public void setSearchFieldLike(String searchFieldLike) {
this.searchFieldLike = searchFieldLike;
}

public String getMessageContentLike() {
return messageContentLike;
}

public void setMessageContentLike(String messageContentLike) {
this.messageContentLike = messageContentLike;
}

public Date getMessageDateFrom() {
return messageDateFrom;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ public interface Strings {
String promptEventsSearchFieldEventParticipants = "promptEventsSearchFieldEventParticipants";
String promptExternalIdExternalSurveillanceTool = "promptExternalIdExternalSurveillanceTool";
String promptExternalJournalForceDeletion = "promptExternalJournalForceDeletion";
String promptExternalMessagesContentSearchField = "promptExternalMessagesContentSearchField";
String promptExternalMessagesDateFrom = "promptExternalMessagesDateFrom";
String promptExternalMessagesDateTo = "promptExternalMessagesDateTo";
String promptExternalMessagesPersonBirthDateFrom = "promptExternalMessagesPersonBirthDateFrom";
Expand Down
1 change: 1 addition & 0 deletions sormas-api/src/main/resources/strings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ promptImmunizationDateTo = ... to
promptImmunizationEpiWeekFrom = New immunizations from epi week...
promptImmunizationEpiWeekTo = ... to epi week
promptExternalMessagesSearchField = UUID, name, postal code, reporter name, reporter postal code
promptExternalMessagesContentSearchField = External message content
promptExternalMessagesDateFrom = Message date from...
promptExternalMessagesDateTo = ... to
promptExternalMessagesPersonBirthDateFrom = Birth date from...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ExtendedPostgreSQL94Dialect extends PostgreSQL94Dialect {
public final static String GREATEST = "greatest";
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 final static String FULLTEXT_SEARCH = "fulltext_search";

public ExtendedPostgreSQL94Dialect() {
super();
Expand Down Expand Up @@ -57,5 +58,6 @@ public ExtendedPostgreSQL94Dialect() {
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'"));
registerFunction(FULLTEXT_SEARCH, new SQLFunctionTemplate(StandardBasicTypes.BOOLEAN, "?1 @@ plainto_tsquery('simple', unaccent(?2))"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public class ExternalMessage extends AbstractDomainObject {
public static final String PERSON_HOUSE_NUMBER = "personHouseNumber";
public static final String PERSON_PHONE = "personPhone";
public static final String PERSON_EMAIL = "personEmail";
public static final String REPORTER_MESSAGE_DETAILS = "externalMessageDetails";
public static final String EXTERNAL_MESSAGE_DETAILS = "externalMessageDetails";
public static final String STATUS = "status";
public static final String REPORT_ID = "reportId";
public static final String REPORT_MESSAGE_ID = "reportMessageId";
public static final String ASSIGNEE = "assignee";
public static final String SURVEILLANCE_REPORT = "surveillanceReport";
public static final String TSV = "tsv";

private ExternalMessageType type;
private Disease disease;
Expand Down Expand Up @@ -108,6 +109,7 @@ public class ExternalMessage extends AbstractDomainObject {

private List<SampleReport> sampleReports;
private SurveillanceReport surveillanceReport;
private String tsv;

@Enumerated(EnumType.STRING)
public ExternalMessageType getType() {
Expand Down Expand Up @@ -372,4 +374,13 @@ public List<SampleReport> getSampleReports() {
public void setSampleReports(List<SampleReport> sampleReports) {
this.sampleReports = sampleReports;
}

@Column
public String getTsv() {
return tsv;
}

public void setTsv(String tsv) {
this.tsv = tsv;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import de.symeda.sormas.api.ReferenceDto;
import de.symeda.sormas.api.caze.surveillancereport.SurveillanceReportReferenceDto;
import de.symeda.sormas.api.externalmessage.ExternalMessageCriteria;
import de.symeda.sormas.api.sample.SampleReferenceDto;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.backend.ExtendedPostgreSQL94Dialect;
import de.symeda.sormas.backend.caze.Case;
import de.symeda.sormas.backend.caze.surveillancereport.SurveillanceReport;
import de.symeda.sormas.backend.common.AbstractDomainObject;
Expand Down Expand Up @@ -125,6 +128,20 @@ public Predicate buildCriteriaFilter(CriteriaBuilder cb, Root<ExternalMessage> l
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
}
if (StringUtils.isNotBlank(criteria.getMessageContentLike())) {
filter = CriteriaBuilderHelper.and(
cb,
filter,
cb.equal(
cb.function(
ExtendedPostgreSQL94Dialect.FULLTEXT_SEARCH,
Boolean.class,
labMessage.get(ExternalMessage.TSV),
cb.literal(
// replace xml tag marks
criteria.getMessageContentLike().replaceAll("[<>]", " "))),
true));
}
if (criteria.getMessageDateFrom() != null) {
filter = CriteriaBuilderHelper
.and(cb, filter, cb.greaterThanOrEqualTo(labMessage.get(ExternalMessage.MESSAGE_DATE_TIME), criteria.getMessageDateFrom()));
Expand Down
19 changes: 19 additions & 0 deletions sormas-backend/src/main/resources/sql/sormas_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12326,4 +12326,23 @@ DROP INDEX idx_cases_disease;

INSERT INTO schema_version (version_number, comment) VALUES (512, 'Limit case duplicate merging comparison based on creation date and archived status #11465');

-- 2023-03-31 [DEMIS2SORMAS] Introduce a messages content search field #7647
ALTER TABLE externalmessage ADD COLUMN tsv tsvector;
ALTER TABLE externalmessage_history ADD COLUMN tsv tsvector;
UPDATE externalmessage SET tsv = to_tsvector('simple', unaccent(regexp_replace(externalmessagedetails, E'[<>]', ' ', 'g')));
CREATE INDEX idx_externalmessage_tsv ON externalmessage USING GIN (tsv);
CREATE OR REPLACE FUNCTION externalmessage_tsv_update() RETURNS TRIGGER AS $$
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
new.tsv = to_tsvector('simple', unaccent(regexp_replace(new.externalmessagedetails, E'[<>]', ' ', 'g')));
END IF;

RETURN new;
END
$$ LANGUAGE 'plpgsql';
CREATE TRIGGER externalmessage_tsv_update BEFORE INSERT OR UPDATE OF externalmessagedetails ON externalmessage
FOR EACH ROW EXECUTE PROCEDURE externalmessage_tsv_update();

INSERT INTO schema_version (version_number, comment) VALUES (513, '[DEMIS2SORMAS] Introduce a messages content search field #7647');

-- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. ***
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected ExternalMessageGridFilterForm() {
protected String[] getMainFilterLocators() {
return new String[] {
ExternalMessageCriteria.SEARCH_FIELD_LIKE,
ExternalMessageCriteria.MESSAGE_CONTENT_LIKE,
ExternalMessageCriteria.ASSIGNEE,
ExternalMessageCriteria.TYPE,
ExternalMessageCriteria.DISEASE,
Expand All @@ -84,6 +85,13 @@ protected void addFields() {
200));
searchField.setNullRepresentation("");

TextField contentSearchField = addField(
FieldConfiguration.withCaptionAndPixelSized(
ExternalMessageCriteria.MESSAGE_CONTENT_LIKE,
I18nProperties.getString(Strings.promptExternalMessagesContentSearchField),
200));
contentSearchField.setNullRepresentation("");

ComboBoxWithPlaceholder assignee = addField(ExternalMessageCriteria.ASSIGNEE, ComboBoxWithPlaceholder.class);
assignee.addItem(new UserReferenceDto(ReferenceDto.NO_REFERENCE_UUID, "", "", I18nProperties.getCaption(Captions.unassigned)));
assignee.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRights(user.getRegion(), null, UserRight.EXTERNAL_MESSAGE_PROCESS));
Expand Down

0 comments on commit 3e23ad8

Please sign in to comment.